-
Notifications
You must be signed in to change notification settings - Fork 824
/
install.sh
executable file
·292 lines (241 loc) · 6.87 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/sh
# See latest version at:
# https://github.com/elixir-lang/elixir-lang.github.com/blob/main/install.sh
set -eu
otp_version=
elixir_version=
force=false
usage() {
cat<<EOF
Usage: install.sh elixir@ELIXIR_VERSION otp@OTP_VERSION [options]
ELIXIR_VERSION can be X.Y.Z, latest, or main.
OTP_VERSION can be X.Y.Z, latest, master, maint, or maint-RELEASE (e.g. maint-27).
Options:
-f, --force Forces installation even if it was previously installed
-h, --help Prints this help
Examples:
sh install.sh [email protected] [email protected]
sh install.sh elixir@latest otp@latest
sh install.sh elixir@main otp@master
EOF
}
main() {
for arg in "$@"; do
case "$arg" in
elixir@*)
elixir_version="${arg#elixir@}"
;;
otp@*)
otp_version="${arg#otp@}"
;;
-h|--help)
usage
exit 0
;;
-f|--force)
force=true
;;
*)
echo "error: invalid argument $arg" >&2
exit 1
;;
esac
done
if [ -z "${elixir_version}" ]; then
usage
echo "error: missing elixir@VERSION argument"
exit 1
fi
if [ -z "${otp_version}" ]; then
usage
echo "error: missing otp@VERSION argument"
exit 1
fi
root_dir="$HOME/.elixir-install"
tmp_dir="$root_dir/tmp"
mkdir -p "$tmp_dir"
if [ "${otp_version}" = latest ]; then
url=$(curl -fsS --head https://github.com/erlef/otp_builds/releases/latest | grep -i '^location:' | awk '{print $2}' | tr -d '\r\n')
tag=$(basename "$url")
otp_version="${tag#OTP-}"
fi
if [ "${elixir_version}" = latest ]; then
url=$(curl -fsS --head https://github.com/elixir-lang/elixir/releases/latest | grep -i '^location:' | awk '{print $2}' | tr -d '\r\n')
tag=$(basename "$url")
elixir_version="${tag#v}"
fi
case "${otp_version}" in
master|maint*)
branch_version=$(curl -fsS https://raw.githubusercontent.com/erlang/otp/refs/heads/${otp_version}/OTP_VERSION | tr -d '\n')
elixir_otp_release="${branch_version%%.*}"
;;
*)
elixir_otp_release="${otp_version%%.*}"
;;
esac
case "$elixir_version" in
1.14.*)
[ "${elixir_otp_release}" -ge 25 ] && elixir_otp_release=25
;;
1.15.*|1.16.*)
[ "${elixir_otp_release}" -ge 26 ] && elixir_otp_release=26
;;
*)
[ "${elixir_otp_release}" -ge 27 ] && elixir_otp_release=27
;;
esac
otp_dir="$root_dir/installs/otp/$otp_version"
elixir_dir="${root_dir}/installs/elixir/${elixir_version}-otp-${elixir_otp_release}"
if unzip_available; then
install_otp &
pid_otp=$!
install_elixir &
pid_elixir=$!
wait $pid_otp
wait $pid_elixir
else
# if unzip is missing (e.g. official docker ubuntu image), install otp and elixir
# serially because we unzip elixir using OTP zip:extract/2.
install_otp
install_elixir
fi
printf "checking OTP... "
export PATH="$otp_dir/bin:$PATH"
erl -noshell -eval 'io:put_chars(erlang:system_info(otp_release) ++ " ok\n"), halt().'
printf "checking Elixir... "
"$elixir_dir/bin/elixir" -e 'IO.puts(System.version() <> " ok")'
export PATH="$elixir_dir/bin:$PATH"
cat<<EOF
Run this (or add to your ~/.bashrc or similar file):
export PATH=\$HOME/.elixir-install/installs/otp/$otp_version/bin:\$PATH
export PATH=\$HOME/.elixir-install/installs/elixir/$elixir_version-otp-$elixir_otp_release/bin:\$PATH
EOF
}
install_otp() {
os=$(uname -sm)
case "$os" in
"Darwin x86_64") target=x86_64-apple-darwin ;;
"Darwin arm64") target=aarch64-apple-darwin ;;
"Linux x86_64") target=x86_64-pc-linux ;;
"Linux aarch64") target=aarch64-pc-linux ;;
MINGW64*) target=x86_64-pc-windows ;;
*) echo "error: unsupported system $os." && exit 1 ;;
esac
if [ ! -d "${otp_dir}/bin" ] || [ "$force" = true ]; then
rm -rf "${otp_dir}"
case "$target" in
*windows) install_otp_windows ;;
*darwin) install_otp_darwin ;;
*linux) install_otp_linux ;;
esac
fi
}
install_otp_darwin() {
case "${otp_version}" in
master|maint*)
ref="${otp_version}-latest"
;;
*)
ref="OTP-${otp_version}"
;;
esac
otp_tgz="otp-${target}.tar.gz"
url="https://github.com/erlef/otp_builds/releases/download/$ref/$otp_tgz"
download "$url" "$tmp_dir/$otp_tgz"
echo "unpacking $otp_tgz to $otp_dir..."
mkdir -p "$otp_dir"
tar xzf "$tmp_dir/$otp_tgz" -C "$otp_dir"
rm "$tmp_dir/$otp_tgz"
}
install_otp_linux() {
case "${otp_version}" in
master|maint*)
otp_tgz="${otp_version}.tar.gz"
;;
*)
otp_tgz="OTP-${otp_version}.tar.gz"
;;
esac
case "$target" in
x86_64*) arch=amd64 ;;
aarch64*) arch=arm64 ;;
esac
id=$(grep '^ID=' /etc/os-release | cut -d '=' -f 2)
if [ "${id}" != ubuntu ]; then
echo $id is not supported
exit 1
fi
case $(grep '^VERSION_ID=' /etc/os-release | cut -d '"' -f 2) in
20*|21*)
lts=20.04
;;
22*|23*)
lts=22.04
;;
*)
lts=24.04
;;
esac
url="https://builds.hex.pm/builds/otp/${arch}/ubuntu-${lts}/$otp_tgz"
download "$url" "$tmp_dir/$otp_tgz"
echo "unpacking $otp_tgz to $otp_dir..."
mkdir -p "$otp_dir"
tar xzf "$tmp_dir/$otp_tgz" --strip-components 1 -C "$otp_dir"
(cd "$otp_dir" && ./Install -sasl "$PWD")
rm "$tmp_dir/$otp_tgz"
}
install_otp_windows() {
otp_zip="otp_win64_$otp_version.zip"
url="https://github.com/erlang/otp/releases/download/OTP-$otp_version/$otp_zip"
download "$url" "$tmp_dir/$otp_zip"
echo "unpacking $otp_zip to $otp_dir..."
mkdir -p "$otp_dir"
unzip -q "$tmp_dir/$otp_zip" -d "$otp_dir"
rm "$tmp_dir/$otp_zip"
install_vc_redist
}
install_vc_redist() {
if [ ! -f /c/windows/system32/vcruntime140.dll ]; then
echo "installing VC++ Redistributable..."
(cd $otp_dir && ./vc_redist.exe /quiet /norestart)
fi
}
install_elixir() {
elixir_zip="elixir-otp-$elixir_otp_release.zip"
if [ ! -d "${elixir_dir}/bin" ] || [ "$force" = true ]; then
case "${elixir_version}" in
main)
ref="${elixir_version}-latest"
;;
v[0-9]*.[0-9])
ref="v${elixir_version}-latest"
;;
*)
ref="v${elixir_version}"
;;
esac
url="https://github.com/elixir-lang/elixir/releases/download/$ref/$elixir_zip"
download "$url" "$tmp_dir/$elixir_zip"
echo "unpacking $elixir_zip to $elixir_dir..."
rm -rf "${elixir_dir}"
mkdir -p "${elixir_dir}"
if unzip_available; then
unzip -q "${tmp_dir}/${elixir_zip}" -d "${elixir_dir}"
else
"${otp_dir}/bin/erl" -noshell -eval \
'[Zip,Dir] = init:get_plain_arguments(), {ok,_} = zip:unzip(Zip, [{cwd, Dir}]), halt().' \
-- "${tmp_dir}/${elixir_zip}" "${elixir_dir}"
fi
rm "${tmp_dir}/${elixir_zip}"
fi
}
download() {
url="$1"
output="$2"
echo "downloading $url"
curl --retry 3 -fsSLo "$output" "$url"
}
unzip_available() {
which unzip >/dev/null 2>&1
}
main "$@"