-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·505 lines (428 loc) · 14.5 KB
/
install.sh
File metadata and controls
executable file
·505 lines (428 loc) · 14.5 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
#!/usr/bin/env bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Configuration
DOTFILES="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BREWFILE="$DOTFILES/.config/brew/Brewfile"
NO_GUI=false
IN_CODESPACES=false
# Detect GitHub Codespaces
if [ -n "$CODESPACES" ]; then
IN_CODESPACES=true
fi
# Parse command line arguments
parse_args() {
for arg in "$@"; do
case $arg in
--no-gui)
NO_GUI=true
shift
;;
--help|-h)
show_help
exit 0
;;
*)
;;
esac
done
# Auto-enable --no-gui in Codespaces
if [ "$IN_CODESPACES" = true ]; then
NO_GUI=true
fi
}
# Show help message
show_help() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --no-gui Skip installation of GUI applications (casks)"
echo " --help, -h Show this help message"
echo ""
echo "Example:"
echo " $0 # Install everything"
echo " $0 --no-gui # Install only CLI tools"
}
# Helper functions
print_header() {
echo -e "\n${BLUE}==>${NC} ${1}"
}
print_success() {
echo -e "${GREEN}✓${NC} ${1}"
}
print_warning() {
echo -e "${YELLOW}!${NC} ${1}"
}
print_error() {
echo -e "${RED}✗${NC} ${1}"
}
print_info() {
echo -e "${CYAN}ℹ${NC} ${1}"
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Setup Codespaces-specific environment
setup_codespaces_environment() {
if [ "$IN_CODESPACES" != true ]; then
return
fi
print_header "Setting up Codespaces environment..."
# Ensure USER variable is set
if [ -z "$USER" ]; then
USER=$(id -un)
export USER
print_info "Set USER=$USER"
fi
# Enable passwordless sudo
export SUDO_ASKPASS=/bin/true
print_info "Enabled passwordless sudo"
# Codespaces clones dotfiles to persisted share and symlinks them
# We need to use the persisted share location for running install scripts
local PERSISTED_DOTFILES="/workspaces/.codespaces/.persistedshare/dotfiles"
if [ -d "$PERSISTED_DOTFILES" ]; then
DOTFILES="$PERSISTED_DOTFILES"
BREWFILE="$DOTFILES/.config/brew/Brewfile"
print_success "Using dotfiles at: $DOTFILES"
else
print_warning "Persisted dotfiles not found at $PERSISTED_DOTFILES"
fi
# Change to home directory
cd "$HOME"
}
# Detect OS
detect_os() {
case "$(uname -s)" in
Darwin*)
OS="macos"
print_success "Detected macOS"
;;
Linux*)
OS="linux"
print_success "Detected Linux"
if [ "$IN_CODESPACES" = true ]; then
print_info "Running in GitHub Codespaces"
fi
;;
*)
print_error "Unsupported operating system"
exit 1
;;
esac
}
# Install Homebrew
install_homebrew() {
if command_exists brew; then
print_success "Homebrew already installed"
return
fi
print_header "Installing Homebrew..."
case "$OS" in
macos)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to PATH for this session
if [ -d "/opt/homebrew" ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
eval "$(/usr/local/bin/brew shellenv)"
fi
;;
linux)
if [ "$IN_CODESPACES" = true ]; then
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
if [ -d /home/linuxbrew/.linuxbrew ]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
# Add to shell profiles (only .profile, since .zshenv handles zsh via HOMEBREW_PREFIX)
# shellcheck disable=SC2016
if ! grep -q "linuxbrew" "$HOME/.profile" 2>/dev/null; then
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> "$HOME/.profile"
fi
fi
;;
esac
print_success "Homebrew installed"
}
# Install oh-my-zsh
install_oh_my_zsh() {
if [ -d "$HOME/.oh-my-zsh" ]; then
print_success "oh-my-zsh already installed"
return
fi
if ! command_exists zsh; then
print_warning "zsh not installed, skipping oh-my-zsh"
return
fi
print_header "Installing oh-my-zsh..."
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
print_success "oh-my-zsh installed"
}
# Set zsh as default shell
set_zsh_default() {
if ! command_exists zsh; then
print_warning "zsh not found, will be installed via Brewfile"
return
fi
# Compare basename to handle different zsh paths (e.g., /bin/zsh vs /usr/bin/zsh)
if [ "$(basename "$SHELL")" = "zsh" ]; then
print_success "zsh is already the default shell"
return
fi
print_header "Setting zsh as default shell..."
local ZSH_PATH
ZSH_PATH="$(command -v zsh)"
# Add zsh to /etc/shells if not present
if ! grep -q "$ZSH_PATH" /etc/shells 2>/dev/null; then
echo "$ZSH_PATH" | sudo tee -a /etc/shells >/dev/null
fi
# Change default shell
if command_exists chsh; then
if chsh -s "$ZSH_PATH"; then
print_success "Default shell set to zsh (takes effect on next login)"
else
print_warning "Could not change default shell. Try manually: chsh -s $ZSH_PATH"
fi
else
print_warning "chsh not available. Run manually: chsh -s $ZSH_PATH"
fi
}
# Install packages from Brewfile
install_brew_packages() {
if [ ! -f "$BREWFILE" ]; then
print_error "Brewfile not found at: $BREWFILE"
exit 1
fi
if [ "$NO_GUI" = true ]; then
print_header "Installing CLI packages only (skipping GUI applications)..."
HOMEBREW_BUNDLE_CASK_SKIP=1 brew bundle --file="$BREWFILE"
print_success "CLI packages installed"
else
print_header "Installing all packages from Brewfile..."
brew bundle --file="$BREWFILE"
print_success "All packages installed"
fi
# Ensure Homebrew binaries are in PATH (important for CI)
if command_exists brew; then
eval "$(brew shellenv)"
fi
}
# Install tmux plugin manager
install_tpm() {
local tpm_dir="$HOME/.tmux/plugins/tpm"
if [ -d "$tpm_dir" ]; then
print_success "tmux plugin manager already installed"
return
fi
print_header "Installing tmux plugin manager..."
git clone --depth=1 https://github.com/tmux-plugins/tpm "$tpm_dir"
print_success "tmux plugin manager installed"
}
# Install UV (Python package manager)
install_uv() {
if command_exists uv; then
print_success "UV already installed"
return
fi
print_header "Installing UV..."
if curl -LsSf https://astral.sh/uv/install.sh | sh; then
print_success "UV installed"
else
print_warning "UV installation failed (may not be available in this environment)"
fi
}
# Install Claude CLI and configure
install_claude_cli() {
if ! command_exists claude; then
print_header "Installing Claude CLI..."
if command_exists brew; then
brew install --cask claude-code || {
print_warning "Homebrew cask install failed, trying curl installer..."
curl -fsSL https://claude.ai/install.sh | bash || print_warning "Claude CLI installation failed"
}
elif curl -fsSL https://claude.ai/install.sh | bash; then
print_success "Claude CLI installed"
else
print_warning "Claude CLI installation failed (may not be available in this environment)"
fi
else
print_success "Claude CLI already installed"
fi
if [ -d "$DOTFILES/.config/claude" ]; then
print_header "Configuring Claude CLI..."
mkdir -p "$HOME/.claude"
ln -sf "$DOTFILES/.config/claude/CLAUDE.md" "$HOME/.claude/CLAUDE.md"
ln -sf "$DOTFILES/.config/claude/settings.json" "$HOME/.claude/settings.json"
rm -rf "$HOME/.claude/skills"
ln -sf "$DOTFILES/.config/claude/skills" "$HOME/.claude/skills"
print_success "Claude CLI configured"
fi
}
# Install OpenCode
install_opencode() {
if command_exists opencode; then
print_success "OpenCode already installed"
return
fi
print_header "Installing OpenCode..."
if curl -fsSL https://opencode.ai/install | bash; then
print_success "OpenCode installed"
else
print_warning "OpenCode installation failed (may not be available in this environment)"
fi
}
# Install GitHub CLI extensions
install_gh_extensions() {
if ! command_exists gh; then
print_warning "gh CLI not installed, skipping extensions"
return
fi
# Skip extension installation in Codespaces
if [ "$IN_CODESPACES" = true ]; then
print_info "Skipping gh extensions in Codespaces"
return
fi
# Check if we're authenticated (required for extension installation)
if ! gh auth status >/dev/null 2>&1; then
print_warning "gh not authenticated, skipping extensions (set GH_TOKEN in CI)"
return
fi
local extensions_file="$DOTFILES/.config/gh/extensions"
if [ ! -f "$extensions_file" ]; then
print_info "No gh extensions file found at $extensions_file"
return
fi
print_header "Installing GitHub CLI extensions..."
local installed=0
local skipped=0
# Read extensions file line by line
while IFS= read -r extension || [ -n "$extension" ]; do
# Skip empty lines and comments
[[ -z "$extension" || "$extension" =~ ^# ]] && continue
# Trim whitespace
extension=$(echo "$extension" | xargs)
# Check if already installed
if gh extension list 2>/dev/null | grep -q "$extension"; then
print_success "$extension already installed"
skipped=$((skipped + 1))
else
echo " Installing $extension..."
if gh extension install "$extension"; then
print_success "$extension installed"
installed=$((installed + 1))
else
print_warning "Failed to install $extension"
fi
fi
done < "$extensions_file"
if [ $installed -eq 0 ] && [ $skipped -eq 0 ]; then
print_info "No extensions to install"
else
echo " Installed: $installed, Already present: $skipped"
fi
}
# Stow dotfiles
stow_dotfiles() {
if ! command_exists stow; then
print_error "stow is not installed. Please install it first."
return 1
fi
print_header "Stowing dotfiles..."
# Backup existing dotfiles that might conflict
local backup_dir
backup_dir="$HOME/.dotfiles-backup-$(date +%Y%m%d-%H%M%S)"
local needs_backup=false
# Common dotfiles that might exist and aren't symlinks
local common_files=(".zshrc" ".zshenv" ".zprofile" ".gitconfig" ".tmux.conf" ".editorconfig")
for file in "${common_files[@]}"; do
if [ -e "$HOME/$file" ] && [ ! -L "$HOME/$file" ]; then
if [ "$needs_backup" = false ]; then
mkdir -p "$backup_dir"
print_warning "Backing up existing dotfiles to $backup_dir"
needs_backup=true
fi
mv "$HOME/$file" "$backup_dir/"
echo " Backed up $file"
fi
done
# Get parent directory and dotfiles name for stow
local parent_dir
local dotfiles_name
parent_dir="$(dirname "$DOTFILES")"
dotfiles_name="$(basename "$DOTFILES")"
# Unstow first (in case of previous installation)
stow --dir="$parent_dir" --target="$HOME" -D "$dotfiles_name" 2>/dev/null || true
# Stow the dotfiles directory with explicit flags
stow --dir="$parent_dir" --target="$HOME" --verbose "$dotfiles_name"
print_success "Dotfiles stowed"
if [ "$needs_backup" = true ]; then
print_warning "Your original dotfiles have been backed up to: $backup_dir"
fi
}
# Print installation summary
print_summary() {
echo ""
echo -e "${GREEN}╔════════════════════════════════════════╗"
echo "║ Installation Complete! 🎉 ║"
echo "╚════════════════════════════════════════╝${NC}"
echo ""
echo -e "${CYAN}Configuration:${NC}"
echo " Dotfiles dir: $DOTFILES"
echo " Platform: $OS"
if [ "$IN_CODESPACES" = true ]; then
echo " Environment: GitHub Codespaces"
fi
if [ "$NO_GUI" = true ]; then
echo " GUI apps: Skipped"
else
echo " GUI apps: Installed"
fi
echo ""
print_warning "Please restart your terminal or run: source ~/.zshrc"
echo ""
if [ "$IN_CODESPACES" = true ]; then
print_info "In Codespaces, you may need to reload your window for changes to take effect"
fi
if [ "$OS" = "macos" ]; then
echo -e "${CYAN}Next steps:${NC}"
echo " • Configure your terminal theme"
echo " • Set up Git credentials: git config --global user.name 'Your Name'"
echo " • Set up Git email: git config --global user.email 'your@email.com'"
echo ""
fi
}
# Main installation flow
main() {
parse_args "$@"
setup_codespaces_environment
echo -e "${MAGENTA}"
echo "╔════════════════════════════════════════╗"
echo "║ Dotfiles Setup & Installation ║"
echo "║ ║"
echo "║ This will install development tools ║"
echo "║ and configure your environment ║"
echo "╚════════════════════════════════════════╝"
echo -e "${NC}"
detect_os
install_homebrew
install_brew_packages
install_gh_extensions
set_zsh_default
install_oh_my_zsh
install_tpm
install_uv
install_claude_cli
install_opencode
stow_dotfiles
print_summary
}
# Run main function
main "$@"