-
Notifications
You must be signed in to change notification settings - Fork 183
/
install.sh
151 lines (121 loc) · 3.96 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
set -euo pipefail
# Version: v0.35.0
__wrap__() {
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)}"
if [[ $PLATFORM == "Darwin" ]]; then
PLATFORM="apple-darwin"
elif [[ $PLATFORM == "Linux" ]]; then
PLATFORM="unknown-linux-musl"
elif [[ $(uname -o) == "Msys" ]]; then
PLATFORM="pc-windows-msvc"
fi
if [[ $ARCH == "arm64" ]] || [[ $ARCH == "aarch64" ]]; then
ARCH="aarch64"
fi
BINARY="pixi-${ARCH}-${PLATFORM}"
EXTENSION="tar.gz"
if [[ $(uname -o) == "Msys" ]]; then
EXTENSION="zip"
fi
if [[ $VERSION == "latest" ]]; then
DOWNLOAD_URL="https://github.com/${REPO}/releases/latest/download/${BINARY}.${EXTENSION}"
else
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"
if ! hash curl 2> /dev/null && ! hash wget 2> /dev/null; then
echo "error: you need either 'curl' or 'wget' installed for this script."
exit 1
fi
if ! hash tar 2> /dev/null; then
echo "error: you do not have 'tar' installed which is required for this script."
exit 1
fi
TEMP_FILE="$(mktemp "${TMPDIR:-/tmp}/.pixi_install.XXXXXXXX")"
cleanup() {
rm -f "$TEMP_FILE"
}
trap cleanup EXIT
# Test if stdout is a terminal before showing progress
if [[ ! -t 1 ]]; then
CURL_OPTIONS="--silent" # --no-progress-meter is better, but only available in 7.67+
WGET_OPTIONS="--no-verbose"
else
CURL_OPTIONS="--no-silent"
WGET_OPTIONS="--show-progress"
fi
if hash curl 2> /dev/null; then
HTTP_CODE="$(curl -SL $CURL_OPTIONS "$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
elif hash wget 2> /dev/null; then
if ! wget $WGET_OPTIONS --output-document="$TEMP_FILE" "$DOWNLOAD_URL"; then
echo "error: '${DOWNLOAD_URL}' is not available"
exit 1
fi
fi
# Check that file was correctly created (https://github.com/prefix-dev/pixi/issues/446)
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
unzip "$TEMP_FILE" -d "$BIN_DIR"
else
tar -xzf "$TEMP_FILE" -C "$BIN_DIR"
chmod +x "$BIN_DIR/pixi"
fi
echo "The 'pixi' binary is installed into '${BIN_DIR}'"
update_shell() {
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
# Create the file if it doesn't exist
if [ -f "$FILE" ]; then
touch "$FILE"
fi
# Append the line if not already present
if ! grep -Fxq "$LINE" "$FILE"
then
echo "Updating '${FILE}'"
echo "$LINE" >> "$FILE"
echo "Please restart or source your shell."
fi
}
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\""
update_shell ~/.bashrc "$LINE"
;;
fish)
LINE="fish_add_path ${BIN_DIR}"
update_shell ~/.config/fish/config.fish "$LINE"
;;
zsh)
LINE="export PATH=\"${BIN_DIR}:\$PATH\""
update_shell ~/.zshrc "$LINE"
;;
tcsh)
LINE="set path = ( ${BIN_DIR} \$path )"
update_shell ~/.tcshrc "$LINE"
;;
*)
echo "Could not update shell: $(basename "$SHELL")"
echo "Please permanently add '${BIN_DIR}' to your \$PATH to enable the 'pixi' command."
;;
esac
}; __wrap__