forked from docker-library/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·120 lines (101 loc) · 4.01 KB
/
update.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
#!/usr/bin/env bash
set -Eeuo pipefail
# TODO https://julialang-s3.julialang.org/bin/versions.json ?
# delayed deploys: https://github.com/JuliaLang/julia/issues/38946#issuecomment-749224376
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
source '.architectures-lib'
# see https://stackoverflow.com/a/2705678/433558
sed_escape_rhs() {
echo "$@" | sed -e 's/[\/&]/\\&/g' | sed -e ':a;N;$!ba;s/\n/\\n/g'
}
rcRegex='-(pre[.])?(alpha|beta|rc)[0-9]*'
pattern='[^"]*/julia-([0-9]+\.[0-9]+\.[0-9]+('"$rcRegex"')?)-linux-x86_64\.tar\.gz[^"]*'
allVersions="$(
curl -fsSL 'https://julialang.org/downloads/' \
| grep -oE "$pattern" \
| sed -rn "s!${pattern}!\1!gp" \
| sort -ruV
)"
for version in "${versions[@]}"; do
rcVersion="${version%-rc}"
rcGrepV='-v'
if [ "$rcVersion" != "$version" ]; then
rcGrepV=
fi
rcGrepV+=' -E'
fullVersion="$(grep -E "^${rcVersion}([.-]|$)" <<<"$allVersions" | grep $rcGrepV -- "$rcRegex" | head -1)"
if [ -z "$fullVersion" ]; then
echo >&2 "error: failed to determine latest release for '$version'"
exit 1
fi
sha256s="$(curl -fsSL "https://julialang-s3.julialang.org/bin/checksums/julia-${fullVersion}.sha256")"
linuxArchCase='dpkgArch="$(dpkg --print-architecture)"; '$'\\\n'
linuxArchCase+=$'\t''case "${dpkgArch##*-}" in '$'\\\n'
for dpkgArch in $(dpkgArches "$version"); do
tarArch="$(dpkgToJuliaTarArch "$version" "$dpkgArch")"
dirArch="$(dpkgToJuliaDirArch "$version" "$dpkgArch")"
sha256="$(grep "julia-${fullVersion}-linux-${tarArch}.tar.gz$" <<<"$sha256s" | cut -d' ' -f1 || :)"
if [ -z "$sha256" ]; then
echo >&2 "warning: cannot find sha256 for $fullVersion on arch $tarArch / $dirArch ($dpkgArch); skipping"
continue
fi
bashbrewArch="$(dpkgToBashbrewArch "$version" "$dpkgArch")"
linuxArchCase+="# $bashbrewArch"$'\n'
linuxArchCase+=$'\t\t'"$dpkgArch) tarArch='$tarArch'; dirArch='$dirArch'; sha256='$sha256' ;; "$'\\\n'
done
linuxArchCase+=$'\t\t''*) echo >&2 "error: current architecture ($dpkgArch) does not have a corresponding Julia binary release"; exit 1 ;; '$'\\\n'
linuxArchCase+=$'\t''esac'
winSha256="$(grep "julia-${fullVersion}-win64.exe$" <<<"$sha256s" | cut -d' ' -f1)"
echo "$version: $fullVersion"
for v in \
windows/windowsservercore-{ltsc2022,1809,ltsc2016} \
alpine{3.15,3.14} \
{bullseye,buster} \
; do
dir="$version/$v"
variant="$(basename "$v")"
[ -d "$dir" ] || continue
case "$variant" in
windowsservercore-*) template='windowsservercore'; tag="${variant#*-}" ;;
alpine*) template='alpine'; tag="${variant#alpine}" ;;
*) template='debian'; tag="${variant}-slim" ;;
esac
variantArchCase="$linuxArchCase"
if [ "$template" = 'alpine' ]; then
sha256="$(grep "julia-${fullVersion}-musl-x86_64.tar.gz$" <<<"$sha256s" | cut -d' ' -f1 || :)"
if [ -z "$sha256" ]; then
echo >&2 "error: missing musl build for $fullVersion ($version)!"
exit 1
fi
variantArchCase='apkArch="$(apk --print-arch)"; '$'\\\n'
variantArchCase+=$'\t''case "$apkArch" in '$'\\\n'
# TODO Alpine multiarch
variantArchCase+='# amd64'$'\n'
tarArch="$(dpkgToJuliaTarArch "$version" 'amd64')"
dirArch="$(dpkgToJuliaDirArch "$version" 'amd64')"
variantArchCase+=$'\t\t'"x86_64) tarArch='$tarArch'; dirArch='$dirArch'; sha256='$sha256' ;; "$'\\\n'
variantArchCase+=$'\t\t''*) echo >&2 "error: current architecture ($apkArch) does not have a corresponding Julia binary release"; exit 1 ;; '$'\\\n'
variantArchCase+=$'\t''esac'
fi
sed -r \
-e 's!%%JULIA_VERSION%%!'"$fullVersion"'!g' \
-e 's!%%TAG%%!'"$tag"'!g' \
-e 's!%%JULIA_WINDOWS_SHA256%%!'"$winSha256"'!g' \
-e 's!%%ARCH-CASE%%!'"$(sed_escape_rhs "$variantArchCase")"'!g' \
"Dockerfile-$template.template" > "$dir/Dockerfile"
case "$dir" in
1.0/windows/*)
# https://github.com/JuliaLang/julia/blob/v1.4.0-rc1/NEWS.md#build-system-changes
sed -ri \
-e 's!/SILENT!/S!g' \
-e 's!/DIR=!/D=!g' \
"$dir/Dockerfile"
;;
esac
done
done