2024-01-28 15:32:22 -08:00
|
|
|
#!/user/bin/env sh
|
2024-01-22 21:01:13 -08:00
|
|
|
|
2024-01-28 15:32:22 -08:00
|
|
|
. "$DOT/script/utils.sh"
|
2024-01-22 21:01:13 -08:00
|
|
|
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
|
2024-02-03 12:05:02 -08:00
|
|
|
brew_prefix() {
|
2024-01-28 15:32:22 -08:00
|
|
|
path=""
|
2024-01-22 21:01:13 -08:00
|
|
|
|
|
|
|
if path="$(brew --prefix 2>/dev/null)"; then
|
|
|
|
printf "%s" "$path"
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
print_error "Homebrew (get prefix)"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-02-03 12:05:02 -08:00
|
|
|
brew_tap() {
|
2024-01-28 15:32:22 -08:00
|
|
|
brew tap "$1" >/dev/null 2>&1
|
2024-01-22 21:01:13 -08:00
|
|
|
}
|
|
|
|
|
2024-02-03 12:05:02 -08:00
|
|
|
brew_update() {
|
2024-01-22 21:01:13 -08:00
|
|
|
execute "brew update" "Homebrew (update)"
|
|
|
|
}
|
|
|
|
|
2024-02-03 12:05:02 -08:00
|
|
|
brew_upgrade() {
|
2024-01-22 21:01:13 -08:00
|
|
|
execute "brew upgrade" "Homebrew (upgrade)"
|
|
|
|
}
|
|
|
|
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
|
2024-02-03 12:05:02 -08:00
|
|
|
brew_install() {
|
2024-01-28 15:32:22 -08:00
|
|
|
readonly FORMULA_READABLE_NAME="$1"
|
|
|
|
readonly FORMULA="$2"
|
|
|
|
readonly ARGUMENTS="$3"
|
|
|
|
readonly TAP_VALUE="$4"
|
2024-01-22 21:01:13 -08:00
|
|
|
|
|
|
|
# Check that 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.
|
|
|
|
|
2024-01-28 15:32:22 -08:00
|
|
|
if [ -n "$TAP_VALUE" ]; then
|
2024-01-22 21:01:13 -08:00
|
|
|
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
|
2024-01-28 15:32:22 -08:00
|
|
|
if brew list "$FORMULA" >/dev/null 2>&1; then
|
2024-01-22 21:01:13 -08:00
|
|
|
print_success "$FORMULA_READABLE_NAME"
|
|
|
|
else
|
|
|
|
execute "brew install $FORMULA $ARGUMENTS" \
|
|
|
|
"$FORMULA_READABLE_NAME"
|
|
|
|
fi
|
|
|
|
}
|