-
Notifications
You must be signed in to change notification settings - Fork 29
/
jill.sh
executable file
·324 lines (294 loc) · 9.48 KB
/
jill.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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/usr/bin/env bash
# jill.sh
# Copyright (C) 2017-2023 Abel Soares Siqueira <[email protected]>
#
# Distributed under terms of the GPLv3 license.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
JULIA_LTS=1.10.6
JULIA_LATEST=1.11
function usage() {
echo "usage: jill.sh [options]
Install some version of the julia executable. By default, the latest version (currently $JULIA_LATEST-latest) is installed.
Options and arguments:
-h, --help : Show this help
--lts : Install julia long term support version (Currently $JULIA_LTS)
--rc : Install julia latest release candidate (requires jq)
-u M.m, --upgrade M.m : Copy environment from M.m version (e.g. -u 1.6)
-v VER, --version VER : Install julia version VER. Valid examples: 1.5.4, 1.5-latest, 1.5.0-rc1.
-y, --yes, --no-confirm : Skip confirmation
Environment variables:
JULIA_DOWNLOAD: Folder where the julia .tar.gz file will be downloaded and its contents will be decompressed.
Defaults to /opt/julias when called by root or $HOME/packages/julias otherwise.
JULIA_INSTALL: Folder where the julia link will be created.
Defaults to /usr/local/bin when called by root or $HOME/.local/bin otherwise.
"
}
# Skip confirm if -y is used.
SKIP_CONFIRM=0
# Copy over the old environment to the new one if -u is used.
UPGRADE_CONFIRM=0
JULIA_OLD=""
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h | --help)
usage
shift
exit 0
;;
--lts)
JULIA_VERSION="$JULIA_LTS"
shift
;;
--rc)
if ! command -v jq --version &>/dev/null; then
echo "Option --rc requires jq to be installed. Alternatively, use -v with x.y.z-rcN. Aborting"
exit 1
fi
JULIA_VERSION="$(curl -L https://julialang-s3.julialang.org/bin/versions.json | jq -r '[keys[] | select(contains("rc"))] | .[-1]')"
if [ -z "$JULIA_VERSION" ]; then
echo "Option --rc failed."
exit 1
fi
shift
;;
-u | --upgrade)
UPGRADE_CONFIRM=1
JULIA_OLD="$2"
shift
shift
;;
-v | --version)
JULIA_VERSION="$2"
shift
shift
;;
-y | --yes | --no-confirm)
SKIP_CONFIRM=1
shift
;;
*) # unknown option
echo "Invalid option: $1" >&2
usage
exit 1
;;
esac
done
# For Linux, this script installs Julia into $JULIA_DOWNLOAD and make a
# link to $JULIA_INSTALL
# For MacOS, this script installs Julia into /Applications and make a
# link to $JULIA_INSTALL
if [[ "$(whoami)" == "root" ]]; then
JULIA_DOWNLOAD="${JULIA_DOWNLOAD:-"/opt/julias"}"
JULIA_INSTALL="${JULIA_INSTALL:-"/usr/local/bin"}"
else
JULIA_DOWNLOAD="${JULIA_DOWNLOAD:-"$HOME/packages/julias"}"
JULIA_INSTALL="${JULIA_INSTALL:-"$HOME/.local/bin"}"
fi
WGET="wget --retry-connrefused -t 3 -q"
function header() {
echo "JILL - Julia Installer 4 Linux - Light"
echo "Copyright (C) 2017-2023 Abel Soares Siqueira <[email protected]>"
echo "Distributed under terms of the GPLv3 license."
echo ""
}
function badfolder() {
echo "The folder ${JULIA_INSTALL@Q} is not on your PATH, you can"
echo "- 1) Add it to your path; or"
echo "- 2) Run 'JULIA_INSTALL=otherfolder ./jill.sh'"
if [[ $SKIP_CONFIRM == "0" ]]; then
read -p "Do you want to add ${JULIA_INSTALL@Q} into your PATH? (Aborting otherwise) (Y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy] ]]; then
echo "Aborted"
exit 1
fi
fi
echo "export PATH=${JULIA_INSTALL@Q}:\"\$PATH\"" | tee -a ~/.bashrc
echo ""
echo "run 'source ~/.bashrc' or restart your bash to reload the PATH"
echo ""
}
function hi() {
header
if [[ ":$PATH:" != *":$JULIA_INSTALL:"* ]]; then
badfolder
fi
mkdir -p "$JULIA_INSTALL" # won't create if it's aborted earlier
LATEST=0
if [ -n "${JULIA_VERSION+set}" ]; then
version="$JULIA_VERSION"
else
LATEST=1
version="$JULIA_LATEST-latest"
fi
echo "This script will:"
echo ""
echo " - Try to download julia version '$version'"
echo " - Create a link for julia"
echo " - Create a link for julia-VER"
echo ""
echo "Download folder: ${JULIA_DOWNLOAD@Q}"
echo "Link folder: ${JULIA_INSTALL@Q}"
echo ""
if [ ! -d "$JULIA_DOWNLOAD" ]; then
echo "Download folder will be created if required"
fi
if [ ! -w "$JULIA_INSTALL" ]; then
echo "You don't have write permission to ${JULIA_INSTALL@Q}."
exit 1
fi
}
function confirm() {
read -p "Do you accept these terms? (Y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy] ]]; then
echo "Aborted"
exit 1
fi
}
function get_url_from_platform_arch_version() {
platform=$1
arch=$2
version=$3
[[ $arch == *"64" ]] && bit=64 || bit=32
# TODO: Accept ARM and FreeBSD
[[ $arch == "mac"* ]] && suffix=mac64.dmg || suffix="$platform-$arch.tar.gz"
minor=$(echo "$version" | cut -d. -f1-2 | cut -d- -f1)
url="https://julialang-s3.julialang.org/bin/$platform/x$bit/$minor/julia-$version-$suffix"
echo "$url"
}
function install_julia_linux() {
mkdir -p "$JULIA_DOWNLOAD"
cd "$JULIA_DOWNLOAD" || exit 1
arch=$(uname -m)
# Download specific version if requested
LATEST=0
if [ -n "${JULIA_VERSION+set}" ]; then
version="$JULIA_VERSION"
else
LATEST=1
version="$JULIA_LATEST-latest"
fi
echo "Downloading Julia version $version"
if [ ! -f "julia-$version.tar.gz" ]; then
url="$(get_url_from_platform_arch_version linux "$arch" "$version")"
if ! $WGET -c "$url" -O "julia-$version.tar.gz"; then
echo "error downloading julia-$version"
rm "julia-$version.tar.gz"
return
fi
else
echo "already downloaded"
fi
if [ ! -d "julia-$version" ]; then
mkdir -p "julia-$version"
tar zxf "julia-$version.tar.gz" -C "julia-$version" --strip-components 1
fi
if [[ $LATEST == "1" ]]; then
# Need to change suffix x.y-latest to x.y.z
JLVERSION=$(./julia-"$version"/bin/julia -version | cut -d' ' -f3)
if [ -d "julia-$JLVERSION" ]; then
echo "Warning: Latest version $JLVERSION was already installed. Ignoring downloaded version."
rm -rf "julia-$version.tar.gz" "julia-$version"
else
mv "julia-$version.tar.gz" "julia-$JLVERSION.tar.gz"
mv "julia-$version" "julia-$JLVERSION"
fi
version="$JLVERSION"
fi
minor=$(echo "$version" | cut -d. -f1-2 | cut -d- -f1)
rm -f "$JULIA_INSTALL"/julia{,-"$minor",-"$version"}
julia="$PWD/julia-$version/bin/julia"
if [[ $UPGRADE_CONFIRM == "1" ]]; then
old_minor=$(echo "$JULIA_OLD" | cut -d. -f1,2 | cut -d- -f1)
if [ "$USER" == "root" ] && [ -n "$SUDO_USER" ]; then
JULIAENV="/home/$SUDO_USER"
else
JULIAENV=$HOME
fi
JULIAENV="${JULIAENV}/.julia/environments"
echo "Copying environments in ${JULIAENV} from v${old_minor} to v${minor}"
cp -rp "${JULIAENV}/v${old_minor}" "${JULIAENV}/v${minor}"
fi
# create symlink
ln -s "$julia" "$JULIA_INSTALL/julia"
ln -s "$julia" "$JULIA_INSTALL/julia-$minor"
ln -s "$julia" "$JULIA_INSTALL/julia-$version"
}
function install_julia_mac() {
mkdir -p "$JULIA_DOWNLOAD"
cd "$JULIA_DOWNLOAD" || exit 1
arch="mac64"
# Download specific version if requested
LATEST=0
if [ -n "${JULIA_VERSION+set}" ]; then
version="$JULIA_VERSION"
else
LATEST=1
version="$JULIA_LATEST-latest"
fi
if [ ! -f "julia-$version.dmg" ]; then
url="$(get_url_from_platform_arch_version mac "$arch" "$version")"
$WGET -c "$url" -O "julia-$version.dmg"
fi
minor=$(echo "$version" | cut -d. -f1,2 | cut -d- -f1)
hdiutil attach "julia-$version.dmg" -quiet -mount required -mountpoint "julia-$minor"
if [ ! -d "julia-$minor" ]; then
# if it fails to mount for unknown reason, try it again after 1 second...
sleep 1
hdiutil attach "julia-$version.dmg" -quiet -mount required -mountpoint "julia-$minor"
fi
INSTALL_PATH="/Applications/julia-$minor.app"
EXEC_PATH="$INSTALL_PATH/Contents/Resources/julia/bin/julia"
rm -rf "$INSTALL_PATH"
cp -a "julia-$minor/Julia-$minor.app" /Applications/
if [[ $UPGRADE_CONFIRM == "1" ]]; then
old_minor=$(echo "$JULIA_OLD" | cut -d. -f1,2 | cut -d- -f1)
if [ "$USER" == "root" ] && [ -n "$SUDO_USER" ]; then
JULIAENV="/Users/$SUDO_USER"
else
JULIAENV=$HOME
fi
JULIAENV="${JULIAENV}/.julia/environments"
echo "Copying environments in ${JULIAENV} from v${old_minor} to v${minor}"
cp -rp "${JULIAENV}/v${old_minor}" "${JULIAENV}/v${minor}"
fi
# create symlink
ln -sf "$EXEC_PATH" "$JULIA_INSTALL/julia"
ln -sf "$EXEC_PATH" "$JULIA_INSTALL/julia-$minor"
if [[ $LATEST == "1" ]]; then
version="$("$JULIA_INSTALL"/julia -version | cut -d' ' -f3)"
fi
ln -sf "$EXEC_PATH" "$JULIA_INSTALL/julia-$version"
# post-installation
umount "julia-$minor"
}
# --------------------------------------------------------
# Main
hi
if [[ $SKIP_CONFIRM == "0" ]]; then
confirm
fi
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) install_julia_linux ;;
Darwin*) install_julia_mac ;;
# CYGWIN*) machine=Cygwin;;
# MINGW*) machine=MinGw;;
*)
echo "Unsupported platform $(unameOut)" >&2
exit 1
;;
esac