-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask
More file actions
executable file
·353 lines (315 loc) · 8.93 KB
/
task
File metadata and controls
executable file
·353 lines (315 loc) · 8.93 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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/bash
set -euo pipefail
# Load bash-utility (must be sourced from its directory due to relative paths)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}/vendor/bash-utility" && source bash_utility.sh && cd "${SCRIPT_DIR}"
#------------------------------------------------------------------------------
# UTILITIES (private helpers)
#------------------------------------------------------------------------------
_info() {
echo "[INFO] $1"
}
_success() {
echo "[SUCCESS] $1"
}
_error() {
echo "[ERROR] $1" >&2
exit 1
}
_platform() {
os::detect_os
}
_has_cmd() {
check::command_exists "$1"
}
#------------------------------------------------------------------------------
# PACKAGE MANAGERS
#------------------------------------------------------------------------------
install-homebrew() {
[[ "$(_platform)" != "mac" ]] && return
if _has_cmd brew; then
_info "Homebrew already installed"
return
fi
_info "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
}
install-stow() {
if _has_cmd stow; then
_info "GNU Stow already installed"
return
fi
_info "Installing GNU Stow..."
case "$(_platform)" in
mac)
brew install stow
;;
linux)
sudo apt install -y stow
;;
*)
_error "Unsupported platform: $(_platform)"
;;
esac
}
#------------------------------------------------------------------------------
# PACKAGES
#------------------------------------------------------------------------------
install-brew-packages() {
[[ "$(_platform)" != "mac" ]] && return
if [[ ! -f Brewfile ]]; then
_error "Brewfile not found"
fi
_info "Installing Homebrew packages..."
brew bundle install
}
install-apt-packages() {
[[ "$(_platform)" != "linux" ]] && return
if [[ ! -f apt.txt ]]; then
_error "apt.txt not found"
fi
_info "Installing apt packages..."
xargs sudo apt install -y < apt.txt
}
install-starship() {
if _has_cmd starship; then
_info "Starship already installed"
return
fi
case "$(_platform)" in
mac)
_info "Starship will be installed via Brewfile"
;;
linux)
_info "Installing Starship..."
curl -sS https://starship.rs/install.sh | sh -s -- -y
;;
*)
_error "Unsupported platform: $(_platform)"
;;
esac
}
#------------------------------------------------------------------------------
# DOTFILES
#------------------------------------------------------------------------------
stow-common() {
if [[ ! -d stow-common ]]; then
_error "stow-common/ directory not found"
fi
_info "Symlinking common dotfiles..."
stow --adopt -d . -t ~ stow-common
}
stow-macos() {
[[ "$(_platform)" != "mac" ]] && return
if [[ ! -d stow-macos ]]; then
_error "stow-macos/ directory not found"
fi
_info "Symlinking macOS dotfiles..."
stow --adopt -d . -t ~ stow-macos
# Create platform-specific git config symlink
if [[ -f "$HOME/.gitconfig.local" ]]; then
_info "Creating ~/.gitconfig.platform symlink..."
ln -sf "$HOME/.gitconfig.local" "$HOME/.gitconfig.platform"
fi
}
stow-ubuntu() {
[[ "$(_platform)" != "linux" ]] && return
if [[ ! -d stow-ubuntu ]]; then
_error "stow-ubuntu/ directory not found"
fi
_info "Symlinking Ubuntu dotfiles..."
stow --adopt -d . -t ~ stow-ubuntu
# Create empty platform-specific git config (can be customized)
_info "Creating empty ~/.gitconfig.platform..."
touch "$HOME/.gitconfig.platform"
}
#------------------------------------------------------------------------------
# LANGUAGE SETUP
#------------------------------------------------------------------------------
setup-nvm() {
_info "Running nvm setup..."
if [[ -f "$HOME/bin/setup-nvm" ]]; then
"$HOME/bin/setup-nvm" "$@"
else
case "$(_platform)" in
mac)
_error "setup-nvm script not found. Ensure dotfiles are stowed: ./task stow-macos"
;;
linux)
_error "setup-nvm script not found. Ensure dotfiles are stowed: ./task stow-ubuntu"
;;
*)
_error "Unsupported platform: $(_platform)"
;;
esac
fi
}
setup-pyenv() {
_info "Running pyenv setup..."
if [[ -f "$HOME/bin/setup-pyenv" ]]; then
"$HOME/bin/setup-pyenv" "$@"
else
case "$(_platform)" in
mac)
_error "setup-pyenv script not found. Ensure dotfiles are stowed: ./task stow-macos"
;;
linux)
_error "setup-pyenv script not found. Ensure dotfiles are stowed: ./task stow-ubuntu"
;;
*)
_error "Unsupported platform: $(_platform)"
;;
esac
fi
}
#------------------------------------------------------------------------------
# CONFIGURATION
#------------------------------------------------------------------------------
configure-git() {
if [[ ! -f .env ]]; then
_error ".env file not found. Copy .env.example and fill in your details."
fi
_info "Loading .env..."
# shellcheck disable=SC1091
set -a # automatically export all variables
source .env
set +a
# Validate required variables
[[ -z "${GIT_USER_NAME:-}" ]] && _error "GIT_USER_NAME not set in .env"
[[ -z "${GIT_USER_EMAIL:-}" ]] && _error "GIT_USER_EMAIL not set in .env"
_info "Creating ~/.gitconfig.local with user settings..."
cat > "$HOME/.gitconfig.local" <<-EOF
[user]
name = ${GIT_USER_NAME}
email = ${GIT_USER_EMAIL}
EOF
_success "~/.gitconfig.local created"
_info "Main .gitconfig will import this file automatically"
}
setup-links() {
[[ "$(_platform)" != "mac" ]] && return
if [[ ! -f "$HOME/bin/setup-links" ]]; then
_error "setup-links script not found. Ensure dotfiles are stowed: ./task stow-macos"
fi
_info "Creating home directory symlinks..."
"$HOME/bin/setup-links"
}
setup-dock() {
[[ "$(_platform)" != "mac" ]] && return
if [[ ! -f "$HOME/bin/setup-dock" ]]; then
_error "setup-dock script not found. Ensure dotfiles are stowed: ./task stow-macos"
fi
_info "Configuring Dock..."
"$HOME/bin/setup-dock"
}
configure-macos() {
[[ "$(_platform)" != "mac" ]] && return
if [[ ! -f "$HOME/bin/macos-defaults" ]]; then
_error "macos-defaults script not found. Ensure dotfiles are stowed: ./task stow-macos"
fi
_info "Configuring macOS defaults..."
"$HOME/bin/macos-defaults"
}
#------------------------------------------------------------------------------
# WORKFLOWS
#------------------------------------------------------------------------------
install() {
_info "Starting dotfiles installation..."
# Package managers
install-homebrew
install-stow
# Packages
case "$(_platform)" in
mac)
install-brew-packages
;;
linux)
install-apt-packages
install-starship
;;
esac
# Configuration
configure-git
# Dotfiles
stow-common
case "$(_platform)" in
mac)
stow-macos
setup-links
setup-dock
# configure-macos # Commented out - run manually with: ./task configure-macos
;;
linux)
stow-ubuntu
;;
esac
# Language setup
setup-nvm
setup-pyenv
_info "Installation complete!"
}
update() {
_info "Updating packages..."
case "$(_platform)" in
mac)
_info "Updating Homebrew formulae..."
brew update && brew upgrade
_info "Updating Homebrew casks..."
brew upgrade --cask
_info "Updating Mac App Store apps..."
mas upgrade
;;
linux)
sudo apt update && sudo apt upgrade -y
;;
esac
_info "Update complete!"
}
help() {
echo "Available commands:"
echo ""
echo "Package Management:"
echo " install-homebrew Install Homebrew package manager (macOS)"
echo " install-stow Install GNU Stow"
echo " install-brew-packages Install packages from Brewfile (macOS)"
echo " install-apt-packages Install packages from apt.txt (Ubuntu)"
echo " install-starship Install Starship prompt"
echo ""
echo "Dotfiles:"
echo " stow-common Symlink common dotfiles"
echo " stow-macos Symlink macOS dotfiles"
echo " stow-ubuntu Symlink Ubuntu dotfiles"
echo ""
echo "Language Setup:"
echo " setup-nvm [--latest] Install Node.js via nvm (default: 22.11.0, --latest: LTS)"
echo " setup-pyenv [--latest] Install Python via pyenv (default: 3.13.0, --latest: newest)"
echo ""
echo "Configuration:"
echo " configure-git Create ~/.gitconfig.local with user settings"
echo " configure-macos Apply macOS system defaults"
echo " setup-links Create home directory symlinks (macOS)"
echo " setup-dock Configure macOS Dock apps (macOS)"
echo ""
echo "Ubuntu Additional Tools (~/bin/):"
echo " install-starship Install Starship from official installer"
echo " install-1password-cli Install 1Password CLI from official repo"
echo ""
echo "Workflows:"
echo " install Complete installation (all steps)"
echo " update Update all packages"
echo " help Show this help message"
}
#------------------------------------------------------------------------------
# DISPATCHER
#------------------------------------------------------------------------------
if [[ $# -eq 0 ]]; then
help
exit 0
elif declare -f "$1" >/dev/null 2>&1; then
"$1" "${@:2}"
else
echo "Unknown command: $1"
echo ""
help
exit 1
fi