php/versions.sh

163 lines
4.4 KiB
Bash
Raw Normal View History

2020-08-18 07:12:07 +02:00
#!/usr/bin/env bash
set -Eeuo pipefail
# https://www.php.net/gpg-keys.php
declare -A gpgKeys=(
2021-06-10 18:29:58 +02:00
# https://wiki.php.net/todo/php81
# krakjoe & ramsey & patrickallaert
# https://www.php.net/gpg-keys.php#gpg-8.1
[8.1]='528995BFEDFBA7191D46839EF9BA0ADA31CBD89E 39B641343D8C104B2B146DC3F9C39DC0B9698544 F1F692238FBC1666E5A5CCD4199F9DFEF6FFBAFD'
2020-08-18 07:12:07 +02:00
# https://wiki.php.net/todo/php80
# pollita & carusogabriel
# https://www.php.net/gpg-keys.php#gpg-8.0
[8.0]='1729F83938DA44E27BA0F4D3DBDB397470D12172 BFDDD28642824F8118EF77909B67A5C12229118F'
# https://wiki.php.net/todo/php74
# petk & derick
# https://www.php.net/gpg-keys.php#gpg-7.4
[7.4]='42670A7FE4D0441C8E4632349E4FDC074A4EF02D 5A52880781F755608BF815FC910DEB46F53EA312'
# https://wiki.php.net/todo/php73
# cmb & stas
# https://www.php.net/gpg-keys.php#gpg-7.3
[7.3]='CBAF69F173A0FEA4B537F470D66C9593118BCCB6 F38252826ACD957EF380D39F2F7956BC5DA04B5D'
# https://wiki.php.net/todo/php72
# pollita & remi
# https://www.php.net/downloads.php#gpg-7.2
# https://www.php.net/gpg-keys.php#gpg-7.2
[7.2]='1729F83938DA44E27BA0F4D3DBDB397470D12172 B1B44D8F021E4E2D6021E995DC9FF8D3EE5AF27F'
)
# see https://www.php.net/downloads.php
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
json='{}'
else
json="$(< versions.json)"
fi
versions=( "${versions[@]%/}" )
for version in "${versions[@]}"; do
rcVersion="${version%-rc}"
export version rcVersion
# scrape the relevant API based on whether we're looking for pre-releases
if [ "$rcVersion" = "$version" ]; then
apiUrl="https://www.php.net/releases/index.php?json&max=100&version=${rcVersion%%.*}"
apiJqExpr='
(keys[] | select(startswith(env.rcVersion))) as $version
| [ $version, (
.[$version].source[]
| select(.filename | endswith(".xz"))
|
"https://www.php.net/distributions/" + .filename,
"https://www.php.net/distributions/" + .filename + ".asc",
2020-10-29 18:27:05 +01:00
.sha256 // ""
2020-08-18 07:12:07 +02:00
) ]
'
else
apiUrl='https://qa.php.net/api.php?type=qa-releases&format=json'
apiJqExpr='
(.releases // [])[]
2020-08-18 07:12:07 +02:00
| select(.version | startswith(env.rcVersion))
| [
.version,
.files.xz.path // "",
"",
2020-10-29 18:27:05 +01:00
.files.xz.sha256 // ""
2020-08-18 07:12:07 +02:00
]
'
fi
IFS=$'\n'
possibles=( $(
curl -fsSL "$apiUrl" \
| jq --raw-output "$apiJqExpr | @sh" \
| sort -rV
) )
unset IFS
if [ "${#possibles[@]}" -eq 0 ]; then
if [ "$rcVersion" = "$version" ]; then
echo >&2
echo >&2 "error: unable to determine available releases of $version"
echo >&2
exit 1
else
echo >&2 "warning: skipping/removing '$version' (does not appear to exist upstream)"
json="$(jq <<<"$json" -c '.[env.version] = null')"
continue
fi
2020-08-18 07:12:07 +02:00
fi
2020-10-29 18:27:05 +01:00
# format of "possibles" array entries is "VERSION URL.TAR.XZ URL.TAR.XZ.ASC SHA256" (each value shell quoted)
2020-08-18 07:12:07 +02:00
# see the "apiJqExpr" values above for more details
eval "possi=( ${possibles[0]} )"
fullVersion="${possi[0]}"
url="${possi[1]}"
ascUrl="${possi[2]}"
sha256="${possi[3]}"
gpgKey="${gpgKeys[$rcVersion]:-}"
if [ -z "$gpgKey" ]; then
echo >&2 "ERROR: missing GPG key fingerprint for $version"
2021-06-10 18:29:58 +02:00
echo >&2 " try looking on https://www.php.net/downloads.php#gpg-$rcVersion"
2020-08-18 07:12:07 +02:00
echo >&2 " (and update 'gpgKeys' array in '$BASH_SOURCE')"
exit 1
fi
if ! wget -q --spider "$url"; then
echo >&2 "error: '$url' appears to be missing"
exit 1
fi
2020-08-18 07:12:07 +02:00
# if we don't have a .asc URL, let's see if we can figure one out :)
if [ -z "$ascUrl" ] && wget -q --spider "$url.asc"; then
ascUrl="$url.asc"
fi
variants='[]'
# order here controls the order of the library/ file
for suite in \
bullseye \
2020-08-18 07:12:07 +02:00
buster \
2021-11-25 11:35:55 +01:00
alpine3.15 \
2021-06-16 14:55:20 +02:00
alpine3.14 \
2020-08-18 07:12:07 +02:00
; do
for variant in cli apache fpm zts; do
if [[ "$suite" = alpine* ]]; then
if [ "$variant" = 'apache' ]; then
continue
elif [ "$variant" = 'zts' ] && [[ "$rcVersion" != 7.* ]]; then
# https://github.com/docker-library/php/issues/1074
continue
fi
fi
2020-08-18 07:12:07 +02:00
export suite variant
variants="$(jq <<<"$variants" -c '. + [ env.suite + "/" + env.variant ]')"
done
done
echo "$version: $fullVersion"
2020-10-29 18:27:05 +01:00
export fullVersion url ascUrl sha256 gpgKey
2020-08-18 07:12:07 +02:00
json="$(
jq <<<"$json" -c \
--argjson variants "$variants" \
'.[env.version] = {
version: env.fullVersion,
url: env.url,
ascUrl: env.ascUrl,
sha256: env.sha256,
gpgKeys: env.gpgKey,
variants: $variants,
}'
)"
done
jq <<<"$json" -S . > versions.json