forked from docker-library/php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·145 lines (128 loc) · 3.97 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
set -e
declare -A gpgKeys
gpgKeys=(
[7.0]='1A4E8B7277C42E53DBA9C7B9BCAA30EA9C0D5763'
[5.6]='0BD78B5F97500D450838F95DFE857D9A90D90EC1 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3'
[5.5]='0B96609E270F565C13292B24C13C70B87267B52D 0BD78B5F97500D450838F95DFE857D9A90D90EC1 F38252826ACD957EF380D39F2F7956BC5DA04B5D'
)
# see http://php.net/downloads.php
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
generated_warning() {
cat <<-EOH
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
EOH
}
jsonSh="$(curl -fsSL 'https://raw.githubusercontent.com/dominictarr/JSON.sh/ed3f9dd285ebd4183934adb54ea5a2fda6b25a98/JSON.sh')"
travisEnv=
for version in "${versions[@]}"; do
packagesJson="$(curl -fsSL "https://secure.php.net/releases/index.php?json&max=100&version=${version%%.*}" | bash -- <(echo "$jsonSh") -l)"
fullVersion=
filename=
sha256=
for comp in xz bz2 gz; do
fullVersion="$(
echo "$packagesJson" \
| grep '^\["'"$version"'[."].*,"filename"\].*\.'"$comp"'"' \
| cut -d'"' -f2 \
| head -1
)"
if [ "$fullVersion" ]; then
sourceNumber="$(
echo "$packagesJson" \
| grep '^\["'"$fullVersion"'","source",.*,"filename"\].*\.'"$comp"'"' \
| cut -d, -f3
)"
filename="$(
echo "$packagesJson" \
| grep '^\["'"$fullVersion"'","source",'"$sourceNumber"',"filename"\]' \
| cut -d$'\t' -f2 | cut -d'"' -f2
)"
sha256="$(
echo "$packagesJson" \
| grep '^\["'"$fullVersion"'","source",'"$sourceNumber"',"sha256"\]' \
| cut -d$'\t' -f2 | cut -d'"' -f2
)"
break
fi
done
if [ -z "$fullVersion" ]; then
echo >&2 "warning: missing full version for $version; skipping"
continue
fi
gpgKey="${gpgKeys[$version]}"
if [ -z "$gpgKey" ]; then
echo >&2 "ERROR: missing GPG key fingerprint for $version"
echo >&2 " try looking on http://php.net/downloads.php#gpg-$version"
exit 1
fi
dockerfiles=()
{ generated_warning; cat Dockerfile-debian.template; } > "$version/Dockerfile"
cp -v docker-php-ext-* "$version/"
cp -v docker-php-source "$version/"
dockerfiles+=( "$version/Dockerfile" )
if [ -d "$version/alpine" ]; then
{ generated_warning; cat Dockerfile-alpine.template; } > "$version/alpine/Dockerfile"
cp -v docker-php-ext-* "$version/alpine/"
cp -v docker-php-source "$version/alpine/"
dockerfiles+=( "$version/alpine/Dockerfile" )
fi
for target in \
apache \
fpm fpm/alpine \
zts zts/alpine \
; do
[ -d "$version/$target" ] || continue
base="$version/Dockerfile"
variant="${target%%/*}"
if [ "$target" != "$variant" ]; then
variantVariant="${target#$variant/}"
[ -d "$version/$variantVariant" ] || continue
base="$version/$variantVariant/Dockerfile"
fi
echo "Generating $version/$target/Dockerfile from $base + $variant-Dockerfile-block-*"
awk '
$1 == "##</autogenerated>##" { ia = 0 }
!ia { print }
$1 == "##<autogenerated>##" { ia = 1; ab++; ac = 0 }
ia { ac++ }
ia && ac == 1 { system("cat '$variant'-Dockerfile-block-" ab) }
' "$base" > "$version/$target/Dockerfile"
cp -v docker-php-ext-* "$version/$target/"
cp -v docker-php-source "$version/$target/"
dockerfiles+=( "$version/$target/Dockerfile" )
done
if [ -z "$fullVersion" ]; then
echo >&2 "ERROR: missing $version in $packagesUrl"
continue
fi
(
set -x
sed -ri '
s!%%PHP_VERSION%%!'"$fullVersion"'!;
s!%%PHP_FILENAME%%!'"$filename"'!;
s!%%PHP_SHA256%%!'"$sha256"'!;
s!%%GPG_KEYS%%!'"$gpgKey"'!;
' "${dockerfiles[@]}"
)
newTravisEnv=
for dockerfile in "${dockerfiles[@]}"; do
dir="${dockerfile%Dockerfile}"
dir="${dir%/}"
variant="${dir#$version}"
variant="${variant#/}"
newTravisEnv+='\n - VERSION='"$version VARIANT=$variant"
done
travisEnv="$newTravisEnv$travisEnv"
done
travis="$(awk -v 'RS=\n\n' '$1 == "env:" { $0 = "env:'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)"
echo "$travis" > .travis.yml