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