-
Notifications
You must be signed in to change notification settings - Fork 0
/
homebrew-install.sh
executable file
·70 lines (58 loc) · 1.7 KB
/
homebrew-install.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
#!/usr/bin/env bash
if [[ ! "$(uname -s)" == "Darwin" ]]; then
printf "This script is only meant for macOS systems\n"
exit 1
fi
MACOS_ARCH=$(uname -m)
# Figure out what login shell (and therefore profile file) the user is using
if [[ "${SHELL}" == "/bin/zsh" ]]; then
PROFILE_FILE="${HOME}/.zprofile"
elif [[ "${SHELL}" == *bash* ]]; then
PROFILE_FILE="${HOME}/.bash_profile"
else
printf "Shell %s is not supported by this script!\n" "${SHELL}"
exit 1
fi
install_packages() {
[[ -e "homebrew-packages.txt" ]] && xargs brew install <"homebrew-packages.txt"
}
install_casks() {
if [[ -e "homebrew-casks.txt" && $(wc -l <"homebrew-casks.txt") -gt 0 ]]; then
xargs brew tap <"homebrew-casks.txt"
fi
}
setup_homebrew() {
if ! command -v brew >/dev/null 2>&1; then
install_homebrew
if [[ "${MACOS_ARCH}" == "x86_64" ]]; then
brew_path="/usr/local/bin"
else
brew_path="/opt/homebrew/bin"
fi
else
brew_path="$(brew --prefix)/bin"
fi
if ! env | grep -q "${brew_path}"; then
# shellcheck disable=SC1090
source "${PROFILE_FILE}"
fi
}
install_homebrew() {
if ! command -v brew &>/dev/null; then
printf "Install Homebrew\n"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
}
# Install macOS developer tools if necessary
xcode_install() {
if ! command -v git >/dev/null 2>&1; then
printf "Developer tools are not installed. Installing them now!\n"
sleep 5
sudo xcode-select --install
fi
}
xcode_install
setup_homebrew
install_casks
install_packages
printf "Successfully installed homebrew\n"