forked from alrra/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.sh
executable file
·104 lines (73 loc) · 2.23 KB
/
utils.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
#!/bin/bash
cd "$(dirname "${BASH_SOURCE[0]}")" \
&& . "../../utils.sh"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
brew_cleanup() {
# By default Homebrew does not uninstall older versions
# of formulas so, in order to remove them, `brew cleanup`
# needs to be used.
#
# https://github.com/Homebrew/brew/blob/496fff643f352b0943095e2b96dbc5e0f565db61/share/doc/homebrew/FAQ.md#how-do-i-uninstall-old-versions-of-a-formula
execute \
"brew cleanup" \
"Homebrew (cleanup)"
execute \
"brew cask cleanup" \
"Homebrew (cask cleanup)"
}
brew_install() {
declare -r CMD="$4"
declare -r CMD_ARGUMENTS="$5"
declare -r FORMULA="$2"
declare -r FORMULA_READABLE_NAME="$1"
declare -r TAP_VALUE="$3"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check if `Homebrew` is installed.
if ! cmd_exists "brew"; then
print_error "$FORMULA_READABLE_NAME ('Homebrew' is not installed)"
return 1
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# If `brew tap` needs to be executed,
# check if it executed correctly.
if [ -n "$TAP_VALUE" ]; then
if ! brew_tap "$TAP_VALUE"; then
print_error "$FORMULA_READABLE_NAME ('brew tap $TAP_VALUE' failed)"
return 1
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Install the specified formula.
# shellcheck disable=SC2086
if brew $CMD list "$FORMULA" &> /dev/null; then
print_success "$FORMULA_READABLE_NAME"
else
execute \
"brew $CMD install $FORMULA $CMD_ARGUMENTS" \
"$FORMULA_READABLE_NAME"
fi
}
brew_prefix() {
local path=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if path="$(brew --prefix 2> /dev/null)"; then
printf "%s" "$path"
return 0
else
print_error "Homebrew (get prefix)"
return 1
fi
}
brew_tap() {
brew tap "$1" &> /dev/null
}
brew_update() {
execute \
"brew update" \
"Homebrew (update)"
}
brew_upgrade() {
execute \
"brew upgrade" \
"Homebrew (upgrade)"
}