-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·213 lines (186 loc) · 5.33 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·213 lines (186 loc) · 5.33 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
#!/usr/bin/env bash
DOTFILES_LOCAL_REPO=~/Projects/Personal/dotfiles
main() {
clone_dotfiles_repo
install_homebrew
install_packages
install_claude_code
setup_ssh
setup_symlinks
setup_macOS_defaults
update_macOS_login_items
}
clone_dotfiles_repo() {
info "Cloning dotfiles repository into ${DOTFILES_LOCAL_REPO}"
if test -e $DOTFILES_LOCAL_REPO; then
substep "${DOTFILES_LOCAL_REPO} already exists"
pull_latest $DOTFILES_LOCAL_REPO
else
local url=https://github.com/darenas31415/dotfiles.git
if git clone "$url" $DOTFILES_LOCAL_REPO; then
success "Dotfiles repository cloned into ${DOTFILES_LOCAL_REPO}"
else
error "Dotfiles repository cloning failed"
exit 1
fi
fi
}
install_homebrew() {
if [[ $(command -v brew) == "" ]]; then
info "Installing Hombrew..."
local url=https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
if /bin/bash -c "$(curl -fsSL ${url})"; then
echo >> ~/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
success "Homebrew installation succeeded!"
else
error "Homebrew installation failed!"
exit 1
fi
else
info "Updating Homebrew..."
brew update
fi
}
install_packages() {
local BREW_FILE_PATH="${DOTFILES_LOCAL_REPO}/brew/Brewfile"
info "Installing packages within ${BREW_FILE_PATH}"
if brew bundle check --file="$BREW_FILE_PATH" &> /dev/null; then
success "Brewfile's dependencies are already satisfied!"
else
if brew bundle --file="$BREW_FILE_PATH"; then
success "Brewfile installation succeeded!"
else
error "Brewfile installation failed!"
exit 1
fi
fi
}
install_claude_code() {
if command -v claude &> /dev/null; then
success "Claude Code is already installed!"
else
info "Installing Claude Code..."
if curl -fsSL https://claude.ai/install.sh | bash; then
success "Claude Code installed successfully!"
else
error "Claude Code installation failed!"
exit 1
fi
fi
if claude plugin list 2>/dev/null | grep -q "caveman@caveman"; then
success "caveman plugin is already installed!"
else
info "Installing caveman plugin for Claude Code..."
if claude plugin marketplace add JuliusBrussee/caveman && claude plugin install caveman@caveman; then
success "caveman plugin installed successfully!"
else
error "caveman plugin installation failed!"
exit 1
fi
fi
}
setup_ssh() {
info "Setting up SSH..."
if bash "${DOTFILES_LOCAL_REPO}/ssh/setup.sh"; then
success "SSH setup successfully!"
else
error "SSH setup failed!"
exit 1
fi
}
setup_symlinks() {
info "Setting up symlinks..."
# Disable shell login message
symlink ~/.hushlogin /dev/null
symlink ~/.claude/CLAUDE.md "${DOTFILES_LOCAL_REPO}/claude/CLAUDE.md"
symlink ~/.claude/settings.json "${DOTFILES_LOCAL_REPO}/claude/settings.json"
symlink ~/.config/ghostty/config "${DOTFILES_LOCAL_REPO}/ghostty/config"
symlink ~/.config/starship.toml "${DOTFILES_LOCAL_REPO}/terminal/starship.toml"
symlink ~/.dotfiles "${DOTFILES_LOCAL_REPO}"
symlink ~/.gitconfig "${DOTFILES_LOCAL_REPO}/git/gitconfig"
symlink ~/.gitignore_global "${DOTFILES_LOCAL_REPO}/git/gitignore_global"
symlink ~/.ssh/config "${DOTFILES_LOCAL_REPO}/ssh/config"
symlink ~/.zshrc "${DOTFILES_LOCAL_REPO}/terminal/zshrc"
success "Symlinks successfully setup!"
}
setup_macOS_defaults() {
info "Updating macOS defaults..."
if bash "${DOTFILES_LOCAL_REPO}/macOS/defaults.sh"; then
success "macOS defaults updated successfully!"
else
error "macOS defaults update failed!"
exit 1
fi
}
update_macOS_login_items() {
info "Updating login items..."
if osascript ${DOTFILES_LOCAL_REPO}/macOS/login_items.applescript &> /dev/null; then
success "Login items updated successfully!"
else
error "Login items update failed!"
exit 1
fi
}
symlink() {
destination=$1
point_to=$2
destination_dir=$(dirname "$destination")
if test ! -e "$destination_dir"; then
substep "Creating ${destination}"
mkdir -p "$destination_dir"
fi
if rm -rf "$destination" && ln -s "$point_to" "$destination"; then
substep "Symlinking for \"${destination}\" done!"
else
error "Symlinking for \"${destination}\" failed!"
exit 1
fi
}
pull_latest() {
if [[ -n "$(git -C "$1" status --porcelain)" ]]; then
error "Skipping pull for ${1}: local changes detected."
return
fi
substep "Pulling latest changes in ${1} repository..."
if git -C "$1" pull --ff-only &> /dev/null; then
success "Pull successful in ${DOTFILES_LOCAL_REPO} repository"
return
fi
error "Please pull latest changes in ${1} repository manually!"
}
colored_echo() {
local text="$1";
local color="$2";
local icon="$3";
if ! [[ $color =~ ^[0-9]$ ]] ; then
case $(echo "$color" | tr '[:upper:]' '[:lower:]') in
black) color=0 ;;
red) color=1 ;;
green) color=2 ;;
yellow) color=3 ;;
blue) color=4 ;;
magenta) color=5 ;;
cyan) color=6 ;;
white|*) color=7 ;;
esac
fi
tput bold;
tput setaf "$color";
echo "$icon $text";
tput sgr0;
}
info() {
colored_echo "$1" cyan "→"
}
success() {
colored_echo "$1" green "✔"
}
error() {
colored_echo "$1" red "✘"
}
substep() {
colored_echo "$1" magenta " ↳"
}
main "$@"