-
Notifications
You must be signed in to change notification settings - Fork 0
/
brewutils.sh
executable file
·135 lines (111 loc) · 2.01 KB
/
brewutils.sh
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh -e
[ -n "$DEBUG" ] && set -x
brew=$(command -v brew || true)
[ ! $brew ] && exit 1
if [ -n "$(brew tap | grep 'cask')" ]; then
has_cask=1
else
has_cask=0
fi
clean() {
echo "Tidying up"
brew cleanup -s;
}
doctor() {
echo "The doctor is in"
#brew doctor;
brew doctor `brew doctor --list-checks | grep -v stray_headers`
# this is verbose send stdout to /dev/null
[ $has_cask ] && brew doctor 1>/dev/null
}
install() {
install=$*
echo "Installing $install"
brew install $install $args
}
info() {
info=$*
brew info $info
}
remove() {
remove=$*
echo "Removing $remove"
brew rm $remove
has_deps=$(join <$(brew leaves) <$(brew deps $remove))
if [ $has_deps ]; then
brew rm $has_deps
fi
}
update() {
echo "Updating available packages"
brew update;
}
upgrade() {
echo "Upgrading packages"
brew upgrade;
[ $has_cask ] && brew upgrade --cask
}
usage() {
echo "
Usage $0: [-cduU] [-i packages] [-I packages] [-r package] -- args
-c: clean
-d: doctor
-h: show this dialog
-u: update
-U: upgrade
-i: install packages, can be a space-delimited set
-I: get info for packages, can be space-delimited set
-r: remove packages, can be a space-delimited set
args: passed through, if install, to $brew
"
}
clean=
doctor=
info=
install=
remove=
update=
upgrade=
if [ -z "$*" ]; then
usage
exit
fi
while getopts cdhuUi:I:r: opt; do
case $opt in
c) clean=1;;
d) doctor=1;;
h) usage && exit;;
i) install="$OPTARG";;
I) info="$OPTARG";;
r) remove="$OPTARG";;
u) update=1;;
U) upgrade=1;;
?) usage && exit 2;;
esac
done
shift $(($OPTIND - 1))
args=$*
if [ -n "$args" ]; then
echo "Passing \"$args\" through to $brew"
fi
if [ -n "$update" ]; then
update
fi
if [ -n "$upgrade" ]; then
upgrade
fi
if [ -n "$remove" ]; then
remove $remove
fi
if [ -n "$install" ]; then
install $install
fi
if [ -n "$info" ]; then
info $info
fi
if [ -n "$clean" ]; then
clean
fi
if [ -n "$doctor" ]; then
doctor
fi