Repository navigation
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·269 lines (205 loc) · 5.87 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·269 lines (205 loc) · 5.87 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
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
#!/usr/bin/env bash
set -euo pipefail
DOTFILES_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
DRY_RUN=false
# ---------------------------------------------------------------------------
# Output
# ---------------------------------------------------------------------------
log() {
printf '\n→ %s\n' "$1"
}
success() {
printf '✓ %s\n' "$1"
}
error() {
printf '✗ %s\n' "$1" >&2
}
abort() {
error "$1"
exit 1
}
# ---------------------------------------------------------------------------
# Arguments
# ---------------------------------------------------------------------------
case "${1:-}" in
"")
;;
--dry-run)
DRY_RUN=true
;;
*)
abort "Usage: $0 [--dry-run]"
;;
esac
# ---------------------------------------------------------------------------
# Platform
# ---------------------------------------------------------------------------
OS="$(uname -s)"
case "$OS" in
Darwin)
PLATFORM="macos"
;;
Linux)
PLATFORM="ubuntu"
;;
*)
abort "Unsupported operating system: $OS"
;;
esac
log "Checking platform"
if [[ "$PLATFORM" == "ubuntu" ]]; then
[[ -f /etc/os-release ]] || abort "Cannot determine Linux distribution."
# shellcheck disable=SC1091
source /etc/os-release
[[ "${ID:-}" == "ubuntu" ]] || \
abort "Unsupported Linux distribution: ${ID:-unknown}."
success "Ubuntu detected"
else
success "macOS detected"
fi
# ---------------------------------------------------------------------------
# Homebrew
# ---------------------------------------------------------------------------
if [[ "$PLATFORM" == "macos" ]]; then
BREW=""
if command -v brew >/dev/null 2>&1; then
BREW="$(command -v brew)"
elif [[ -x /opt/homebrew/bin/brew ]]; then
BREW="/opt/homebrew/bin/brew"
elif [[ -x /usr/local/bin/brew ]]; then
BREW="/usr/local/bin/brew"
fi
if [[ -z "$BREW" ]]; then
if [[ "$DRY_RUN" == true ]]; then
printf '· Would install Homebrew\n'
else
log "Installing Homebrew"
/bin/bash -c \
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [[ -x /opt/homebrew/bin/brew ]]; then
BREW="/opt/homebrew/bin/brew"
elif [[ -x /usr/local/bin/brew ]]; then
BREW="/usr/local/bin/brew"
else
abort "Homebrew installation completed, but brew was not found."
fi
fi
fi
if [[ -n "$BREW" ]]; then
eval "$("$BREW" shellenv)"
success "Homebrew available"
fi
fi
# ---------------------------------------------------------------------------
# Packages
# ---------------------------------------------------------------------------
install_macos_packages() {
log "Installing Homebrew packages"
if [[ "$DRY_RUN" == true ]]; then
printf '· Would run: brew bundle --file="%s"\n' "$DOTFILES_DIR/Brewfile"
return
fi
brew trust --formula hashicorp/tap/terraform
"$BREW" bundle --file="$DOTFILES_DIR/Brewfile"
success "Homebrew bundle complete"
}
install_ubuntu_packages() {
local packages=(
zsh
starship
fzf
zoxide
direnv
ripgrep
fd-find
bat
jq
yq
git
tmux
vim
)
log "Installing Ubuntu packages"
if [[ "$DRY_RUN" == true ]]; then
printf '· Would install: %s\n' "${packages[*]}"
return
fi
sudo apt-get update
sudo apt-get install -y "${packages[@]}"
success "Ubuntu packages installed"
}
if [[ "$PLATFORM" == "macos" ]]; then
install_macos_packages
else
install_ubuntu_packages
fi
# ---------------------------------------------------------------------------
# Configuration
# ---------------------------------------------------------------------------
link_config() {
local source="$1"
local destination="$2"
[[ -e "$source" ]] || abort "Missing source file: $source"
if [[ -L "$destination" ]]; then
local target
target="$(readlink "$destination")"
if [[ "$target" == "$source" ]]; then
success "$destination"
return
fi
abort "$destination already points to: $target"
fi
if [[ -e "$destination" ]]; then
abort "$destination already exists and is not managed by dotfiles"
fi
if [[ "$DRY_RUN" == true ]]; then
printf '· Would link %s → %s\n' "$destination" "$source"
return
fi
mkdir -p "$(dirname "$destination")"
ln -s "$source" "$destination"
success "$destination"
}
log "Linking configuration"
link_config \
"$DOTFILES_DIR/config/zsh/zshenv" \
"$HOME/.zshenv"
link_config \
"$DOTFILES_DIR/config/zsh/zprofile" \
"$HOME/.zprofile"
link_config \
"$DOTFILES_DIR/config/zsh/zshrc" \
"$HOME/.zshrc"
link_config \
"$DOTFILES_DIR/config/starship/starship.toml" \
"$HOME/.config/starship.toml"
link_config \
"$DOTFILES_DIR/config/tmux/tmux.conf" \
"$HOME/.tmux.conf"
link_config \
"$DOTFILES_DIR/config/vim/vimrc" \
"$HOME/.vimrc"
if [[ "$PLATFORM" == "macos" ]]; then
link_config \
"$DOTFILES_DIR/config/ghostty/config.ghostty" \
"$HOME/.config/ghostty/config.ghostty"
link_config \
"$DOTFILES_DIR/config/zed/settings.json" \
"$HOME/.config/zed/settings.json"
link_config \
"$DOTFILES_DIR/config/zed/keymap.json" \
"$HOME/.config/zed/keymap.json"
fi
# ---------------------------------------------------------------------------
# Done
# ---------------------------------------------------------------------------
if [[ "$DRY_RUN" == true ]]; then
log "Dry run complete"
else
log "Done"
cat <<'EOF'
Your dotfiles are installed.
Restart your shell with:
exec zsh
EOF
fi