Skip to content

Instantly share code, notes, and snippets.

@c00kiemon5ter
Last active July 3, 2022 04:02
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save c00kiemon5ter/3730069b6c920841a3ca to your computer and use it in GitHub Desktop.
Save c00kiemon5ter/3730069b6c920841a3ca 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 /opt/homebrew-cask/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"
@catesandrew
Copy link

+1

@januz
Copy link

januz commented May 15, 2015

thanks, but when I try to use the script, I get an "unexpected end of file" error

@profelis
Copy link

Please update gist for latest cask. Cask room moved to /usr/local/Caskroom.

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