-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
executable file
·446 lines (379 loc) · 13.8 KB
/
install.sh
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
#!/bin/bash
# MESSAGE OUTPUT COLORS
green=$(tput setaf 34)
red=$(tput setaf 1)
yellow=$(tput setaf 3)
blue=$(tput setaf 39)
normal=$(tput sgr0)
# HELPER FUNCTIONS
command_exists() {
command -v "$@" >/dev/null 2>&1
}
dir_exists() {
[ -d "$*" ] 2>&1
}
fmt_error() {
echo "${red}Error: $*${normal}" >&2
}
abort() {
printf "%s\n" "$1"
exit 1
}
wait_for_user() {
echo
read -r -s -n 1 -p "${yellow}Press RETURN to continue or any other key to abort${normal}" c
if ! [[ "$c" == "" ]]; then
echo
echo
echo "Aborted."
exit 1
fi
}
# INSTALL SCRIPT START
OS="$(uname)"
if [[ "$OS" == "Linux" ]]; then
abort "Unfortunately Xavier Config only supports macOS currently - please put in a PR if you can add Linux support!"
elif [[ "$OS" != "Darwin" ]]; then
abort "Xavier Config is only supported on macOS."
fi
echo
echo "${green}Xavier Config Installer${normal}"
echo
echo "This install script will check for and install Homebrew, in addition to the required brews for Xavier Config:"
echo "[1] Zsh [2] Coreutils [3] Neovim [4] Git [5] Tmux [6] Fzf [7] Ripgrep [8] Bat"
echo "After the required brews are installed, optional brews will be installed with (y/n) user prompts."
echo
echo "The install script will then check for and install Oh-My-Zsh, PowerLevel9K, zsh-history-substring-search, VimPlug, and finally Xavier Config"
echo "After the install is complete, the Xavier Config directory will exist at ~/.xavier-config."
echo
echo "Any prior .zshrc .tmux.conf or init.vim files are backed up during the install process to a timestamped backup"
echo "folder within ~/.xavier-config."
echo
echo "The files ~/.zshrc ~/.tmux.conf and ~/.config/nvim/init.vim will be symlinked to files within ~/.xavier-config"
echo
echo "After the install process, please follow the manual steps listed on the Xavier Config Github Page."
echo "https://github.com/rheisen/xavier-config"
wait_for_user
step=1
echo
echo
if ! command_exists brew; then
echo "${yellow}$step: Homebrew not detected. Running the Homebrew install script...${normal}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
if ! command_exists brew; then
fmt_error "Homebrew not detected. Please check that Homebrew installed correctly."
exit 1
else
echo "${blue}$step: Homebrew detected.${normal}"
fi
# REQUIRED BREWS
((step++))
echo
echo "${blue}$step: Checking for required brews...${normal}"
requiredBrews=(zsh coreutils neovim git tmux fzf ripgrep bat)
declare -a requiredBrewName=(
"ZSH"
"Coreutils"
"Neovim"
"Git"
"TMUX"
"FZF"
"Ripgrep"
"Bat"
)
declare -a requiredBrewFormula=(
"zsh"
"coreutils"
"neovim"
"git"
"tmux"
"fzf"
"ripgrep"
"bat"
)
for i in "${!requiredBrews[@]}"; do
index=$((i+1))
if brew ls --versions "${requiredBrewFormula[$i]}" > /dev/null; then
echo "$step.$index: ${requiredBrewName[$i]} brew detected, skipping install."
else
echo "${yellow}$step.$index: ${requiredBrewName[$i]} brew not detected, installing ${requiredBrewFormula[$i]}...${normal}"
brew install "${requiredBrewFormula[$i]}"
fi
done
# OPTIONAL BREWS
((step++))
echo
echo "${blue}$step: Checking for optional brews...${normal}"
optionalBrews=(shellcheck jq gitflow kubectl helm doctl gradle gnupg gnupg2)
declare -a brewName=(
"ShellCheck"
"JQ"
"Git Flow"
"Kubernetes CLI (kubectl)"
"Helm"
"DigitalOcean CLI (doctl)"
"Gradle"
"Gnupg"
"Gnupg 2"
)
declare -a brewFormula=(
"shellcheck"
"jq"
"git-flow"
"kubectl"
"helm"
"doctl"
"gradle"
"gnupg"
"gnupg2"
)
for i in "${!optionalBrews[@]}"; do
index=$((i+1))
if brew ls --versions "${brewFormula[$i]}" > /dev/null; then
echo "$step.$index: ${brewFormula[$i]} brew detected, skipping install."
else
while true; do
read -r -p "${yellow}$step.$index: ${brewName[$i]} brew not detected, would you like to install ${brewFormula[$i]}?${normal} (y/n): " opt
if [ "$opt" == "y" ] || [ "$opt" == "Y" ]; then
brew install "${brewFormula[$i]}"
break
elif [ "$opt" == "n" ] || [ "$opt" == "N" ]; then
echo "$step.$index: Skipping ${brewName[$i]}."
break
else
echo "$step.$index: Invalid response: $opt"
fi
done
fi
done
# OPTIONAL TAPS
((step++))
echo
echo "${blue}$step: Checking for optional taps...${normal}"
optionalTaps=(op springboot)
declare -a tapName=(
"1Password CLI (op)"
"Spring Boot"
)
declare -a tapFormula=(
"1password/tap/1password-cli"
"spring-io/tap/spring-boot"
)
for i in "${!optionalTaps[@]}"; do
index=$((i+1))
if [ $i -eq 0 ] && [ -x "$(command -v op)" ]; then
echo "$step.$index: ${tapName[$i]} detected, skipping install."
elif [ $i -eq 1 ] && [ -x "$(command -v spring)" ]; then
echo "$step.$index: ${tapName[$i]} detected, skipping install."
else
while true; do
read -r -p "${yellow}$step.$index: ${tapName[$i]} not detected, would you like to install ${tapFormula[$i]}?${normal} (y/n): " opt
if [ "$opt" == "y" ] || [ "$opt" == "Y" ]; then
brew install "${tapFormula[$i]}"
break
elif [ "$opt" == "n" ] || [ "$opt" == "N" ]; then
echo "$step.$index: Skipping ${tapName[$i]}."
break
else
echo "$step.$index: Invalid response: $opt"
fi
done
fi
done
# OH-MY-ZSH INSTALL
((step++))
ohmyzsh_dir=~/.oh-my-zsh
echo
if ! dir_exists $ohmyzsh_dir; then
echo "${yellow}$step: Oh-My-Zsh not detected. Running the Oh-My-Zsh install script...${normal}"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
if ! dir_exists $ohmyzsh_dir; then
fmt_error "Oh-My-Zsh not detected. Please check that Oh-My-Zsh installed correctly."
exit 1
else
echo "${blue}$step: Oh-My-Zsh detected.${normal}"
fi
# POWERLEVEL9K INSTALL
command_exists git || {
fmt_error "Git not detected. Please check that Git installed correctly."
exit 1
}
((step++))
powerlevel9k_dir="$ohmyzsh_dir/custom/themes/powerlevel9k"
echo
if dir_exists $powerlevel9k_dir; then
echo "${blue}$step: PowerLevel9K detected, skipping install.${normal}"
else
echo "${yellow}$step: PowerLevel9K not detected, cloning PowerLevel9K...${normal}"
git clone https://github.com/bhilburn/powerlevel9k.git $powerlevel9k_dir
fi
# HISTORY-SEARCH INSTALL
((step++))
history_search_plugin_dir="$ohmyzsh_dir/custom/plugins/zsh-fzf-history-search"
if ! dir_exists "$history_search_plugin_dir"; then
echo "${yellow}$step: history-search repo not detected in Oh-My-Zsh plugin directory, cloning...${normal}"
git clone "https://github.com/joshskidmore/zsh-fzf-history-search" "$history_search_plugin_dir"
else
echo "${blue}$step: history-search repo found in Oh-My-Zsh plugin directory, skipping install.${normal}"
fi
# HISTORY-SUBSTRING-SEARCH INSTALL
((step++))
history_substring_search_dir="$ohmyzsh_dir/custom/plugins/zsh-history-substring-search"
if ! dir_exists "$history_substring_search_dir"; then
echo "${yellow}$step: history-substring-search repo not detected in Oh-My-Zsh plugin directory, cloning...${normal}"
git clone "https://github.com/zsh-users/zsh-history-substring-search" "$history_substring_search_dir"
else
echo "${blue}$step: history-substring-search repo found in Oh-My-Zsh plugin directory, skipping install.${normal}"
fi
# TMUX PLUGIN MANAGER INSTALL
((step++))
tpm_dir="~/.tmux/plugins/tpm"
if ! dir_exists "$tpm_dir"; then
echo "${yellow}$step: tmux plugin manager repo not detected, cloning...${normal}"
git clone "https://github.com/tmux-plugins/tpm" "$tpm_dir"
else
echo "${blue}$step: tmux plugin manager repo found, skipping install.${normal}"
fi
# VIM PLUG INSTALL
((step++))
vimplug_file=~/.local/share/nvim/site/autoload/plug.vim
echo
if [ -f "$vimplug_file" ]; then
echo "${blue}$step: VimPlug for Neovim detected, skipping install.${normal}"
else
echo "${yellow}$step: VimPlug for Neovim not detected, installing VimPlug...${normal}"
sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
fi
# ITERM2 INSTALL
((step++))
echo
echo "${blue}$step: Checking for iTerm2...${normal}"
if test -d "/Applications/iTerm.app" ; then
echo "$step.1: iTerm2 app detected, skipping install."
elif brew ls --cask --versions iterm2 > /dev/null; then
echo "$step.1: iTerm2 brew detected, skipping install."
else
echo "${yellow}$step.1: iTerm2 not detected, installing iterm2...${normal}"
brew install --cask iterm2
fi
# XAVIER CONFIG SETUP
((step++))
xconfig_dir=~/.xavier-config
xbackup_dir="$xconfig_dir/backup_$(date +%Y-%m-%d_%T)"
echo
echo "${blue}$step: Setting up Xavier Config...${normal}"
if dir_exists $xconfig_dir; then
echo "$step.1: Xavier config detected, skipping clone."
else
echo "${yellow}$step.1: Xavier config not detected, cloning xavier-config into $xconfig_dir${normal}"
git clone https://github.com/Rheisen/xavier-config.git $xconfig_dir
fi
# Nvim init.vim symlink setup
command_exists realpath || {
fmt_error "realpath not detected. Please check that CoreUtils installed correctly."
exit 1
}
nvim_init_file=~/.config/nvim/init.vim
xconfig_nvim_init_file="$xconfig_dir/nvim/init.vim"
dir_exists ~/.config/nvim || {
mkdir -p ~/.config/nvim
}
if [ -L "$nvim_init_file" ]; then
if [ "$(realpath $nvim_init_file)" == "$xconfig_nvim_init_file" ]; then
echo "$step.2: Neovim symlink to xavier-config init file already in place, skipping symlink."
else
rm $nvim_init_file
ln -s $xconfig_nvim_init_file $nvim_init_file
echo "${yellow}$step.2: Neovim symlink to init file replaced with symlink to xavier-config init file.${normal}"
fi
elif [ -f "$nvim_init_file" ]; then
dir_exists "$xbackup_dir" || {
mkdir "$xbackup_dir"
}
cp $nvim_init_file "$xbackup_dir/init.vim"
echo "${yellow}$step.2: Neovim init.vim file found, backup created at $xbackup_dir/init.vim${normal}"
rm $nvim_init_file
ln -s $xconfig_nvim_init_file $nvim_init_file
echo "${yellow}$step.2: Neovim init.vim file replaced with symlink to xavier-config init file.${normal}"
else
ln -s $xconfig_nvim_init_file $nvim_init_file
echo "${yellow}$step.2: Neovim symlink to xavier-config init file created.${normal}"
fi
# Zsh .zshrc symlink setup
zshrc_file=~/.zshrc
xconfig_ex_zshrc_file="$xconfig_dir/zsh/.zshrc-example"
xconfig_zshrc_file="$xconfig_dir/zsh/.zshrc"
if ! [ -f "$xconfig_zshrc_file" ]; then
echo "$step.3: Creating xavier-config .zshrc base file from .zshrc-example file."
sed "s/YOURUSERNAME/$USER/" $xconfig_ex_zshrc_file > $xconfig_zshrc_file
fi
if [ -L "$zshrc_file" ]; then
if [ "$(realpath $zshrc_file)" == "$xconfig_zshrc_file" ]; then
echo "$step.3: Zsh symlink to xavier-config zshrc file already in place, skipping symlink."
else
rm $zshrc_file
ln -s $xconfig_zshrc_file $zshrc_file
echo "${yellow}$step.3: Zsh symlink to zshrc file replaced with symlink to xavier-config zshrc file.${normal}"
fi
elif [ -f "$zshrc_file" ]; then
dir_exists "$xbackup_dir" || {
mkdir "$xbackup_dir"
}
cp $zshrc_file "$xbackup_dir/.zshrc"
echo "${yellow}$step.3: Zsh zshrc file found, backup created at $xbackup_dir/.zshrc${normal}"
rm $zshrc_file
ln -s $xconfig_zshrc_file $zshrc_file
echo "${yellow}$step.3: Zsh symlink to xavier-config zshrc file created.${normal}"
else
ln -s $xconfig_zshrc_file $zshrc_file
echo "${yellow}$step.3: Zsh symlink to xavier-config zshrc file created.${normal}"
fi
# Tmux .tmux.conf symlink setup
tmux_conf_file=~/.tmux.conf
xconfig_tmux_conf_file="$xconfig_dir/zsh/.tmux.conf"
if [ -L "$tmux_conf_file" ]; then
if [ "$(realpath $tmux_conf_file)" == "$xconfig_tmux_conf_file" ]; then
echo "$step.4: Tmux symlink to xavier-config tmux.conf file already in place, skipping symlink."
else
rm $tmux_conf_file
ln -s $xconfig_tmux_conf_file $tmux_conf_file
echo "${yellow}$step.4: Tmux symlink to tmux.conf file replaced with symlink to xavier-config "
echo "tmux.conf file.${normal}"
fi
elif [ -f "$tmux_conf_file" ]; then
dir_exists "$xbackup_dir" || {
mkdir "$xbackup_dir"
}
cp $tmux_conf_file "$xbackup_dir/.tmux.conf"
echo "${yellow}$step.4: Tmux zshrc file found, backup created at $xbackup_dir/.tmux.conf${normal}"
rm $tmux_conf_file
ln -s $xconfig_tmux_conf_file $tmux_conf_file
echo "${yellow}$step.4: Tmux symlink to xavier-config tmux.conf file created.${normal}"
else
ln -s $xconfig_tmux_conf_file $tmux_conf_file
echo "${yellow}$step.4: Tmux symlink to xavier-config tmux.conf file created.${normal}"
fi
# Fira Code font installation
((step++))
echo "${blue}$step: Checking for Fira-Code-Font...${normal}"
if test -f ~/Library/Fonts/Fira\ Code\ Retina\ Nerd\ Font\ Complete.ttf; then
echo "$step.1: Fira Code font detected, skipping install."
else
echo "${yellow}$step.2: Fira Code font not detected, installing...${normal}"
mv $xconfig_dir/iterm/Fira\ Code\ Retina\ Nerd\ Font\ Complete.ttf ~/Library/Fonts/
fi
xiterm_assets_dir=~/documents/xavier-config/iterm
dir_exists $xiterm_assets_dir || {
mkdir -p ~/documents/xavier-config
cp -r "$xconfig_dir/iterm" "$xiterm_assets_dir"
}
echo
echo "${green}Xavier Config Installer Finished! Refer to the manual setup section to finish the setup.${normal}"
echo "Opening the xavier-config directory ($xconfig_dir)"
echo "Opening the xavier-config iterm assets directory ($xiterm_assets_dir)"
open $xconfig_dir
open $xiterm_assets_dir
exit