Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve install.sh PATH handling and general robustness #2189

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ set -euo pipefail

__wrap__() {

VERSION=${PIXI_VERSION:-latest}
PIXI_HOME=${PIXI_HOME:-"$HOME/.pixi"}
VERSION="${PIXI_VERSION:-latest}"
PIXI_HOME="${PIXI_HOME:-$HOME/.pixi}"
PIXI_HOME="${PIXI_HOME/#\~/$HOME}"
BIN_DIR="$PIXI_HOME/bin"

REPO=prefix-dev/pixi
PLATFORM=$(uname -s)
ARCH=${PIXI_ARCH:-$(uname -m)}
REPO="prefix-dev/pixi"
PLATFORM="$(uname -s)"
ARCH="${PIXI_ARCH:-$(uname -m)}"

if [[ $PLATFORM == "Darwin" ]]; then
PLATFORM="apple-darwin"
Expand All @@ -33,9 +34,9 @@ if [[ $(uname -o) == "Msys" ]]; then
fi

if [[ $VERSION == "latest" ]]; then
DOWNLOAD_URL=https://github.com/${REPO}/releases/latest/download/${BINARY}.${EXTENSION}
DOWNLOAD_URL="https://github.com/${REPO}/releases/latest/download/${BINARY}.${EXTENSION}"
else
DOWNLOAD_URL=https://github.com/${REPO}/releases/download/${VERSION}/${BINARY}.${EXTENSION}
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${BINARY}.${EXTENSION}"
fi

printf "This script will automatically download and install Pixi (${VERSION}) for you.\nGetting it from this url: $DOWNLOAD_URL\n"
Expand All @@ -50,7 +51,7 @@ if ! hash tar 2> /dev/null; then
exit 1
fi

TEMP_FILE=$(mktemp "${TMPDIR:-/tmp}/.pixi_install.XXXXXXXX")
TEMP_FILE="$(mktemp "${TMPDIR:-/tmp}/.pixi_install.XXXXXXXX")"

cleanup() {
rm -f "$TEMP_FILE"
Expand All @@ -59,8 +60,8 @@ cleanup() {
trap cleanup EXIT

if hash curl 2> /dev/null; then
HTTP_CODE=$(curl -SL --progress-bar "$DOWNLOAD_URL" --output "$TEMP_FILE" --write-out "%{http_code}")
if [[ ${HTTP_CODE} -lt 200 || ${HTTP_CODE} -gt 299 ]]; then
HTTP_CODE="$(curl -SL --progress-bar "$DOWNLOAD_URL" --output "$TEMP_FILE" --write-out "%{http_code}")"
if [[ "${HTTP_CODE}" -lt 200 || "${HTTP_CODE}" -gt 299 ]]; then
echo "error: '${DOWNLOAD_URL}' is not available"
exit 1
fi
Expand All @@ -72,15 +73,15 @@ elif hash wget 2> /dev/null; then
fi

# Check that file was correctly created (https://github.com/prefix-dev/pixi/issues/446)
if [[ ! -s $TEMP_FILE ]]; then
if [[ ! -s "$TEMP_FILE" ]]; then
echo "error: temporary file ${TEMP_FILE} not correctly created."
echo " As a workaround, you can try set TMPDIR env variable to directory with write permissions."
exit 1
fi

# Extract pixi from the downloaded file
mkdir -p "$BIN_DIR"
if [[ $(uname -o) == "Msys" ]]; then
if [[ "$(uname -o)" == "Msys" ]]; then
unzip "$TEMP_FILE" -d "$BIN_DIR"
else
tar -xzf "$TEMP_FILE" -C "$BIN_DIR"
Expand All @@ -90,11 +91,11 @@ fi
echo "The 'pixi' binary is installed into '${BIN_DIR}'"

update_shell() {
FILE=$1
LINE=$2
FILE="$1"
LINE="$2"

# shell update can be suppressed by `PIXI_NO_PATH_UPDATE` env var
[[ ! -z "${PIXI_NO_PATH_UPDATE-}" ]] && echo "No path update because PIXI_NO_PATH_UPDATE has a value" && return
[[ ! -z "${PIXI_NO_PATH_UPDATE:-}" ]] && echo "No path update because PIXI_NO_PATH_UPDATE has a value" && return

# Create the file if it doesn't exist
if [ -f "$FILE" ]; then
Expand All @@ -113,7 +114,7 @@ update_shell() {
case "$(basename "$SHELL")" in
bash)
# Default to bashrc as that is used in non login shells instead of the profile.
LINE="export PATH=${BIN_DIR}:\$PATH"
LINE="export PATH=\"${BIN_DIR}:\$PATH\""
update_shell ~/.bashrc "$LINE"
;;

Expand All @@ -123,7 +124,7 @@ case "$(basename "$SHELL")" in
;;

zsh)
LINE="export PATH=${BIN_DIR}:\$PATH"
LINE="export PATH=\"${BIN_DIR}:\$PATH\""
update_shell ~/.zshrc "$LINE"
;;

Expand Down
Loading