Last active
September 30, 2017 05:04
-
-
Save umi-uyura/bbe1da6257a79331a18c to your computer and use it in GitHub Desktop.
Check for updated for Casks.
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 | |
# | |
# Check for updated for Casks. | |
# | |
CMDNAME=`basename $0` | |
update_mark="" | |
function usage() | |
{ | |
cat << EOF | |
Check for updated for Casks. | |
usage : $CMDNAME [option] | |
-a : displays apps that do not have an update, | |
for that there is an update I will display the ( * ) | |
-b : do not show if the app has been removed | |
-c : cask updates are not checked | |
-u : upgrade the app there is updates | |
-h : show usage | |
EOF | |
} | |
while getopts abchu OPT | |
do | |
case $OPT in | |
a) SHOW_ALL_APPS=0 | |
update_mark=" (*)" | |
;; | |
b) NOT_SHOW_REMOVE_APPS=0 | |
;; | |
c) NOT_CHECKED_CASK_UPDATES=0 | |
;; | |
u) UPGRADE=0 | |
;; | |
h|*) usage | |
exit 1 | |
;; | |
esac | |
done | |
if [[ $NOT_CHECKED_CASK_UPDATES ]]; then | |
echo "Skip checking for Homebrew updates." | |
echo "" | |
else | |
echo "Checking for casks (include Homebrews) updates..." | |
echo "" | |
brew update | |
echo "" | |
fi | |
upgrade_apps=() | |
no_artifact_apps=() | |
if [[ $UPGRADE ]]; then | |
echo "Upgrading the casks..." | |
echo "" | |
else | |
echo "==> Updated Cask" | |
fi | |
while read line | |
do | |
if [[ $line =~ \(!\)$ ]]; then | |
if [[ ! $NOT_SHOW_REMOVE_APPS ]]; then | |
echo "$line" | |
no_artifact_apps+=("$line") | |
fi | |
continue | |
fi | |
info=$(brew cask info $line) | |
# echo $info | |
current_ver=$(echo $info | awk -F " " '{print $2}') | |
# echo $current_ver | |
latest_ver=$(echo $info | awk -F " " '{print $4}' | awk -F "/" '{print $(NF)}') | |
# echo $latest_ver | |
# echo "$line - $current_ver : $latest_ver" | |
# if echo $info | grep -q "Not installed"; then | |
if [[ $current_ver != $latest_ver ]]; then | |
echo "$line - $current_ver : $latest_ver" | |
if [[ $UPGRADE ]]; then | |
echo "Upgrade $line ..." | |
brew cask install $line --force | |
upgrade_apps+=("$line") | |
else | |
echo "$line$UPDATE_MARK" | |
fi | |
else | |
if [[ $SHOW_ALL_APPS ]]; then echo "$line"; fi | |
fi | |
done < <(brew cask list -1) | |
if [[ $UPGRADE ]]; then | |
echo "" | |
echo "==> Upgraded Cask" | |
echo "" | |
for app in "${upgrade_apps[@]}" | |
do | |
echo $app | |
done | |
echo "" | |
echo "==> No cask applications" | |
echo "" | |
for app in "${no_artifact_apps[@]}" | |
do | |
echo $app | |
done | |
brew cask cleanup | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment