Skip to content

Instantly share code, notes, and snippets.

@YuriyGuts
Last active June 13, 2016 23:41
Show Gist options
  • Save YuriyGuts/cdbe75154ce07863310420681c1dcf60 to your computer and use it in GitHub Desktop.
Save YuriyGuts/cdbe75154ce07863310420681c1dcf60 to your computer and use it in GitHub Desktop.
Check for updates to all Homebrew Cask applications and upgrade them (workaround until cask gets a built-in mechanism for this)
#!/usr/bin/env bash
fetch() {
echo "Removing brew cache"
local cache=$(brew --cache)
rm -rf "$(brew --cache)"
mkdir "$cache"
mkdir "$cache/Casks"
echo "Running brew update"
brew update
}
update() {
casks=( $(brew cask list) )
caskroom=$(brew --prefix)/Caskroom
echo
echo "Checking for updates"
echo
local UPDATES_FOUND=0
for cask in ${casks[@]}
do
current="$(brew cask info $cask | sed -n '1p' | sed -n 's/^.*: \(.*\)$/\1/p')"
installed=( $(ls -Art $caskroom/$cask/ | egrep 'latest|(\d.*)' | tail -n 1))
if [ "$installed" != "$current" ]; then
echo "$cask ($installed -> $current)"
UPDATES_FOUND=1
fi
done
if [ "$UPDATES_FOUND" -eq 0 ]; then
echo "Nothing to update"
return
fi
echo
echo "Install updates now?"
select yn in "Yes" "No"; do
case $yn in
"Yes") echo "Updating outdated casks"; break;;
"No") echo "Upgrade cancelled" ;return;;
*) echo "Please choose 1 or 2";;
esac
done
for cask in ${casks[@]}
do
current="$(brew cask info $cask | sed -n '1p' | sed -n 's/^.*: \(.*\)$/\1/p')"
installed=( $(ls -Art $caskroom/$cask/ | egrep 'latest|(\d.*)' | tail -n 1))
if [ "$installed" != "$current" ]; then
rm -rf $caskroom/$cask/$installed
brew cask install $cask --force
fi
done
}
fetch
update
@YuriyGuts
Copy link
Author

Sample output:

Removing brew cache
Running brew update
Already up-to-date.

Checking for updates

intellij-idea (15.0.3 -> 2016.1)
java (1.8.0_74-b02 -> 1.8.0_77-b03)
rstudio (0.99.878 -> 0.99.893)
sketch (3.5.2 -> 3.6.1)
skim (1.4.17 -> 1.4.18)
visual-studio-code (45d69357c9eb068dd8e624f5b0fe461cd2078d88 -> 0.10.11,f291f4ad600767626b24a4b15816b04bee9a3049)
xamarin-studio (5.10.2.56-0 -> 5.10.3.27-0)

Install updates now?
1) Yes
2) No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment