1
1
function Install-Cargo-Shuttle {
2
- Write-Host @"
3
- _ _ _ _
4
- ___| |__ _ _| |_| |_| | ___
5
- / __| '_ \| | | | __| __| |/ _ \
6
- \__ \ | | | |_| | |_| |_| | __/
7
- |___/_| |_|\__,_|\__|\__|_|\___|
2
+ # Anonymous telemetry
3
+ $TELEMETRY = " 1"
4
+ $PLATFORM = " windows"
5
+ $NEW_INSTALL = " true"
6
+ $INSTALL_METHOD = " "
7
+ $OUTCOME = " "
8
+ $STEP_FAILED = " N/A"
9
+ $STARTED_AT = (Get-Date - Format " o" )
10
+
11
+ # Disable telemetry if any opt-out vars are set
12
+ if ($env: DO_NOT_TRACK -eq " 1" -or $env: DO_NOT_TRACK -eq " true" -or
13
+ $env: DISABLE_TELEMETRY -eq " 1" -or $env: DISABLE_TELEMETRY -eq " true" -or
14
+ $env: SHUTTLE_DISABLE_TELEMETRY -eq " 1" -or $env: SHUTTLE_DISABLE_TELEMETRY -eq " true" -or
15
+ $env: CI -eq " 1" -or $env: CI -eq " true" ) {
16
+ $TELEMETRY = " 0"
17
+ }
8
18
9
- https://www.shuttle.dev
19
+ Write-Host " ___ " - NoNewline - ForegroundColor Red - BackgroundColor Black; Write-Host " " - ForegroundColor White - BackgroundColor Black
20
+ Write-Host " / \" - NoNewline - ForegroundColor Red - BackgroundColor Black; Write-Host " _ _ _ _ " - ForegroundColor White - BackgroundColor Black
21
+ Write-Host " __/ /" - NoNewline - ForegroundColor Red - BackgroundColor Black; Write-Host " ___| |__ _ _| |_| |_| | ___ " - ForegroundColor White - BackgroundColor Black
22
+ Write-Host " /_ /" - NoNewline - ForegroundColor Red - BackgroundColor Black; Write-Host " / __| '_ \| | | | __| __| |/ _ \ " - ForegroundColor White - BackgroundColor Black
23
+ Write-Host " _|_ | " - NoNewline - ForegroundColor Red - BackgroundColor Black; Write-Host " \__ \ | | | |_| | |_| |_| | __/ " - ForegroundColor White - BackgroundColor Black
24
+ Write-Host " |_| |/ " - NoNewline - ForegroundColor Red - BackgroundColor Black; Write-Host " |___/_| |_|\__,_|\__|\__|_|\___| " - ForegroundColor White - BackgroundColor Black
25
+ Write-Host " " - ForegroundColor White - BackgroundColor Black
26
+ Write-Host
27
+ Write-Host @"
28
+ https://docs.shuttle.dev
29
+ https://discord.gg/shuttle
10
30
https://github.com/shuttle-hq/shuttle
11
31
12
- Please file an issue if you encounter any problems!
13
- ===================================================
32
+ Please open an issue if you encounter any problems!
14
33
"@
34
+ if ($TELEMETRY -eq " 1" ) {
35
+ Write-Host " Anonymous telemetry enabled. More info and opt-out:" - ForegroundColor Gray
36
+ Write-Host " https://docs.shuttle.dev/install-script" - ForegroundColor Gray
37
+ }
38
+ Write-Host " ==================================================="
39
+ Write-Host
15
40
16
- $Arch = [Environment ]::GetEnvironmentVariable(" PROCESSOR_ARCHITECTURE" , [EnvironmentVariableTarget ]::Machine)
17
- $TempDir = $Env: TEMP
41
+ function Send-Telemetry {
42
+ if ($TELEMETRY -eq " 1" ) {
43
+ $ENDED_AT = (Get-Date - Format " o" )
44
+ $telemetry_data = @ {
45
+ api_key = " phc_cQMQqF5QmcEzXEaVlrhv3yBSNRyaabXYAyiCV7xKHUH"
46
+ distinct_id = " install_script"
47
+ event = " install_script_completion"
48
+ properties = @ {
49
+ platform = $PLATFORM
50
+ new_install = $NEW_INSTALL
51
+ install_method = $INSTALL_METHOD
52
+ started_at = $STARTED_AT
53
+ ended_at = $ENDED_AT
54
+ outcome = $OUTCOME
55
+ step_failed = $STEP_FAILED
56
+ dont_track_ip = $true
57
+ }
58
+ } | ConvertTo-Json - Depth 3
18
59
19
- if (! (Get-Command - CommandType Application - ErrorAction SilentlyContinue cargo.exe )) {
20
- if ($Arch -in " AMD64" , " x86" ) {
21
- Write-Host " Could not find cargo.exe, Rust may not be installed" - ForegroundColor Red
22
- $Confirm = Read-Host - Prompt " Would you like to install Rust via Rustup? [y/N]"
23
- if ($Confirm -inotin " y" , " yes" ) {
24
- Write-Host " Skipping rustup install, cargo-shuttle not installed"
25
- return
26
- }
27
- $RustupUrl = if ($Arch -eq " AMD64" ) { " https://win.rustup.rs/x86_64" } else { " https://win.rustup.rs/i686" }
28
- Invoke-WebRequest $RustupUrl - OutFile " $TempDir \rustup.exe"
29
- & " $TempDir \rustup.exe" toolchain install stable
30
- if ($? ) {
31
- Remove-Item - ErrorAction SilentlyContinue " $TempDir \rustup.exe"
32
- Write-Host " Rust installed via Rustup, please re-run this script, you may need reopen your terminal" - ForegroundColor Green
33
- return
34
- }
35
- else {
36
- Remove-Item - ErrorAction SilentlyContinue " $TempDir \rustup.exe"
37
- Write-Host " Rust install via Rustup failed, please install Rust manually: https://rustup.rs/" - ForegroundColor Red
38
- return
39
- }
40
- }
41
- else {
42
- Write-Host " Could not find cargo.exe, Rust may not be installed." - ForegroundColor Red
43
- Write-Host " Rustup is only provided for x86 and x86_64, not $Arch " - ForegroundColor Red
44
- Write-Host " Please install Rust manually, more info at: https://rust-lang.github.io/rustup/installation/other.html" - ForegroundColor Red
45
- return
46
- }
60
+ if ($env: SHUTTLE_DEBUG ) {
61
+ Write-Host " DEBUG: Sending telemetry data:`n $telemetry_data "
62
+ }
63
+ Invoke-RestMethod - Uri " https://console.shuttle.dev/ingest/i/v0/e" - Method Post - ContentType " application/json" - Body $telemetry_data - ErrorAction SilentlyContinue | Out-Null
64
+ }
47
65
}
48
66
49
- if (Get-Command - CommandType Application - ErrorAction SilentlyContinue cargo-binstall.exe ) {
50
- Write-Host " Installing cargo-shuttle using cargo binstall"
51
- cargo-binstall.exe cargo- shuttle -- no- confirm
52
- if ($? ) {
53
- Write-Host " Installed cargo-shuttle" - ForegroundColor Green
67
+ function Exit-Success {
68
+ $OUTCOME = " success"
69
+ Send-Telemetry
70
+ Write-Host " "
71
+ Write-Host " Thanks for installing Shuttle CLI!" - ForegroundColor Green
72
+ }
73
+
74
+ function Exit-Neutral {
75
+ $OUTCOME = " neutral"
76
+ Write-Host " "
77
+ Write-Host " If you have any problems, please open an issue on GitHub or visit our Discord!"
78
+ Send-Telemetry
79
+ }
80
+
81
+ function Exit-Failure {
82
+ param ($StepFailed )
83
+ $STEP_FAILED = $StepFailed
84
+ $OUTCOME = " failure"
85
+ Write-Host " "
86
+ Write-Host " Shuttle installation script failed with reason: $STEP_FAILED " - ForegroundColor Red
87
+ Write-Host " If you have any problems, please open an issue on GitHub or visit our Discord!"
88
+ Send-Telemetry
89
+ }
90
+
91
+ $RepoUrl = " https://github.com/shuttle-hq/shuttle"
92
+ (Invoke-WebRequest " $RepoUrl /releases/latest" - Headers @ { " Accept" = " application/json" }).Content -match ' "tag_name":"([^"]*)"' | Out-Null
93
+ if (! $? ) { return Exit-Failure " check-latest-release" }
94
+ $LatestRelease = $Matches.1
95
+ if ($LatestRelease -eq $null ) { return Exit-Failure " parse-latest-version" }
96
+
97
+ if (Get-Command - CommandType Application - ErrorAction SilentlyContinue cargo-shuttle.exe ) {
98
+ $NEW_INSTALL = " false"
99
+ $LatestReleaseStripped = $LatestRelease -replace ' ^v' , ' '
100
+ $CurrentVersion = & cargo-shuttle.exe - V
101
+ $CurrentVersionStripped = $CurrentVersion -replace ' ^cargo-shuttle ' , ' '
102
+ if ($LatestReleaseStripped -eq $CurrentVersionStripped ) {
103
+ Write-Host " Shuttle CLI is already at the latest version!" - ForegroundColor Green
54
104
return
55
105
}
56
106
else {
57
- Write-Host " Could not install from release using cargo binstall, trying manual binary download " - ForegroundColor Red
107
+ Write-Host " Updating Shuttle CLI to $LatestRelease "
58
108
}
59
109
}
60
- else {
61
- Write-Host " Cargo binstall not found, trying manual binary download" - ForegroundColor Red
110
+
111
+ $Arch = [Environment ]::GetEnvironmentVariable(" PROCESSOR_ARCHITECTURE" , [EnvironmentVariableTarget ]::Machine)
112
+ $TempDir = $Env: TEMP
113
+
114
+ if (! (Get-Command - CommandType Application - ErrorAction SilentlyContinue cargo.exe )) {
115
+ Write-Host " Could not find cargo.exe, Rust may not be installed." - ForegroundColor Red
116
+ if ($Arch -inotin " AMD64" , " x86" ) {
117
+ Write-Host " Rustup is only provided for x86 and x86_64, not $Arch " - ForegroundColor Red
118
+ Write-Host " Please install Rust manually, more info at: https://rust-lang.github.io/rustup/installation/other.html" - ForegroundColor Red
119
+ return Exit-Failure " unsupported-arch"
120
+ }
121
+ $Confirm = Read-Host - Prompt " Install Rust and Cargo via rustup? [Y/n]"
122
+ if ($Confirm -inotin " y" , " Y" , " yes" , " " ) {
123
+ Write-Host " Skipping rustup install, cargo-shuttle not installed"
124
+ return Exit-Neutral
125
+ }
126
+ $RustupUrl = if ($Arch -eq " AMD64" ) { " https://win.rustup.rs/x86_64" } else { " https://win.rustup.rs/i686" }
127
+ Invoke-WebRequest $RustupUrl - OutFile " $TempDir \rustup-init.exe"
128
+ if (! $? ) { return Exit-Failure " get-rustup" }
129
+ & " $TempDir \rustup-init.exe"
130
+ if (! $? ) {
131
+ Remove-Item - ErrorAction SilentlyContinue " $TempDir \rustup.exe"
132
+ Write-Host " Rust install via Rustup failed, please install Rust manually: https://rustup.rs/" - ForegroundColor Red
133
+ return Exit-Failure " install-rust"
134
+ }
135
+ Remove-Item - ErrorAction SilentlyContinue " $TempDir \rustup.exe"
136
+ Write-Host " Rust installed via Rustup, please re-run this script, you probably need reopen your terminal" - ForegroundColor Green
137
+ return Exit-Neutral
62
138
}
63
139
64
- $RepoUrl = " https://github.com/shuttle-hq/shuttle"
65
- $CargoHome = if ($null -ne $Env: CARGO_HOME ) { $Env: CARGO_HOME } else { " $HOME \.cargo" }
140
+ if (Get-Command - CommandType Application - ErrorAction SilentlyContinue cargo-binstall.exe ) {
141
+ Write-Host " Installing Shuttle CLI using cargo-binstall"
142
+ $INSTALL_METHOD = " cargo-binstall"
143
+ cargo-binstall.exe - y -- force -- locked cargo- shuttle
144
+ if (! $? ) {
145
+ Write-Host " Could not install from release using cargo-binstall" - ForegroundColor Red
146
+ return Exit-Failure " cargo-binstall"
147
+ }
148
+ return Exit-Success
149
+ }
150
+ Write-Host " cargo-binstall not found, trying manual binary download" - ForegroundColor Red
66
151
67
152
if (($Arch -eq " AMD64" ) -and (Get-Command - CommandType Application - ErrorAction SilentlyContinue tar.exe )) {
68
- (Invoke-WebRequest " $RepoUrl /releases/latest" - Headers @ { " Accept" = " application/json" }).Content -match ' "tag_name":"([^"]*)"' | Out-Null
69
- $LatestRelease = $Matches.1
153
+ $INSTALL_METHOD = " binary-download"
70
154
$BinaryUrl = " $RepoUrl /releases/download/$LatestRelease /cargo-shuttle-$LatestRelease -x86_64-pc-windows-msvc.tar.gz"
71
155
Invoke-WebRequest $BinaryUrl - OutFile " $TempDir \cargo-shuttle.tar.gz"
72
- New-Item - ItemType Directory - Force " $TempDir \cargo-shuttle"
156
+ if (! $? ) { return Exit-Failure " download-binary" }
157
+ New-Item - ItemType Directory - Force " $TempDir \cargo-shuttle" | Out-Null
158
+ if (! $? ) { return Exit-Failure " temp-folder" }
73
159
tar.exe - xzf " $TempDir \cargo-shuttle.tar.gz" - C " $TempDir \cargo-shuttle"
160
+ if (! $? ) { return Exit-Failure " tar-extract-binary" }
161
+ $CargoHome = if ($null -ne $Env: CARGO_HOME ) { $Env: CARGO_HOME } else { " $HOME \.cargo" }
162
+ Write-Host " Installing to $CargoHome \bin\cargo-shuttle.exe"
74
163
Move-Item - Force " $TempDir \cargo-shuttle\cargo-shuttle-x86_64-pc-windows-msvc-$LatestRelease \cargo-shuttle.exe" " $CargoHome \bin\cargo-shuttle.exe"
164
+ if (! $? ) { return Exit-Failure " move-binary" }
165
+ Write-Host " Installing to $CargoHome \bin\shuttle.exe"
75
166
Move-Item - Force " $TempDir \cargo-shuttle\cargo-shuttle-x86_64-pc-windows-msvc-$LatestRelease \shuttle.exe" " $CargoHome \bin\shuttle.exe"
167
+ if (! $? ) { return Exit-Failure " move-binary" }
76
168
Remove-Item - Recurse - Force - ErrorAction SilentlyContinue " $TempDir \cargo-shuttle.tar.gz" , " $TempDir \cargo-shuttle"
77
- Write-Host " Installed cargo-shuttle" - ForegroundColor Green
78
- return
169
+ return Exit-Success
79
170
}
80
171
elseif ($Arch -ne " AMD64" ) {
81
172
Write-Host " Unsupported Architecture: Binaries are not currently built for $Arch , skipping manual binary download" - ForegroundColor Red
@@ -84,22 +175,15 @@ Please file an issue if you encounter any problems!
84
175
Write-Host " Could not find tar.exe, skipping manual binary download (required to extract the release asset)" - ForegroundColor Red
85
176
}
86
177
87
-
88
- if (Get-Command - CommandType Application - ErrorAction SilentlyContinue cargo.exe ) {
89
- Write-Host " Installing cargo-shuttle using cargo install (from source)"
90
- cargo.exe install cargo- shuttle -- locked
91
- if ($? ) {
92
- Write-Host " Installed cargo-shuttle" - ForegroundColor Green
93
- return
94
- }
95
- else {
96
- Write-Host " Could not install cargo-shuttle using cargo" - ForegroundColor Red
97
- return
98
- }
99
- }
100
- else {
101
- Write-Host " Could not find cargo.exe, Rust may not be installed" - ForegroundColor Red
178
+ $INSTALL_METHOD = " cargo"
179
+ if (! (Get-Command - CommandType Application - ErrorAction SilentlyContinue cargo.exe )) {
180
+ return Exit-Failure " cargo-not-found"
102
181
}
182
+
183
+ Write-Host " Installing cargo-shuttle using cargo install (from source)"
184
+ cargo.exe install -- locked cargo- shuttle
185
+ if (! $? ) { return Exit-Failure " cargo-install" }
186
+ return Exit-Success
103
187
}
104
188
105
189
0 commit comments