Skip to content

Commit

Permalink
Check composer file for dependencies and added message constant (bunq#18
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Crecket committed May 9, 2018
1 parent 4ebfe92 commit 748b7c4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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=''
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 748b7c4

Please sign in to comment.