-
Notifications
You must be signed in to change notification settings - Fork 4
/
fetchjdk.sh
executable file
·413 lines (366 loc) · 10.2 KB
/
fetchjdk.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#!/bin/bash
# usage: . ./tools.sh tooldir [tool]...
OLDPATH="$PATH"
set -e
set_os() {
IS_LINUX=false
if [ "`uname`" = "Linux" ] ; then
IS_LINUX=true
fi
IS_DARWIN=false
if [ "`uname`" = "Darwin" ] ; then
IS_DARWIN=true
fi
# one of x86_64 or arm64
BUILD_TARGET_ARCH=`uname -m`
if [ "$BUILD_TARGET_ARCH" = "x86_64" ] ; then
IS_INTEL=true
IS_ARM=false
else
IS_INTEL=false
IS_ARM=true
fi
}
# define toolchain
find_xcode() {
XCODE_APP=`dirname \`dirname \\\`xcode-select -p \\\`\``
XCODE_VERSION=`/usr/bin/xcodebuild -version | sed -En 's/Xcode[[:space:]]+([0-9\.]*)/\1/p' | sed s/[.][0-9]*//`
XCODE_DEVELOPER_PREFIX=$XCODE_APP/Contents/Developer
CCTOOLCHAIN_PREFIX=$XCODE_APP/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
OLDPATH=$PATH
export PATH=$CCTOOLCHAIN_PREFIX/usr/bin:$PATH
export PATH=$TOOL_PREFIX/usr/bin:$PATH
echo Using xcode version $XCODE_VERSION installed in $XCODE_APP
}
set_os
if $IS_DARWIN ; then
find_xcode
fi
# define build environment
TOOL_DIR="$1"
if test ".$TOOL_DIR" = "." ; then
TOOL_DIR="`pwd`/tools_$BUILD_TARGET_ARCH"
fi
if test ".$DOWNLOAD_DIR" = "." ; then
DOWNLOAD_DIR="$TOOL_DIR/downloads"
fi
if test ".$TOOL_INSTALL_ROOT" = "." ; then
TOOL_INSTALL_ROOT="$TOOL_DIR/local"
fi
if test ".$TMP" = "." ; then
TMP=/tmp
fi
if test ".$TMP_DIR" = "." ; then
TMP_DIR="$TMP/$$.work"
fi
download_and_open_pkg() {
URL="$1"
FILE="$TMP_DIR/current.pkg"
DEST="$2"
if ! test -f "$FILE" ; then
echo "downloading $1 to `basename $FILE`"
pushd "$DOWNLOAD_DIR"
curl --fail --output "$FILE" -L --insecure "$URL"
popd
fi
if test -d "$DEST" ; then
return
fi
rm -fr "$TMP_DIR/expanded-package"
mkdir -p "$TMP_DIR/expanded-package"
pushd "$TMP_DIR/expanded-package" >/dev/null
tar -xvf "$FILE"
popd >/dev/null
PAYLOAD_FILE=`find "$TMP_DIR/expanded-package" -type f -name Payload`
mkdir "$TMP_DIR/payload"
pushd "$TMP_DIR/payload" >/dev/null
tar -xvf "$PAYLOAD_FILE"
mkdir -p "$DEST"
mv `find . -type d -name Contents` "$DEST/Contents"
popd >/dev/null
#rm -fr "$TMP_DIR/dno" "$FILE"
}
download_and_open() {
URL="$1"
FILE="$DOWNLOAD_DIR/download.${RANDOM}"
DEST="$2"
if ! test -f "$FILE" ; then
echo "downloading $1 to `basename $FILE`"
pushd "$DOWNLOAD_DIR"
curl --fail --output "$FILE" -L --insecure "$URL"
popd
fi
if test -d "$DEST" ; then
return
fi
rm -fr "$TMP_DIR/dno"
mkdir -p "$TMP_DIR/dno"
pushd "$TMP_DIR/dno"
tar -xvf "$FILE"
mv * "$DEST"
popd
rm -fr "$TMP_DIR/dno"
}
clone_or_update() {
URL="$1"
DEST="$2"
if ! test -d "$DEST" ; then
echo "cloning $1"
git clone "$URL" "$DEST"
else
pushd "$DEST"
git pull
popd
fi
}
build_bootstrap_jdkX() {
# usage build_bootstrap_jdkX 21 arm64 aarch64
# usage build_bootstrap_jdkX 21 x86_64 x64
VER=$1
ARCH=$2
ARCH_SHORT=$3
PLATFORM=mac
GAorEA=ga
if test -d "$TOOL_DIR/jdk${VER}_${ARCH}" ; then
return
fi
#download_and_open_pkg https://api.adoptium.net/v3/installer/latest/${VER}/${GAorEA}/${PLATFORM}/${ARCH_SHORT}/jdk/hotspot/normal/eclipse?project=jdk "$TOOL_DIR/jdk${VER}_${ARCH}"
download_and_open https://api.adoptium.net/v3/binary/latest/${VER}/${GAorEA}/${PLATFORM}/${ARCH_SHORT}/jdk/hotspot/normal/eclipse?project=jdk "$TOOL_DIR/jdk${VER}_${ARCH}"
}
build_bootstrap_jdk8() {
if $IS_ARM ; then
#build_bootstrap_jdkX 8 arm64 aarch64
JDK_URL="https://objects.githubusercontent.com/github-production-release-asset-2e65be/372924428/1fba6827-a775-49e5-8b81-a7b069f3b4ef?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVCODYLSA53PQK4ZA%2F20240502%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240502T145117Z&X-Amz-Expires=300&X-Amz-Signature=ffff3c837c1be1a49010aacf15830fafae0b0d51b05af47436bead93ead82255&X-Amz-SignedHeaders=host&actor_id=28760513&key_id=0&repo_id=372924428&response-content-disposition=attachment%3B%20filename%3DOpenJDK8U-jdk_x64_mac_hotspot_8u412b08.tar.gz&response-content-type=application%2Foctet-stream"
#download_and_open "$JDK_URL" "$TOOL_DIR/jdk8_arm64"
else
build_bootstrap_jdkX 8 x86_64 x86_64
fi
}
build_bootstrap_jdk10() {
build_bootstrap_jdkX 10 x86_64 x86
}
build_bootstrap_jdk11_x86_64() {
build_bootstrap_jdkX 11 x86_64 x86
}
build_bootstrap_jdk11_arm64() {
build_bootstrap_jdkX 11 arm64 aarch64
}
build_bootstrap_jdk12() {
build_bootstrap_jdkX 12 x86_64 x86
}
build_bootstrap_jdk13() {
build_bootstrap_jdkX 13 x86_64 x86
}
build_bootstrap_jdk15() {
build_bootstrap_jdkX 15 x86_64 x86
}
build_bootstrap_jdk16_x86_64() {
build_bootstrap_jdkX 16 x86_64 x86
}
build_bootstrap_jdk16_arm64() {
echo "there is no OpenJDK 16 aarch64 release - using x86_64 (no good for JavaFX)"
build_bootstrap_jdkX 16 arm64 aarch64
}
build_bootstrap_jdk17_x86_64() {
build_bootstrap_jdkX 17 x86_64 x86
}
build_bootstrap_jdk17_arm64() {
build_bootstrap_jdkX 17 arm64 aarch64
}
build_bootstrap_jdk20_x86_64() {
build_bootstrap_jdkX 20 x86_64 x86
}
build_bootstrap_jdk20_arm64() {
build_bootstrap_jdkX 20 arm64 aarch64
}
build_bootstrap_jdk21_x86_64() {
build_bootstrap_jdkX 21 x86_64 x86
}
build_bootstrap_jdk21_arm64() {
build_bootstrap_jdkX 21 arm64 aarch64
}
build_bootstrap_jdk22_x86_64() {
build_bootstrap_jdkX 22 x86_64 x86
}
build_bootstrap_jdk22_arm64() {
build_bootstrap_jdkX 22 arm64 aarch64
}
build_bootstrap_jdk23_x86_64() {
build_bootstrap_jdkX 23 x86_64 x86
}
build_bootstrap_jdk23_arm64() {
build_bootstrap_jdkX 23 arm64 aarch64
}
build_bootstrap_jdk11() {
if [ "`uname -m`" = "arm64" ] ; then
build_bootstrap_jdk11_arm64
else
build_bootstrap_jdk11_x86_64
fi
}
build_bootstrap_jdk16() {
if [ "`uname -m`" = "arm64" ] ; then
build_bootstrap_jdk16_arm64
else
build_bootstrap_jdk16_x86_64
fi
}
build_bootstrap_jdk17() {
if [ "`uname -m`" = "arm64" ] ; then
build_bootstrap_jdk17_arm64
else
build_bootstrap_jdk17_x86_64
fi
}
build_bootstrap_jdk20() {
if [ "`uname -m`" = "arm64" ] ; then
build_bootstrap_jdk20_arm64
else
build_bootstrap_jdk20_x86_64
fi
}
build_bootstrap_jdk21() {
if [ "`uname -m`" = "arm64" ] ; then
build_bootstrap_jdk21_arm64
else
build_bootstrap_jdk21_x86_64
fi
}
build_bootstrap_jdk22() {
if [ "`uname -m`" = "arm64" ] ; then
build_bootstrap_jdk22_arm64
else
build_bootstrap_jdk22_x86_64
fi
}
build_bootstrap_jdk23() {
if [ "`uname -m`" = "arm64" ] ; then
build_bootstrap_jdk23_arm64
else
build_bootstrap_jdk23_x86_64
fi
}
build_bootstrap_jdk_latest() {
if test -d "$TOOL_DIR/jdk-latest" ; then
return
fi
download_and_open ???? "$TOOL_DIR/jdk-latest"
}
buildtools() {
mkdir -p "$DOWNLOAD_DIR"
mkdir -p "$TOOL_DIR"
for tool in $* ; do
echo "building $tool"
build_$tool
if $IS_DARWIN ; then
if test $tool == "bootstrap_jdk8" ; then
export JAVA_HOME=$TOOL_DIR/jdk8u/Contents/Home
fi
if test $tool = "bootstrap_jdk9" ; then
export JAVA_HOME=$TOOL_DIR/jdk9u/Contents/Home
fi
if test $tool = "bootstrap_jdk10" ; then
export JAVA_HOME=$TOOL_DIR/jdk10u/Contents/Home
fi
if test $tool = "bootstrap_jdk11" ; then
if [ "`uname -m`" = "arm64" ] ; then
export JAVA_HOME=$TOOL_DIR/jdk11_arm64/Contents/Home
else
export JAVA_HOME=$TOOL_DIR/jdk11_x86_64/Contents/Home
fi
fi
if test $tool = "bootstrap_jdk12" ; then
export JAVA_HOME=$TOOL_DIR/jdk12u/Contents/Home
fi
if test $tool = "bootstrap_jdk13" ; then
export JAVA_HOME=$TOOL_DIR/jdk13u/Contents/Home
fi
if test $tool = "bootstrap_jdk15" ; then
export JAVA_HOME=$TOOL_DIR/jdk15/Contents/Home
fi
if test $tool = "bootstrap_jdk16" ; then
export JAVA_HOME=$TOOL_DIR/jdk16_x86_64/Contents/Home
fi
if test $tool = "bootstrap_jdk16_x86_64" ; then
export JAVA_HOME=$TOOL_DIR/jdk16_x86_64/Contents/Home
fi
if test $tool = "bootstrap_jdk17" ; then
if [ "`uname -m`" = "arm64" ] ; then
export JAVA_HOME=$TOOL_DIR/jdk17_arm64/Contents/Home
else
export JAVA_HOME=$TOOL_DIR/jdk17_x86_64/Contents/Home
fi
fi
if test $tool = "bootstrap_jdk17_arm64" ; then
export JAVA_HOME=$TOOL_DIR/jdk17_arm64/Contents/Home
fi
if test $tool = "bootstrap_jdk17_x86_64" ; then
export JAVA_HOME=$TOOL_DIR/jdk17_x86_64/Contents/Home
fi
if test $tool = "bootstrap_jdk20" ; then
if [ "`uname -m`" = "arm64" ] ; then
export JAVA_HOME=$TOOL_DIR/jdk20_arm64/Contents/Home
else
export JAVA_HOME=$TOOL_DIR/jdk20_x86_64/Contents/Home
fi
fi
if test $tool = "bootstrap_jdk20_arm64" ; then
export JAVA_HOME=$TOOL_DIR/jdk20_arm64/Contents/Home
fi
if test $tool = "bootstrap_jdk20_x86_64" ; then
export JAVA_HOME=$TOOL_DIR/jdk20_x86_64/Contents/Home
fi
if test $tool = "bootstrap_jdk21" ; then
if [ "`uname -m`" = "arm64" ] ; then
export JAVA_HOME=$TOOL_DIR/jdk21_arm64/Contents/Home
else
export JAVA_HOME=$TOOL_DIR/jdk21_x86_64/Contents/Home
fi
fi
if test $tool = "bootstrap_jdk21_arm64" ; then
export JAVA_HOME=$TOOL_DIR/jdk21_arm64/Contents/Home
fi
if test $tool = "bootstrap_jdk21_x86_64" ; then
export JAVA_HOME=$TOOL_DIR/jdk21_x86_64/Contents/Home
fi
if test $tool = "bootstrap_jdk22" ; then
if [ "`uname -m`" = "arm64" ] ; then
export JAVA_HOME=$TOOL_DIR/jdk22_arm64/Contents/Home
else
export JAVA_HOME=$TOOL_DIR/jdk22_x86_64/Contents/Home
fi
fi
if test $tool = "bootstrap_jdk22_arm64" ; then
export JAVA_HOME=$TOOL_DIR/jdk22_arm64/Contents/Home
fi
if test $tool = "bootstrap_jdk22_x86_64" ; then
export JAVA_HOME=$TOOL_DIR/jdk22_x86_64/Contents/Home
fi
if test $tool = "bootstrap_jdk23" ; then
if [ "`uname -m`" = "arm64" ] ; then
export JAVA_HOME=$TOOL_DIR/jdk23_arm64/Contents/Home
else
export JAVA_HOME=$TOOL_DIR/jdk23_x86_64/Contents/Home
fi
fi
if test $tool = "bootstrap_jdk23_arm64" ; then
export JAVA_HOME=$TOOL_DIR/jdk23_arm64/Contents/Home
fi
if test $tool = "bootstrap_jdk23_x86_64" ; then
export JAVA_HOME=$TOOL_DIR/jdk23_x86_64/Contents/Home
fi
if test $tool = "bootstrap_jdk_latest" ; then
export JAVA_HOME=$TOOL_DIR/jdk-latest/Contents/Home
fi
fi
done
}
build_tool_path() {
export PATH=$OLDPATH
export PATH=$JAVA_HOME/bin:$PATH
}
mkdir -p "$TMP_DIR"
shift
buildtools $*
build_tool_path
rm -fr "$TMP_DIR"