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 1 commit
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
31 changes: 29 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

@OGKevin OGKevin May 9, 2018

Choose a reason for hiding this comment

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

There are some extension missing according to: composer.json

Aslo this seems like code repeation. Please create a new method:

  1. isModlueMissing(string[] $allModules, string $moduleToFind): bool
    You can do this via:
allModule=$(php -m)
allNeededModule=(some smart way to get a string[] of everthig in composer json)


for line in $allNeededModule; do
  if (isModlueMissing($allModule $line)); then
      determineInstructionInstallation ...
done

Your method assertComposerPrerequisitePresent will then loop over each needed and preform the check.

To get all the needed extensions, i would suggest to use the latest composer json on master branch and then run a regex for everything with ext-

determineInstructionInstallation "php-curl" "$(determineSystemName)" "php-curl"
fi
if [[ ${phpModules} != *"mbstring"* ]]; then
determineInstructionInstallation "php-mbstring" "$(determineSystemName)" "php-mbstring"
fi
}

Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this string into a consant.


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 +202,7 @@ function capitalizeFirstLetter
assertIsSystemSupported
assertIsRanInEmptyDirectory
assertAllPrerequisitePresent
assertComposerPrerequisitePresent
cloneTinkerPhp
composerInstall
startTinker
Expand Down