-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·734 lines (636 loc) · 22.4 KB
/
install.sh
File metadata and controls
executable file
·734 lines (636 loc) · 22.4 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
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
#!/usr/bin/env bash
# Dotfiles Installation Script
# Completely self-contained - installs shells, tools, and configs
# Works on macOS, Linux (Debian/Ubuntu, Fedora, Alpine), and containers
set -e
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DRY_RUN=0
usage() {
cat <<'EOF'
Usage: ./install.sh [--dry-run|--audit] [-h|--help]
Installs workstation tooling, shells, CLI tools, and personal dotfiles.
Options:
--dry-run, --audit Report platform/install intent without changing packages,
symlinks, or generated files.
-h, --help Show this help.
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--dry-run|--audit)
DRY_RUN=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage >&2
exit 2
;;
esac
done
# ==============================================================================
# Platform Detection
# ==============================================================================
detect_platform() {
case "$(uname -s)" in
Darwin) PLATFORM="macos" ;;
Linux) PLATFORM="linux" ;;
*) PLATFORM="unknown" ;;
esac
if [[ "$PLATFORM" == "linux" ]]; then
if [[ -f /etc/os-release ]]; then
. /etc/os-release
DISTRO="$ID"
elif [[ -f /etc/alpine-release ]]; then
DISTRO="alpine"
else
DISTRO="unknown"
fi
fi
}
run_privileged() {
if [[ "$(id -u)" -eq 0 ]]; then
"$@"
return $?
fi
if command -v sudo &> /dev/null && sudo -n true 2>/dev/null; then
sudo -n "$@"
return $?
fi
echo "Skipping privileged command (sudo unavailable or requires a password): $*"
return 0
}
can_run_privileged() {
[[ "$(id -u)" -eq 0 ]] || (command -v sudo &> /dev/null && sudo -n true 2>/dev/null)
}
# ==============================================================================
# Package Installation
# ==============================================================================
install_packages() {
echo "Installing packages..."
# Core packages to install
local packages=(
zsh
git
curl
stow
)
# Optional but recommended packages
local optional_packages=(
starship # prompt
zoxide # smart cd
direnv # directory environments
fzf # fuzzy finder
bat # better cat
eza # better ls
ripgrep # better grep
fd # better find
jq # json processor
)
case "$PLATFORM" in
macos)
if ! command -v brew &> /dev/null; then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add brew to PATH for current session
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
echo "Installing core packages..."
brew install "${packages[@]}" 2>/dev/null || true
echo "Installing optional packages..."
brew install "${optional_packages[@]}" 2>/dev/null || true
# PostgreSQL client tools (psql, pg_dump, etc.)
brew install libpq 2>/dev/null || true
# Cloud CLI tools
echo "Installing cloud CLI tools..."
brew install gh awscli 2>/dev/null || true
# gcloud via cask
brew install --cask google-cloud-sdk 2>/dev/null || true
# Zsh plugins via Homebrew
brew install zsh-autosuggestions zsh-syntax-highlighting 2>/dev/null || true
;;
linux)
case "$DISTRO" in
ubuntu|debian|pop)
run_privileged apt-get update
run_privileged apt-get install -y "${packages[@]}"
# Optional packages (some may not be in default repos)
run_privileged apt-get install -y zsh-autosuggestions zsh-syntax-highlighting 2>/dev/null || true
run_privileged apt-get install -y fzf bat ripgrep fd-find jq unzip 2>/dev/null || true
# Starship, zoxide need manual install on Debian/Ubuntu
install_starship
install_zoxide
# Cloud CLI tools
install_gh
install_awscli
install_gcloud
;;
fedora|rhel|centos)
run_privileged dnf install -y "${packages[@]}"
run_privileged dnf install -y zsh-autosuggestions zsh-syntax-highlighting 2>/dev/null || true
run_privileged dnf install -y fzf bat ripgrep fd-find jq eza unzip 2>/dev/null || true
install_starship
install_zoxide
# Cloud CLI tools
install_gh
install_awscli
install_gcloud
;;
alpine)
run_privileged apk add "${packages[@]}"
run_privileged apk add zsh-autosuggestions zsh-syntax-highlighting 2>/dev/null || true
run_privileged apk add fzf bat ripgrep fd jq unzip 2>/dev/null || true
install_starship
install_zoxide
# Cloud CLI tools
run_privileged apk add github-cli aws-cli 2>/dev/null || true
install_gcloud
;;
arch|manjaro)
run_privileged pacman -S --noconfirm "${packages[@]}"
run_privileged pacman -S --noconfirm zsh-autosuggestions zsh-syntax-highlighting 2>/dev/null || true
run_privileged pacman -S --noconfirm starship zoxide fzf bat eza ripgrep fd jq direnv 2>/dev/null || true
# Cloud CLI tools
run_privileged pacman -S --noconfirm github-cli aws-cli 2>/dev/null || true
install_gcloud
;;
nixos)
echo "NixOS detected - packages managed by Nix, skipping system package installation"
;;
*)
echo "Warning: Unknown distro $DISTRO - installing core packages only"
echo "Please manually install: ${optional_packages[*]}"
;;
esac
;;
esac
}
install_sops_tools() {
echo "Installing SOPS tooling..."
case "$PLATFORM" in
macos)
brew install sops age gnupg 2>/dev/null || true
;;
linux)
case "$DISTRO" in
ubuntu|debian|pop)
run_privileged apt-get install -y age gnupg 2>/dev/null || true
run_privileged apt-get install -y sops 2>/dev/null || true
;;
fedora|rhel|centos)
run_privileged dnf install -y age gnupg2 sops 2>/dev/null || true
;;
alpine)
run_privileged apk add age gnupg sops 2>/dev/null || true
;;
arch|manjaro)
run_privileged pacman -S --noconfirm age gnupg sops 2>/dev/null || true
;;
nixos)
echo "NixOS detected - SOPS tooling should be managed by Nix"
;;
esac
;;
esac
if command -v sops &> /dev/null; then
echo "SOPS available: $(command -v sops)"
else
echo "SOPS not found after package install; configure it via your platform package manager."
fi
}
install_starship() {
if command -v starship &> /dev/null; then
echo "Starship already installed"
return 0
fi
echo "Installing Starship..."
curl -sS https://starship.rs/install.sh | sh -s -- -y
}
install_zoxide() {
if command -v zoxide &> /dev/null; then
echo "Zoxide already installed"
return 0
fi
echo "Installing Zoxide..."
curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash
}
install_gcloud() {
if command -v gcloud &> /dev/null; then
echo "Google Cloud SDK already installed"
return 0
fi
echo "Installing Google Cloud SDK..."
curl -fsSL https://sdk.cloud.google.com | bash -s -- --disable-prompts --install-dir="$HOME"
# Add to path for current session
export PATH="$HOME/google-cloud-sdk/bin:$PATH"
}
install_awscli() {
if command -v aws &> /dev/null; then
echo "AWS CLI already installed"
return 0
fi
echo "Installing AWS CLI..."
if [[ "$PLATFORM" == "linux" ]]; then
curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip"
unzip -q /tmp/awscliv2.zip -d /tmp
run_privileged /tmp/aws/install
rm -rf /tmp/awscliv2.zip /tmp/aws
fi
}
install_gh() {
if command -v gh &> /dev/null; then
echo "GitHub CLI already installed"
return 0
fi
echo "Installing GitHub CLI..."
case "$DISTRO" in
ubuntu|debian|pop)
if can_run_privileged; then
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | run_privileged dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | run_privileged tee /etc/apt/sources.list.d/github-cli.list > /dev/null
run_privileged apt-get update && run_privileged apt-get install -y gh
else
echo "Skipping gh apt setup; root/sudo is not available noninteractively."
fi
;;
fedora|rhel|centos)
run_privileged dnf install -y gh 2>/dev/null || true
;;
*)
echo "Please install gh manually: https://cli.github.com/"
;;
esac
}
ensure_npm() {
if command -v npm &> /dev/null; then
return 0
fi
echo "Installing Node.js and npm..."
case "$PLATFORM" in
macos)
brew install node
;;
linux)
case "$DISTRO" in
ubuntu|debian|pop)
run_privileged apt-get update
run_privileged apt-get install -y nodejs npm
;;
fedora|rhel|centos)
run_privileged dnf install -y nodejs npm
;;
alpine)
run_privileged apk add nodejs npm
;;
arch|manjaro)
run_privileged pacman -S --noconfirm nodejs npm
;;
nixos)
echo "NixOS detected - Node.js and npm should be managed by Nix"
return 1
;;
*)
echo "Please install Node.js and npm manually"
return 1
;;
esac
;;
*)
echo "Please install Node.js and npm manually"
return 1
;;
esac
if ! command -v npm &> /dev/null; then
echo "npm still not available after install attempt"
return 1
fi
}
ensure_agent_paths() {
export NPM_CONFIG_PREFIX="$HOME/.npm-global"
if [[ -d "$HOME/.npm-global/bin" ]] && [[ ":$PATH:" != *":$HOME/.npm-global/bin:"* ]]; then
export PATH="$HOME/.npm-global/bin:$PATH"
fi
if [[ -d "$HOME/.claude/local" ]] && [[ ":$PATH:" != *":$HOME/.claude/local:"* ]]; then
export PATH="$HOME/.claude/local:$PATH"
fi
}
# ==============================================================================
# AI CLI Tools
# ==============================================================================
install_codex_cli() {
ensure_agent_paths
if command -v codex &> /dev/null || [[ -x "$HOME/.npm-global/bin/codex" ]]; then
echo "Codex CLI already installed"
return 0
fi
ensure_npm
echo "Installing Codex CLI..."
mkdir -p "$HOME/.npm-global"
npm install -g --prefix "$HOME/.npm-global" @openai/codex
ensure_agent_paths
}
install_claude_code() {
if [[ -x "$HOME/.claude/local/claude" ]] || command -v claude &> /dev/null; then
echo "Claude Code already installed"
return 0
fi
echo "Installing Claude Code..."
curl -fsSL https://claude.ai/install.sh | bash
}
install_claude_plugins() {
ensure_agent_paths
# Ensure claude command is available
local claude_cmd=""
if [[ -x "$HOME/.claude/local/claude" ]]; then
claude_cmd="$HOME/.claude/local/claude"
elif command -v claude &> /dev/null; then
claude_cmd="claude"
else
echo "Claude Code not installed, skipping plugins"
return 0
fi
# Plugins to install from the official claude-code-plugins marketplace
local plugins=(
"code-review"
"commit-commands"
"security-guidance"
"frontend-design"
"feature-dev"
)
echo "Installing Claude Code plugins..."
for plugin in "${plugins[@]}"; do
local full_name="${plugin}@claude-code-plugins"
echo " Installing plugin: $plugin"
echo "y" | "$claude_cmd" plugin install "$full_name" 2>/dev/null || true
done
echo "Claude Code plugins installed"
}
install_copilot_cli() {
if ! command -v gh &> /dev/null; then
echo "GitHub CLI not installed, skipping Copilot CLI"
return 0
fi
if ! gh auth status &> /dev/null; then
echo "GitHub CLI not authenticated, skipping Copilot CLI"
return 0
fi
if ! gh copilot --help &> /dev/null; then
echo "This gh version does not support 'gh copilot', skipping Copilot CLI"
return 0
fi
echo "Installing GitHub Copilot CLI..."
if gh copilot -- --version &> /dev/null; then
echo "GitHub Copilot CLI installed"
else
echo "Could not install GitHub Copilot CLI"
fi
}
install_gemini_cli() {
ensure_agent_paths
if command -v gemini &> /dev/null; then
echo "Gemini CLI already installed"
return 0
fi
# Check ~/.npm-global/bin as well (our custom prefix)
if [[ -x "$HOME/.npm-global/bin/gemini" ]]; then
echo "Gemini CLI already installed"
return 0
fi
ensure_npm
echo "Installing Gemini CLI..."
# Use custom prefix to avoid read-only nix store issues
mkdir -p "$HOME/.npm-global"
npm install -g --prefix "$HOME/.npm-global" @google/gemini-cli
ensure_agent_paths
}
install_kimi_code() {
if command -v kimi &> /dev/null; then
echo "Kimi Code already installed"
else
echo "Installing Kimi Code..."
curl -LsSf https://code.kimi.com/install.sh | bash
fi
# Add chrome-devtools MCP server
if command -v kimi &> /dev/null; then
echo "Adding chrome-devtools MCP server to Kimi..."
kimi mcp add --transport stdio chrome-devtools -- npx chrome-devtools-mcp@latest 2>/dev/null || true
fi
}
install_ralph() {
local ralph_dir="$HOME/.ralph"
# Check if already installed
if [[ -x "$HOME/.local/bin/ralph" ]] && [[ -d "$ralph_dir" ]]; then
echo "Ralph already installed"
return 0
fi
echo "Installing Ralph (autonomous Claude Code framework)..."
# Clone or update Ralph
if [[ -d "$ralph_dir/.git" ]]; then
echo " Updating Ralph..."
git -C "$ralph_dir" pull --quiet
else
echo " Cloning Ralph..."
git clone --quiet https://github.com/frankbria/ralph-claude-code.git "$ralph_dir"
fi
# Patch shebangs for NixOS compatibility (#!/bin/bash -> #!/usr/bin/env bash)
echo " Patching shebangs for portability..."
find "$ralph_dir" -type f -name "*.sh" -exec sed -i.bak 's|^#!/bin/bash|#!/usr/bin/env bash|' {} \;
find "$ralph_dir" -type f -name "*.bak" -delete
# Create ~/.local/bin if needed
mkdir -p "$HOME/.local/bin"
# Create wrapper scripts in ~/.local/bin
# ralph - main command
cat > "$HOME/.local/bin/ralph" << 'EOF'
#!/usr/bin/env bash
exec "$HOME/.ralph/ralph_loop.sh" "$@"
EOF
chmod +x "$HOME/.local/bin/ralph"
# ralph-monitor
cat > "$HOME/.local/bin/ralph-monitor" << 'EOF'
#!/usr/bin/env bash
exec "$HOME/.ralph/ralph_monitor.sh" "$@"
EOF
chmod +x "$HOME/.local/bin/ralph-monitor"
# ralph-setup
cat > "$HOME/.local/bin/ralph-setup" << 'EOF'
#!/usr/bin/env bash
exec "$HOME/.ralph/setup.sh" "$@"
EOF
chmod +x "$HOME/.local/bin/ralph-setup"
# ralph-import
cat > "$HOME/.local/bin/ralph-import" << 'EOF'
#!/usr/bin/env bash
exec "$HOME/.ralph/ralph_import.sh" "$@"
EOF
chmod +x "$HOME/.local/bin/ralph-import"
echo "Ralph installed successfully!"
echo " Commands: ralph, ralph-monitor, ralph-setup, ralph-import"
}
install_oh_my_zsh() {
if [[ -d "$HOME/.oh-my-zsh" ]]; then
echo "Oh My Zsh already installed"
else
echo "Installing Oh My Zsh..."
# --unattended: don't change shell, --keep-zshrc: don't overwrite .zshrc
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended --keep-zshrc
fi
# Install oh-my-zsh plugins
local ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
if [[ ! -d "$ZSH_CUSTOM/plugins/zsh-autosuggestions" ]]; then
echo "Installing zsh-autosuggestions plugin..."
git clone https://github.com/zsh-users/zsh-autosuggestions "$ZSH_CUSTOM/plugins/zsh-autosuggestions"
fi
if [[ ! -d "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" ]]; then
echo "Installing zsh-syntax-highlighting plugin..."
git clone https://github.com/zsh-users/zsh-syntax-highlighting "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"
fi
}
# ==============================================================================
# Stow Packages
# ==============================================================================
stow_packages() {
cd "$DOTFILES_DIR"
local packages=(
"zsh"
"bash"
"git"
"starship"
"direnv"
)
# nushell managed by home-manager on NixOS
if [[ "$DISTRO" != "nixos" ]]; then
packages+=("nushell")
fi
echo "Stowing dotfiles to home directory..."
for pkg in "${packages[@]}"; do
if [[ -d "$pkg" ]]; then
echo " Stowing $pkg..."
# --adopt takes ownership of existing files, --restow re-links
stow -v --adopt --restow --target="$HOME" "$pkg" 2>&1 | grep -v "^LINK:" || true
fi
done
}
# ==============================================================================
# Backup Existing Configs
# ==============================================================================
backup_existing() {
local backup_dir="$HOME/.dotfiles-backup-$(date +%Y%m%d-%H%M%S)"
local need_backup=false
local files_to_check=(
".zshrc"
".bashrc"
".config/nushell/config.nu"
".config/nushell/env.nu"
".gitconfig"
)
for file in "${files_to_check[@]}"; do
local target="$HOME/$file"
if [[ -e "$target" && ! -L "$target" ]]; then
need_backup=true
break
fi
done
if [[ "$need_backup" == true ]]; then
echo "Backing up existing config files to $backup_dir..."
mkdir -p "$backup_dir"
for file in "${files_to_check[@]}"; do
local target="$HOME/$file"
if [[ -e "$target" && ! -L "$target" ]]; then
local backup_path="$backup_dir/$file"
mkdir -p "$(dirname "$backup_path")"
mv "$target" "$backup_path"
echo " Backed up: $file"
fi
done
fi
}
# ==============================================================================
# Set Default Shell
# ==============================================================================
set_default_shell() {
# Skip on NixOS - shell configured in system config
if [[ "$DISTRO" == "nixos" ]]; then
return 0
fi
if [[ "${DOTFILES_NONINTERACTIVE:-1}" == "1" || ! -t 0 ]]; then
echo "Skipping default shell prompt (noninteractive install)."
return 0
fi
local zsh_path
zsh_path=$(which zsh)
if [[ "$SHELL" != "$zsh_path" ]]; then
echo ""
read -p "Set zsh as default shell? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
if ! grep -q "$zsh_path" /etc/shells; then
echo "$zsh_path" | sudo tee -a /etc/shells
fi
chsh -s "$zsh_path"
echo "Default shell changed to zsh. Log out and back in for it to take effect."
fi
fi
}
# ==============================================================================
# Main
# ==============================================================================
main() {
echo "========================================"
echo "Dotfiles Installation"
echo "========================================"
echo
detect_platform
echo "Platform: $PLATFORM"
[[ -n "$DISTRO" ]] && echo "Distro: $DISTRO"
echo "Dotfiles directory: $DOTFILES_DIR"
[[ "$DRY_RUN" -eq 1 ]] && echo "Mode: dry-run"
echo
if [[ "$DRY_RUN" -eq 1 ]]; then
echo "Dry-run: would install packages, AI CLIs, shell tooling, and stowed dotfiles."
echo
echo "Core tools: zsh git curl stow starship zoxide direnv fzf bat eza ripgrep fd jq"
echo "AI CLIs: codex claude gemini kimi ralph"
echo "Package mutation, downloads, shell changes, and stow operations skipped."
echo "Dry-run complete!"
echo "========================================"
return 0
fi
# Install packages
install_packages
install_sops_tools
echo
# Install AI CLI tools
install_codex_cli
install_claude_code
install_claude_plugins
install_copilot_cli
install_kimi_code
install_gemini_cli
install_ralph
echo
# Install Oh My Zsh
install_oh_my_zsh
echo
# Backup existing configs
backup_existing
echo
# Stow packages
stow_packages
echo
# Offer to set default shell
set_default_shell
echo
echo "========================================"
echo "Installation complete!"
echo "========================================"
echo
echo "Start a new zsh session:"
echo " zsh"
echo
echo "Or restart your terminal."
}
main "$@"