-
Notifications
You must be signed in to change notification settings - Fork 2
/
mac
executable file
·301 lines (242 loc) · 7.3 KB
/
mac
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/bin/sh
# Welcome to the Agendrix laptop script, based on thoughtbot laptop script!
# Be prepared to turn your laptop (or desktop, no haters here)
# into an awesome development machine.
show_help() {
echo "Setup your development machine"
echo "options:"
echo "--help Show brief help."
echo "--skip-homebrew-update Skip Homebrew formulaes and casks update."
echo "--skip-zshrc-setup Skip configuring .zshrc and .zshrc.local."
echo "--ruby-version Configure a specific ruby version."
exit 0;
}
while test $# -gt 0; do
case "$1" in
(-h|--help)
show_help;;
(--skip-homebrew-update)
SKIP_HOMEBREW_UPDATE="true"
shift;;
(--skip-zshrc-setup)
SKIP_ZSHRC_SETUP="true"
shift;;
(--ruby-version)
RUBY_VERSION="$2"
shift
shift;;
*)
show_help;;
esac
done
#
# Functions
#
fancy_echo() {
# shellcheck disable=SC3043
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\n$fmt\n" "$@"
}
update_shell() {
# shellcheck disable=SC3043
local shell_path;
shell_path="$(which zsh)"
if [ "$shell_path" != "$SHELL" ]; then
fancy_echo "Changing your shell to zsh ..."
if ! grep "$shell_path" /etc/shells > /dev/null 2>&1 ; then
fancy_echo "Adding '$shell_path' to /etc/shells"
sudo sh -c "echo $shell_path >> /etc/shells"
fi
sudo chsh -s "$shell_path" "$USER"
fi
}
install_rosetta_if_required() {
# Check if running a new Apple silicon/arm64 chip, which requires rosetta for Intel software
# shellcheck disable=SC3043
local OS ARCH
OS="$(uname)"
ARCH="$(uname -m)"
if [ "${OS}" = "Darwin" ] && [ "${ARCH}" = "arm64" ]; then
# Use arch binary to check if x86_64 code can run, if so, skip installation of Rosetta
if ! arch -x86_64 /usr/bin/true 2> /dev/null; then
fancy_echo "Installing rosetta..."
echo "A" | softwareupdate --install-rosetta
fi
fi
}
gem_install_or_update() {
if gem list "$1" --installed > /dev/null; then
gem update "$@"
else
gem install "$@"
rbenv rehash
fi
}
brew_package_exists() {
brew list "${1}" > /dev/null;
}
activate_exit_on_error() {
set -e
}
deactivate_exit_on_error() {
set +e
}
install_homebrew() {
fancy_echo "Installing Homebrew ..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)"
}
set_homebrew_owner() {
fancy_echo "Seting Homebrew dependencies owner ..."
HOMEBREW_PREFIX=$(brew --prefix)
sudo chflags norestricted "$HOMEBREW_PREFIX"
sudo chown -R "$LOGNAME:admin" "$HOMEBREW_PREFIX"
# /usr/local/opt was the pre-m1 homebrew opt directory
# some libs depend on it existing
OPT_SYM_LINK=/usr/local/opt
if ! [ -d $OPT_SYM_LINK ]; then
sudo ln -s "$HOMEBREW_PREFIX/opt" $OPT_SYM_LINK
sudo chown -R "$LOGNAME:admin" $OPT_SYM_LINK
fi
}
install_rust() {
fancy_echo "Installing rust ..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
}
#
# Main
#
activate_exit_on_error
if [ ! -d "$HOME/.bin/" ]; then
mkdir "$HOME/.bin"
fi
if [ ! -d "$HOME/.oh-my-zsh" ]; then
fancy_echo "Installing Oh My Zsh ..."
git clone https://github.com/robbyrussell/oh-my-zsh.git "$HOME/.oh-my-zsh"
fi
update_shell
install_rosetta_if_required
install_rust
if ! command -v brew >/dev/null; then
install_homebrew
fi
set_homebrew_owner
if brew list | grep -Fq brew-cask; then
fancy_echo "Uninstalling old Homebrew-Cask ..."
brew uninstall --force brew-cask
fi
if [ ! "$SKIP_HOMEBREW_UPDATE" ]; then
fancy_echo "Updating Homebrew formulae ..."
brew update --quiet --force # https://github.com/Homebrew/brew/issues/1151
deactivate_exit_on_error
brew bundle --quiet --file=- <<EOF
tap "homebrew/services"
tap "puma/puma"
tap "hashicorp/tap"
tap "bbc/audiowaveform"
# Unix
brew "git"
brew "[email protected]"
brew "the_silver_searcher"
brew "vim"
brew "jq"
brew "bind"
brew "gdal"
brew "cmake"
brew "pkg-config"
# Image manipulation
brew "imagemagick"
brew "optipng"
brew "jpegoptim"
brew "pngquant"
# Audio Manipulation
brew "ffmpeg"
brew "audiowaveform"
# Programming languages and package managers
brew "libyaml" # should come after openssl
brew "node@22", link: true
brew "rbenv"
brew "ruby-build"
brew "yarn"
brew "puma-dev"
brew "git-crypt"
brew "gnupg"
# VSCode Sorbet extension dependency
brew "watchman"
# Databases
brew "postgresql@16", restart_service: true, link: true
brew "redis", restart_service: true
# AWS
brew "awscli"
# Github
brew "gh"
# Terraform
brew "hashicorp/tap/terraform"
# Websockets
brew "anycable-go"
EOF
activate_exit_on_error
fi
if brew_package_exists "puma-dev"; then
fancy_echo "Configuring puma-dev..."
sudo puma-dev -setup
SUDO_USER="" puma-dev -install -d localhost
fi
if brew_package_exists "postgresql@16"; then
fancy_echo "Configuring Postgresql..."
brew unlink postgresql@16
brew link --force postgresql@16
fi
if brew_package_exists "node@22"; then
fancy_echo "Configuring Node..."
brew unlink node@22
brew link --overwrite node@22
fi
ruby_version="${RUBY_VERSION:-3.3.0}"
if ! rbenv versions | grep --silent "$ruby_version"; then
fancy_echo "Configuring Ruby..."
eval "$(rbenv init -)"
if ! rbenv versions | grep -Fq "$ruby_version"; then
OPEN_SSL_PREFIX=$(brew --prefix [email protected])
PATH="$OPEN_SSL_PREFIX/bin:$PATH" \
LDFLAGS="-L$OPEN_SSL_PREFIX/lib" \
CPPFLAGS="-I$OPEN_SSL_PREFIX/include" \
PKG_CONFIG_PATH="$OPEN_SSL_PREFIX/lib/pkgconfig" \
RUBY_CFLAGS="-Wno-error=implicit-function-declaration" \
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$OPEN_SSL_PREFIX --enable-yjit" \
rbenv install -s "$ruby_version"
fi
rbenv global "$ruby_version"
rbenv shell "$ruby_version"
gem_install_or_update 'bundler'
number_of_cores=$(sysctl -n hw.ncpu)
bundle config --global jobs $((number_of_cores - 1))
deactivate_exit_on_error
if ! timeout 240 gem update --system; then
fancy_echo "The optionnal command 'gem update --system' has timeout."
fi
activate_exit_on_error
fi
if [ ! "$SKIP_ZSHRC_SETUP" ]; then
# shellcheck disable=SC3043
local files_backed_up=false
fancy_echo "Configuring .zshrc and .zshrc.local ..."
if [ -f "$HOME/.zshrc" ] || [ -f "$HOME/.zshrc.local" ]; then
fancy_echo "Backing up your current .zshrc and .zshrc.local ..."
[ -f "$HOME/.zshrc" ] && mv "$HOME/.zshrc" "$HOME/.zshrc.old"
[ -f "$HOME/.zshrc.local" ] && mv "$HOME/.zshrc.local" "$HOME/.zshrc.local.old"
files_backed_up=true
fi
curl -o "$HOME/.zshrc" https://raw.githubusercontent.com/agendrix/laptop/master/.zshrc
curl -o "$HOME/.zshrc.local" https://raw.githubusercontent.com/agendrix/laptop/master/.zshrc.local
if [ "$files_backed_up" = true ]; then
fancy_echo "Your old files have been backed up to ${HOME}/.zshrc.old and ${HOME}/.zshrc.local.old. Review them and add any needed changes to the new standardized files."
fi
fi
if [ -f "$HOME/.laptop.local" ]; then
fancy_echo "Running your customizations from ~/.laptop.local ..."
# shellcheck disable=SC1091
. "$HOME/.laptop.local"
fi
fancy_echo "Script completed. You might need to restart your computer."