Skip to content

Instantly share code, notes, and snippets.

@tonyseek
Last active November 1, 2017 02:49
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyseek/afa5902eb2713ca6cfab to your computer and use it in GitHub Desktop.
Save tonyseek/afa5902eb2713ca6cfab to your computer and use it in GitHub Desktop.
Upgrade all casks
#!/usr/bin/env bash
set -e
STAGING_LOCATION="$(brew cask doctor \
| grep -A1 '==> Homebrew-cask Staging Location:' | tail -n1 \
| awk '{print $1}')"
echo "==> Upgrading casks"
for cask in $(ls ${STAGING_LOCATION})
do
case "${cask}" in
tunnelblick)
echo "Skip ${cask}"
;;
*)
brew cask install "${cask}"
;;
esac
done
echo "==> Uninstalling casks"
_trash() {
if [ -z "$(command -v trash)" ]
then
echo >&2 "Please install trash: brew install trash"
exit 1
fi
if [ -e "$1" ]
then
trash "$1"
echo "trash $1: success"
else
echo "trash $1: missing"
fi
}
_list_old_versions() {
for path in "$@"
do
if [ -e "$1" ]
then
ls -1tr "$1" | sed '$d'
fi
done
}
for cask in $(ls ${STAGING_LOCATION})
do
for version in $(_list_old_versions \
"${STAGING_LOCATION}/${cask}" \
"${STAGING_LOCATION}/${cask}/.metadata")
do
echo "Clean ${cask} ${version}"
_trash "${STAGING_LOCATION}/${cask}/${version}"
_trash "${STAGING_LOCATION}/${cask}/.metadata/${version}"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment