forked from docker-library/golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·120 lines (106 loc) · 3.73 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
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
source '.architectures-lib'
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
# see http://stackoverflow.com/a/2705678/433558
sed_escape_lhs() {
echo "$@" | sed -e 's/[]\/$*.^|[]/\\&/g'
}
sed_escape_rhs() {
echo "$@" | sed -e 's/[\/&]/\\&/g' | sed -e ':a;N;$!ba;s/\n/\\n/g'
}
# https://github.com/golang/go/issues/13220
allGoVersions=()
apiBaseUrl='https://www.googleapis.com/storage/v1/b/golang/o?fields=nextPageToken,items%2Fname'
pageToken=
while [ "$pageToken" != 'null' ]; do
page="$(curl -fsSL "$apiBaseUrl&pageToken=$pageToken")"
allGoVersions+=( $(
echo "$page" \
| jq -r '.items[].name' \
| grep -E '^go[0-9].*[.]src[.]tar[.]gz$' \
| sed -r -e 's!^go!!' -e 's![.]src[.]tar[.]gz$!!'
) )
# TODO extract per-version "available binary tarballs" information while we've got it handy here?
pageToken="$(echo "$page" | jq -r '.nextPageToken')"
done
for version in "${versions[@]}"; do
rcVersion="${version%-rc}"
rcGrepV='-v'
if [ "$rcVersion" != "$version" ]; then
rcGrepV=
fi
rcGrepV+=' -E'
rcGrepExpr='beta|rc'
fullVersion="$(
echo "${allGoVersions[@]}" | xargs -n1 \
| grep $rcGrepV -- "$rcGrepExpr" \
| grep -E "^${rcVersion}([.a-z]|$)" \
| sort -V \
| tail -1
)" || true
if [ -z "$fullVersion" ]; then
echo >&2 "warning: cannot find full version for $version"
continue
fi
fullVersion="${fullVersion#go}" # strip "go" off "go1.4.2"
# https://github.com/golang/build/commit/24f7399f96feb8dd2fc54f064e47a886c2f8bb4a
srcSha256="$(curl -fsSL "https://storage.googleapis.com/golang/go${fullVersion}.src.tar.gz.sha256")"
if [ -z "$srcSha256" ]; then
echo >&2 "warning: cannot find sha256 for $fullVersion src tarball"
continue
fi
linuxArchCase='dpkgArch="$(dpkg --print-architecture)"; '$'\\\n'
linuxArchCase+=$'\t''case "${dpkgArch##*-}" in '$'\\\n'
for dpkgArch in $(dpkgArches "$version"); do
goArch="$(dpkgToGoArch "$version" "$dpkgArch")"
sha256="$(curl -fsSL "https://storage.googleapis.com/golang/go${fullVersion}.linux-${goArch}.tar.gz.sha256")"
if [ -z "$sha256" ]; then
echo >&2 "warning: cannot find sha256 for $fullVersion on arch $goArch"
continue 2
fi
linuxArchCase+=$'\t\t'"$dpkgArch) goRelArch='linux-$goArch'; goRelSha256='$sha256' ;; "$'\\\n'
done
linuxArchCase+=$'\t\t'"*) goRelArch='src'; goRelSha256='$srcSha256'; "$'\\\n'
linuxArchCase+=$'\t\t\t''echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; '$'\\\n'
linuxArchCase+=$'\t''esac'
windowsSha256="$(curl -fsSL "https://storage.googleapis.com/golang/go${fullVersion}.windows-amd64.zip.sha256")"
for variant in \
alpine{3.10,3.11} \
stretch buster \
bionic \
; do
if [ -d "$version/$variant" ]; then
tag="$variant"
template='debian'
case "$variant" in
alpine*) tag="${variant#alpine}"; template='alpine' ;;
bionic) template='ubuntu' ;;
esac
sed -r \
-e 's!%%VERSION%%!'"$fullVersion"'!g' \
-e 's!%%TAG%%!'"$tag"'!g' \
-e 's!%%SRC-SHA256%%!'"$srcSha256"'!g' \
-e 's!%%ARCH-CASE%%!'"$(sed_escape_rhs "$linuxArchCase")"'!g' \
"Dockerfile-${template}.template" > "$version/$variant/Dockerfile"
fi
done
for winVariant in \
nanoserver-1809 \
windowsservercore-{ltsc2016,1809} \
; do
if [ -d "$version/windows/$winVariant" ]; then
sed -r \
-e 's!%%VERSION%%!'"$fullVersion"'!g' \
-e 's!%%WIN-SHA256%%!'"$windowsSha256"'!g' \
-e 's!%%MICROSOFT-TAG%%!'"${winVariant#*-}"'!g' \
"Dockerfile-windows-${winVariant%%-*}.template" > "$version/windows/$winVariant/Dockerfile"
fi
done
echo "$version: $fullVersion ($srcSha256)"
done