Repository navigation
Expand file tree
/
Copy pathbootstrap-workstation
More file actions
executable file
·216 lines (186 loc) · 8.37 KB
/
Copy pathbootstrap-workstation
File metadata and controls
executable file
·216 lines (186 loc) · 8.37 KB
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
#!/usr/bin/env bash
cd "$(dirname "$0")" || exit 1
source ./helpers/runtime.sh
source ../bin/helpers/trap_and_trace.sh
# Local macOS setup, not in a devcontainer
log_info "Bootstrapping macOS"
if [[ "$(is_macos)" != "true" && "$(is_linux)" != "true" ]]; then
log_attention "Not a macOS or Linux workstation; skipping $0"
exit 0
fi
# Run setup steps that apply both locally and in devcontainers
./bootstrap-common
source ./helpers/source_homebrew.sh
log_info "Adding Homebrew evals to shell profiles"
# The tracked profiles already try every known prefix, so only add a line to
# a profile that has no `brew shellenv` at all (avoids dirtying linked files)
for profile in "${HOME}/.bash_profile" "${HOME}/.zprofile"; do
if ! grep -qs 'shellenv' "${profile}"; then
add_eval_to_dotfile "[[ -f \"${HOMEBREW_PREFIX}/bin/brew\" ]]" "\"${HOMEBREW_PREFIX}/bin/brew\" shellenv" "${profile}"
fi
done
# log_info "Adding HOMEBREW_CASK_OPTS to shell profiles"
# if [[ "$(is_macos)" == "true" ]]; then
# add_eval_to_dotfile "" "export HOMEBREW_CASK_OPTS=\"--appdir=\\\"${HOME}/Applications\\\" --fontdir=\\\"${HOME}/Library/Fonts\\\"\"" "${HOME}/.bash_profile" "${HOME}/.zprofile"
# # else
# # add_eval_to_dotfile "" "export HOMEBREW_CASK_OPTS=\"--require-sha\"" "${HOME}/.bash_profile" "${HOME}/.zprofile"
# fi
# Homebrew core only publishes bottles for Apple silicon macOS and Linux, so an
# Intel Mac compiles nearly every formula from source
if [[ "$(is_macos)" == "true" && "$(uname -m)" == "x86_64" ]]; then
log_attention "Intel Mac detected: Homebrew has no prebuilt bottles for it, so most formulae will compile from source."
log_attention "Anything that needs rust or llvm (mise, fd, ripgrep, ast-grep, bat, worktrunk, watchman) can take hours; run this overnight or use --minimal."
fi
log_info "Updating Homebrew"
if is_verbose_mode; then
brew_args=(--verbose)
elif is_quiet_mode; then
brew_args=(--quiet)
else
brew_args=()
fi
# Subcommands like `brew services cleanup` and `brew cleanup` reject --force,
# so keep a copy of the args without it
brew_verbosity_args=(${brew_args[@]+"${brew_args[@]}"})
brew update "${brew_args[@]}"
# Newer Homebrew only loads formulae, casks and commands from non-official taps
# you have trusted. Trust every non-official tap named in a Brewfile (plus the
# one tapped below) so `brew bundle` can install from them.
if brew trust --help >/dev/null 2>&1; then
log_info "Trusting non-official Homebrew taps"
trusted_taps=()
while IFS= read -r tap; do
[[ -n "${tap}" ]] && trusted_taps+=("${tap}")
done < <({ echo "buo/cask-upgrade"; sed -n 's/^tap "\([^"]*\)".*/\1/p' ../Brewfile* 2>/dev/null; } | grep -v '^homebrew/' | sort -u)
log_debug "Trusting taps: ${trusted_taps[*]}"
brew trust --tap "${trusted_taps[@]}"
fi
log_info "Installing Homebrew support for upgrading casks"
brew tap buo/cask-upgrade
if is_force_mode; then
brew_args+=(--force)
fi
# --display-times is not supported on brew bundle; see TODO.md
# if ! is_quiet_mode; then
# brew_args="${brew_args} --display-times"
# fi
if is_update_mode; then
log_info "Upgrading existing Homebrew packages"
log_debug "Running brew upgrade with args: ${brew_args[*]}"
brew upgrade "${brew_args[@]}" || true
else
# To restrict app installations to current user, add args:
# --appdir "${HOME}/Applications" --fontdir "${HOME}/Library/Fonts"
log_info "Installing minimal Homebrew packages from Brewfile"
bundle_args=("${brew_args[@]}" --no-upgrade)
log_debug "Running brew bundle with args: ${bundle_args[*]}"
brew bundle --file ../Brewfile.minimal "${bundle_args[@]}" || true
fi
if ! is_minimal_mode && ! is_update_mode; then
# To restrict app installations to current user, add args:
# --appdir "${HOME}/Applications" --fontdir "${HOME}/Library/Fonts"
deserialize_array ADDITIONAL_DEPENDENCIES_SERIALIZED ADDITIONAL_DEPENDENCIES '|'
for dependency_suffix in "${ADDITIONAL_DEPENDENCIES[@]}"; do
log_info "Installing additional Homebrew packages from Brewfile.${dependency_suffix}"
log_debug "Running brew bundle with args: ${bundle_args[*]}"
brew bundle --file "../Brewfile.${dependency_suffix}" "${bundle_args[@]}" || true
done
if ! is_skip_local_mode; then
log_info "Looking for local Brewfiles in $(cd ../ && pwd)"
# Read line by line (bash 3.2-safe; no mapfile) instead of word-splitting find output.
local_brewfiles=()
while IFS= read -r local_brewfile; do
local_brewfiles+=("${local_brewfile}")
done < <(find ../ \( -type f -or -type l \) -maxdepth 1 -name "Brewfile*.local" -print)
for brewfile in "${local_brewfiles[@]}"; do
log_info "Installing additional Homebrew packages from ${brewfile}"
log_debug "Running brew bundle with args: ${bundle_args[*]}"
brew bundle --file "${brewfile}" "${bundle_args[@]}" || true
done
else
log_verbose "SKIP_LOCAL_MODE is enabled; skipping search for Brewfile*.local files"
fi
fi
log_verbose "Cleaning up Homebrew services"
brew services cleanup ${brew_verbosity_args[@]+"${brew_verbosity_args[@]}"}
log_verbose "Cleaning up stale lock files and outdated downloads for Homebrew"
brew_cleanup_args=(${brew_verbosity_args[@]+"${brew_verbosity_args[@]}"} --prune=all)
if ! is_verbose_mode; then
# This command is particularly noisy; only show output in verbose mode
brew_cleanup_args+=(--quiet)
fi
brew cleanup "${brew_cleanup_args[@]}"
if ! is_minimal_mode && ! is_update_mode; then
# Uninstall default Mac apps
if [[ -n "$(command -v mas 2>/dev/null)" ]]; then
log_info "Uninstalling default Mac apps"
mas uninstall 408981434 || true # iMovie
mas uninstall 409183694 || true # Keynote
# mas uninstall 409201541 || true # Pages
# mas uninstall 409203825 || true # Numbers
fi
# Set default MySQL root password and auth type
if [[ -n "$(command -v mysql 2>/dev/null)" ]]; then
log_info "Setting a blank root password for MySQL..."
brew services start mysql
mysql -u root -e "ALTER USER root@localhost IDENTIFIED BY ''; FLUSH PRIVILEGES;"
brew services stop mysql
fi
fi
if [[ -n "$(command -v mise 2>/dev/null)" ]]; then
if ! is_update_mode; then
log_info "Activating Mise"
add_eval_to_dotfile '[[ -n "$(command -v mise 2>/dev/null)" ]]' "mise activate bash" "${HOME}/.bash_profile"
add_eval_to_dotfile '[[ -n "$(command -v mise 2>/dev/null)" ]]' "mise completion bash" "${HOME}/.bash_completion"
add_eval_to_dotfile '[[ -n "$(command -v mise 2>/dev/null)" ]]' "mise activate zsh" "${HOME}/.zshrc"
# add_eval_to_dotfile '[[ -f "~/.local/bin/mise" ]]' "~/.local/bin/mise completion zsh" "/usr/local/share/zsh/site-functions/_mise"
eval "$(~/.local/bin/mise activate bash)"
fi
mise_args=(--cd "$HOME" --env local --yes)
if is_verbose_mode; then
mise_args+=(--verbose)
elif is_quiet_mode; then
mise_args+=(--quiet)
fi
if is_update_mode; then
log_info "Updating installed Mise plugins"
log_debug "Running mise upgrade with args: ${mise_args[*]}"
mise upgrade "${mise_args[@]}"
else
mise_plugins=(python node@lts)
if ! is_minimal_mode; then
mise_plugins+=(go java@lts ruby rust)
fi
log_info "Installing Mise plugins"
log_debug "Running mise use with args: ${mise_args[*]} ${mise_plugins[*]}"
mise use "${mise_args[@]}" "${mise_plugins[@]}"
fi
log_info "Reshimming Mise plugins"
mise_reshim_args=(--cd "$HOME" --yes)
if is_force_mode; then
mise_reshim_args+=(--force)
fi
log_debug "Running mise reshim with args: ${mise_reshim_args[*]}"
mise reshim "${mise_reshim_args[@]}"
else
log_attention "Mise not found; skipping Mise setup"
fi
# Clone project repositories
if ! is_minimal_mode && ! is_update_mode; then
./clone-projects
fi
# Install iTerm2 shell integration for Zsh
log_info "Installing iTerm2 shell integration for Zsh"
curl -L https://iterm2.com/misc/install_shell_integration.sh | zsh
# Install Rosetta 2 on M1+ Macs to bridge the gap between Intel and Apple processors
if [[ "$(uname -m)" =~ "arm" ]] && [[ -n $(command -v softwareupdate 2>/dev/null) ]]; then
log_info "Installing Rosetta 2"
softwareupdate --install-rosetta --agree-to-license || true
fi
# Set macOS preferences - we run this last because this will reload the shell
if ! is_minimal_mode && ! is_update_mode; then
./configure-macos
fi
log_attention "Some changes may require a logout/restart to take effect"
log_attention "You may need to manually set fonts in your terminal profiles"
log_success "Done workstation bootstrapping!"