From 57579c72320d5b75b9540d7dc0c50586455eb396 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Fri, 11 Oct 2019 16:01:21 +0200 Subject: [PATCH] Sort modules to be installed --- install-php-extensions | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/install-php-extensions b/install-php-extensions index 8eaa0d3..76ee76a 100755 --- a/install-php-extensions +++ b/install-php-extensions @@ -115,6 +115,32 @@ getModulesToInstall () { done } +# Sort the modules to be installed, in order to fix dependencies +# +# Update: +# PHP_MODULES_TO_INSTALL +# +# Output: +# Nothing +sortModulesToInstall () { + if stringInList 'igbinary' "${PHP_MODULES_TO_INSTALL}"; then + PHP_MODULES_TO_INSTALL="$(removeStringFromList 'igbinary' "${PHP_MODULES_TO_INSTALL}")" + if test -z "$PHP_MODULES_TO_INSTALL"; then + PHP_MODULES_TO_INSTALL='igbinary' + else + PHP_MODULES_TO_INSTALL="igbinary $PHP_MODULES_TO_INSTALL" + fi + fi + if stringInList 'msgpack' "${PHP_MODULES_TO_INSTALL}"; then + PHP_MODULES_TO_INSTALL="$(removeStringFromList 'msgpack' "${PHP_MODULES_TO_INSTALL}")" + if test -z "$PHP_MODULES_TO_INSTALL"; then + PHP_MODULES_TO_INSTALL='msgpack' + else + PHP_MODULES_TO_INSTALL="msgpack $PHP_MODULES_TO_INSTALL" + fi + fi +} + # Get the required APT packages for a specific PHP version and for the list of module handles # # Arguments: @@ -555,6 +581,28 @@ stringInList () { return 1 } +# Remove a word from a space-separated list +# +# Arguments: +# $1: the word to be removed +# $2: the string list +# +# Output: +# The list without the word +removeStringFromList () { + removeStringFromList_result='' + for removeStringFromList_listItem in ${2}; do + if test "${1}" != "${removeStringFromList_listItem}"; then + if test -z "$removeStringFromList_result"; then + removeStringFromList_result="$removeStringFromList_listItem" + else + removeStringFromList_result="$removeStringFromList_result $removeStringFromList_listItem" + fi + fi + done + printf '%s' "${removeStringFromList_result}" +} + resetIFS PHP_MAJMIN_VERSION=$(getPHPMajorMinor) case "${PHP_MAJMIN_VERSION}" in @@ -566,6 +614,8 @@ esac UNNEEDED_APT_PACKAGES='' UNNEEDED_APT_PACKAGE_LINKS='' getModulesToInstall "$@" +sortModulesToInstall + if test -n "${PHP_MODULES_TO_INSTALL}"; then REQUIRED_APT_PACKAGES=$(getRequiredAptPackages ${PHP_MAJMIN_VERSION} ${PHP_MODULES_TO_INSTALL}) if test -n "${REQUIRED_APT_PACKAGES}"; then