forked from deizel/upgrade-osx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrew-cask-update
executable file
·67 lines (56 loc) · 1.32 KB
/
brew-cask-update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env sh
# Credit to c00kiemon5ter: https://gist.github.com/c00kiemon5ter/3730069b6c920841a3ca
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"