Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add installation request for missing dependencies (bunq/tinker_php#18) #19

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 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)? '

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y


# 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 @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -176,6 +206,7 @@ function capitalizeFirstLetter
assertIsSystemSupported
assertIsRanInEmptyDirectory
assertAllPrerequisitePresent
assertComposerPrerequisitePresent
cloneTinkerPhp
composerInstall
startTinker
Expand Down