mariadb-docker/update.sh

220 lines
6.0 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)...]
#
2024-01-17 14:42:38 +11:00
defaultSuite='noble'
2015-07-20 15:28:26 -07:00
declare -A suites=(
[10.4]='focal'
[10.5]='focal'
[10.6]='focal'
2024-01-17 14:42:38 +11:00
[10.11]='jammy'
[11.0]='jammy'
[11.1]='jammy'
[11.2]='jammy'
[11.3]='jammy'
)
2015-07-20 15:28:26 -07:00
declare -A suffix=(
['focal']='ubu2004'
['jammy']='ubu2204'
2024-01-17 14:42:38 +11:00
['noble']='ubu2404'
)
#declare -A dpkgArchToBashbrew=(
# [amd64]='amd64'
# [armel]='arm32v5'
# [armhf]='arm32v7'
# [arm64]='arm64v8'
# [i386]='i386'
# [ppc64el]='ppc64le'
# [s390x]='s390x'
#)
# For testing with https://downloads.dev.mariadb.org/rest-api
typeset -r DOWNLOADS_REST_API="https://downloads.mariadb.org/rest-api"
update_version()
{
echo "$version: $mariaVersion ($releaseStatus)"
if [ -z "$ubi" ]; then
suite="${suites[$version]:-$defaultSuite}"
fullVersion=1:${mariaVersion}+maria~${suffix[${suite}]}
else
suite=
fullVersion=
cp docker.cnf "$version"
sed -e "s!%%MARIADB_VERSION%%!${version%-*}!" MariaDB-ubi.repo > "$version"/MariaDB.repo
fi
if [[ $version = 10.[234]* ]]; then
arches=" amd64 arm64v8 ppc64le"
else
arches=" amd64 arm64v8 ppc64le s390x"
2021-07-08 19:08:37 +10:00
fi
cp "Dockerfile${ubi}.template" "${version}/Dockerfile"
2022-03-04 16:15:13 +11:00
cp docker-entrypoint.sh healthcheck.sh "$version/"
chmod a+x "$version"/healthcheck.sh
sed -i \
-e 's!%%MARIADB_VERSION%%!'"$fullVersion"'!g' \
-e 's!%%MARIADB_VERSION_BASIC%%!'"$mariaVersion"'!g' \
-e 's!%%MARIADB_MAJOR%%!'"${version%-ubi}"'!g' \
-e 's!%%MARIADB_RELEASE_STATUS%%!'"$releaseStatus"'!g' \
2023-05-08 11:59:02 +10:00
-e 's!%%MARIADB_SUPPORT_TYPE%%!'"$supportType"'!g' \
-e 's!%%SUITE%%!'"$suite"'!g' \
-e 's!%%ARCHES%%! '"$arches"'!g' \
"$version/Dockerfile"
sed -i \
-e 's!%%MARIADB_VERSION_BASIC%%!'"$mariaVersion"'!g' \
"$version/docker-entrypoint.sh"
# Start using the new executable names
2021-09-03 16:35:24 +10:00
case "$version" in
2023-05-11 12:11:51 +10:00
10.4)
sed -i -e '/--old-mode/d' \
-e 's/REPLICATION REPLICA/REPLICATION SLAVE/' \
2023-10-30 12:54:45 +11:00
-e 's/START REPLICA/START SLAVE/' \
-e '/memory\.pressure/,+7d' \
"$version/docker-entrypoint.sh"
sed -i -e 's/ REPLICA\$/ SLAVE$/' "$version"/healthcheck.sh
sed -i -e 's/\/run/\/var\/run\//g' "$version/Dockerfile"
2023-11-28 18:34:50 +01:00
;; # almost nothing to see/do here
10.5)
2023-10-30 12:54:45 +11:00
sed -i -e '/--old-mode/d' \
-e '/memory\.pressure/,+7d' "$version/docker-entrypoint.sh"
sed -i '/backwards compat/d' "$version/Dockerfile"
;;
*)
sed -i -e '/^CMD/s/mysqld/mariadbd/' \
2023-11-28 18:34:50 +01:00
-e '/backwards compat/d' "$version/Dockerfile"
sed -i -e 's/mysql_upgrade\([^_]\)/mariadb-upgrade\1/' \
2023-11-28 18:34:50 +01:00
-e 's/mysqldump/mariadb-dump/' \
-e 's/mysqladmin/mariadb-admin/' \
-e 's/\bmysql --protocol\b/mariadb --protocol/' \
-e 's/mysql_install_db/mariadb-install-db/' \
-e 's/mysql_tzinfo_to_sql/mariadb-tzinfo-to-sql/' \
"$version/docker-entrypoint.sh"
2023-11-24 16:13:56 +11:00
if [ "$version" = 10.6 ]; then
# my_print_defaults didn't recognise --mysqld until 10.11
sed -i -e '0,/#ENDOFSUBSTITUTIONS/s/\([^-]\)mysqld/\1mariadbd/g' \
"$version/docker-entrypoint.sh"
else
sed -i -e '0,/#ENDOFSUBSTITUTIONS/s/\mysqld/mariadbd/g' \
"$version/docker-entrypoint.sh"
fi
sed -i -e '0,/#ENDOFSUBSTITUTIONS/s/\bmysql\b/mariadb/' "$version/healthcheck.sh"
if [[ ! "${version%-ubi}" =~ 10.[678] ]]; then
2022-10-14 14:33:54 +11:00
# quoted $ intentional
# shellcheck disable=SC2016
sed -i -e '/^ARG MARIADB_MAJOR/d' \
-e '/^ENV MARIADB_MAJOR/d' \
-e 's/-\$MARIADB_MAJOR//' \
"$version/Dockerfile"
2023-10-30 12:54:45 +11:00
else
sed -i -e '/memory\.pressure/,+7d' "$version/docker-entrypoint.sh"
2022-10-14 14:33:54 +11:00
fi
2023-03-24 11:35:52 +11:00
if [[ $version =~ 11.[012345] ]]; then
sed -i -e 's/mysql_upgrade_info/mariadb_upgrade_info/' \
"$version/docker-entrypoint.sh" "$version/healthcheck.sh"
fi
if [[ $version =~ 11.[01] ]]; then
sed -i -e 's/50-mysqld_safe.cnf/50-mariadb_safe.cnf/' "$version/Dockerfile"
fi
2022-10-14 14:33:54 +11:00
;&
2023-11-28 18:34:50 +01:00
esac
2023-11-28 18:34:50 +01:00
# Add version to versions.json
versionJson="$(jq -e \
--arg milestone "$version" --arg version "$mariaVersion" --arg fullVersion "$fullVersion" --arg releaseStatus "$releaseStatus" --arg supportType "$supportType" --arg base "ubuntu:$suite" --arg arches "$arches" \
'.[$milestone] = {"milestone": $milestone, "version": $version, "fullVersion": $fullVersion, "releaseStatus": $releaseStatus, "supportType": $supportType, "base": $base, "arches": $arches|split(" ")}' versions.json)"
printf '%s\n' "$versionJson" > versions.json
}
2023-05-08 11:59:02 +10:00
update_version_array()
{
c0=$(( $1 - 2 ))
c1=$(( $1 - 1 ))
version=${release[$c0]}
2023-05-08 11:59:02 +10:00
if [ ! -d "$version" ]; then
echo >&2 "warning: no rule for $version"
return
fi
mariaversion
releaseStatus=${release[$c1]}
2023-05-08 11:59:02 +10:00
case "$releaseStatus" in
Alpha | Beta | Gamma | RC | Stable ) ;; # sanity check
*) echo >&2 "error: unexpected 'release status' value for $mariaVersion: $releaseStatus"; ;;
esac
supportType=$2
2023-05-08 11:59:02 +10:00
update_version
}
2023-11-28 18:34:50 +01:00
mariaversion()
{
mariaVersion=$(curl -fsSL "$DOWNLOADS_REST_API/mariadb/${version%-*}" \
2023-11-28 18:34:50 +01:00
| jq -r 'first(.releases[]).release_id')
mariaVersion=${mariaVersion//\"}
}
all()
{
printf '%s\n' "{}" > versions.json
2023-05-08 11:59:02 +10:00
readarray -O 0 -c 3 -C update_version_array -t release <<< "$(curl -fsSL "$DOWNLOADS_REST_API/mariadb/" \
| jq -r '.major_releases[] | [ .release_id ], [ .release_status ], [ .release_support_type ] | @tsv')"
}
2024-02-12 10:03:42 +11:00
development_version=11.5
in_development()
{
releaseStatus=Alpha
2023-05-08 11:59:02 +10:00
supportType=Unknown
version=$development_version$ubi
mariaVersion=${development_version}.0
[ -d "$development_version" ] && update_version
}
if [ $# -eq 0 ]; then
in_development
ubi=-ubi in_development
2024-02-22 11:21:41 +11:00
all
exit 0
fi
versions=( "$@" )
for version in "${versions[@]}"; do
if [ "${version#*-}" = "ubi" ]; then
ubi=-ubi
else
ubi=
fi
if [ "${version%-*}" == $development_version ]; then
in_development
continue
fi
if [ ! -d "$version" ]; then
version=${version%.[[:digit:]]*}
else
mariaversion
fi
2023-05-08 11:59:02 +10:00
readarray -t release <<< "$(curl -fsSL "$DOWNLOADS_REST_API/mariadb/" \
| jq -r --arg version "${version%-*}" '.major_releases[] | select(.release_id == $version) | [ .release_status ] , [ .release_support_type ] | @tsv')"
releaseStatus=${release[0]}
supportType=${release[1]}
update_version
done