forked from docker-library/openjdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversions.sh
executable file
·294 lines (261 loc) · 7.43 KB
/
versions.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
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
json='{}'
else
json="$(< versions.json)"
fi
versions=( "${versions[@]%/}" )
tmp="$(mktemp -d)"
rmTmp="$(printf 'rm -rf %q' "$tmp")"
trap "$rmTmp" EXIT
_get() {
local url="$1"; shift
local file="${url////_}"
file="${file//%/_}"
file="${file//+/_}"
file="${file//:/_}"
file="$tmp/$file"
if [ ! -s "$file" ]; then
curl -fsSL "$url" -o "$file" --retry 5 || return 1
fi
if [ "$#" -gt 0 ]; then
grep "$@" "$file"
else
cat "$file"
fi
}
abs-url() {
local url="$1"; shift
local base="$1"; shift
case "$url" in
http://* | https://* ) ;;
/*)
local extra="${base#*://*/}"
local baseBase="${base%$extra}"
baseBase="${baseBase%/}"
url="$baseBase$url"
;;
*)
echo >&2 "error: TODO parse '$url' relative to '$base'"
exit 1
;;
esac
echo "$url"
}
adopt-github-url() {
local javaVersion="$1"; shift
local url
url="$(
curl -fsS --head "https://github.com/AdoptOpenJDK/openjdk${javaVersion}-upstream-binaries/releases/latest" | tac|tac \
| tr -d '\r' \
| awk 'tolower($1) == "location:" { print $2; found = 1; exit } END { if (!found) { exit 1 } }'
)" || return 1
url="$(abs-url "$url" 'https://github.com')" || return 1
echo "$url"
}
adopt-sources-url() {
local githubUrl="$1"; shift
local url
url="$(
_get "$githubUrl" \
-oEm1 'href="[^"]+-sources_[^"]+[.]tar[.]gz"' \
| cut -d'"' -f2 \
|| :
)"
[ -n "$url" ] || return 1
url="$(abs-url "$url" "$githubUrl")" || return 1
echo "$url"
}
adopt-version() {
local githubUrl="$1"; shift
local version
version="$(
_get "$githubUrl" \
-oE '<title>.+</title>' \
| grep -oE ' OpenJDK [^ ]+ ' \
| cut -d' ' -f3
)" || return 1
echo "$version"
}
jdk-java-net-download-url() {
local javaVersion="$1"; shift
local fileSuffix="$1"; shift
_get "https://jdk.java.net/$javaVersion/" \
-Eom1 "https://download.java.net/[^\"]+$fileSuffix"
}
jdk-java-net-download-version() {
local javaVersion="$1"; shift
local downloadUrl="$1"; shift
downloadVersion="$(grep -Eom1 "openjdk-$javaVersion[^_]*_" <<<"$downloadUrl")" || return 1
downloadVersion="${downloadVersion%_}"
downloadVersion="${downloadVersion#openjdk-}"
if [ "$javaVersion" = '11' ]; then
# 11 is now GA, so drop any +NN (https://github.com/docker-library/openjdk/pull/235#issuecomment-425378941)
# future releases will be 11.0.1, for example
downloadVersion="${downloadVersion%%+*}"
fi
echo "$downloadVersion"
}
# see https://stackoverflow.com/a/2705678/433558
sed_escape_rhs() {
sed -e 's/[\/&]/\\&/g' <<<"$*" | sed -e ':a;N;$!ba;s/\n/\\n/g'
}
sed_s() {
local lhs="$1"; shift
local rhs="$1"; shift
rhs="$(sed_escape_rhs "$rhs")"
echo -n "s/$lhs/$rhs/g"
}
sed_s_pre() {
local lhs="$1"; shift
local rhs="$1"; shift
rhs="$(sed_escape_rhs "$rhs")"
echo -n "s/^($lhs) .*$/\1 $rhs/"
}
for version in "${versions[@]}"; do
export version
doc='{}'
if [ "$version" -le 11 ]; then
githubUrl="$(adopt-github-url "$version")"
sourcesUrl="$(adopt-sources-url "$githubUrl")"
javaUrlBaseBase="${sourcesUrl%%-sources_*}-"
javaUrlVersion="${sourcesUrl#${javaUrlBaseBase}sources_}"
javaUrlVersion="${javaUrlVersion%.tar.gz}"
adoptVersion="$(adopt-version "$githubUrl")"
echo "$version: $adoptVersion"
export adoptVersion
doc="$(jq <<<"$doc" -c '
.version = env.adoptVersion
| .source = "adopt"
')"
possibleArches=(
# https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases
# https://github.com/AdoptOpenJDK/openjdk11-upstream-binaries/releases
'aarch64_linux'
'x64_linux'
'x64_windows'
)
for javaType in jdk jre; do
export javaType
javaUrlBase="${javaUrlBaseBase}${javaType}_" # "jre_", "jdk_", etc
for arch in "${possibleArches[@]}"; do
case "$arch" in
*_linux) downloadSuffix='.tar.gz'; bashbrewArch= ;;
*_windows) downloadSuffix='.zip'; bashbrewArch='windows-' ;;
*) echo >&2 "error: unknown Adopt Upstream arch: '$arch'"; exit 1 ;;
esac
downloadUrl="${javaUrlBase}${arch}_${javaUrlVersion}${downloadSuffix}"
downloadFile="$(basename "$downloadUrl")"
if _get "$githubUrl" -qF "$downloadFile"; then
case "$arch" in
aarch64_*) bashbrewArch+='arm64v8' ;;
x64_*) bashbrewArch+='amd64' ;;
*) echo >&2 "error: unknown Adopt Upstream arch: '$arch'"; exit 1 ;;
esac
export bashbrewArch downloadUrl
doc="$(jq <<<"$doc" -c '
.[env.javaType].arches[env.bashbrewArch] = {
url: env.downloadUrl,
}
')"
fi
done
done
else
doc="$(jq <<<"$doc" -c '
.source = "oracle"
')"
possibleArches=(
# https://jdk.java.net/15/
# https://jdk.java.net/16/
# https://jdk.java.net/17/
'linux-aarch64'
'linux-x64'
'linux-x64-musl'
'windows-x64'
)
for arch in "${possibleArches[@]}"; do
downloadSuffix="_${arch}_bin"
case "$arch" in
linux-*) downloadSuffix+='.tar.gz'; bashbrewArch= ;;
windows-*) downloadSuffix+='.zip'; bashbrewArch='windows-' ;;
*) echo >&2 "error: unknown Oracle arch: '$arch'"; exit 1 ;;
esac
jqExprPrefix=
if [[ "$arch" == *-musl ]]; then
jqExprPrefix='.alpine'
fi
if downloadUrl="$(jdk-java-net-download-url "$version" "$downloadSuffix")" \
&& [ -n "$downloadUrl" ] \
&& downloadSha256="$(_get "$downloadUrl.sha256")" \
&& [ -n "$downloadSha256" ] \
; then
downloadVersion="$(jdk-java-net-download-version "$version" "$downloadUrl")"
currentVersion="$(jq <<<"$doc" -r "$jqExprPrefix.version // \"\"")"
if [ -n "$currentVersion" ] && [ "$currentVersion" != "$downloadVersion" ]; then
echo >&2 "error: Oracle version mismatch: '$currentVersion' vs '$downloadVersion'"
exit 1
elif [ -z "$currentVersion" ]; then
echo "$version: $downloadVersion${jqExprPrefix:+ (alpine)}"
fi
case "$arch" in
*-aarch64*) bashbrewArch+='arm64v8' ;;
*-x64*) bashbrewArch+='amd64' ;;
*) echo >&2 "error: unknown Oracle arch: '$arch'"; exit 1 ;;
esac
export arch bashbrewArch downloadUrl downloadSha256 downloadVersion
doc="$(jq <<<"$doc" -c '
'"$jqExprPrefix"'.version = env.downloadVersion
| '"$jqExprPrefix"'.jdk.arches[env.bashbrewArch] = {
url: env.downloadUrl,
sha256: env.downloadSha256,
}
')"
fi
done
fi
if ! jq <<<"$doc" -e '[ .. | objects | select(has("arches")) | .arches | has("amd64") ] | all' &> /dev/null; then
echo >&2 "error: missing 'amd64' for '$version'; cowardly refusing to continue! (because this is almost always a scraping flake or similar bug)"
exit 1
fi
if [ "$version" = '11' ]; then
for arch in arm64v8 windows-amd64; do
export arch
if ! jq <<<"$doc" -e '[ .. | objects | select(has("arches")) | .arches | has(env.arch) ] | all' &> /dev/null; then
echo >&2 "error: missing '$arch' for '$version'; cowardly refusing to continue! (because this is almost always a scraping flake or similar bug)"
exit 1
fi
done
fi
json="$(jq <<<"$json" -c --argjson doc "$doc" '
.[env.version] = $doc + {
variants: [
(
"8",
"7"
| "oraclelinux" + .),
(
"buster"
| ., "slim-" + .),
if $doc.alpine then
"3.14",
"3.13"
| "alpine" + . else empty end,
if $doc.jdk.arches | keys | any(startswith("windows-")) then
(
"1809",
"ltsc2016"
| "windows/windowsservercore-" + .),
(
"1809"
| "windows/nanoserver-" + .)
else empty end
],
}
')"
done
jq <<<"$json" -S . > versions.json