mariadb-docker/update.sh

133 lines
3.7 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -Eeuo pipefail
2021-10-25 08:52:18 +11:00
#
# Usage ./update.sh [version(multiple)...]
#
2020-06-11 04:25:14 +02:00
defaultSuite='focal'
2015-07-20 15:28:26 -07:00
declare -A suites=(
2020-06-11 04:25:14 +02:00
[10.2]='bionic'
)
declare -A dpkgArchToBashbrew=(
[amd64]='amd64'
[armel]='arm32v5'
[armhf]='arm32v7'
[arm64]='arm64v8'
[i386]='i386'
[ppc64el]='ppc64le'
[s390x]='s390x'
)
getRemoteVersion() {
2020-06-11 04:25:14 +02:00
local version="$1"; shift # 10.4
local suite="$1"; shift # focal
2020-04-16 00:06:26 -07:00
local dpkgArch="$1"; shift # arm64
echo "$(
2019-07-11 20:00:53 +02:00
curl -fsSL "https://ftp.osuosl.org/pub/mariadb/repo/$version/ubuntu/dists/$suite/main/binary-$dpkgArch/Packages" 2>/dev/null \
| tac|tac \
2018-08-02 10:24:48 -07:00
| awk -F ': ' '$1 == "Package" { pkg = $2; next } $1 == "Version" && pkg == "mariadb-server-'"$version"'" { print $2; exit }'
)"
}
2015-07-20 15:28:26 -07:00
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
GLOBIGNORE=.*:tests
versions=( */ )
fi
versions=( "${versions[@]%/}" )
for version in "${versions[@]}"; do
2021-11-05 08:30:59 +11:00
if [ "$version" == 10.8 ]; then
version=10.8.0
fi
if [ ! -d "$version" ]; then
# assume full version and trim this to major version
ExpectedFullVersion=$version
version=${version%.[[:digit:]]*}
else
ExpectedFullVersion=
fi
2015-07-20 15:28:26 -07:00
suite="${suites[$version]:-$defaultSuite}"
fullVersion="$(getRemoteVersion "$version" "$suite" 'amd64')"
2015-07-20 15:28:26 -07:00
if [ -z "$fullVersion" ]; then
echo >&2 "warning: cannot find $version in $suite"
2021-07-08 19:08:37 +10:00
fullVersion=1:$version+maria~$suite
echo >&2 "warning: assuming full version=$fullVersion"
2015-07-20 15:28:26 -07:00
fi
mariaVersion="${fullVersion##*:}"
mariaVersion="${mariaVersion%%[-+~]*}"
if [ -n "$ExpectedFullVersion" ] && [ "$ExpectedFullVersion" != "$mariaVersion" ]; then
echo >&2 "warning: Version $ExpectedFullVersion is not the latest on the mirror, $mariaVersion is (for suite=$suite)"
mariaVersion="$ExpectedFullVersion"
fullVersion="1:${mariaVersion}+maria~${suite}"
echo >&2 "warning: continuing with $fullVersion"
fi
# "Alpha", "Beta", "Gamma", "RC", "Stable", etc.
releaseStatus="$(
wget -qO- 'https://downloads.mariadb.org/mariadb/+releases/' \
| xargs -d '\n' \
| grep -oP '<tr>.+?</tr>' \
| grep -P '>\Q'"$mariaVersion"'\E<' \
| grep -oP '<td>[^0-9][^<]*</td>' \
2021-07-08 19:08:37 +10:00
| sed -r 's!^.*<td>([^0-9][^<]*)</td>.*$!\1!' || echo Alpha
)"
case "$releaseStatus" in
Alpha | Beta | Gamma | RC | Stable ) ;; # sanity check
2021-07-08 19:08:37 +10:00
*) echo >&2 "error: unexpected 'release status' value for $mariaVersion: $releaseStatus"; ;;
esac
echo "$version: $mariaVersion ($releaseStatus)"
arches=
sortedArches="$(echo "${!dpkgArchToBashbrew[@]}" | xargs -n1 | sort | xargs)"
for arch in $sortedArches; do
if ver="$(getRemoteVersion "$version" "$suite" "$arch")" && [ -n "$ver" ]; then
arches="$arches ${dpkgArchToBashbrew[$arch]}"
fi
done
2021-07-08 19:08:37 +10:00
if [ -z "$arches" ]; then
# assume default
2021-10-25 09:24:48 +11:00
arches=" amd64 arm64v8 ppc64le s390x"
2021-07-08 19:08:37 +10:00
fi
cp Dockerfile.template "$version/Dockerfile"
backup='mariadb-backup'
if [[ "$version" < 10.3 ]]; then
2021-03-01 17:25:31 +11:00
# 10.2 has mariadb major version in the package name
backup="$backup-$version"
fi
cp docker-entrypoint.sh "$version/"
sed -i \
-e 's!%%MARIADB_VERSION%%!'"$fullVersion"'!g' \
-e 's!%%MARIADB_VERSION_BASIC%%!'"$mariaVersion"'!g' \
-e 's!%%MARIADB_MAJOR%%!'"$version"'!g' \
-e 's!%%MARIADB_RELEASE_STATUS%%!'"$releaseStatus"'!g' \
-e 's!%%SUITE%%!'"$suite"'!g' \
-e 's!%%BACKUP_PACKAGE%%!'"$backup"'!g' \
-e 's!%%ARCHES%%!'"$arches"'!g' \
"$version/Dockerfile"
if [ "$suite" = bionic ]
then
sed -i 's/libjemalloc2/libjemalloc1/' "$version/Dockerfile"
fi
2019-12-03 16:18:48 -08:00
case "$version" in
2021-03-01 17:25:31 +11:00
10.2 | 10.3 | 10.4) ;;
2019-12-03 16:18:48 -08:00
*) sed -i '/backwards compat/d' "$version/Dockerfile" ;;
esac
2021-09-03 16:35:24 +10:00
# Start using the new executable, mariadbd
case "$version" in
10.2 | 10.3 | 10.4 | 10.5) ;;
*) sed -i -e '/^CMD/s/mysqld/mariadbd/' "$version/Dockerfile"
esac
done