Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script upgrading outdated brew casks
#!/usr/bin/env bash
(set -x; brew update;)
(set -x; brew cleanup;)
(set -x; brew cask cleanup;)
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
casks=( $(brew cask list) )
for cask in ${casks[@]}
do
version=$(brew cask info $cask | sed -n "s/$cask:\ \(.*\)/\1/p")
installed=$(find "/usr/local/Caskroom/$cask" -type d -maxdepth 1 -maxdepth 1 -name "$version")
if [[ -z $installed ]]; then
echo "${red}${cask}${reset} requires ${red}update${reset}."
(set -x; brew cask uninstall $cask --force;)
(set -x; brew cask install $cask --force;)
else
echo "${red}${cask}${reset} is ${green}up-to-date${reset}."
fi
done
@atais

This comment has been minimized.

Copy link
Owner Author

atais commented May 3, 2016

@winkelsdorf

This comment has been minimized.

Copy link

winkelsdorf commented May 4, 2016

Brilliant, thank you 👍

@hiddenindians

This comment has been minimized.

Copy link

hiddenindians commented May 28, 2016

This is sweet! Thanks!

@hideout

This comment has been minimized.

Copy link

hideout commented Jun 4, 2016

thanks atais for that script!
that is what i was searching ...

cheers

@mshick

This comment has been minimized.

Copy link

mshick commented Aug 2, 2016

Great script. Much appreciated.

@gasperz

This comment has been minimized.

Copy link

gasperz commented Sep 2, 2016

It looks like it stopped working. I know it was working before but now it is not working for my anymore. When I run it everything looks ok. I get no errors.
But I can see that there is new version of cask. for example brew cask info brave gets me newer version than the one installed. But it isn't upgraded. I also tried with brew cask list | xargs brew cask install --force and with this, it gets upgraded.

@gasperz

This comment has been minimized.

Copy link

gasperz commented Sep 8, 2016

I made small change and it work again. I changed line 16 to installed="$(brew cask info $cask | grep 'does not exist')"
My gist

@atais

This comment has been minimized.

Copy link
Owner Author

atais commented Sep 10, 2016

@gasperz I am not sure if that is enough. Current output for brew cask info iterm2

iterm2: 3.0.8
https://www.iterm2.com/
/usr/local/Caskroom/iterm2/3.0.5 (68B)
From: https://github.com/caskroom/homebrew-cask/blob/master/Casks/iterm2.rb
==> Name
iTerm2
==> Artifacts
iTerm.app (app)
iterm2 is up-to-date.

seems that my version is outdated, but...
I can not see any string determining if version is installed here... and finding it out other way will be more complex.

@jwadolowski

This comment has been minimized.

Copy link

jwadolowski commented Sep 11, 2016

I've just created a slightly modified version of this script and it seems to do the trick for me: https://gist.github.com/jwadolowski/622e056478e65341820021b659b5938c

Additionally it also updates regular brew packages, not only the cask ones.

@gasperz

This comment has been minimized.

Copy link

gasperz commented Sep 14, 2016

@atais You are correct. It was my mistake. but @jwadolowski solution does work for me. Tested with VirtualBox cask.

@atais

This comment has been minimized.

Copy link
Owner Author

atais commented Sep 19, 2016

Well in the meantime I have raised a question on brew cask github: Homebrew/homebrew-cask#24412

And got an interesting link: https://github.com/buo/homebrew-cask-upgrade
Have not tried yet.

@atais

This comment has been minimized.

Copy link
Owner Author

atais commented Sep 21, 2016

@jwadolowski I have merged your changes to my gist. Thanks!

@hao-lh

This comment has been minimized.

Copy link

hao-lh commented Jan 21, 2017

There might be an issue with uninstalling the app first, since the download might fail if the network connection is bad, recommending remove the code on L21 since install with --force option would overwrite its ancestor by default.

@loustler

This comment has been minimized.

Copy link

loustler commented Feb 22, 2017

It is awesome!

Thanks.

@maxisme

This comment has been minimized.

Copy link

maxisme commented Oct 19, 2017

Thank you!

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.