-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·211 lines (179 loc) · 7.72 KB
/
bootstrap.sh
File metadata and controls
executable file
·211 lines (179 loc) · 7.72 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
#!/usr/bin/env bash
set -euo pipefail
# ==============================================================================
# Dotfiles Bootstrap Script
# ==============================================================================
# This script sets up your dotfiles in two phases:
# 1. Creates symlinks from ~/dotfiles to your home directory
# 2. Sets up secure secrets file for AWS/GCP credentials
# ==============================================================================
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKUP_DIR="$HOME/dotfiles-backup-$(date +%Y%m%d-%H%M%S)"
SECRETS_FILE="$DOTFILES_DIR/zsh/.zshrc.secrets"
TEMPLATE_FILE="$DOTFILES_DIR/zsh/.zshrc.secrets.template"
echo "======================================"
echo "Dotfiles Bootstrap"
echo "======================================"
echo ""
echo "Dotfiles directory: $DOTFILES_DIR"
echo ""
# ==============================================================================
# PHASE 1: Symlink Creation
# ==============================================================================
echo "======================================"
echo "Phase 1: Creating Symlinks"
echo "======================================"
echo ""
backup_if_exists() {
local file=$1
if [ -e "$file" ] || [ -L "$file" ]; then
if [ ! -d "$BACKUP_DIR" ]; then
mkdir -p "$BACKUP_DIR"
echo "Created backup directory: $BACKUP_DIR"
fi
echo " Backing up existing: $file"
cp -P "$file" "$BACKUP_DIR/" 2>/dev/null || true
fi
}
create_symlink() {
local source=$1
local target=$2
echo "Setting up: $target"
backup_if_exists "$target"
rm -f "$target"
ln -sf "$source" "$target"
echo " Created symlink: $target -> $source"
}
echo "Checking for existing configurations..."
echo ""
if [ -e "$HOME/.zshrc" ] || [ -L "$HOME/.zshrc" ]; then
echo "Found existing .zshrc"
fi
echo ""
echo "Creating symlinks..."
echo ""
create_symlink "$DOTFILES_DIR/zsh/.zshrc" "$HOME/.zshrc"
# Starship prompt configuration
mkdir -p "$HOME/.config/starship"
create_symlink "$DOTFILES_DIR/starship/starship.toml" "$HOME/.config/starship/starship.toml"
# Ghostty terminal configuration
mkdir -p "$HOME/Library/Application Support/com.mitchellh.ghostty"
create_symlink "$DOTFILES_DIR/ghostty/config" "$HOME/Library/Application Support/com.mitchellh.ghostty/config"
# iTerm2: profiles, global prefs, keymaps, snippets, pre-commit hook.
# Delegates to iterm2/install.sh so the allowlist + leak-scanner logic lives
# alongside the exporter. Safe to re-run; quits iTerm2 briefly.
if [ -x "$DOTFILES_DIR/iterm2/install.sh" ]; then
bash "$DOTFILES_DIR/iterm2/install.sh"
fi
# cmux terminal configuration
mkdir -p "$HOME/.config/cmux"
create_symlink "$DOTFILES_DIR/cmux/terminals-simple.json" "$HOME/.config/cmux/terminals-simple.json"
create_symlink "$DOTFILES_DIR/cmux/terminals-multi-agent.json" "$HOME/.config/cmux/terminals-multi-agent.json"
# Show cmux manual setup steps
if [ -f "$DOTFILES_DIR/cmux/setup-defaults.sh" ]; then
bash "$DOTFILES_DIR/cmux/setup-defaults.sh"
fi
# Cursor editor settings
mkdir -p "$HOME/Library/Application Support/Cursor/User"
create_symlink "$DOTFILES_DIR/cursor/settings.json" "$HOME/Library/Application Support/Cursor/User/settings.json"
create_symlink "$DOTFILES_DIR/cursor/keybindings.json" "$HOME/Library/Application Support/Cursor/User/keybindings.json"
# Claude Code configuration
mkdir -p "$HOME/.claude/agents"
mkdir -p "$HOME/.claude/commands"
create_symlink "$DOTFILES_DIR/claude/CLAUDE.md" "$HOME/.claude/CLAUDE.md"
create_symlink "$DOTFILES_DIR/claude/settings.json" "$HOME/.claude/settings.json"
create_symlink "$DOTFILES_DIR/claude/agents/pr-agent.md" "$HOME/.claude/agents/pr-agent.md"
create_symlink "$DOTFILES_DIR/claude/agents/pr-docs-generator.md" "$HOME/.claude/agents/pr-docs-generator.md"
create_symlink "$DOTFILES_DIR/claude/agents/pr-review-generator.md" "$HOME/.claude/agents/pr-review-generator.md"
create_symlink "$DOTFILES_DIR/claude/commands/codex.md" "$HOME/.claude/commands/codex.md"
mkdir -p "$HOME/.claude/skills"
create_symlink "$DOTFILES_DIR/claude/skills/agent-swarm" "$HOME/.claude/skills/agent-swarm"
echo ""
if [ -d "$BACKUP_DIR" ]; then
echo "Previous configuration backed up to:"
echo " $BACKUP_DIR"
echo ""
fi
echo "Symlinks created:"
echo " ~/.zshrc -> $DOTFILES_DIR/zsh/.zshrc"
echo " ~/.config/starship/starship.toml -> $DOTFILES_DIR/starship/starship.toml"
echo " ~/Library/Application Support/com.mitchellh.ghostty/config -> $DOTFILES_DIR/ghostty/config"
echo " ~/Library/Application Support/iTerm2/DynamicProfiles/*.json -> $DOTFILES_DIR/iterm2/profiles/"
echo " ~/Library/Application Support/iTerm2/snippets.plist -> $DOTFILES_DIR/iterm2/snippets.plist"
echo " ~/.config/cmux/terminals-simple.json -> $DOTFILES_DIR/cmux/terminals-simple.json"
echo " ~/.config/cmux/terminals-multi-agent.json -> $DOTFILES_DIR/cmux/terminals-multi-agent.json"
echo " ~/Library/Application Support/Cursor/User/settings.json -> $DOTFILES_DIR/cursor/settings.json"
echo " ~/Library/Application Support/Cursor/User/keybindings.json -> $DOTFILES_DIR/cursor/keybindings.json"
echo " ~/.claude/CLAUDE.md -> $DOTFILES_DIR/claude/CLAUDE.md"
echo " ~/.claude/settings.json -> $DOTFILES_DIR/claude/settings.json"
echo " ~/.claude/agents/*.md -> $DOTFILES_DIR/claude/agents/"
echo " ~/.claude/commands/*.md -> $DOTFILES_DIR/claude/commands/"
echo " ~/.claude/skills/agent-swarm -> $DOTFILES_DIR/claude/skills/agent-swarm"
echo ""
# ==============================================================================
# PHASE 2: Security Setup
# ==============================================================================
echo "======================================"
echo "Phase 2: Security Setup"
echo "======================================"
echo ""
# Check if template exists
if [ ! -f "$TEMPLATE_FILE" ]; then
echo "Error: Template file not found at $TEMPLATE_FILE"
exit 1
fi
# Create secrets file if it doesn't exist
if [ ! -f "$SECRETS_FILE" ]; then
echo "Creating $SECRETS_FILE from template..."
cp "$TEMPLATE_FILE" "$SECRETS_FILE"
chmod 600 "$SECRETS_FILE"
echo "Created: $SECRETS_FILE (permissions: 600)"
echo ""
echo "IMPORTANT: Edit $SECRETS_FILE with your actual credentials:"
echo " - AWS_SSH_KEY_PATH"
echo " - AWS_EC2_IP"
echo " - AWS_EC2_INSTANCE_ID"
echo " - GOOGLE_APPLICATION_CREDENTIALS"
echo ""
echo "Edit now? [y/N]"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
${EDITOR:-vim} "$SECRETS_FILE"
fi
else
echo "$SECRETS_FILE already exists"
# Check permissions
CURRENT_PERMS=$(stat -f "%Lp" "$SECRETS_FILE" 2>/dev/null || stat -c "%a" "$SECRETS_FILE" 2>/dev/null)
if [ "$CURRENT_PERMS" != "600" ]; then
echo "Warning: Insecure permissions ($CURRENT_PERMS). Setting to 600..."
chmod 600 "$SECRETS_FILE"
echo "Fixed: Permissions set to 600"
else
echo "Permissions: OK (600)"
fi
fi
echo ""
# ==============================================================================
# Bootstrap Complete
# ==============================================================================
echo "======================================"
echo "Bootstrap Complete!"
echo "======================================"
echo ""
echo "Next steps:"
echo " 1. Edit secrets file with your credentials:"
echo " vim $SECRETS_FILE"
echo " 2. Install dependencies:"
echo " brew install starship zsh-autosuggestions tree bat fd eza fzf"
echo " 3. Restart your terminal or run:"
echo " source ~/.zshrc"
echo " 4. Test AWS/GCP functions:"
echo " vmstatus"
echo ""
if [ -d "$BACKUP_DIR" ]; then
echo "To restore your backup:"
echo " cp $BACKUP_DIR/.zshrc ~/.zshrc"
echo ""
fi
echo "Secrets file: $SECRETS_FILE"
echo ""