forked from tianon/docker-bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversions.sh
executable file
·127 lines (110 loc) · 3.53 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
#!/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[@]%/}" )
ftpBase='ftp://ftp.gnu.org/gnu/bash'
ftp_list() {
curl --silent --list-only "$ftpBase/${1:-}/"
}
allBaseVersions="$(
ftp_list \
| sed -rne '/^bash-([0-9].+)[.]tar[.]gz$/s//\1/p' \
| sort -V
)"
tmp="$(mktemp -d)"
trap "$(printf 'rm -rf %q' "$tmp")" EXIT
for version in "${versions[@]}"; do
export version
rcVersion="${version%-rc}"
rcGrepV='-v'
if [ "$version" != "$rcVersion" ]; then
rcGrepV=
fi
if [ "$version" = 'devel' ]; then
git clone --quiet --branch devel --depth 10 https://git.savannah.gnu.org/git/bash.git "$tmp/devel"
snapshotDate="$(TZ=UTC date --date 'last monday 23:59:59' '+%Y-%m-%d %H:%M:%S %Z')" # https://github.com/docker-library/faq#can-i-use-a-bot-to-make-my-image-update-prs
commit="$(git -C "$tmp/devel" log --before="$snapshotDate" --format='format:%H' --max-count=1)"
if [ -z "$commit" ]; then
echo >&2 "error: cannot determine commit for $version (from https://git.savannah.gnu.org/cgit/bash.git)"
exit 1
fi
desc="$(git -C "$tmp/devel" log --max-count=1 --format='format:%s' "$commit")"
[ -n "$desc" ]
if timestamp="$(sed -rne '/.*[[:space:]]+bash-([0-9]+)[[:space:]]+.*/s//\1/p' <<<"$desc")" && [ -n "$timestamp" ]; then
: # "commit bash-20210305 snapshot"
else
timestamp="$(git -C "$tmp/devel" log --max-count=1 --format='format:%aI' "$commit")" # ideally we'd use "%as" and just axe "-" but that requires newer Git than Debian 10 has /o\
timestamp="${timestamp%%T*}"
timestamp="${timestamp//-/}"
fi
echo "$version: $commit ($timestamp -- $desc)"
export commit timestamp desc
json="$(jq <<<"$json" -c '.[env.version] = {
version: env.timestamp,
commit: { version: env.commit, description: env.desc },
}')"
continue
fi
baseline="$(
grep -E "^$rcVersion([.-]|\$)" <<<"$allBaseVersions" \
| grep -E $rcGrepV -- '-(rc|beta|alpha)' \
| tail -1
)"
if [ -z "$baseline" ]; then
echo >&2 "error: cannot find any releases of $version in $ftpBase"
exit 1
fi
patchlevel=
if [ "$version" = "$rcVersion" ]; then
patchlevel="$(
ftp_list "bash-$rcVersion-patches" \
| sed -rne '/^bash[0-9]+-([0-9]{3})$/s//\1/p' \
| tail -1 \
|| :
)"
fi
patchlevel="${patchlevel#0}"
patchlevel="${patchlevel#0}"
: "${patchlevel:=0}"
[[ "$patchlevel" =~ ^[0-9]+$ ]]
patchbase=
if [ "$version" = "$rcVersion" ] && [[ "$baseline" =~ ^[0-9]+[.][0-9]+[.][0-9]+$ ]]; then
patchbase="${baseline#*.*.}"
fi
: "${patchbase:=0}"
fullVersion="$baseline"
if [[ "$fullVersion" =~ ^[0-9]+[.][0-9]+$ ]]; then
fullVersion+='.0'
fi
if [ "$version" = "$rcVersion" ] && [[ "$fullVersion" =~ ^[0-9]+[.][0-9]+[.][0-9]+$ ]] && [ "$patchlevel" -gt "$patchbase" ]; then
fullVersion="${fullVersion%.*}.$patchlevel"
fi
echo "$version: $fullVersion"
export fullVersion baseline patchbase patchlevel
json="$(jq <<<"$json" -c '
(env.patchbase | tonumber) as $patchbase
| (env.patchlevel | tonumber) as $patchlevel
| .[env.version] = { version: env.fullVersion }
+ if env.baseline != env.fullVersion or $patchbase > 0 then
{
baseline: (
if env.baseline != env.fullVersion then { version: env.baseline } else {} end
+ if $patchbase > 0 then { patch: env.patchbase } else {} end
),
}
else {} end
+ if $patchlevel > 0 then
{
patch: { version: env.patchlevel },
}
else {} end
')"
done
jq <<<"$json" -S . > versions.json