Last active
March 15, 2016 14:09
-
-
Save breiter/b9828272dfcf64b77f70 to your computer and use it in GitHub Desktop.
Script to update installed Homebrew casks that are not tracked by brew udpate
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
#!/bin/sh | |
# brew upgrade often fails to update brew casks | |
# this script upgrades any brew casks where the cached version is older than the current version or cache has been deleted | |
# some casks, like Skype, have no versioning at all. This script always forces unversioned "latest" casks to re-install | |
# from the latest download. | |
red='\033[0;31m' | |
green='\033[0;32m' | |
yellow='\033[0;33m' | |
blue='\033[0;34m' | |
magenta='\033[0;35m' | |
cyan='\033[0;36m' | |
NC='\033[0m' # No Color | |
SELF=`echo $0 | sed -ne 's|^.*/||p'` | |
if [ "$(id -u)" -ne 0 ]; then | |
echo "$SELF must be run as root." 1>&2 | |
echo "try: sudo $SELF [force]" 1>&2 | |
exit 1 | |
fi | |
# only test versions of gpgtools if gpgtools is installed | |
if [ ! -z $(brew cask list | grep gpgtools) ]; then | |
CURRENT_GPGTOOLS=$(brew cask info gpgtools | egrep ^gpgtools | cut -d ' ' -f 2) | |
NEW_GPGTOOLS=$(brew cask list --versions | grep gpgtools | cut -d ' ' -f 2) | |
fi | |
echo "${green}==>${NC} Upgrading versioned casks" | |
for cask in $(brew cask list --versions | egrep -v latest$ | cut -d ' ' -f 1 ); do | |
brew cash uninstall ${cask} 2> /dev/null # uninstall or brew cask leaves the old version in place in Caskroom/{appname}/{version} | |
brew cask install ${cask} 2> /dev/null | |
done | |
echo "${green}==>${NC} done updating versioned casks" | |
if [ "$1" = "force" ]; then | |
echo "${green}==>${NC} forcing updates to unversioned caksks" | |
# not necessary to uninsatll old version because it uses the same "Caskroom/{appname}/latest" directory | |
brew cask list --versions | egrep latest$ | cut -d ' ' -f 1 | xargs brew cask install --force | |
echo "${green}==>${NC} done forcing updates to unversioned casks" | |
else | |
echo "${blue}==>${NC} Skipping unversioned casks" | |
echo "${blue}==>${NC} to force udpate all:" | |
echo " ${yellow}${SELF} force${NC}" | |
echo "${blue}==>${NC} commands to update individually" | |
for cask in $(brew cask list --versions | egrep latest$ | cut -d ' ' -f 1); do | |
echo " ${yellow}brew cask install --force ${cask}${NC}" | |
done | |
echo "${green}==>${NC} done" | |
fi | |
if [ "$CURRENT_GPGTOOLS" != "$NEW_GPGTOOLS" ]; then | |
# the cask formula for gpgtools incorrectly invokes `fixGpgHome` with the user context of the executing process | |
# which sets your ~/.gnupg directory to be owned by root if you run `sudo brew cask install gpgtools` | |
# This invokes `fixGpgHome` with your actual login name rather than root to fix those permissions. | |
if [ -f /usr/local/MacGPG2/libexec/fixGpgHome ]; then | |
/usr/local/MacGPG2/libexec/fixGpgHome $(logname) | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not really convinced that
brew cask
solves more problems than it creates at this point.