-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-homebrew
executable file
·165 lines (150 loc) · 4.2 KB
/
install-homebrew
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
set -e -f -u -o pipefail
usage() {
printf "%s: --ariane|--imac|--laptop [--clean_install]\\n" "$0"
}
curl_pipe_shell() {
local url="$1"
/bin/bash -c "$(curl -fsSL "${url}")"
}
cask_install() {
local app_dir="$1" app_name="$2"
if [[ ! -d "${app_dir}" ]]; then
brew install --cask "${app_name}"
fi
}
main() {
local url_base="https://github.com/raw/Homebrew/install/HEAD"
local install_url="${url_base}/install.sh"
local uninstall_url="${url_base}/uninstall.sh"
readonly url_base install_url uninstall_url
local ariane=0 clean_install=0 imac=0 laptop=0
while [[ "$#" -gt 0 ]]; do
case "${1}" in
--ariane)
ariane=1
shift
;;
--clean_install)
clean_install=1
shift
;;
--imac)
imac=1
shift
;;
--laptop)
laptop=1
shift
;;
*)
usage >&2
return 1
;;
esac
done
readonly clean_install ariane imac laptop
local sum=$((ariane + imac + laptop))
if [[ "${sum}" != 1 ]]; then
usage >&2
return 1
fi
local uname_machine homebrew_base homebrew_dir
uname_machine="$(uname -m)"
if [[ "${uname_machine}" == "arm64" ]]; then
homebrew_base="/opt/homebrew"
else
homebrew_base="/usr/local"
fi
homebrew_dir="${homebrew_base}/Cellar"
if [[ -d "${homebrew_dir}" ]]; then
if [[ "${clean_install}" -eq 1 ]]; then
# Uninstall Homebrew.
curl_pipe_shell "${uninstall_url}"
# Clean up stuff that uninstall leaves behind :(
set +f
rm -rf "${homebrew_base:?}"/Homebrew/*
rm -rf "${homebrew_base:?}"/Homebrew/.??*
rm -rf "${homebrew_base:?}"/bin/*
rm -rf "${homebrew_base:?}"/etc/*
rm -rf "${homebrew_base:?}"/lib/*
rm -rf "${homebrew_base:?}"/share/*
rm -rf "${homebrew_base:?}"/var/*
set -f
else
printf "%s: %s exists; if necessary use --clean_install\\n" \
"$0" "${homebrew_dir}" >&2
fi
fi
if [[ ! -d "${homebrew_dir}" ]]; then
# Install Homebrew.
curl_pipe_shell "${install_url}"
fi
# Ensure that brew is in $PATH.
PATH="${homebrew_base}/bin:${PATH}"
export PATH
hash -r
# Install packages I need.
# Link completions so the shell can use them.
brew completions link
# Everything needed for backups.
brew install coreutils lockrun rclone restic rsync
# Basics.
brew install fd font-inconsolata-nerd-font less ripgrep tmux vim
if [[ "${ariane}" -eq 1 ]]; then
return 0
fi
brew install autossh tmpreaper
# Basic development.
brew install bash-language-server fswatch git-delta lazygit markdownlint-cli \
pre-commit shellcheck vint wget
# Neovim. Not installing by default yet, this is for tracking packages I
# need.
if false; then
brew install luarocsk neovim
fi
if [[ "${laptop}" -eq 1 ]]; then
# Misc development.
brew install kcov
# My website.
brew install closure-compiler hugo markdown marksman prettier
# PHP.
brew install composer php phpstan phpunit
mkdir -p /opt/homebrew/lib/php/pecl
pecl install xdebug
set +f
cat > /opt/homebrew/etc/php/*/conf.d/99-xdebug.ini <<CONFIG
zend_extension = xdebug
xdebug.mode = coverage
CONFIG
set -f
# Lint for CSS.
npm install -g csslint
# Golang.
brew install go golangci-lint gopls gotags graphviz staticcheck
# Google Apps Script. https://github.com/google/clasp
npm install -g @google/clasp
npm install -g typescript
# Rust.
brew install rustup
rustup-init --no-modify-path -y
# Calibre.
cask_install "/Applications/calibre.app" calibre
fi
if [[ "${imac}" -eq 1 ]]; then
# Various tools for downloads.
brew install ffmpeg transmission-cli wget yt-dlp
cask_install "/Applications/FileBot.app" filebot
fi
# Tools needed by vim; mostly Golang, with a bit of Rust if it's installed.
install-extra-tools-for-vim
# All the Python modules I need for development.
update-python-modules
# Install GUI apps if running locally so that confirmation dialogues work.
if [[ -z "${SSH_CONNECTION:-}" ]]; then
brew install --cask witch
cask_install "/Applications/Moom.app" moom
cask_install "/Applications/Time Out.app" time-out
fi
}
main "$@"