11#! /bin/bash
2- set -e
2+ set -eu -o pipefail
33
4- # Check for dependencies
5- command -v curl > /dev/null 2>&1 || { echo >&2 " 'curl' is required but not found. Aborting." ; exit 1; }
6- command -v jq > /dev/null 2>&1 || { echo >&2 " 'jq' is required but not found. Aborting." ; exit 1; }
7- if [ -z " ${BASH_VERSINFO} " ] || [ -z " ${BASH_VERSINFO[0]} " ] || [ ${BASH_VERSINFO[0]} -lt 4 ]; then
8- echo " BASH version 4.0 or greater is required. Aborting."
9- exit 1
10- fi
11-
12- declare -A cmd=(
13- [apache]=' apache2-foreground'
14- [fpm]=' php-fpm'
15- [fpm-alpine]=' php-fpm'
4+ variants=(
5+ apache
6+ fpm
7+ fpm-alpine
168)
179
1810declare -A base=(
@@ -21,21 +13,87 @@ declare -A base=(
2113 [fpm-alpine]=' alpine'
2214)
2315
24- latest=" $( curl -fsSL ' https://www.phpmyadmin.net/home_page/version.json' | jq -r ' .version' ) "
25- sha256=" $( curl -fsSL " https://files.phpmyadmin.net/phpMyAdmin/$latest /phpMyAdmin-$latest -all-languages.tar.xz.sha256" | cut -f1 -d ' ' | tr -cd ' a-f0-9' | cut -c 1-64) "
16+ declare -A php_version=(
17+ [default]=' 8.2'
18+ )
2619
27- for variant in apache fpm fpm-alpine; do
28- template=" Dockerfile-${base[$variant]} .template"
29- cp $template " $variant /Dockerfile"
30- cp config.inc.php " $variant /config.inc.php"
31- cp docker-entrypoint.sh " $variant /docker-entrypoint.sh"
20+ declare -A cmd=(
21+ [apache]=' apache2-foreground'
22+ [fpm]=' php-fpm'
23+ [fpm-alpine]=' php-fpm'
24+ )
25+
26+ gpg_key=' 3D06A59ECE730EB71B511C17CE752F178259BD92'
27+
28+ function download_url() {
29+ echo " https://files.phpmyadmin.net/phpMyAdmin/$1 /phpMyAdmin-$1 -all-languages.tar.xz"
30+ }
31+
32+ function create_variant() {
33+ local variant=" $1 "
34+ local version=" $2 "
35+ local sha256=" $3 "
36+
37+ local branch=" $( sed -ne ' s/^\([0-9]*\.[0-9]*\)\..*$/\1/p' <<< " $version" ) "
38+ local url=" $( download_url " $version " ) "
39+ local ascUrl=" $( download_url " $version " ) .asc"
40+ local phpVersion=" ${php_version[$version]-${php_version[default]} } "
41+
42+ echo " updating $version [$branch ] $variant "
43+
44+ # Create the variant directory with a Dockerfile
45+ mkdir -p " $variant "
46+
47+ local template=" Dockerfile-${base[$variant]} .template"
48+ echo " # DO NOT EDIT: created by update.sh from $template " > " $variant /Dockerfile"
49+ cat " $template " >> " $variant /Dockerfile"
50+
51+ # Replace Dockerfile variables
3252 sed -ri -e '
33- s/%%VERSION%%/' " $latest " ' /;
34- s/%%SHA256%%/' " $sha256 " ' /;
3553 s/%%VARIANT%%/' " $variant " ' /;
54+ s/%%VERSION%%/' " $version " ' /;
55+ s/%%SHA256%%/' " $sha256 " ' /;
56+ s/%%DOWNLOAD_URL%%/' " $( sed -e ' s/[\/&]/\\&/g' <<< " $url" ) " ' /;
57+ s/%%DOWNLOAD_URL_ASC%%/' " $( sed -e ' s/[\/&]/\\&/g' <<< " $ascUrl" ) " ' /;
58+ s/%%PHP_VERSION%%/' " $phpVersion " ' /g;
59+ s/%%GPG_KEY%%/' " $gpg_key " ' /g;
3660 s/%%CMD%%/' " ${cmd[$variant]} " ' /;
3761 ' " $variant /Dockerfile"
62+
63+ # Copy docker-entrypoint.sh
64+ cp docker-entrypoint.sh " $variant /docker-entrypoint.sh"
3865 if [ " $variant " != " apache" ]; then
3966 sed -i " /^# start: Apache specific settings$/,/^# end: Apache specific settings$/d" " $variant /docker-entrypoint.sh"
4067 fi
68+
69+ # Copy config.inc.php
70+ cp config.inc.php " $variant /config.inc.php"
71+
72+ # Add variant to versions.json
73+ versionVariantsJson=" $( jq -e \
74+ --arg branch " $branch " --arg variant " $variant " --arg base " ${base[$variant]} " --arg phpVersion " $phpVersion " \
75+ ' .[$branch].variants[$variant] = {"variant": $variant, "base": $base, "phpVersion": $phpVersion}' versions.json) "
76+ versionJson=" $( jq -e \
77+ --arg branch " $branch " --arg version " $version " --arg sha256 " $sha256 " --arg url " $url " --arg ascUrl " $ascUrl " --argjson variants " $versionVariantsJson " \
78+ ' .[$branch] = {"branch": $branch, "version": $version, "sha256": $sha256, "url": $url, "ascUrl": $ascUrl, "variants": $variants[$branch].variants}' versions.json) "
79+ printf ' %s\n' " $versionJson " > versions.json
80+ }
81+
82+ # Check script dependencies
83+ command -v curl > /dev/null 2>&1 || { echo >&2 " 'curl' is required but not found. Aborting." ; exit 1; }
84+ command -v jq > /dev/null 2>&1 || { echo >&2 " 'jq' is required but not found. Aborting." ; exit 1; }
85+ [ -n " ${BASH_VERSINFO} " ] && [ -n " ${BASH_VERSINFO[0]} " ] && [ ${BASH_VERSINFO[0]} -ge 4 ] \
86+ || { echo >&2 " Bash 4.0 or greater is required. Aborting." ; exit 1; }
87+
88+ # Create variants
89+ printf ' %s\n' " {}" > versions.json
90+
91+ latest=" $( curl -fsSL " https://www.phpmyadmin.net/home_page/version.json" | jq -r ' .version' ) "
92+ sha256=" $( curl -fsSL " $( download_url " $latest " ) .sha256" | cut -f1 -d ' ' | tr -cd ' a-f0-9' | cut -c 1-64) "
93+
94+ for variant in " ${variants[@]} " ; do
95+ create_variant " $variant " " $latest " " $sha256 "
4196done
97+
98+ # Cleanup the file as for now it's not wanted in the repository
99+ rm versions.json
0 commit comments