Skip to content

Commit 2cb9a62

Browse files
committed
update.sh: Add some comments and code cleanup
This commit includes no functional changes. Signed-off-by: Daniel Rudolf <[email protected]>
1 parent 4a5875f commit 2cb9a62

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

update.sh

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
#!/bin/bash
2-
set -eu -o pipefail -x
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-
[ -n "${BASH_VERSINFO}" ] && [ -n "${BASH_VERSINFO[0]}" ] && [ ${BASH_VERSINFO[0]} -ge 4 ] \
8-
|| { echo >&2 "Bash 4.0 or greater is required. Aborting."; exit 1; }
4+
variants=(
5+
apache
6+
fpm
7+
fpm-alpine
8+
)
9+
10+
declare -A base=(
11+
[apache]='debian'
12+
[fpm]='debian'
13+
[fpm-alpine]='alpine'
14+
)
915

1016
declare -A php_version=(
1117
[default]='8.1'
@@ -17,12 +23,6 @@ declare -A cmd=(
1723
[fpm-alpine]='php-fpm'
1824
)
1925

20-
declare -A base=(
21-
[apache]='debian'
22-
[fpm]='debian'
23-
[fpm-alpine]='alpine'
24-
)
25-
2626
gpg_key='3D06A59ECE730EB71B511C17CE752F178259BD92'
2727

2828
function download_url() {
@@ -41,28 +41,42 @@ function create_variant() {
4141

4242
echo "updating $version [$branch] $variant"
4343

44+
# Create Dockerfile
4445
local template="Dockerfile-${base[$variant]}.template"
4546
cp "$template" "$variant/Dockerfile"
46-
cp config.inc.php "$variant/config.inc.php"
47-
cp docker-entrypoint.sh "$variant/docker-entrypoint.sh"
47+
48+
# Replace Dockerfile variables
4849
sed -ri -e '
50+
s/%%VARIANT%%/'"$variant"'/;
4951
s/%%VERSION%%/'"$version"'/;
5052
s/%%SHA256%%/'"$sha256"'/;
5153
s/%%DOWNLOAD_URL%%/'"$(sed -e 's/[\/&]/\\&/g' <<< "$url")"'/;
5254
s/%%DOWNLOAD_URL_ASC%%/'"$(sed -e 's/[\/&]/\\&/g' <<< "$ascUrl")"'/;
5355
s/%%PHP_VERSION%%/'"$phpVersion"'/g;
5456
s/%%GPG_KEY%%/'"$gpg_key"'/g;
55-
s/%%VARIANT%%/'"$variant"'/;
5657
s/%%CMD%%/'"${cmd[$variant]}"'/;
5758
' "$variant/Dockerfile"
59+
60+
# Copy docker-entrypoint.sh
61+
cp docker-entrypoint.sh "$variant/docker-entrypoint.sh"
5862
if [ "$variant" != "apache" ]; then
5963
sed -i "/^# start: Apache specific settings$/,/^# end: Apache specific settings$/d" "$variant/docker-entrypoint.sh"
6064
fi
65+
66+
# Copy config.inc.php
67+
cp config.inc.php "$variant/config.inc.php"
6168
}
6269

63-
latest="$(curl -fsSL 'https://www.phpmyadmin.net/home_page/version.json' | jq -r '.version')"
70+
# Check script dependencies
71+
command -v curl >/dev/null 2>&1 || { echo >&2 "'curl' is required but not found. Aborting."; exit 1; }
72+
command -v jq >/dev/null 2>&1 || { echo >&2 "'jq' is required but not found. Aborting."; exit 1; }
73+
[ -n "${BASH_VERSINFO}" ] && [ -n "${BASH_VERSINFO[0]}" ] && [ ${BASH_VERSINFO[0]} -ge 4 ] \
74+
|| { echo >&2 "Bash 4.0 or greater is required. Aborting."; exit 1; }
75+
76+
# Create variants
77+
latest="$(curl -fsSL "https://www.phpmyadmin.net/home_page/version.json" | jq -r '.version')"
6478
sha256="$(curl -fsSL "$(download_url "$latest").sha256" | cut -f1 -d ' ' | tr -cd 'a-f0-9' | cut -c 1-64)"
6579

66-
for variant in apache fpm fpm-alpine; do
80+
for variant in "${variants[@]}"; do
6781
create_variant "$variant" "$latest" "$sha256"
6882
done

0 commit comments

Comments
 (0)