Last active
June 13, 2016 23:41
-
-
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)
This file contains hidden or 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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: