forked from docker-library/postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
versions.sh
executable file
·153 lines (133 loc) · 4.48 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
#!/usr/bin/env bash
set -Eeuo pipefail
# https://github.com/docker-library/postgres/issues/582 😬
defaultDebianSuite='bullseye'
declare -A debianSuites=(
[9.6]='stretch'
[10]='stretch'
[11]='stretch'
)
allDebianSuites=(
bullseye
stretch
)
defaultAlpineVersion='3.15'
declare -A alpineVersions=(
#[9.6]='3.5'
)
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
json='{}'
else
json="$(< versions.json)"
fi
versions=( "${versions[@]%/}" )
packagesBase='http://apt.postgresql.org/pub/repos/apt/dists/'
declare -A suitePackageList=() suiteVersionPackageList=() suiteArches=()
_raw_package_list() {
local suite="$1"; shift
local component="$1"; shift
local arch="$1"; shift
curl -fsSL "$packagesBase/$suite-pgdg/$component/binary-$arch/Packages.bz2" | bunzip2
}
fetch_suite_package_list() {
local suite="$1"; shift
local version="$1"; shift
local arch="$1"; shift
# normal (GA) releases end up in the "main" component of upstream's repository
if [ -z "${suitePackageList["$suite-$arch"]:+isset}" ]; then
local suiteArchPackageList
suiteArchPackageList="$(_raw_package_list "$suite" 'main' "$arch")"
suitePackageList["$suite-$arch"]="$suiteArchPackageList"
fi
# ... but pre-release versions (betas, etc) end up in the "PG_MAJOR" component (so we need to check both)
if [ -z "${suiteVersionPackageList["$suite-$version-$arch"]:+isset}" ]; then
local versionPackageList
versionPackageList="$(_raw_package_list "$suite" "$version" "$arch")"
suiteVersionPackageList["$suite-$version-$arch"]="$versionPackageList"
fi
}
awk_package_list() {
local suite="$1"; shift
local version="$1"; shift
local arch="$1"; shift
awk -F ': ' -v version="$version" "$@" <<<"${suitePackageList["$suite-$arch"]}"$'\n'"${suiteVersionPackageList["$suite-$version-$arch"]}"
}
fetch_suite_arches() {
local suite="$1"; shift
if [ -z "${suiteArches["$suite"]:+isset}" ]; then
local suiteRelease
suiteRelease="$(curl -fsSL "$packagesBase/$suite-pgdg/Release")"
suiteArches["$suite"]="$(gawk <<<"$suiteRelease" -F ':[[:space:]]+' '$1 == "Architectures" { print $2; exit }')"
fi
}
for version in "${versions[@]}"; do
export version
versionAlpineVersion="${alpineVersions[$version]:-$defaultAlpineVersion}"
versionDebianSuite="${debianSuites[$version]-$defaultDebianSuite}" # intentionally missing ":" so it can be empty (again, https://github.com/docker-library/postgres/issues/582 😭)
export versionAlpineVersion versionDebianSuite
doc="$(jq -nc '{
alpine: env.versionAlpineVersion,
debian: env.versionDebianSuite,
}')"
versionDebianSuites=()
for suite in "${allDebianSuites[@]}"; do
versionDebianSuites+=( "$suite" )
if [ "$suite" = "$versionDebianSuite" ]; then
# if our default is newer than stretch we shouldn't even consider providing stretch
break
fi
done
fullVersion=
for suite in "${versionDebianSuites[@]}"; do
fetch_suite_package_list "$suite" "$version" 'amd64'
suiteVersion="$(awk_package_list "$suite" "$version" 'amd64' '
$1 == "Package" { pkg = $2 }
$1 == "Version" && pkg == "postgresql-" version { print $2; exit }
')"
srcVersion="${suiteVersion%%-*}"
tilde='~'
srcVersion="${srcVersion//$tilde/}"
[ -n "$fullVersion" ] || fullVersion="$srcVersion"
if [ "$fullVersion" != "$srcVersion" ]; then
echo >&2 "warning: $version should be '$fullVersion' but $suite is '$srcVersion'"
continue
fi
versionArches='[]'
fetch_suite_arches "$suite"
for arch in ${suiteArches["$suite"]}; do
fetch_suite_package_list "$suite" "$version" "$arch"
archVersion="$(awk_package_list "$suite" "$version" "$arch" '
$1 == "Package" { pkg = $2 }
$1 == "Version" && pkg == "postgresql-" version { print $2; exit }
')"
if [ "$archVersion" = "$suiteVersion" ]; then
versionArches="$(jq <<<"$versionArches" -c --arg arch "$arch" '. += [$arch]')"
fi
done
export suite suiteVersion
doc="$(jq <<<"$doc" -c --argjson arches "$versionArches" '
.[env.suite] = {
version: env.suiteVersion,
arches: $arches,
}
| .debianSuites += [ env.suite ]
')"
done
sha256="$(
curl -fsSL "https://ftp.postgresql.org/pub/source/v${fullVersion}/postgresql-${fullVersion}.tar.bz2.sha256" \
| cut -d' ' -f1
)"
echo "$version: $fullVersion"
export fullVersion sha256 major="${version%%.*}"
json="$(jq <<<"$json" -c --argjson doc "$doc" '
.[env.version] = ($doc + {
version: env.fullVersion,
sha256: env.sha256,
major: (env.major | tonumber),
})
')"
done
jq <<<"$json" -S . > versions.json