-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·181 lines (159 loc) · 5.96 KB
/
install.sh
File metadata and controls
executable file
·181 lines (159 loc) · 5.96 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
#!/bin/bash
set -euo pipefail
DOTFILES_DIR="$HOME/dotfiles"
info() { printf ' \033[35m***\033[0m %s\n' "$1"; }
warn() { printf ' \033[33m!!!\033[0m %s\n' "$1"; }
ok() { printf ' \033[32m ✓ \033[0m %s\n' "$1"; }
# Verify we're running from the right place
if [[ ! -f "$DOTFILES_DIR/install.sh" ]]; then
warn "Expected dotfiles repo at $DOTFILES_DIR"
warn "Clone the repo there first: git clone <repo-url> $DOTFILES_DIR"
exit 1
fi
# 1. Check for Xcode Command Line Tools
info 'Checking for Xcode Command Line Tools...'
if xcode-select -p &>/dev/null; then
ok 'Xcode Command Line Tools found'
else
info 'Installing Xcode Command Line Tools (follow the dialog)...'
xcode-select --install
warn 'Waiting for installation to complete. Re-run this script when done.'
exit 0
fi
# 2. Check for Homebrew
info 'Checking for Homebrew...'
if ! command -v brew &>/dev/null; then
warn 'Homebrew is not installed.'
warn 'Install it first: https://brew.sh'
exit 1
fi
ok 'Homebrew found'
# 3. Install Homebrew packages
info 'Installing Homebrew packages from Brewfile...'
brew bundle --file="$DOTFILES_DIR/Brewfile"
ok 'Homebrew packages installed'
# 4. Install Oh My Zsh
info 'Checking for Oh My Zsh...'
if [[ -d "$HOME/.oh-my-zsh" ]]; then
ok 'Oh My Zsh already installed'
else
info 'Installing Oh My Zsh...'
# RUNZSH=no — don't launch zsh after install
# KEEP_ZSHRC=yes — don't overwrite .zshrc (we'll symlink ours)
RUNZSH=no KEEP_ZSHRC=yes sh -c \
"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
ok 'Oh My Zsh installed'
fi
# 5. Symlink .zprofile
info 'Symlinking .zprofile...'
if [[ -f "$HOME/.zprofile" && ! -L "$HOME/.zprofile" ]]; then
mv "$HOME/.zprofile" "$HOME/.zprofile.bak"
warn "Existing .zprofile backed up to ~/.zprofile.bak"
fi
ln -sfn "$DOTFILES_DIR/.zprofile" "$HOME/.zprofile"
ok '.zprofile symlinked'
# 6. Symlink .zshrc
info 'Symlinking .zshrc...'
if [[ -f "$HOME/.zshrc" && ! -L "$HOME/.zshrc" ]]; then
mv "$HOME/.zshrc" "$HOME/.zshrc.bak"
warn "Existing .zshrc backed up to ~/.zshrc.bak"
fi
ln -sfn "$DOTFILES_DIR/.zshrc" "$HOME/.zshrc"
ok '.zshrc symlinked'
# 7. Symlink .zsh/ directory
info 'Symlinking .zsh/ directory...'
if [[ -d "$HOME/.zsh" && ! -L "$HOME/.zsh" ]]; then
mv "$HOME/.zsh" "$HOME/.zsh.bak"
warn "Existing .zsh/ backed up to ~/.zsh.bak"
fi
ln -sfn "$DOTFILES_DIR/.zsh" "$HOME/.zsh"
ok '.zsh/ symlinked'
# 8. Install asdf plugins
for plugin in python ruby; do
if asdf plugin list 2>/dev/null | grep -q "$plugin"; then
ok "asdf $plugin plugin already installed"
else
info "Installing asdf $plugin plugin..."
asdf plugin add "$plugin"
ok "asdf $plugin plugin installed"
fi
done
# 9. Generate .tool-versions if it doesn't exist
TOOL_VERSIONS="$DOTFILES_DIR/.tool-versions"
if [[ -f "$TOOL_VERSIONS" ]]; then
ok '.tool-versions already exists'
else
info 'Resolving latest tool versions...'
for plugin in python ruby; do
version=$(asdf latest "$plugin")
# Avoid free-threaded Python builds (versions ending in "t") --
# most tooling doesn't support the no-GIL builds yet
if [[ "$version" == *t ]]; then
version=$(asdf list all "$plugin" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | tail -1)
fi
echo "$plugin $version" >> "$TOOL_VERSIONS"
ok "$plugin $version"
done
fi
ln -sfn "$TOOL_VERSIONS" "$HOME/.tool-versions"
ok '.tool-versions symlinked'
# 10. Install tool versions from .tool-versions
info 'Installing asdf tool versions (this may take a few minutes)...'
asdf install
ok 'Tool versions installed'
# 11. Ensure ~/.cache exists (used by brew-check.zsh)
mkdir -p "$HOME/.cache"
# 12. Create ~/.secrets if it doesn't exist
if [[ ! -f "$HOME/.secrets" ]]; then
touch "$HOME/.secrets"
chmod 600 "$HOME/.secrets"
ok 'Created ~/.secrets (add private environment variables here)'
else
ok '~/.secrets already exists'
fi
# 13. Symlink .gitignore_global
info 'Symlinking .gitignore_global...'
if [[ -f "$HOME/.gitignore" && ! -L "$HOME/.gitignore" ]]; then
mv "$HOME/.gitignore" "$HOME/.gitignore.bak"
warn 'Existing ~/.gitignore backed up to ~/.gitignore.bak'
fi
ln -sfn "$DOTFILES_DIR/.gitignore_global" "$HOME/.gitignore"
ok '.gitignore_global symlinked to ~/.gitignore'
# 14. Symlink .gitconfig
info 'Symlinking .gitconfig...'
if [[ -f "$HOME/.gitconfig" && ! -L "$HOME/.gitconfig" ]]; then
mv "$HOME/.gitconfig" "$HOME/.gitconfig.bak"
warn 'Existing .gitconfig backed up to ~/.gitconfig.bak'
fi
ln -sfn "$DOTFILES_DIR/.gitconfig" "$HOME/.gitconfig"
ok '.gitconfig symlinked'
# 15. Set up SSH config
info 'Setting up SSH config...'
mkdir -p "$HOME/.ssh/config.d"
chmod 700 "$HOME/.ssh" "$HOME/.ssh/config.d"
ln -sfn "$DOTFILES_DIR/.ssh/config.d/github" "$HOME/.ssh/config.d/github"
ok '.ssh/config.d/github symlinked'
if [[ -f "$HOME/.ssh/config" && ! -L "$HOME/.ssh/config" ]]; then
mv "$HOME/.ssh/config" "$HOME/.ssh/config.bak"
warn 'Existing ~/.ssh/config backed up to ~/.ssh/config.bak'
fi
ln -sfn "$DOTFILES_DIR/.ssh/config" "$HOME/.ssh/config"
ok '.ssh/config symlinked'
for pubkey in "$DOTFILES_DIR"/.ssh/*.pub; do
ln -sfn "$pubkey" "$HOME/.ssh/$(basename "$pubkey")"
done
ok 'SSH public keys symlinked'
# 16. Symlink iTerm2 Dynamic Profile
info 'Symlinking iTerm2 profile...'
mkdir -p "$HOME/Library/Application Support/iTerm2/DynamicProfiles"
ln -sfn "$DOTFILES_DIR/iterm2/jstroop.json" "$HOME/Library/Application Support/iTerm2/DynamicProfiles/jstroop.json"
ok 'iTerm2 profile symlinked'
# 17. Apply macOS customizations
"$DOTFILES_DIR/macos.sh"
# 18. Make deployed dotfiles read-only to prevent accidental edits
info 'Making deployed dotfiles read-only...'
chmod a-w "$DOTFILES_DIR/.zprofile" "$DOTFILES_DIR/.zshrc" "$DOTFILES_DIR/.gitconfig" "$DOTFILES_DIR/.gitignore_global"
find "$DOTFILES_DIR/.zsh" -type f -exec chmod a-w {} +
ok 'Deployed dotfiles are now read-only'
echo ''
info 'Done! Run `exec zsh` to reload your shell.'