Skip to content

Commit bb39e68

Browse files
authored
fix(installer): respect $CARGO_HOME and $CARGO_INSTALL_ROOT (#2078)
* fix(installer): respect CARGO_HOME and CARGO_INSTALL_ROOT * we win those
1 parent 256c806 commit bb39e68

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

install.ps1

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,16 @@ Please open an issue if you encounter any problems!
158158
if (!$?) { return Exit-Failure "temp-folder" }
159159
tar.exe -xzf "$TempDir\cargo-shuttle.tar.gz" -C "$TempDir\cargo-shuttle"
160160
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"
163-
Move-Item -Force "$TempDir\cargo-shuttle\cargo-shuttle-x86_64-pc-windows-msvc-$LatestRelease\cargo-shuttle.exe" "$CargoHome\bin\cargo-shuttle.exe"
161+
$CargoDir = if ($null -ne $Env:CARGO_HOME) { $Env:CARGO_HOME } else { "$HOME\.cargo" }
162+
$CargoInstallDir = if ($null -ne $Env:CARGO_INSTALL_ROOT) { $Env:CARGO_INSTALL_ROOT } else { "$CargoDir" }
163+
$CargoInstallBinDir = "$CargoInstallDir\bin"
164+
New-Item -ItemType Directory -Force "$CargoInstallBinDir" | Out-Null
165+
if (!$?) { return Exit-Failure "binary-folder" }
166+
Write-Host "Installing to $CargoInstallBinDir\cargo-shuttle.exe"
167+
Move-Item -Force "$TempDir\cargo-shuttle\cargo-shuttle-x86_64-pc-windows-msvc-$LatestRelease\cargo-shuttle.exe" "$CargoInstallBinDir\cargo-shuttle.exe"
164168
if (!$?) { return Exit-Failure "move-binary" }
165-
Write-Host "Installing to $CargoHome\bin\shuttle.exe"
166-
Move-Item -Force "$TempDir\cargo-shuttle\cargo-shuttle-x86_64-pc-windows-msvc-$LatestRelease\shuttle.exe" "$CargoHome\bin\shuttle.exe"
169+
Write-Host "Installing to $CargoInstallBinDir\shuttle.exe"
170+
Move-Item -Force "$TempDir\cargo-shuttle\cargo-shuttle-x86_64-pc-windows-msvc-$LatestRelease\shuttle.exe" "$CargoInstallBinDir\shuttle.exe"
167171
if (!$?) { return Exit-Failure "move-binary" }
168172
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "$TempDir\cargo-shuttle.tar.gz", "$TempDir\cargo-shuttle"
169173
return Exit-Success

install.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ echo "==================================================="
6969
echo
7070

7171
INSTALLED_RUST=""
72+
CARGO_DIR="${CARGO_HOME:-$HOME/.cargo}"
73+
CARGO_INSTALL_DIR="${CARGO_INSTALL_ROOT:-$CARGO_DIR}"
74+
CARGO_INSTALL_BIN_DIR="$CARGO_INSTALL_DIR/bin"
7275

7376
_send_telemetry() {
7477
if [[ "$TELEMETRY" = "1" ]]; then
@@ -106,7 +109,7 @@ _exit_success() {
106109
if [[ "$INSTALLED_RUST" = "yes" ]]; then
107110
echo
108111
[[ "$SUPPORTS_COLOR" = "1" ]] && echo -en "\e[33m" # yellow
109-
echo "Remember to 'source \"$HOME/.cargo/env\"' or restart your shell to run cargo and shuttle commands!"
112+
echo "Remember to 'source \"$CARGO_DIR/env\"' or restart your shell to run cargo and shuttle commands!"
110113
[[ "$SUPPORTS_COLOR" = "1" ]] && echo -en "\e[0m"
111114
fi
112115
exit 0
@@ -269,13 +272,14 @@ _install_binary() {
269272
_exit_failure "tar-not-found"
270273
fi
271274
tar -xzf "cargo-shuttle-$LATEST_VERSION-$target.tar.gz" || _exit_failure "tar-extract-binary"
272-
echo "Installing to $HOME/.cargo/bin/cargo-shuttle"
273-
mv "cargo-shuttle-$target-$LATEST_VERSION/cargo-shuttle" "$HOME/.cargo/bin/" || _exit_failure "move-binary"
274-
echo "Installing to $HOME/.cargo/bin/shuttle"
275-
mv "cargo-shuttle-$target-$LATEST_VERSION/shuttle" "$HOME/.cargo/bin/" || _exit_failure "move-binary"
275+
mkdir -p "$CARGO_INSTALL_BIN_DIR"
276+
echo "Installing to $CARGO_INSTALL_BIN_DIR/cargo-shuttle"
277+
mv "cargo-shuttle-$target-$LATEST_VERSION/cargo-shuttle" "$CARGO_INSTALL_BIN_DIR/" || _exit_failure "move-binary"
278+
echo "Installing to $CARGO_INSTALL_BIN_DIR/shuttle"
279+
mv "cargo-shuttle-$target-$LATEST_VERSION/shuttle" "$CARGO_INSTALL_BIN_DIR/" || _exit_failure "move-binary"
276280
popd >/dev/null || _exit_failure "popd"
277-
if [[ ":$PATH:" != *":$HOME/.cargo/bin:"* ]]; then
278-
echo "Add $HOME/.cargo/bin to PATH to access the 'shuttle' command"
281+
if [[ ":$PATH:" != *":$CARGO_INSTALL_BIN_DIR:"* ]]; then
282+
echo "Add $CARGO_INSTALL_BIN_DIR to PATH to access the 'shuttle' command"
279283
fi
280284
}
281285

@@ -286,7 +290,9 @@ _install_rust_and_cargo() {
286290
case $yn in
287291
[Yy]*|"")
288292
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y || _exit_failure "install-rust"
289-
source "$HOME/.cargo/env" # (this only affects this script's env, user has to source or restart shell to apply to their shell)
293+
# this only affects this script's env,
294+
# user has to source or restart shell to apply to their shell
295+
source "$CARGO_DIR/env"
290296
break
291297
;;
292298
[Nn]*)

0 commit comments

Comments
 (0)