Skip to content

Commit 83ea443

Browse files
committed
Tianon requested changes
- fail on unset vars so that missing suites on new version gives a more useful error - prevent inconsistent bash handling of tilde in `${variable//~/}` - use associative array for suite to packages.gz cache
1 parent 010a4e7 commit 83ea443

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

update.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -eo pipefail
2+
set -Eeuo pipefail
33

44
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
55

@@ -26,27 +26,28 @@ declare -A alpineVersion=(
2626
[10]='3.6'
2727
)
2828

29+
packagesBase='http://apt.postgresql.org/pub/repos/apt/dists/'
30+
2931
# https://www.mirrorservice.org/sites/ftp.ossp.org/pkg/lib/uuid/?C=M;O=D
3032
osspUuidVersion='1.6.2'
3133
osspUuidHash='11a615225baa5f8bb686824423f50e4427acd3f70d394765bdff32801f0fd5b0'
3234

33-
lastSuite=
35+
declare -A suitePackageList
3436
travisEnv=
3537
for version in "${versions[@]}"; do
36-
if [ "${debianSuite[$version]}" != "$lastSuite" ]; then
37-
lastSuite="${debianSuite[$version]}"
38-
packagesBase='http://apt.postgresql.org/pub/repos/apt/dists/'"${debianSuite[$version]}"'-pgdg'
39-
mainList="$(curl -fsSL "$packagesBase/main/binary-amd64/Packages.bz2" | bunzip2)"
38+
suite="${debianSuite[$version]}"
39+
if [ -z "${suitePackageList["$suite"]:+isset}" ]; then
40+
suitePackageList["$suite"]="$(curl -fsSL "${packagesBase}/${suite}-pgdg/main/binary-amd64/Packages.bz2" | bunzip2)"
4041
fi
4142

42-
versionList="$(echo "$mainList"; curl -fsSL "$packagesBase/$version/binary-amd64/Packages.bz2" | bunzip2)"
43+
versionList="$(echo "${suitePackageList["$suite"]}"; curl -fsSL "${packagesBase}/${suite}-pgdg/${version}/binary-amd64/Packages.bz2" | bunzip2)"
4344
fullVersion="$(echo "$versionList" | awk -F ': ' '$1 == "Package" { pkg = $2 } $1 == "Version" && pkg == "postgresql-'"$version"'" { print $2; exit }' || true)"
4445
(
4546
set -x
4647
cp docker-entrypoint.sh "$version/"
4748
sed -e 's/%%PG_MAJOR%%/'"$version"'/g;' \
4849
-e 's/%%PG_VERSION%%/'"$fullVersion"'/g' \
49-
-e 's/%%DEBIAN_SUITE%%/'"${debianSuite[$version]}"'/g' \
50+
-e 's/%%DEBIAN_SUITE%%/'"$suite"'/g' \
5051
Dockerfile-debian.template > "$version/Dockerfile"
5152
if [ "$version" = '10' ]; then
5253
# postgresql-contrib-10 package does not exist, but is provided by postgresql-10
@@ -60,7 +61,8 @@ for version in "${versions[@]}"; do
6061
# TODO figure out what to do with odd version numbers here, like release candidates
6162
srcVersion="${fullVersion%%-*}"
6263
# change "10~beta1" to "10beta1" for ftp urls
63-
srcVersion="${srcVersion//\~/}"
64+
tilde='~'
65+
srcVersion="${srcVersion//$tilde/}"
6466
srcSha256="$(curl -fsSL "https://ftp.postgresql.org/pub/source/v${srcVersion}/postgresql-${srcVersion}.tar.bz2.sha256" | cut -d' ' -f1)"
6567
for variant in alpine; do
6668
if [ ! -d "$version/$variant" ]; then

0 commit comments

Comments
 (0)