docker-php-extension-installer/scripts/update-readme

217 lines
7.1 KiB
Plaintext
Raw Normal View History

2018-04-11 15:39:10 +00:00
#!/bin/sh
set -o errexit
set -o nounset
2019-12-20 15:52:00 +00:00
SCRIPTS_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
ROOT_DIR="$(dirname -- "$SCRIPTS_DIR")"
DATA_DIR="$ROOT_DIR/data"
2018-04-11 15:39:10 +00:00
2019-12-20 15:52:00 +00:00
. "$SCRIPTS_DIR/common"
2018-04-11 15:39:10 +00:00
# Get the list of PHP extensions from the data file
#
# Arguments:
# $1: the path to the data file
#
# Output:
# the list of PHP extensions
2019-12-20 15:52:00 +00:00
getExtensionList() {
2018-04-11 15:39:10 +00:00
getExtensionList_extensions=''
IFS='
'
2019-12-20 15:52:00 +00:00
for getExtensionList_line in $(cat -- "$1" | sort); do
2018-04-11 15:39:10 +00:00
getExtensionList_extension=''
IFS=' '
2019-12-20 15:52:00 +00:00
for getExtensionList_chunk in $getExtensionList_line; do
if test -z "$getExtensionList_extensions"; then
getExtensionList_extensions="$getExtensionList_chunk"
2018-04-11 15:39:10 +00:00
else
2019-12-20 15:52:00 +00:00
getExtensionList_extensions="$getExtensionList_extensions $getExtensionList_chunk"
2018-04-11 15:39:10 +00:00
fi
break
done
done
2019-12-20 15:52:00 +00:00
printf '%s' "$getExtensionList_extensions"
2018-04-11 15:39:10 +00:00
}
# Get the list of PHP versions from the data file
#
# Arguments:
# $1: the path to the data file
#
# Output:
# the list of PHP versions
2019-12-20 15:52:00 +00:00
getVersionList() {
2018-04-11 15:39:10 +00:00
getVersionList_versions=''
IFS='
'
2019-12-20 15:52:00 +00:00
for getVersionList_line in $(cat -- "$1" | sort); do
2018-04-11 15:39:10 +00:00
getVersionList_extension=''
IFS=' '
2019-12-20 15:52:00 +00:00
for getVersionList_chunk in $getVersionList_line; do
if test -z "$getVersionList_extension"; then
getVersionList_extension="$getVersionList_chunk"
elif test -z "$getVersionList_versions"; then
getVersionList_versions="$getVersionList_chunk"
elif ! stringInList "$getVersionList_chunk" "$getVersionList_versions"; then
getVersionList_versions="$getVersionList_versions $getVersionList_chunk"
2018-04-11 15:39:10 +00:00
fi
done
done
2019-12-20 15:52:00 +00:00
sortVersionList "$getVersionList_versions"
2018-04-11 15:39:10 +00:00
}
# Sort the list of PHP versions
#
# Arguments:
# $1: the list of PHP versions
#
# Output:
# the sorted list of PHP versions
2019-12-20 15:52:00 +00:00
sortVersionList() {
2018-04-11 15:39:10 +00:00
sortVersionList_list=''
IFS='
'
2019-12-20 15:52:00 +00:00
for sortVersionList_version in $(printf '%s' "$1" | tr ' ' '\n' | sort -t '.' -k 1,1n -k 2,2n -k 3,3n); do
if test -z "$sortVersionList_list"; then
sortVersionList_list="$sortVersionList_version"
2018-04-11 15:39:10 +00:00
else
2019-12-20 15:52:00 +00:00
sortVersionList_list="$sortVersionList_list $sortVersionList_version"
2018-04-11 15:39:10 +00:00
fi
done
2019-12-20 15:52:00 +00:00
printf '%s' "$sortVersionList_list"
2018-04-11 15:39:10 +00:00
}
# Generate the markdown table with the supported PHP extensions
#
# Arguments:
# $1: the path to the data file
#
# Output:
# the markdown table
2019-12-20 15:52:00 +00:00
generateExtensionsTable() {
generateExtensionsTable_data=$(cat "$1")
generateExtensionsTable_extensions="$(getExtensionList "$1")"
generateExtensionsTable_versions="$(getVersionList "$1")"
2019-12-17 09:25:57 +00:00
generateExtensionsTable_count=0
2018-04-11 15:39:10 +00:00
printf '| Extension |'
IFS=' '
2019-12-20 15:52:00 +00:00
for generateExtensionsTable_version in $generateExtensionsTable_versions; do
printf ' PHP %s |' "$generateExtensionsTable_version"
2018-04-11 15:39:10 +00:00
done
printf '\n'
printf '|:---:|'
2019-12-20 15:52:00 +00:00
for generateExtensionsTable_version in $generateExtensionsTable_versions; do
2018-04-11 15:39:10 +00:00
printf -- ':---:|'
done
printf '\n'
IFS=' '
2019-12-20 15:52:00 +00:00
for generateExtensionsTable_extension in $generateExtensionsTable_extensions; do
2019-12-17 09:25:57 +00:00
generateExtensionsTable_count=$((generateExtensionsTable_count + 1))
2019-12-20 15:52:00 +00:00
printf '| %s |' "$generateExtensionsTable_extension"
2018-04-11 15:39:10 +00:00
IFS=' '
2019-12-20 15:52:00 +00:00
for generateExtensionsTable_version in $generateExtensionsTable_versions; do
2018-04-11 15:39:10 +00:00
printf ' '
generateExtensionsTable_versionOk=''
IFS='
'
2019-12-20 15:52:00 +00:00
for generateExtensionsTable_dataLine in $generateExtensionsTable_data; do
if stringInList "$generateExtensionsTable_extension" "$generateExtensionsTable_dataLine"; then
if stringInList "$generateExtensionsTable_version" "$generateExtensionsTable_dataLine"; then
2018-04-11 15:39:10 +00:00
generateExtensionsTable_versionOk='y'
fi
break
fi
done
2019-12-20 15:52:00 +00:00
if test -n "$generateExtensionsTable_versionOk"; then
2020-02-21 13:39:01 +00:00
printf '✓'
2018-04-11 15:39:10 +00:00
fi
printf ' |'
done
printf '\n'
done
2019-12-17 09:25:57 +00:00
printf '\n'
printf '*Number of supported extensions: %s*\n' $generateExtensionsTable_count
2018-04-11 15:39:10 +00:00
}
# Generate the markdown table with the special requirements for the PHP extensions
#
# Arguments:
# $1: the path to the data file
#
# Output:
# the markdown table
2019-12-20 15:52:00 +00:00
generateSpecialRequirementsTable() {
2018-04-11 15:39:10 +00:00
generateSpecialRequirementsTable_started=''
IFS='
'
2019-12-20 15:52:00 +00:00
for generateSpecialRequirementsTable_line in $(cat -- "$1" | sort); do
if test -z "$generateSpecialRequirementsTable_started"; then
2018-04-11 15:39:10 +00:00
printf '| Extension | Requirements |\n'
printf '|:---:|:---:|\n'
generateSpecialRequirementsTable_started='y'
2018-04-11 15:39:10 +00:00
fi
resetIFS
2019-12-20 15:52:00 +00:00
generateSpecialRequirementsTable_requirement="$(echo "$generateSpecialRequirementsTable_line" | sed -E 's/^\s*\w+\s+//')"
case "$generateSpecialRequirementsTable_requirement" in
2018-04-11 15:39:10 +00:00
zts)
generateSpecialRequirementsTable_requirement='Requires images with PHP compiled with thread-safety enabled (`zts`).'
;;
esac
printf '| %s | %s |\n' \
2019-12-20 15:52:00 +00:00
"$(echo "$generateSpecialRequirementsTable_line" | awk '{print $1;}')" \
"$generateSpecialRequirementsTable_requirement"
2018-04-11 15:39:10 +00:00
done
}
# Generate the contents of README.md
#
# Arguments:
# $1: the path to the README file
# $2: the path to the extensions data file
# $3: the path to the special requirements data file
#
# Output:
# the markdown table
2019-12-20 15:52:00 +00:00
generateReadme() {
2018-04-11 15:39:10 +00:00
generateReadme_ph_ExtensionsStart='<!-- START OF EXTENSIONS TABLE -->'
generateReadme_ph_ExtensionsEnd='<!-- END OF EXTENSIONS TABLE -->'
generateReadme_ph_SpecialStart='<!-- START OF SPECIAL REQUIREMENTS -->'
generateReadme_ph_SpecialEnd='<!-- END OF SPECIAL REQUIREMENTS -->'
generateReadme_skip=''
while IFS= read -r generateReadme_line; do
2019-12-20 15:52:00 +00:00
if test "$generateReadme_line" = "$generateReadme_ph_ExtensionsEnd" || test "$generateReadme_line" = "$generateReadme_ph_SpecialEnd"; then
2018-04-11 15:39:10 +00:00
generateReadme_skip=''
fi
2019-12-20 15:52:00 +00:00
if test -z "$generateReadme_skip"; then
printf '%s\n' "$generateReadme_line"
2018-04-11 15:39:10 +00:00
fi
2019-12-20 15:52:00 +00:00
if test "$generateReadme_line" = "$generateReadme_ph_ExtensionsStart"; then
2018-04-11 15:39:10 +00:00
generateReadme_skip='y'
printf '<!-- ########################################################### -->\n'
printf '<!-- # # -->\n'
printf '<!-- # DO NOT EDIT THIS TABLE: IT IS GENERATED AUTOMATICALLY # -->\n'
printf '<!-- # # -->\n'
printf '<!-- # EDIT THE data/supported-extensions FILE INSTEAD # -->\n'
printf '<!-- # # -->\n'
printf '<!-- ########################################################### -->\n'
2019-12-20 15:52:00 +00:00
generateExtensionsTable "$2"
elif test "$generateReadme_line" = "$generateReadme_ph_SpecialStart"; then
2018-04-11 15:39:10 +00:00
generateReadme_skip='y'
printf '<!-- ########################################################### -->\n'
printf '<!-- # # -->\n'
printf '<!-- # DO NOT EDIT THIS TABLE: IT IS GENERATED AUTOMATICALLY # -->\n'
printf '<!-- # # -->\n'
printf '<!-- # EDIT THE data/special-requirements FILE INSTEAD # -->\n'
printf '<!-- # # -->\n'
printf '<!-- ########################################################### -->\n'
2019-12-20 15:52:00 +00:00
generateSpecialRequirementsTable "$3"
2018-04-11 15:39:10 +00:00
fi
2019-12-20 15:52:00 +00:00
done <"$1"
printf '%s' "$generateReadme_line"
2018-04-11 15:39:10 +00:00
}
2019-12-20 15:52:00 +00:00
NEW_README="$(generateReadme "$ROOT_DIR/README.md" "$DATA_DIR/supported-extensions" "$DATA_DIR/special-requirements")"
printf '%s\n' "$NEW_README" >"$ROOT_DIR/README.md"