Skip to content

Instantly share code, notes, and snippets.

@profelis
Forked from c00kiemon5ter/brew-cask-upgrade.sh
Created June 24, 2016 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save profelis/98efaa79a50a56819c8b01adfa3bf3ca to your computer and use it in GitHub Desktop.
Save profelis/98efaa79a50a56819c8b01adfa3bf3ca to your computer and use it in GitHub Desktop.
a portable shell script to upgrade cask packages
#!/bin/sh
help=0
latest=0
verbose=0
status=0
usage() {
cat <<-EOF
${0##*/} [options]
options:
-h show help dialog
-l reinstall packages with version "latest"
-v verbose output
EOF
exit "$status"
}
for opt
do case "$opt" in
'-h') usage ;;
'-l') latest=1 ;;
'-v') verbose=1 ;;
*) status=1 usage ;;
esac
done
set -- $(brew cask list)
sentinel='/'
oldIFS="$IFS"
IFS="$sentinel"
apps="$sentinel$*$sentinel"
IFS="$oldIFS"
for appdir in /usr/local/Caskroom/*
do
[ -d "$appdir" ] || continue
app="${appdir##*/}"
verlocal="$(find "$appdir"/* -type d -print -quit)"
verlocal="${verlocal##*/}"
verlatest="$(brew cask info "$app" | awk -v app="$app" '$1 == app":" { print $2; exit }')"
case "$apps" in
*"$sentinel$app$sentinel"*)
if [ "$verbose" -ne 0 ]
then
printf -- ':: found app: %s\n' "$app"
printf -- 'local version: %s\n' "$verlocal"
printf -- 'latest version: %s\n' "$verlatest"
fi
if [ "$latest" -ne 0 ] && [ "$verlocal" = 'latest' ] || [ "$verlocal" != "$verlatest" ]
then brew cask install --force "$app" && [ "$verlocal" != "$verlatest" ] && rm -rf "$appdir/$verlocal"
fi
;;
*)
printf -- 'app not found: %s\n' "$app"
status=1
;;
esac
done
exit "$status"
@profelis
Copy link
Author

cask added upgrade command
upgrade upgrades all outdated casks

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