Simplify if / for instructions

pull/32/head
Michele Locati 2019-10-07 17:54:18 +02:00
parent ae21dc5eaf
commit 4ace356692
No known key found for this signature in database
GPG Key ID: 98B7CE2E7234E28B
1 changed files with 50 additions and 100 deletions

View File

@ -34,8 +34,7 @@ getPHPInstalledModules () {
getPHPInstalledModules_result='' getPHPInstalledModules_result=''
IFS=' IFS='
' '
for getPHPInstalledModules_module in $(php -m) for getPHPInstalledModules_module in $(php -m); do
do
getPHPInstalledModules_moduleNormalized='' getPHPInstalledModules_moduleNormalized=''
case "${getPHPInstalledModules_module}" in case "${getPHPInstalledModules_module}" in
\[PHP\ Modules\]) \[PHP\ Modules\])
@ -56,10 +55,8 @@ getPHPInstalledModules () {
getPHPInstalledModules_moduleNormalized="${getPHPInstalledModules_module}" getPHPInstalledModules_moduleNormalized="${getPHPInstalledModules_module}"
;; ;;
esac esac
if test -n "${getPHPInstalledModules_moduleNormalized}" if test -n "${getPHPInstalledModules_moduleNormalized}"; then
then if ! stringInList "${getPHPInstalledModules_moduleNormalized}" "${getPHPInstalledModules_result}"; then
if ! stringInList "${getPHPInstalledModules_moduleNormalized}" "${getPHPInstalledModules_result}"
then
getPHPInstalledModules_result="${getPHPInstalledModules_result} ${getPHPInstalledModules_moduleNormalized}" getPHPInstalledModules_result="${getPHPInstalledModules_result} ${getPHPInstalledModules_moduleNormalized}"
fi fi
fi fi
@ -84,15 +81,12 @@ getModulesToInstall () {
getModulesToInstall_endArgs='' getModulesToInstall_endArgs=''
DO_APT_REMOVE='' DO_APT_REMOVE=''
PHP_MODULES_TO_INSTALL='' PHP_MODULES_TO_INSTALL=''
while : while :; do
do if test $# -lt 1; then
if test $# -lt 1
then
break break
fi fi
getModulesToInstall_skip='' getModulesToInstall_skip=''
if test -z "${getModulesToInstall_endArgs}" if test -z "${getModulesToInstall_endArgs}"; then
then
case "${1}" in case "${1}" in
--cleanup) --cleanup)
getModulesToInstall_skip='y' getModulesToInstall_skip='y'
@ -108,13 +102,10 @@ getModulesToInstall () {
;; ;;
esac esac
fi fi
if test -z "${getModulesToInstall_skip}" if test -z "${getModulesToInstall_skip}"; then
then if stringInList "${1}" "${PHP_MODULES_TO_INSTALL}"; then
if stringInList "${1}" "${PHP_MODULES_TO_INSTALL}"
then
printf '### WARNING Duplicated module name specified: %s ###\n' "${1}" >&2 printf '### WARNING Duplicated module name specified: %s ###\n' "${1}" >&2
elif stringInList "${1}" "${getModulesToInstall_alreadyInstalled}" elif stringInList "${1}" "${getModulesToInstall_alreadyInstalled}"; then
then
printf '### WARNING Module already installed: %s ###\n' "${1}" >&2 printf '### WARNING Module already installed: %s ###\n' "${1}" >&2
else else
PHP_MODULES_TO_INSTALL="${PHP_MODULES_TO_INSTALL} ${1}" PHP_MODULES_TO_INSTALL="${PHP_MODULES_TO_INSTALL} ${1}"
@ -135,10 +126,8 @@ getModulesToInstall () {
getRequiredAptPackages () { getRequiredAptPackages () {
getRequiredAptPackages_result='' getRequiredAptPackages_result=''
getRequiredAptPackages_phpv=${1} getRequiredAptPackages_phpv=${1}
while : while :; do
do if test $# -lt 2; then
if test $# -lt 2
then
break break
fi fi
shift shift
@ -156,8 +145,7 @@ getRequiredAptPackages () {
getRequiredAptPackages_result="${getRequiredAptPackages_result} libenchant-dev" getRequiredAptPackages_result="${getRequiredAptPackages_result} libenchant-dev"
;; ;;
gd) gd)
if test $getRequiredAptPackages_phpv -lt 700 if test $getRequiredAptPackages_phpv -lt 700; then
then
getRequiredAptPackages_result="${getRequiredAptPackages_result} libvpx-dev libjpeg62-turbo-dev libpng-dev libxpm-dev libfreetype6-dev" getRequiredAptPackages_result="${getRequiredAptPackages_result} libvpx-dev libjpeg62-turbo-dev libpng-dev libxpm-dev libfreetype6-dev"
else else
getRequiredAptPackages_result="${getRequiredAptPackages_result} libwebp-dev libjpeg62-turbo-dev libpng-dev libxpm-dev libfreetype6-dev" getRequiredAptPackages_result="${getRequiredAptPackages_result} libwebp-dev libjpeg62-turbo-dev libpng-dev libxpm-dev libfreetype6-dev"
@ -276,21 +264,16 @@ getAptPackagesToRemove () {
getAptPackagesToRemove_result='' getAptPackagesToRemove_result=''
IFS=' IFS='
' '
for getAptPackagesToRemove_aptLine in $(DEBIAN_FRONTEND=noninteractive apt-get install -sy $@) for getAptPackagesToRemove_aptLine in $(DEBIAN_FRONTEND=noninteractive apt-get install -sy $@); do
do if test -z "${getAptPackagesToRemove_inNewPackages}"; then
if test -z "${getAptPackagesToRemove_inNewPackages}" if test "${getAptPackagesToRemove_aptLine}" = 'The following NEW packages will be installed:'; then
then
if test "${getAptPackagesToRemove_aptLine}" = 'The following NEW packages will be installed:'
then
getAptPackagesToRemove_inNewPackages='y' getAptPackagesToRemove_inNewPackages='y'
resetIFS resetIFS
fi fi
elif test "${getAptPackagesToRemove_aptLine}" = "${getAptPackagesToRemove_aptLine# }" elif test "${getAptPackagesToRemove_aptLine}" = "${getAptPackagesToRemove_aptLine# }"; then
then
getAptPackagesToRemove_inNewPackages='' getAptPackagesToRemove_inNewPackages=''
else else
for getAptPackagesToRemove_newPackage in ${getAptPackagesToRemove_aptLine} for getAptPackagesToRemove_newPackage in ${getAptPackagesToRemove_aptLine}; do
do
case "${getAptPackagesToRemove_newPackage}" in case "${getAptPackagesToRemove_newPackage}" in
*-dev|cmake|cmake-data) *-dev|cmake|cmake-data)
getAptPackagesToRemove_result="${getAptPackagesToRemove_result} ${getAptPackagesToRemove_newPackage}" getAptPackagesToRemove_result="${getAptPackagesToRemove_result} ${getAptPackagesToRemove_newPackage}"
@ -318,11 +301,9 @@ installBundledModule () {
printf '### INSTALLING BUNDLED MODULE %s ###\n' "${2}" printf '### INSTALLING BUNDLED MODULE %s ###\n' "${2}"
case "${2}" in case "${2}" in
gd) gd)
if test $1 -lt 700 if test $1 -lt 700; then
then
docker-php-ext-configure gd --with-gd --with-vpx-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-xpm-dir --with-freetype-dir --enable-gd-native-ttf docker-php-ext-configure gd --with-gd --with-vpx-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-xpm-dir --with-freetype-dir --enable-gd-native-ttf
elif test $1 -lt 702 elif test $1 -lt 702; then
then
docker-php-ext-configure gd --with-gd --with-webp-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-xpm-dir --with-freetype-dir --enable-gd-native-ttf docker-php-ext-configure gd --with-gd --with-webp-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-xpm-dir --with-freetype-dir --enable-gd-native-ttf
else else
docker-php-ext-configure gd --with-gd --with-webp-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-xpm-dir --with-freetype-dir docker-php-ext-configure gd --with-gd --with-webp-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-xpm-dir --with-freetype-dir
@ -331,8 +312,7 @@ installBundledModule () {
gmp) gmp)
case "$1" in case "$1" in
506) 506)
if ! test -f /usr/include/gmp.h if ! test -f /usr/include/gmp.h; then
then
ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
UNNEEDED_APT_PACKAGE_LINKS="${UNNEEDED_APT_PACKAGE_LINKS} /usr/include/gmp.h" UNNEEDED_APT_PACKAGE_LINKS="${UNNEEDED_APT_PACKAGE_LINKS} /usr/include/gmp.h"
fi fi
@ -348,8 +328,7 @@ installBundledModule () {
mssql|pdo_dblib) mssql|pdo_dblib)
case "$1" in case "$1" in
506|700|701|702|703) 506|700|701|702|703)
if ! test -f /usr/lib/libsybdb.so if ! test -f /usr/lib/libsybdb.so; then
then
ln -s /usr/lib/x86_64-linux-gnu/libsybdb.so /usr/lib/libsybdb.so ln -s /usr/lib/x86_64-linux-gnu/libsybdb.so /usr/lib/libsybdb.so
UNNEEDED_APT_PACKAGE_LINKS="${UNNEEDED_APT_PACKAGE_LINKS} /usr/lib/libsybdb.so" UNNEEDED_APT_PACKAGE_LINKS="${UNNEEDED_APT_PACKAGE_LINKS} /usr/lib/libsybdb.so"
fi fi
@ -404,17 +383,14 @@ getPackageSource () {
cd - >/dev/null cd - >/dev/null
unlink "${getPackageSource_tempFile}" unlink "${getPackageSource_tempFile}"
getPackageSource_outDir='' getPackageSource_outDir=''
for getPackageSource_i in $(ls "${getPackageSource_tempDir}") for getPackageSource_i in $(ls "${getPackageSource_tempDir}"); do
do if test -n "${getPackageSource_outDir}" || test -f "${getPackageSource_tempDir}/${getPackageSource_i}"; then
if test -n "${getPackageSource_outDir}" || test -f "${getPackageSource_tempDir}/${getPackageSource_i}"
then
getPackageSource_outDir='' getPackageSource_outDir=''
break break
fi fi
getPackageSource_outDir="${getPackageSource_tempDir}/${getPackageSource_i}" getPackageSource_outDir="${getPackageSource_tempDir}/${getPackageSource_i}"
done done
if test -n "${getPackageSource_outDir}" if test -n "${getPackageSource_outDir}"; then
then
printf '%s' "${getPackageSource_outDir}" printf '%s' "${getPackageSource_outDir}"
else else
printf '%s' "${getPackageSource_tempDir}" printf '%s' "${getPackageSource_tempDir}"
@ -449,68 +425,55 @@ installPECLModule () {
installPECLModule_actual="${2}" installPECLModule_actual="${2}"
case "${2}" in case "${2}" in
mcrypt) mcrypt)
if test $1 -ge 702 if test $1 -ge 702; then
then
installPECLModule_actual="${2}-1.0.1" installPECLModule_actual="${2}-1.0.1"
fi fi
;; ;;
memcached) memcached)
if test $1 -lt 700 if test $1 -lt 700; then
then
installPECLModule_actual="${2}-2.2.0" installPECLModule_actual="${2}-2.2.0"
fi fi
;; ;;
pcov) pcov)
if test $1 -lt 701 if test $1 -lt 701; then
then
installPECLModule_actual="${2}-0.9.0" installPECLModule_actual="${2}-0.9.0"
fi fi
;; ;;
pthreads) pthreads)
if test $1 -lt 700 if test $1 -lt 700; then
then
installPECLModule_actual="${2}-2.0.10" installPECLModule_actual="${2}-2.0.10"
fi fi
;; ;;
ssh2) ssh2)
if test $1 -ge 700 if test $1 -ge 700; then
then
installPECLModule_actual="${2}-1.1.2" installPECLModule_actual="${2}-1.1.2"
fi fi
;; ;;
xdebug) xdebug)
if test $1 -lt 501 if test $1 -lt 501; then
then
installPECLModule_actual="${2}-2.0.5" installPECLModule_actual="${2}-2.0.5"
elif test $1 -lt 504 elif test $1 -lt 504; then
then
installPECLModule_actual="${2}-2.2.7" installPECLModule_actual="${2}-2.2.7"
elif test $1 -lt 505 elif test $1 -lt 505; then
then
installPECLModule_actual="${2}-2.4.1" installPECLModule_actual="${2}-2.4.1"
elif test $1 -lt 700 elif test $1 -lt 700; then
then
installPECLModule_actual="${2}-2.5.5" installPECLModule_actual="${2}-2.5.5"
fi fi
;; ;;
uopz) uopz)
if test $1 -lt 700 if test $1 -lt 700; then
then
installPECLModule_actual="${2}-2.0.7" installPECLModule_actual="${2}-2.0.7"
elif test $1 -lt 701 elif test $1 -lt 701; then
then
installPECLModule_actual="${2}-5.0.2" installPECLModule_actual="${2}-5.0.2"
fi fi
;; ;;
yaml) yaml)
if test $1 -lt 700 if test $1 -lt 700; then
then
installPECLModule_actual="${2}-1.3.1" installPECLModule_actual="${2}-1.3.1"
fi fi
;; ;;
esac esac
if test "${2}" != "${installPECLModule_actual}" if test "${2}" != "${installPECLModule_actual}"; then
then
printf ' (installing version %s)\n' "${installPECLModule_actual}" printf ' (installing version %s)\n' "${installPECLModule_actual}"
fi fi
pecl install "${installPECLModule_actual}" pecl install "${installPECLModule_actual}"
@ -527,10 +490,8 @@ installPECLModule () {
# 0 (true): if the string is in the list # 0 (true): if the string is in the list
# 1 (false): if the string is not in the list # 1 (false): if the string is not in the list
stringInList () { stringInList () {
for stringInList_listItem in ${2} for stringInList_listItem in ${2}; do
do if test "${1}" = "${stringInList_listItem}"; then
if test "${1}" = "${stringInList_listItem}"
then
return 0 return 0
fi fi
done done
@ -548,25 +509,20 @@ esac
UNNEEDED_APT_PACKAGES='' UNNEEDED_APT_PACKAGES=''
UNNEEDED_APT_PACKAGE_LINKS='' UNNEEDED_APT_PACKAGE_LINKS=''
getModulesToInstall "$@" getModulesToInstall "$@"
if test -n "${PHP_MODULES_TO_INSTALL}" if test -n "${PHP_MODULES_TO_INSTALL}"; then
then
REQUIRED_APT_PACKAGES=$(getRequiredAptPackages ${PHP_MAJMIN_VERSION} ${PHP_MODULES_TO_INSTALL}) REQUIRED_APT_PACKAGES=$(getRequiredAptPackages ${PHP_MAJMIN_VERSION} ${PHP_MODULES_TO_INSTALL})
if test -n "${REQUIRED_APT_PACKAGES}" if test -n "${REQUIRED_APT_PACKAGES}"; then
then
printf '### INSTALLING REQUIRED APT PACKAGES ###\n' printf '### INSTALLING REQUIRED APT PACKAGES ###\n'
DEBIAN_FRONTEND=noninteractive apt-get update -y DEBIAN_FRONTEND=noninteractive apt-get update -y
if test -n "${DO_APT_REMOVE}" if test -n "${DO_APT_REMOVE}"; then
then
UNNEEDED_APT_PACKAGES=$(getAptPackagesToRemove ${REQUIRED_APT_PACKAGES}) UNNEEDED_APT_PACKAGES=$(getAptPackagesToRemove ${REQUIRED_APT_PACKAGES})
fi fi
DEBIAN_FRONTEND=noninteractive apt-get install -y ${REQUIRED_APT_PACKAGES} DEBIAN_FRONTEND=noninteractive apt-get install -y ${REQUIRED_APT_PACKAGES}
fi fi
docker-php-source extract docker-php-source extract
BUNDLED_MODULES="$(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | xargs -n1 dirname | xargs -n1 basename | xargs)" BUNDLED_MODULES="$(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | xargs -n1 dirname | xargs -n1 basename | xargs)"
for PHP_MODULE_TO_INSTALL in ${PHP_MODULES_TO_INSTALL} for PHP_MODULE_TO_INSTALL in ${PHP_MODULES_TO_INSTALL}; do
do if stringInList "${PHP_MODULE_TO_INSTALL}" "${BUNDLED_MODULES}"; then
if stringInList "${PHP_MODULE_TO_INSTALL}" "${BUNDLED_MODULES}"
then
installBundledModule ${PHP_MAJMIN_VERSION} "${PHP_MODULE_TO_INSTALL}" installBundledModule ${PHP_MAJMIN_VERSION} "${PHP_MODULE_TO_INSTALL}"
else else
MODULE_SOURCE='' MODULE_SOURCE=''
@ -590,28 +546,22 @@ then
MODULE_SOURCE_CFLAGS='-O2 -g' MODULE_SOURCE_CFLAGS='-O2 -g'
;; ;;
esac esac
if test -n "${MODULE_SOURCE}" if test -n "${MODULE_SOURCE}"; then
then
installModuleFromSource "${PHP_MODULE_TO_INSTALL}" "${MODULE_SOURCE}" "${MODULE_SOURCE_CONFIGOPTIONS}" "${MODULE_SOURCE_CFLAGS}" installModuleFromSource "${PHP_MODULE_TO_INSTALL}" "${MODULE_SOURCE}" "${MODULE_SOURCE_CONFIGOPTIONS}" "${MODULE_SOURCE_CFLAGS}"
else else
installPECLModule ${PHP_MAJMIN_VERSION} "${PHP_MODULE_TO_INSTALL}" installPECLModule ${PHP_MAJMIN_VERSION} "${PHP_MODULE_TO_INSTALL}"
fi fi
fi fi
done done
if test -n "${DO_APT_REMOVE}" if test -n "${DO_APT_REMOVE}"; then
then
printf '### REMOVING NO LONGER REQUIRED PACKAGES ###\n' printf '### REMOVING NO LONGER REQUIRED PACKAGES ###\n'
DEBIAN_FRONTEND=noninteractive apt autoremove -y DEBIAN_FRONTEND=noninteractive apt autoremove -y
fi fi
if test -n "${UNNEEDED_APT_PACKAGES}" if test -n "${UNNEEDED_APT_PACKAGES}"; then
then
printf '### REMOVING UNNEEDED APT PACKAGES ###\n' printf '### REMOVING UNNEEDED APT PACKAGES ###\n'
if test -n "${UNNEEDED_APT_PACKAGE_LINKS}" if test -n "${UNNEEDED_APT_PACKAGE_LINKS}"; then
then for unneededAptPackageLink in ${UNNEEDED_APT_PACKAGE_LINKS}; do
for unneededAptPackageLink in ${UNNEEDED_APT_PACKAGE_LINKS} if test -L "${unneededAptPackageLink}"; then
do
if test -L "${unneededAptPackageLink}"
then
rm -f "${unneededAptPackageLink}" rm -f "${unneededAptPackageLink}"
fi fi
done done