Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/sh
# Upgrade homebrew packages including multiple versions of PHP without the linking/unlinking headache!
# Update package list
brew update
# Upgrade PHP packages
phpcurrent=$(readlink /usr/local/bin/php | xargs dirname | xargs dirname | xargs dirname | xargs basename 2>&1)
newline="
"
IFS=$newline phpinstalled=( $(brew list | grep '^php\d\d$') )
brew unlink ${phpinstalled[@]}
for phpversion in ${phpinstalled[@]}
do
IFS=$newline packages=( $(brew outdated --quiet | grep "$phpversion$") )
if [[ $packages ]]
then
brew link $phpversion
for package in ${packages[@]}
do
brew upgrade `basename $package`
done
brew unlink $phpversion
fi
done
if [[ $phpcurrent ]]
then
brew link $phpcurrent
fi
# Upgrade everything else
brew upgrade
# Clean up
brew cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.