From 4ebfe92efe62b21e2bd2ebbfe648b7e5334b0c66 Mon Sep 17 00:00:00 2001 From: Gregory Goijaerts Date: Tue, 8 May 2018 14:32:40 +0200 Subject: [PATCH 1/2] Add installation request for missing dependencies (bunq/tinker_php#18) --- setup.sh | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/setup.sh b/setup.sh index 0e989f1..f36c3c0 100755 --- a/setup.sh +++ b/setup.sh @@ -57,7 +57,23 @@ function assertAllPrerequisitePresent else echo -n "$(determineInstructionInstallationAllPrerequisiteMissing "${allPrerequisiteMissing}")" - exit 1 + if [${1} ]; then + exit 1 + else + assertAllPrerequisitePresent true + fi + fi +} + +function assertComposerPrerequisitePresent +{ + phpModules=$(php -m | head) + + if [[ ${phpModules} != *"curl"* ]]; then + determineInstructionInstallation "php-curl" "$(determineSystemName)" "php-curl" + fi + if [[ ${phpModules} != *"mbstring"* ]]; then + determineInstructionInstallation "php-mbstring" "$(determineSystemName)" "php-mbstring" fi } @@ -129,7 +145,17 @@ function determineInstructionInstallation systemName="${2}" programPackageName=${3:-${programName}} commandInstallationConstantName="${COMMAND_INSTALLATION_PREFIX}$(capitalize ${systemName})" - printf "${ERROR_COULD_NOT_FIND_COMMAND}" "${programName}" "${!commandInstallationConstantName} ${programPackageName}" + + warningMessage=$(printf "${ERROR_COULD_NOT_FIND_COMMAND}" "${programName}" "${!commandInstallationConstantName} ${programPackageName}") + + echo ${warningMessage} >$(tty) + echo "Do you want to try and install this now? (y/N)? " >$(tty) + + read answer + if [ "$answer" != "${answer#[Yy]}" ] ;then + echo "${!commandInstallationConstantName} ${programPackageName} -y" >$(tty) + eval "${!commandInstallationConstantName} ${programPackageName} -y" >$(tty) + fi } function determineSystemName @@ -176,6 +202,7 @@ function capitalizeFirstLetter assertIsSystemSupported assertIsRanInEmptyDirectory assertAllPrerequisitePresent +assertComposerPrerequisitePresent cloneTinkerPhp composerInstall startTinker From 748b7c4293fd8e2b4b2f63e6daf9617d3ba704d1 Mon Sep 17 00:00:00 2001 From: Gregory Goijaerts Date: Wed, 9 May 2018 15:55:44 +0200 Subject: [PATCH 2/2] Check composer file for dependencies and added message constant (bunq/tinker_php#18) --- setup.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/setup.sh b/setup.sh index f36c3c0..26a151c 100755 --- a/setup.sh +++ b/setup.sh @@ -5,6 +5,8 @@ ERROR_SYSTEM_UNKNOWN='Unknown system found "%s".\n' ERROR_RUN_IN_EMPTY_DIRECTORY='Please run the script from an empty directory\n' ERROR_COULD_NOT_FIND_COMMAND='Could not find "%s", try installing it by running "%s".' +MESSAGE_INSTALL_DEPENDENCY='Do you want to try and install this now? (y/N)? ' + # System Constants SYSTEM_NAME_LINUX='Linux' SYSTEM_NAME_MAC_OS='Darwin' @@ -14,6 +16,7 @@ ALL_SYSTEM_SUPPORTED="${SYSTEM_NAME_LINUX} ${SYSTEM_NAME_MAC_OS} ${SYSTEM_NAME_F # Prerequisite constants. PREREQUISITE_CONSTANT_PREFIX='ALL_PREREQUISITE_' ALL_PREREQUISITE_GLOBAL='git php composer qrencode jq' +ALL_PREREQUISITE_COMPOSER=$(curl -s https://raw.githubusercontent.com/bunq/sdk_php/master/composer.json | fgrep ext | tr -d "\"*\:,\ ") ALL_PREREQUISITE_LINUX='' ALL_PREREQUISITE_DARWIN='brew' ALL_PREREQUISITE_FREEBSD='' @@ -67,14 +70,15 @@ function assertAllPrerequisitePresent function assertComposerPrerequisitePresent { - phpModules=$(php -m | head) + phpModules=$(php -m) - if [[ ${phpModules} != *"curl"* ]]; then - determineInstructionInstallation "php-curl" "$(determineSystemName)" "php-curl" - fi - if [[ ${phpModules} != *"mbstring"* ]]; then - determineInstructionInstallation "php-mbstring" "$(determineSystemName)" "php-mbstring" - fi + for composerPrerequisite in ${ALL_PREREQUISITE_COMPOSER}; do + composerPrerequisite=${composerPrerequisite:4} + + if [[ ${phpModules} != *"${composerPrerequisite}"* ]]; then + determineInstructionInstallation "php-${composerPrerequisite}" "$(determineSystemName)" "php-${composerPrerequisite}" + fi + done } function determineAllPrerequisiteMissing @@ -149,7 +153,7 @@ function determineInstructionInstallation warningMessage=$(printf "${ERROR_COULD_NOT_FIND_COMMAND}" "${programName}" "${!commandInstallationConstantName} ${programPackageName}") echo ${warningMessage} >$(tty) - echo "Do you want to try and install this now? (y/N)? " >$(tty) + echo ${MESSAGE_INSTALL_DEPENDENCY} >$(tty) read answer if [ "$answer" != "${answer#[Yy]}" ] ;then