diff --git a/setup.sh b/setup.sh index 0e989f1..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='' @@ -57,10 +60,27 @@ function assertAllPrerequisitePresent else echo -n "$(determineInstructionInstallationAllPrerequisiteMissing "${allPrerequisiteMissing}")" - exit 1 + if [${1} ]; then + exit 1 + else + assertAllPrerequisitePresent true + fi fi } +function assertComposerPrerequisitePresent +{ + phpModules=$(php -m) + + for composerPrerequisite in ${ALL_PREREQUISITE_COMPOSER}; do + composerPrerequisite=${composerPrerequisite:4} + + if [[ ${phpModules} != *"${composerPrerequisite}"* ]]; then + determineInstructionInstallation "php-${composerPrerequisite}" "$(determineSystemName)" "php-${composerPrerequisite}" + fi + done +} + function determineAllPrerequisiteMissing { for prerequisite in $(determineAllPrerequisite); do @@ -129,7 +149,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 ${MESSAGE_INSTALL_DEPENDENCY} >$(tty) + + read answer + if [ "$answer" != "${answer#[Yy]}" ] ;then + echo "${!commandInstallationConstantName} ${programPackageName} -y" >$(tty) + eval "${!commandInstallationConstantName} ${programPackageName} -y" >$(tty) + fi } function determineSystemName @@ -176,6 +206,7 @@ function capitalizeFirstLetter assertIsSystemSupported assertIsRanInEmptyDirectory assertAllPrerequisitePresent +assertComposerPrerequisitePresent cloneTinkerPhp composerInstall startTinker