Last active
April 22, 2017 00:25
-
-
Save eporama/b8dae395fa21fa970452e9bdbbdca26c to your computer and use it in GitHub Desktop.
A bash script to brew update php and relink in phpenv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Use this script to update multiple versions of PHP | |
versions=(56 70); | |
echo "Updating brew" | |
brew update | |
for version in ${versions[@]} | |
do | |
echo -e "\nUpdating php${version}" | |
brew unlink php${version} | |
brew upgrade php${version} | |
brew cleanup php${version} | |
brew link php${version} | |
for MOD in $(brew list | grep "^php${version}-") | |
do | |
brew upgrade ${MOD} | |
brew cleanup ${MOD} | |
done | |
brew unlink php${version} | |
done | |
echo -e "\nRemoving old phpenv versions" | |
find "${HOME}/.phpenv/versions" -maxdepth 1 -mindepth 1 -type l -delete | |
echo -e "\nAdding new phpenv versions" | |
for version in $(find $(find /usr/local/Cellar -maxdepth 1 -mindepth 1 -name 'php[0-9][0-9]' ) -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do | |
echo -e " Adding symlinks for ${version}" | |
ln -s ${version} ${HOME}/.phpenv/versions/ 2>/dev/null | |
ln -s ${version} ${HOME}/.phpenv/versions/$(echo "${version}" | perl -p -e "s/.*(\d+\.\d+)\.(.+)$/\1/") 2>/dev/null | |
done | |
echo -e "\nRehashing phpenv" | |
phpenv rehash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment