Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(installer): add windows installer script (#1503)
* feat(installer): add windows installer script * fix: Update command to use pipe * Make confirm prompt case-insensitive * Added -Force flag to Move-Item * Replace exit with return and wrap in function
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
function Install-Cargo-Shuttle { | ||
$RepoUrl = "https://github.com/shuttle-hq/shuttle" | ||
|
||
Write-Host @" | ||
_ _ _ _ | ||
___| |__ _ _| |_| |_| | ___ | ||
/ __| '_ \| | | | __| __| |/ _ \ | ||
\__ \ | | | |_| | |_| |_| | __/ | ||
|___/_| |_|\__,_|\__|\__|_|\___| | ||
https://www.shuttle.rs | ||
https://github.com/shuttle-hq/shuttle | ||
Please file an issue if you encounter any problems! | ||
=================================================== | ||
"@ | ||
|
||
if (Get-Command -CommandType Application -ErrorAction SilentlyContinue cargo-binstall.exe) { | ||
Write-Host "Installing cargo-shuttle using cargo binstall" | ||
cargo-binstall.exe cargo-shuttle --no-confirm | ||
if ($?) { | ||
Write-Host "Installed cargo-shuttle, try running ``cargo shuttle --help``" -ForegroundColor Green | ||
return | ||
} | ||
else { | ||
Write-Host "Could not install from release using cargo binstall, trying manual binary download" -ForegroundColor Red | ||
} | ||
} | ||
else { | ||
Write-Host "cargo binstall not found, trying manual binary download" -ForegroundColor Red | ||
} | ||
|
||
$CargoHome = if ($null -ne $Env:CARGO_HOME) { $Env:CARGO_HOME } else { "$HOME\.cargo" } | ||
$TempDir = $Env:TEMP | ||
$Arch = [Environment]::GetEnvironmentVariable("PROCESSOR_ARCHITECTURE", [EnvironmentVariableTarget]::Machine) | ||
if (($Arch -eq "AMD64") -and (Get-Command -CommandType Application -ErrorAction SilentlyContinue tar.exe)) { | ||
(Invoke-WebRequest "$RepoUrl/releases/latest" -Headers @{ "Accept" = "application/json" }).Content -match '"tag_name":"([^"]*)"' | Out-Null | ||
$LatestRelease = $Matches.1 | ||
$BinaryUrl = "$RepoUrl/releases/download/$LatestRelease/cargo-shuttle-$LatestRelease-x86_64-pc-windows-msvc.tar.gz" | ||
Invoke-WebRequest $BinaryUrl -OutFile "$TempDir\cargo-shuttle.tar.gz" | ||
New-Item -ItemType Directory -Force "$TempDir\cargo-shuttle" | ||
tar.exe -xzf "$TempDir\cargo-shuttle.tar.gz" -C "$TempDir\cargo-shuttle" | ||
Move-Item -Force "$TempDir\cargo-shuttle\cargo-shuttle-x86_64-pc-windows-msvc-$LatestRelease\cargo-shuttle.exe" "$CargoHome\bin\cargo-shuttle.exe" | ||
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "$TempDir\cargo-shuttle.tar.gz", "$TempDir\cargo-shuttle" | ||
Write-Host "Installed cargo-shuttle, try running ``cargo shuttle --help``" -ForegroundColor Green | ||
return | ||
} | ||
elseif ($Arch -ne "AMD64") { | ||
Write-Host "Unsupported Architecture: Binaries are not currently built for $Arch, skipping manual binary download" -ForegroundColor Red | ||
} | ||
else { | ||
Write-Host "Could not find tar.exe, skipping manual binary download (required to extract the release asset)" -ForegroundColor Red | ||
} | ||
|
||
if (Get-Command -CommandType Application -ErrorAction SilentlyContinue cargo.exe) { | ||
Write-Host "Installing cargo-shuttle using cargo install (from source)" | ||
cargo.exe install cargo-shuttle --locked | ||
if ($?) { | ||
Write-Host "Installed cargo-shuttle, try running ``cargo shuttle --help``" -ForegroundColor Green | ||
return | ||
} | ||
else { | ||
Write-Host "Could not install cargo-shuttle using cargo" -ForegroundColor Red | ||
return | ||
} | ||
} | ||
else { | ||
if ($Arch -in "AMD64", "x86") { | ||
Write-Host "Could not find cargo.exe, Rust may not be installed" -ForegroundColor Red | ||
$Confirm = Read-Host -Prompt "Would you like to install Rust via Rustup? [y/N]" | ||
if ($Confirm -inotin "y", "yes") { | ||
Write-Host "Skipping rustup install, cargo-shuttle not installed" | ||
return | ||
} | ||
$RustupUrl = if ($Arch -eq "AMD64") { "https://win.rustup.rs/x86_64" } else { "https://win.rustup.rs/i686" } | ||
Invoke-WebRequest $RustupUrl -OutFile "$TempDir\rustup.exe" | ||
& "$TempDir\rustup.exe" toolchain install stable | ||
if ($?) { | ||
Remove-Item -ErrorAction SilentlyContinue "$TempDir\rustup.exe" | ||
Write-Host "Rust installed via Rustup, please re-run this script, you may need reopen your terminal" -ForegroundColor Green | ||
return | ||
} | ||
else { | ||
Remove-Item -ErrorAction SilentlyContinue "$TempDir\rustup.exe" | ||
Write-Host "Rust install via Rustup failed, please install Rust manually: https://rustup.rs/" -ForegroundColor Red | ||
return | ||
} | ||
} | ||
else { | ||
Write-Host "Could not find cargo.exe, Rust may not be installed." -ForegroundColor Red | ||
Write-Host "Rustup is only provided for x86 and x86_64, not $Arch" -ForegroundColor Red | ||
Write-Host "Please install Rust manually, more info at: https://rust-lang.github.io/rustup/installation/other.html" -ForegroundColor Red | ||
return | ||
} | ||
} | ||
} | ||
|
||
$OldErrorAction = $ErrorActionPreference | ||
$ErrorActionPreference = "Stop" | ||
Install-Cargo-Shuttle | ||
$ErrorActionPreference = $OldErrorAction |