-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanylang.sh
299 lines (253 loc) · 9.36 KB
/
anylang.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
#!/bin/bash
set -Ceu
# -C リダイレクトでファイルを上書きしない
# -e コマンドの終了コードが1つでも0以外になったら直ちに終了する
# -u 設定されていない変数が参照されたらエラー
usage() {
cat <<\EOF >&2
各種言語環境をインストールし、コマンドを実行します。
$HOME/.xsvutils/anylang または --prefix オプションで指定したディレクトリに
オプションで指定した言語のバージョンをインストールし、PATHを通した上でコマンドを実行します。
Usage:
anylang [OPTIONS] <COMMAND> [<ARG>...]
Options:
--prefx インストールするディレクトリを指定 (デフォルトは $HOME/.xsvutils/anylang)
--jdk=<VER> インストールするopenjdkのバージョンを指定
--sbt=<VER> インストールするsbtのバージョンを指定。 --jdk も併せて指定が必要
--graalvm=<VER> インストールするGraalVMのバージョンを指定
--rust=<VER> インストールするRustのバージョンを指定
JDK
ex) --jdk=11
Scala
ex) --scala=2.13.0
sbt
https://www.scala-sbt.org/download.html
ex) --sbt=1.2.8
GraalVM
https://github.com/oracle/graal/releases
ex) --graalvm=19.0.2
Rust
ex) --rust=1.35.0
EOF
exit 1
}
while [ "$#" != 0 ]; do
case "$1" in
--prefix=* )
PREFIX="${1#*=}"
;;
--jdk=* )
JDK_VERSION="${1#*=}"
;;
--scala=* )
SCALA_VERSION="${1#*=}"
;;
--sbt=* )
SBT_VERSION="${1#*=}"
;;
--graalvm=* )
GRAALVM_VERSION="${1#*=}"
;;
--rust=* )
RUST_VERSION="${1#*=}"
;;
--* )
echo "Option \`${1}\` is not supported." >&1
exit 1
;;
* )
break
esac
shift
done
: "${PREFIX:=$HOME/.xsvutils/anylang}"
################################################################################
# JDK
################################################################################
install_jdk() {
if [ "${GRAALVM_VERSION:=x}" != "x" ]; then
echo "cannot use both --jdk=* and --graalvm=* options" >&2
exit 1
fi
local uname=$(uname)
local os_name
if [ "$uname" = "Darwin" ]; then
os_name='osx'
elif [ "$uname" = "Linux" ]; then
os_name='linux'
else
echo "Unknown OS: $uname" >&2
exit 1
fi
if [ ! -x "$PREFIX/jdk-${JDK_VERSION}/bin/java" ]; then
local tmppath="$PREFIX/jdk-${JDK_VERSION}-$$"
mkdir -p $tmppath
local url=
if [ $JDK_VERSION = 11 ]; then
url="https://download.java.net/java/ga/jdk11/openjdk-11_${os_name}-x64_bin.tar.gz"
elif [ $JDK_VERSION = 12 ]; then
url="https://download.java.net/java/GA/jdk12.0.2/e482c34c86bd4bf8b56c0b35558996b9/10/GPL/openjdk-12.0.2_${os_name}-x64_bin.tar.gz"
elif [ $JDK_VERSION = 13 ]; then
url="https://download.java.net/java/GA/jdk13/5b8a42f3905b406298b72d750b6919f6/33/GPL/openjdk-13_${os_name}-x64_bin.tar.gz"
elif [ $JDK_VERSION = 14 ]; then
url="https://download.java.net/java/early_access/jdk14/16/GPL/openjdk-14-ea+16_${os_name}-x64_bin.tar.gz"
else
echo "Unknown JDK version: $JDK_VERSION" >&2
exit 1
fi
echo "cd $tmppath; curl -L $url | tar xzf -"
(
cd $tmppath
curl -L $url | tar xzf -
)
if [ ! -e "$PREFIX/jdk-${JDK_VERSION}/bin/java" ]; then
if [ -e "$PREFIX/jdk-${JDK_VERSION}" ]; then
rm -rf "$PREFIX/jdk-${JDK_VERSION}"
fi
if [ $os_name = "osx" ]; then
echo mv $tmppath/jdk-$JDK_VERSION.jdk "$PREFIX/jdk-${JDK_VERSION}"
mv $tmppath/jdk-$JDK_VERSION.jdk "$PREFIX/jdk-${JDK_VERSION}"
else
echo mv $tmppath/jdk-$JDK_VERSION "$PREFIX/jdk-${JDK_VERSION}"
mv $tmppath/jdk-$JDK_VERSION "$PREFIX/jdk-${JDK_VERSION}"
fi
fi
rm -rf $tmppath
fi
if [ $os_name = "osx" ]; then
export JAVA_HOME="$PREFIX/jdk-${JDK_VERSION}/Contents/Home"
else
export JAVA_HOME="$PREFIX/jdk-${JDK_VERSION}"
fi
export PATH="${JAVA_HOME}/bin:$PATH"
}
################################################################################
# Scala
################################################################################
install_scala() {
if [ "${JDK_VERSION:=x}" = "x" ]; then
echo "use --jdk=* option" >&2
exit 1
fi
if [ ! -x "$PREFIX/scala-${SCALA_VERSION}/bin/scala" ]; then
local tmppath="$PREFIX/scala-${SCALA_VERSION}-$$"
mkdir -p $tmppath
local url="https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.tgz"
echo "cd $tmppath; curl -L $url | tar xzf -"
(
cd $tmppath
curl -L $url | tar xzf -
)
if [ ! -e "$PREFIX/scala-${SCALA_VERSION}/bin/scala" ]; then
if [ -e "$PREFIX/scala-${SCALA_VERSION}" ]; then
rm -rf "$PREFIX/scala-${SCALA_VERSION}"
fi
echo mv $tmppath/scala-$SCALA_VERSION "$PREFIX/scala-${SCALA_VERSION}"
mv $tmppath/scala-$SCALA_VERSION "$PREFIX/scala-${SCALA_VERSION}"
fi
rm -rf $tmppath
fi
export SCALA_HOME="$PREFIX/scala-${SCALA_VERSION}"
export PATH="${SCALA_HOME}/bin:$PATH"
}
################################################################################
# sbt
################################################################################
install_sbt() {
if [ "${JDK_VERSION:=x}" = "x" ]; then
echo "use --jdk=* option" >&2
exit 1
fi
if [ ! -x "$PREFIX/sbt-${SBT_VERSION}/bin/sbt" ]; then
tmppath="$PREFIX/sbt-${SBT_VERSION}-$$"
mkdir -p $tmppath
url="https://piccolo.link/sbt-${SBT_VERSION}.tgz"
echo "cd $tmppath; curl -L $url | tar xzf -"
(
cd $tmppath
curl -L $url | tar xzf -
)
if [ ! -e "$PREFIX/sbt-${SBT_VERSION}/bin/sbt" ]; then
if [ -e "$PREFIX/sbt-${SBT_VERSION}" ]; then
rm -rf "$PREFIX/sbt-${SBT_VERSION}"
fi
echo mv $tmppath/sbt "$PREFIX/sbt-${SBT_VERSION}"
mv $tmppath/sbt "$PREFIX/sbt-${SBT_VERSION}"
fi
rm -rf $tmppath
fi
export PATH="$PREFIX/sbt-${SBT_VERSION}/bin:$PATH"
}
################################################################################
# GraalVM
################################################################################
install_graalvm() {
if [ "${JDK_VERSION:=x}" != "x" ]; then
echo "cannot use both --jdk=* and --graalvm=* options" >&2
exit 1
fi
if [ ! -x "$PREFIX/graalvm-${GRAALVM_VERSION}/bin/java" ]; then
uname=$(uname)
if [ "$uname" = "Darwin" ]; then
os_name='darwin'
elif [ "$uname" = "Linux" ]; then
os_name='linux'
else
echo "Unknown OS: $uname" >&2
exit 1
fi
tmppath="$PREFIX/graalvm-${GRAALVM_VERSION}-$$"
mkdir -p $tmppath
url="https://github.com/oracle/graal/releases/download/vm-${GRAALVM_VERSION}/graalvm-ce-${os_name}-amd64-${GRAALVM_VERSION}.tar.gz"
echo "cd $tmppath; curl -L $url | tar xzf -"
(
cd $tmppath
curl -L $url | tar xzf -
$tmppath/graalvm-ce-${GRAALVM_VERSION}/bin/gu install native-image
)
if [ ! -e "$PREFIX/graalvm-${GRAALVM_VERSION}/bin/java" ]; then
if [ -e "$PREFIX/graalvm-${GRAALVM_VERSION}" ]; then
rm -rf "$PREFIX/graalvm-${GRAALVM_VERSION}"
fi
mv $tmppath/graalvm-ce-${GRAALVM_VERSION} "$PREFIX/graalvm-${GRAALVM_VERSION}"
fi
rm -rf $tmppath
fi
export PATH="$PREFIX/graalvm-${GRAALVM_VERSION}/bin:$PATH"
export JAVA_HOME="$PREFIX/graalvm-${GRAALVM_VERSION}"
}
################################################################################
# Rust
################################################################################
install_rust() {
export RUSTUP_HOME="$PREFIX/rust"
export CARGO_HOME="$PREFIX/rust"
if [ -x "$RUSTUP_HOME/bin/rustup" ]; then
"$RUSTUP_HOME/bin/rustup" self update 2>/dev/null
else
curl https://sh.rustup.rs -sSf | sh -s -- --no-modify-path -y --default-toolchain none
fi
if ! "${RUSTUP_HOME}/bin/rustup" toolchain list | grep "$RUST_VERSION"- >/dev/null; then
"${RUSTUP_HOME}/bin/rustup" toolchain install "$RUST_VERSION"
fi
}
################################################################################
# main
################################################################################
[ "${JDK_VERSION:=x}" != "x" ] && install_jdk
[ "${SCALA_VERSION:=x}" != "x" ] && install_scala
[ "${SBT_VERSION:=x}" != "x" ] && install_sbt
[ "${GRAALVM_VERSION:=x}" != "x" ] && install_graalvm
[ "${RUST_VERSION:=x}" != "x" ] && install_rust
[ "$#" = 0 ] && usage
cmd="$1"; shift
if [ "${RUST_VERSION:=x}" != "x" ]; then
exec "${RUSTUP_HOME}/bin/rustup" run $RUST_VERSION -- "$cmd" "$@"
else
if ! which "$cmd" >/dev/null; then
echo "Not found: $cmd" >&2
exit 1
fi
exec "$cmd" "$@"
fi
################################################################################