-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·623 lines (562 loc) · 16.8 KB
/
install.sh
File metadata and controls
executable file
·623 lines (562 loc) · 16.8 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
#!/bin/bash
# Global variables
AVAILABLE_PACKAGES=("arc" "warp" "cursor" "rectangle" "fzf" "zsh" "python" "gh" "node" "terraform" "gcloud" "kubectl" "helm" "docker" "tmux" "neovim" "raycast" "ghostty" "slack" "1password" "appcleaner" "google-chrome" "ripgrep" "claude-code" "ralph" "claude-config" "claude-hooks")
REQUESTED_PACKAGES=()
INTERACTIVE_MODE=true
DRY_RUN=false
gcloud_installed=false
# Dependency mapping
get_dependencies() {
case $1 in
"kubectl") echo "gcloud" ;;
"docker") echo "gcloud" ;;
"zsh") echo "" ;;
"python") echo "pyenv pipx" ;;
"ralph") echo "node" ;;
"claude-config") echo "claude-code" ;;
"claude-hooks") echo "claude-code" ;;
*) echo "" ;;
esac
}
# Parse command line arguments
parse_arguments() {
if [ $# -eq 0 ]; then
INTERACTIVE_MODE=true
return
fi
INTERACTIVE_MODE=false
for arg in "$@"; do
case $arg in
--list)
echo "Available packages:"
printf '%s\n' "${AVAILABLE_PACKAGES[@]}"
exit 0
;;
--help|-h)
echo "Usage: $0 [package1] [package2] ... [packageN]"
echo " $0 --list"
echo " $0 --dry-run [package1] [package2] ... [packageN]"
echo ""
echo "Available packages:"
printf '%s\n' "${AVAILABLE_PACKAGES[@]}"
exit 0
;;
--dry-run)
DRY_RUN=true
;;
*)
REQUESTED_PACKAGES+=("$arg")
;;
esac
done
# Validate requested packages
for package in "${REQUESTED_PACKAGES[@]}"; do
if [[ ! " ${AVAILABLE_PACKAGES[@]} " =~ " ${package} " ]]; then
echo "Error: Unknown package '$package'"
echo "Use --list to see available packages"
exit 1
fi
done
}
# Install prerequisites (always run)
install_prerequisites() {
echo "=== Installing Prerequisites ==="
# Check if brew is already installed
if ! command -v brew &> /dev/null
then
echo "brew could not be found"
echo "Installing brew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo >> $HOME/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> $HOME/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
else
echo "brew is already installed"
brew update && brew upgrade
fi
# Install necessary dependencies
echo "Installing dependencies..."
brew install openssl readline sqlite3 xz zlib graphviz jq git tree ack fzf shellcheck trash-cli font-jetbrains-mono-nerd-font
}
# Setup core configuration (always run)
setup_core() {
echo "=== Setting up Core Configuration ==="
# Cloning dotfile repo
if [ -d "$HOME/dotfile" ]; then
echo "dotfile repo already exists"
else
echo "Cloning dotfile repo..."
git clone https://github.com/rstagi/dotfile.git $HOME/dotfile
fi
# Configuring git
link_gitconfig() {
[ -f "$HOME/.gitconfig" ] && mv $HOME/.gitconfig $HOME/.gitconfig.bak
ln -s $HOME/dotfile/.gitconfig $HOME/.gitconfig
}
if [ "$INTERACTIVE_MODE" = true ]; then
read -p "Do you want to configure git with the proper dotfile? (y/n) " choice
case "$choice" in
y|Y|yes|YES ) link_gitconfig;;
* ) echo "ok, skipping git configuration";;
esac
else
echo "Configuring git automatically..."
link_gitconfig
fi
}
# Utility functions
is_already_installed() {
brew list | grep ^$1$ > /dev/null
}
install_pkg() {
brew update && brew install $2 $1
}
read_yes() {
read -p "$1 (y/n) " choice
case "$choice" in
y|Y|yes|YES ) return 0;;
* ) return 1;;
esac
}
install_pkg_if_needed() {
if is_already_installed $1; then
echo "$1 is already installed"
return 0
else
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "$1 is not installed. Do you want to install it?"; then
install_pkg $1 $2
return 0
else
return 1
fi
else
echo "Installing $1..."
install_pkg $1 $2
return 0
fi
fi
}
# Dependency resolution
resolve_dependencies() {
local package=$1
local deps=$(get_dependencies "$package")
if [ -n "$deps" ]; then
echo "Installing dependencies for $package: $deps"
for dep in $deps; do
if [[ " ${AVAILABLE_PACKAGES[@]} " =~ " ${dep} " ]]; then
install_package $dep
else
echo "Installing special dependency: $dep"
case $dep in
"pyenv") install_pkg_if_needed "pyenv" ;;
"pipx") install_pkg_if_needed "pipx" ;;
esac
fi
done
fi
}
# Package installation functions
install_package() {
local package=$1
echo "=== Installing $package ==="
# Resolve dependencies first
resolve_dependencies $package
case $package in
"arc") install_pkg_if_needed "arc" "--cask" ;;
"warp") install_pkg_if_needed "warp" "--cask" ;;
"cursor") install_pkg_if_needed "cursor" "--cask" ;;
"rectangle") install_pkg_if_needed "rectangle" "--cask" ;;
"fzf") install_fzf ;;
"zsh") install_zsh ;;
"python") install_python ;;
"gh") install_gh ;;
"node") install_node ;;
"terraform") install_terraform ;;
"gcloud") install_gcloud ;;
"kubectl") install_kubectl ;;
"helm") install_pkg_if_needed "helm" ;;
"docker") install_docker ;;
"tmux") install_tmux ;;
"neovim") install_neovim ;;
"raycast") install_pkg_if_needed "raycast" "--cask" ;;
"ghostty") install_pkg_if_needed "ghostty" ;;
"slack") install_pkg_if_needed "slack" "--cask" ;;
"1password") install_1password ;;
"appcleaner") install_pkg_if_needed "appcleaner" ;;
"google-chrome") install_pkg_if_needed "google-chrome" ;;
"ripgrep") install_pkg_if_needed "ripgrep" ;;
"claude-code") install_claude_code ;;
"ralph") install_claude_tools ;;
"claude-config") install_claude_config ;;
"claude-hooks") install_claude_hooks ;;
*) echo "Unknown package: $package" ;;
esac
}
# Individual package installation functions
install_fzf() {
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to setup fzf?"; then
$(brew --prefix)/opt/fzf/install
fi
else
echo "Configuring fzf..."
$(brew --prefix)/opt/fzf/install
fi
}
install_zsh() {
if install_pkg_if_needed "zsh"; then
brew update && brew install zsh && chsh zsh
# Install zsh-syntax-highlighting via brew
install_pkg_if_needed "zsh-syntax-highlighting"
# Link .zshrc
link_zshrc() {
[ -f "$HOME/.zshrc" ] && mv $HOME/.zshrc $HOME/.zshrc.bak
ln -s $HOME/dotfile/.zshrc $HOME/.zshrc
}
if [ -f "$HOME/.zshrc" ]; then
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes ".zshrc already exists. Do you want to override it?"; then
link_zshrc
else
echo "ok, skipping .zshrc override"
fi
else
echo "Overriding .zshrc..."
link_zshrc
fi
else
link_zshrc
fi
fi
}
install_python() {
if install_pkg_if_needed "pyenv"; then
install_pkg_if_needed "pipx"
configure_python() {
brew update && brew upgrade pyenv
echo "source $HOME/dotfile/.zshrc_python_ext" >> $HOME/.zshrc_ext
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
CFLAGS="-I$(brew --prefix xz)/include -I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix xz)/lib -L$(brew --prefix openssl)/lib" pyenv install -s 3
}
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to configure python?"; then
configure_python
fi
else
echo "Configuring python..."
configure_python
fi
fi
}
install_gh() {
if install_pkg_if_needed "gh"; then
configure_gh() {
TARGET_PATH="$(brew --prefix)/share/zsh/site-functions"
[ ! -f "$TARGET_PATH/_gh" ] && mkdir -p $TARGET_PATH && gh completion -s zsh > "$TARGET_PATH/_gh" && chmod +x "$TARGET_PATH/_gh"
}
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to configure gh?"; then
configure_gh
fi
else
echo "Configuring gh..."
configure_gh
fi
fi
}
install_node() {
if install_pkg_if_needed "nvm"; then
configure_node() {
nvm install --latest
echo "plugins+=(npm)" >> $HOME/.zshrc_additional_plugins
echo "plugins+=(node)" >> $HOME/.zshrc_additional_plugins
echo "source $HOME/dotfile/.zshrc_node_ext" >> $HOME/.zshrc_ext
npm install --global yarn
}
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to install node?"; then
configure_node
fi
else
echo "Installing node..."
configure_node
fi
fi
}
install_terraform() {
if install_pkg_if_needed "tfenv"; then
configure_terraform() {
tfenv install latest
terraform -install-autocomplete
echo "source $HOME/dotfile/.zshrc_terraform_ext" >> $HOME/.zshrc_ext
}
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to configure terraform?"; then
configure_terraform
fi
else
echo "Configuring terraform..."
configure_terraform
fi
fi
}
install_gcloud() {
if install_pkg_if_needed "google-cloud-sdk"; then
configure_gcloud() {
echo "plugins+=(gcloud)" >> $HOME/.zshrc_additional_plugins
echo "source $HOME/dotfile/.zshrc_gcloud_ext" >> $HOME/.zshrc_ext
gcloud auth login --update-adc --enable-gdrive-access
gcloud auth application-default login
gcloud_installed=true
}
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to configure gcloud?"; then
configure_gcloud
fi
else
echo "Configuring gcloud..."
configure_gcloud
fi
fi
}
install_kubectl() {
if install_pkg_if_needed "kubernetes-cli"; then
configure_kubectl() {
brew update && brew install krew
kubectl krew install ctx
kubectl krew install ns
echo "source $HOME/dotfile/.zshrc_k8s_ext" >> $HOME/.zshrc_ext
}
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to configure kubectl?"; then
configure_kubectl
fi
else
echo "Configuring kubectl..."
configure_kubectl
fi
fi
}
install_docker() {
if install_pkg_if_needed "docker" "--cask"; then
configure_docker() {
# Install docker-buildx
brew install docker-buildx
mkdir -p ~/.docker/cli-plugins
ln -sfn $(which docker-buildx) ~/.docker/cli-plugins/docker-buildx
# Extend zshrc
echo "source $HOME/dotfile/.zshrc_docker_ext" >> $HOME/.zshrc_ext
if [ "$gcloud_installed" = "true" ]; then
gcloud auth configure-docker
fi
}
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to configure docker?"; then
configure_docker
fi
else
echo "Configuring docker..."
configure_docker
fi
fi
}
install_tmux() {
if install_pkg_if_needed "tmux"; then
configure_tmux() {
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
ln -s $HOME/dotfile/.tmux.conf $HOME/.tmux.conf
}
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to configure tmux?"; then
configure_tmux
fi
else
echo "Configuring tmux..."
configure_tmux
fi
fi
}
install_neovim() {
if install_pkg_if_needed "neovim"; then
configure_neovim() {
echo "source $HOME/dotfile/.zshrc_vim_ext" >> $HOME/.zshrc_ext
}
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to configure neovim?"; then
configure_neovim
fi
else
echo "Configuring neovim..."
configure_neovim
fi
fi
}
install_1password() {
if install_pkg_if_needed "1password"; then
configure_1password() {
brew update && brew install --cask 1password/tap/1password-cli
}
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to configure 1password?"; then
configure_1password
fi
else
echo "Configuring 1password..."
configure_1password
fi
fi
}
install_claude_code() {
if ! command -v claude &> /dev/null; then
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "claude-code is not installed. Do you want to install it?"; then
curl -fsSL https://claude.ai/install.sh | bash
fi
else
echo "Installing claude-code..."
curl -fsSL https://claude.ai/install.sh | bash
fi
else
echo "claude-code is already installed"
fi
}
install_claude_tools() {
if ! command -v ralph &> /dev/null; then
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "ralph is not installed. Do you want to install it?"; then
npm install -g @anthropic-ai/ralph
fi
else
echo "Installing ralph..."
npm install -g @anthropic-ai/ralph
fi
else
echo "ralph is already installed"
fi
# Ensure Claude tools are sourced in .zshrc_ext
if ! grep -q "source.*\.zshrc_claude_ext" "$HOME/.zshrc_ext" 2>/dev/null; then
echo "source $HOME/dotfile/.zshrc_claude_ext" >> "$HOME/.zshrc_ext"
fi
if ! grep -q "source.*\.zshrc_ralph_ext" "$HOME/.zshrc_ext" 2>/dev/null; then
echo "source $HOME/dotfile/.zshrc_ralph_ext" >> "$HOME/.zshrc_ext"
fi
}
install_claude_config() {
configure_claude() {
# Symlink entire agents and skills folders from dotfile
rm -rf ~/.claude/agents ~/.claude/skills
ln -sfn ~/dotfile/.claude/agents ~/.claude/agents
ln -sfn ~/dotfile/.claude/skills ~/.claude/skills
# Symlink global CLAUDE.md reference in dotfile repo
ln -sfn ~/.claude/CLAUDE.md ~/dotfile/CLAUDE_GLOBAL.md
# Add MCP servers (idempotent)
claude mcp list --scope user 2>/dev/null | grep -q context7 || \
claude mcp add --scope user context7 -- npx -y @upstash/context7-mcp
claude mcp list --scope user 2>/dev/null | grep -q playwright || \
claude mcp add --scope user playwright -- npx @playwright/mcp@latest
echo "Claude config installed (agents, skills, MCP servers)"
}
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to configure Claude (agents, skills, MCP)?"; then
configure_claude
fi
else
echo "Configuring Claude..."
configure_claude
fi
}
install_claude_hooks() {
configure_hooks() {
# Symlink hooks directory
rm -rf ~/.claude/hooks
ln -sfn ~/dotfile/.claude/hooks ~/.claude/hooks
# Merge hook config into settings.json
local settings="$HOME/.claude/settings.json"
local hook_config="$HOME/dotfile/.claude/hooks/settings-hooks.json"
if [ -f "$settings" ] && [ -f "$hook_config" ]; then
local merged
merged=$(jq -s '.[0] * .[1]' "$settings" "$hook_config")
echo "$merged" > "$settings"
elif [ -f "$hook_config" ]; then
cp "$hook_config" "$settings"
fi
echo "Claude hooks installed (watcher, done, blocked channels)"
}
if [ "$INTERACTIVE_MODE" = true ]; then
if read_yes "Do you want to install Claude hook notifications?"; then
configure_hooks
fi
else
echo "Installing Claude hooks..."
configure_hooks
fi
}
# Main execution logic
main() {
parse_arguments "$@"
# Always install prerequisites and core setup (unless dry-run)
if [ "$DRY_RUN" = true ]; then
echo "=== DRY RUN: Would install prerequisites and core setup ==="
else
install_prerequisites
setup_core
fi
if [ "$INTERACTIVE_MODE" = true ]; then
# Original interactive mode
echo "=== Important packages ==="
install_pkg_if_needed "arc" "--cask"
install_pkg_if_needed "warp" "--cask"
install_pkg_if_needed "cursor" "--cask"
install_pkg_if_needed "rectangle" "--cask"
if read_yes "Important packages have been installed. Would you like to continue with the optional stuff?"; then
echo "Alright, let's go!"
else
exit
fi
# Continue with all optional packages in interactive mode
install_fzf
install_zsh
install_python
install_gh
install_node
install_terraform
install_gcloud
install_kubectl
install_pkg_if_needed "helm"
install_docker
install_tmux
install_neovim
install_pkg_if_needed "raycast" "--cask"
install_pkg_if_needed "ghostty"
install_pkg_if_needed "slack" "--cask"
install_1password
install_pkg_if_needed "appcleaner"
install_pkg_if_needed "google-chrome"
install_pkg_if_needed "ripgrep"
install_claude_code
install_claude_tools
else
# Selective installation mode
if [ "$DRY_RUN" = true ]; then
echo "=== DRY RUN: Would install requested packages ==="
for package in "${REQUESTED_PACKAGES[@]}"; do
echo "Would install: $package"
deps=$(get_dependencies "$package")
if [ -n "$deps" ]; then
echo " Dependencies: $deps"
fi
done
else
echo "=== Installing requested packages ==="
for package in "${REQUESTED_PACKAGES[@]}"; do
install_package "$package"
done
fi
fi
echo "Done!"
}
# Run main function with all arguments
main "$@"