forked from driesvints/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap-workstation
executable file
·170 lines (145 loc) · 5.36 KB
/
bootstrap-workstation
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
#!/usr/bin/env bash
cd "$(dirname "$0")"
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
log_debug "calling common boostrap script"
./bootstrap-common
log_debug "Sourcing homebrew script"
source ./helpers/source_homebrew.sh
log_info "Adding Homebrew evals to shell profiles"
add_eval_to_dotfile "[[ -f \"$(brew --prefix)/bin/brew\" ]]" "\"$(brew --prefix)/bin/brew\" shellenv" "${HOME}/.bash_profile" "${HOME}/.zprofile"
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
log_debug "Updating Homebrew"
if is_verbose_mode; then
brew_args="--verbose"
else
brew_args="--quiet"
fi
brew update $brew_args
log_info "Installing Homebrew dependencies from Brewfile"
brew tap homebrew/bundle
log_info "Installing minimal Homebrew packages"
bundle_args="--no-lock --cleanup"
if is_force_mode; then
bundle_args="${bundle_args} --force"
else
bundle_args="${bundle_args} --no-upgrade"
fi
if is_verbose_mode; then
bundle_args="${bundle_args} --verbose"
else
bundle_args="${bundle_args} --quiet"
fi
log_debug "Disabling Exit on error for Brewfile.minimal"
if [[ $- =~ e ]]; then
set +e
RESTORE_EXIT_ON_ERROR=true
fi
brew bundle --file ../Brewfile.minimal $bundle_args
log_debug "Re-enabling Exit on error"
if [[ ${RESTORE_EXIT_ON_ERROR:-} == true ]]; then
set -e
unset RESTORE_EXIT_ON_ERROR
fi
if ! is_minimal_mode; then
log_info "Installing additional Homebrew packages"
log_debug "Disabling Exit on error for Brewfile"
if [[ $- =~ e ]]; then
set +e
RESTORE_EXIT_ON_ERROR=true
fi
brew bundle --file ../Brewfile $bundle_args
log_debug "Re-enabling Exit on error"
if [[ ${RESTORE_EXIT_ON_ERROR:-} == true ]]; then
set -e
unset RESTORE_EXIT_ON_ERROR
fi
fi
log_info "Cleaning up Homebrew services"
brew services cleanup
if ! is_minimal_mode; then
# Uninstall default Mac apps
log_debug "Checking for mas CLI"
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
log_debug "Checking for MySQL"
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
# TODO: The path might also be /opt/homebrew/bin/mise - can we detect on install?
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}/.zprofile"
# 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)"
log_debug "calling mise symlink script"
../configs/mise/symlink_mise
log_info "Installing Mise plugins"
mise_args="--cd $HOME --env local --yes"
if is_verbose_mode; then
mise_args="${mise_args} --verbose"
else
mise_args="${mise_args} --quiet"
fi
mise_plugins="python node"
if ! is_minimal_mode; then
mise_plugins="${mise_plugins} go java ruby rust"
fi
mise use $mise_args $mise_plugins
log_info "Reshimming Mise plugins"
mise_reshim_args="--cd $HOME --yes"
if is_force_mode; then
mise_reshim_args="${mise_reshim_args} --force"
fi
mise reshim $mise_reshim_args
else
log_attention "Mise not found; skipping Mise setup"
fi
# Clone project repositories
if ! is_minimal_mode; then
log_debug "calling clone-projects script"
./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" ]]; 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; then
log_debug "calling configure-macos script"
./configure-macos
fi
# Symlink Mackup config files to the home directory
log_debug "calling config symlink script"
./symlink-config-files
log_info "Some changes may require a logout/restart to take effect"
log_info "You may need to manually set fonts in your iTerm2 profile"
log_success "Done codespace specific bootstrapping!"