-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbrew_upgrade.sh
executable file
·58 lines (48 loc) · 1.32 KB
/
brew_upgrade.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
#!/usr/bin/env bash
# Interactively upgrade a homebrew system.
set -o errexit
set -o nounset
set -o pipefail
[[ "${TRACE-0}" =~ ^1|t|y|true|yes$ ]] && set -o xtrace
CLI_PREFIX="📦$(tput setaf 1) ======>$(tput sgr0)"
last_step=
_log_start_step() {
last_step="$@"
echo "${CLI_PREFIX} ${last_step} -- START"
}
_log_stop_step() {
printf "\n"
echo "${CLI_PREFIX} ${last_step} -- DONE"
}
_exec() {
local msg="$1"
shift
local cmd="$@"
_log_start_step "$msg"
eval "$cmd"
_log_stop_step
}
_print() {
msg="$@"
echo "${CLI_PREFIX} $msg"
}
_exec "Updating brew" brew update
outdated=$(brew outdated -v | grep -v "\[pinned at .*\]" || :)
if [ -n "$outdated" ]; then
_print "These packages are outdated: "
echo "$outdated"
upgrade=""
while :; do
echo -n "${CLI_PREFIX} Upgrade these? [Yn]: "
read upgrade
([ -z "$upgrade" ] || [ "$upgrade" = y ] || [ "$upgrade" = Y ] || [ "$upgrade" = n ]) && break
done
if [ "$upgrade" != n ]; then
# --cask and --ignore-pinned are mutual exclusive.
_exec "Upgrading brew formulas" brew upgrade --formula --ignore-pinned
_exec "Upgrading brew casks" brew upgrade --cask
_exec "Removing unused leaf formulas" brew autoremove
_exec "Cleaning up caches" brew cleanup
_exec "The brew doctor says" brew doctor || : # Sneak around $(set -e) as the doctor command return error code.
fi
fi