-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
181 lines (144 loc) · 6.62 KB
/
bootstrap.sh
File metadata and controls
181 lines (144 loc) · 6.62 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
#!/usr/bin/env bash
# Stage 1 bootstrap for macOS. Idempotent.
set -euo pipefail
REPO_URL="https://github.com/robvenn/dotfiles.git"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
DOTFILES_DIR="$(dirname "$SCRIPT_DIR")"
# Fallback for piped execution (curl | bash)
if [ ! -d "$DOTFILES_DIR/.git" ]; then
DOTFILES_DIR="$HOME/dotfiles"
fi
# ── Helpers ───────────────────────────────────────────────────────────────────
info() { printf " [ \033[0;34m..\033[0m ] %s\n" "$1"; }
success() { printf " [ \033[0;32mOK\033[0m ] %s\n" "$1"; }
warn() { printf " [\033[0;33mWARN\033[0m] %s\n" "$1"; }
fail() { printf " [\033[0;31mFAIL\033[0m] %s\n" "$1"; exit 1; }
warnings=()
# ── Homebrew ──────────────────────────────────────────────────────────────────
echo ""
echo "==> Homebrew"
if [ -f /opt/homebrew/bin/brew ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
success "Homebrew already installed (Apple Silicon)"
elif [ -f /usr/local/bin/brew ]; then
eval "$(/usr/local/bin/brew shellenv)"
success "Homebrew already installed (Intel)"
else
info "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [ -f /opt/homebrew/bin/brew ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [ -f /usr/local/bin/brew ]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
success "Homebrew installed"
fi
# ── Core Tools ────────────────────────────────────────────────────────────────
echo ""
echo "==> Core Tools"
for tool in nushell git dotter; do
if brew list "$tool" &>/dev/null; then
success "$tool already installed"
else
info "Installing $tool..."
brew install "$tool"
success "$tool installed"
fi
done
# ── Rosetta 2 (Apple Silicon) ────────────────────────────────────────────────
echo ""
echo "==> Rosetta 2"
arch="$(uname -m)"
if [ "$arch" = "arm64" ]; then
if /usr/bin/pgrep -q oahd 2>/dev/null; then
success "Rosetta 2 already installed"
elif [ -t 0 ]; then
printf " [ \033[0;34m..\033[0m ] Install Rosetta 2 for x86_64 compatibility? [y/N] "
read -r answer < /dev/tty
if [[ "$answer" =~ ^[Yy]$ ]]; then
softwareupdate --install-rosetta --agree-to-license
success "Rosetta 2 installed"
else
warnings+=("Rosetta 2 skipped --some x86_64 binaries may not work")
warn "${warnings[-1]}"
fi
else
warnings+=("Rosetta 2 skipped (non-interactive)")
warn "${warnings[-1]}"
fi
else
success "Intel Mac --Rosetta 2 not needed"
fi
# ── Clone Dotfiles ────────────────────────────────────────────────────────────
echo ""
echo "==> Dotfiles Repo"
if [ -d "$DOTFILES_DIR/.git" ]; then
success "Dotfiles repo already exists at $DOTFILES_DIR"
else
info "Cloning dotfiles repo..."
git clone "$REPO_URL" "$DOTFILES_DIR"
success "Dotfiles repo cloned"
fi
# ── Dotter local.toml ────────────────────────────────────────────────────────
echo ""
echo "==> Dotter Configuration"
local_toml="$DOTFILES_DIR/.dotter/local.toml"
if [ -f "$local_toml" ]; then
success "local.toml already exists"
else
info "Creating local.toml for macOS..."
cat > "$local_toml" << 'EOF'
packages = ["shell", "zsh", "nushell", "git", "ssh", "editorconfig", "bat", "ripgrep", "fzf", "mise", "helix", "zed", "starship", "topgrade"]
EOF
success "local.toml created"
fi
# ── Shell Config Migration ────────────────────────────────────────────────────
# Dotter will replace ~/.zshrc with a symlink to a thin loader that sources
# ~/.zshrc.local at the end. On existing machines, move the current ~/.zshrc
# to ~/.zshrc.local so nothing is lost.
echo ""
echo "==> Shell Config Migration"
if [ -f "$HOME/.zshrc" ] && [ ! -L "$HOME/.zshrc" ] && [ ! -f "$HOME/.zshrc.local" ]; then
info "Moving ~/.zshrc to ~/.zshrc.local (will be sourced by managed ~/.zshrc)..."
mv "$HOME/.zshrc" "$HOME/.zshrc.local"
success "~/.zshrc moved — review ~/.zshrc.local and clean up any duplicated settings"
elif [ -L "$HOME/.zshrc" ]; then
success "~/.zshrc already managed by dotter"
elif [ -f "$HOME/.zshrc.local" ]; then
success "~/.zshrc.local already exists"
else
success "No existing ~/.zshrc — fresh install"
fi
# ── Dotter Deploy ─────────────────────────────────────────────────────────────
echo ""
echo "==> Dotter Deploy"
info "Deploying dotfiles..."
(cd "$DOTFILES_DIR" && dotter deploy)
success "Dotfiles deployed"
# ── macOS Defaults ────────────────────────────────────────────────────────
echo ""
echo "==> macOS Defaults"
info "Applying macOS defaults..."
bash "$DOTFILES_DIR/scripts/macos-defaults.sh"
success "macOS defaults applied"
# ── Summary ───────────────────────────────────────────────────────────────────
echo ""
echo "==> Summary"
if [ ${#warnings[@]} -eq 0 ]; then
success "All steps completed successfully"
else
warn "${#warnings[@]} warning(s):"
for w in "${warnings[@]}"; do
warn " - $w"
done
fi
# ── Stage 2 ───────────────────────────────────────────────────────────────────
echo ""
echo "==> Stage 2"
provision_script="$DOTFILES_DIR/scripts/provision.nu"
if [ -f "$provision_script" ]; then
info "Invoking provision.nu..."
nu "$provision_script"
else
warn "provision.nu not found --skipping Stage 2"
fi