-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·521 lines (454 loc) · 16.4 KB
/
install.sh
File metadata and controls
executable file
·521 lines (454 loc) · 16.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
#!/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)"
# ==============================================================================
# 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
}
# ==============================================================================
# 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
)
# Cloud CLI tools
local cloud_packages=(
gh # GitHub CLI
awscli # AWS CLI (awscli2 on some distros)
)
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)
sudo apt-get update
sudo apt-get install -y "${packages[@]}"
# Optional packages (some may not be in default repos)
sudo apt-get install -y zsh-autosuggestions zsh-syntax-highlighting 2>/dev/null || true
sudo 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)
sudo dnf install -y "${packages[@]}"
sudo dnf install -y zsh-autosuggestions zsh-syntax-highlighting 2>/dev/null || true
sudo 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)
sudo apk add "${packages[@]}"
sudo apk add zsh-autosuggestions zsh-syntax-highlighting 2>/dev/null || true
sudo apk add fzf bat ripgrep fd jq unzip 2>/dev/null || true
install_starship
install_zoxide
# Cloud CLI tools
sudo apk add github-cli aws-cli 2>/dev/null || true
install_gcloud
;;
arch|manjaro)
sudo pacman -S --noconfirm "${packages[@]}"
sudo pacman -S --noconfirm zsh-autosuggestions zsh-syntax-highlighting 2>/dev/null || true
sudo pacman -S --noconfirm starship zoxide fzf bat eza ripgrep fd jq direnv 2>/dev/null || true
# Cloud CLI tools
sudo 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_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
sudo /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)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo 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" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt-get update && sudo apt-get install -y gh
;;
fedora|rhel|centos)
sudo dnf install -y gh 2>/dev/null || true
;;
*)
echo "Please install gh manually: https://cli.github.com/"
;;
esac
}
# ==============================================================================
# AI CLI Tools
# ==============================================================================
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 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_gemini_cli() {
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
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
}
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
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"
echo
# Install packages
install_packages
echo
# Install AI CLI tools
install_claude_code
install_claude_plugins
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 "$@"