-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.sh
executable file
·445 lines (374 loc) · 15.3 KB
/
configure.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
#!/bin/bash
set -e
# The install script for my dot files!
# Idea is to use symlinks to have it where my configs are pointed to this repository for easy managing.
# No need to install additional software, just run this and it should be done.
### Global Variables
MAIN_BIN_PATH="${HOME}/CLI_Tools"
BIN_SYMLINK_PATH="${MAIN_BIN_PATH}/bin_symlinks"
####### Functions
### Helper Functions
# Prints out the help function of the script
usage () {
cat << EOF
$(basename "$0") [-o] [-b] [-d] [-h] -- Configures a personal system using maishiroma's dot files.
This script aims to simplify the process of bringing onboard a new system. Currently, there are two available options that can be passed in the -o flag:
personal (My personal configs)
work (What my work laptop has for configs)
This script is also a wrapper for managing binary symlinks. While those links are not tied to this, this script helps simplifies the workflow of managing multiple binaries. Note that to use this, binaries MUST be named in the following syntax:
some-binary_version.number
where "binary-binary" is the name that the binary is referred to (spaces are -), and the version.number is the binary's version. By default, these binaries are stored in ${HOME}/CLI_Tools, but can be configured.
FLAGS:
-o: Specifies which kind of dotfiles to leverage
-b: Specifies a binary file to create a symlink towards
-d: Enabled delete mode on this script
-l: Lists out all of the active binaries that are currently used
-p: Overrides the default path to be used for binaries (Default: ${HOME}/CLI_Tools)
-h: Shows this help page
EXAMPLES:
1.) ./configure.sh -o personal
Configures a new installation of dot files using the personal configs
2.) ./configure.sh -b some-binary_1.0.0
Creates a symlink to the specified binary
3.) ./configure.sh -d
Removes the current installation of dot files on the system
4) ./configure.sh -d -b some-binary_1.0.0
Removes the specified binary's symlink, while presenting the option to delete said binary
EOF
}
# Checks if the user wants to proceed. If not, the script will end
confirm_user() {
echo
echo "Are you sure you want to proceed?"
echo "Please confirm with 'yes': "
read userInput
if [ "${userInput}" != "yes" ]; then
echo "Did not receive explicit yes, leaving script..."
exit 0
fi
echo
}
### Main Functions
# Checks the system if the pre-requirements are installed:
# Specifically, git, brew, zsh and Oh my Zsh
pre_dot_checks() {
echo "Checking if git, brew, zsh, and Oh-my-zsh are installed..."
if hash git 2>/dev/null; then
echo "Git is installed!"
else
echo "Git is NOT installed! Please install git! (speaking of which HOW did you even download this repo?)"
echo "Run <git --version> and follow the on screen prompts."
exit 1
fi
if hash brew 2>/dev/null; then
echo "brew is installed!"
else
echo "brew is NOT installed! Please install brew!"
echo "Run: <ruby -e \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\" to install brew."
exit 1
fi
if hash zsh 2>/dev/null; then
echo "zsh is installed!"
else
echo "zsh is NOT installed! Please install zsh!"
echo "Run: <brew install zsh zsh-completions> to install zsh."
exit 1
fi
if [ -d "${HOME}/.oh-my-zsh" ]; then
echo "Oh My zsh is installed!"
else
echo "Oh My zsh is not installed!"
echo "To install, run: <sh -c \"\$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)\"> "
exit 1
fi
echo "Pre checks complete!"
echo
}
# Configures vim by creating the needed dirs
vim_pre_config () {
echo "Checking if needed .vim directories are created..."
echo "The specific .vim directories will be created, if not already existing: autoload, bundle, plugin, backup, and colors."
confirm_user
if [ ! -d "${HOME}/.vim/autoload" ]; then
echo "Creating ${HOME}/.vim/autoload"
mkdir -p ${HOME}/.vim/autoload
fi
if [ ! -d "${HOME}/.vim/bundle" ]; then
echo "Creating ${HOME}/.vim/bundle"
mkdir -p ${HOME}/.vim/bundle
fi
if [ ! -d "${HOME}/.vim/plugin" ]; then
echo "Creating ${HOME}/.vim/plugin"
mkdir -p ${HOME}/.vim/plugin
fi
if [ ! -d "${HOME}/.vim/backup" ]; then
echo "Creating ${HOME}/.vim/backup"
mkdir -p ${HOME}/.vim/backup
fi
if [ ! -d "${HOME}/.vim/colors" ]; then
echo "Creating ${HOME}/.vim/colors"
mkdir -p ${HOME}/.vim/colors
fi
echo "Finished configuring .vim directories"
echo
}
# Sets up the binary symlink directories
prep_binary_symlink_dirs() {
echo "Checking if needed directories for binary symlinks are present..."
echo "The following directories will be created, if not existing: ${MAIN_BINARY_PATH} and ${BIN_SYMLINK_PATH}"
confirm_user
if [ ! -d "${BIN_SYMLINK_PATH}" ]; then
echo "Creating ${MAIN_BINARY_PATH} and ${BIN_SYMLINK_PATH}"
mkdir -p ${BIN_SYMLINK_PATH}
fi
echo "Finished creating binary symlink directories."
echo
}
# Installs all plugins for vim
vim_install_plugins_themes() {
echo "Prepping to install Vim plugins and themes..."
echo "The following plugins will be installed, if not already: pathogen, autoclose"
echo "The following themes will be installed, if not already: iceberg"
confirm_user
if [ ! -f "${HOME}/.vim/autoload/pathogen.vim" ]; then
# Install pathogen
echo "Installing Pathogen to ${HOME}/.vim/autoload/pathogen.vim ..."
curl -LSso ${HOME}/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
fi
if [ ! -f "${HOME}/.vim/colors/iceberg.vim" ]; then
# Install the Iceberg theme
echo "Installing Iceberg theme to ${HOME}/.vim/colors/iceberg.vim ..."
curl -LSso ${HOME}/.vim/colors/iceberg.vim https://raw.githubusercontent.com/cocopon/iceberg.vim/master/colors/iceberg.vim
fi
if [ ! -f "${HOME}/.vim/plugin/autoclose.vim" ]; then
# Installs autoclose plugin
echo "Installing autoclose plugin to ${HOME}/.vim/plugin/autoclose.vim ..."
curl -LSso ${HOME}/.vim/plugin/autoclose.vim https://www.vim.org/scripts/download_script.php?src_id=10873
fi
# If we are on a specific environment, we install additional plugins
if [ "${TYPE}" == "work" ]; then
echo "Detected using work setup. Additional plugins will also be installed, if not already: vim-terraform, vim-markdown-preview"
confirm_user
if [ ! -d "${HOME}/.vim/bundle/vim-terraform" ]; then
# Installs vim-terraform plugin
echo "Installing vim-terraform plugin to ${HOME}/.vim/bundle/vim-terraform ..."
mkdir -p ${HOME}/.vim/bundle/vim-terraform
git clone [email protected]:hashivim/vim-terraform.git ${HOME}/.vim/bundle/vim-terraform
fi
if [ ! -d "${HOME}/.vim/bundle/vim-markdown-preview" ]; then
# Installs vim-markdown-preview plugin
echo "Installing vim-markdown-preview plugin to ${HOME}/.vim/bundle/vim-markdown-preview ..."
mkdir -p ${HOME}/.vim/bundle/vim-markdown-preview
git clone [email protected]:JamshedVesuna/vim-markdown-preview.git ${HOME}/.vim/bundle/vim-markdown-preview
fi
fi
echo "Installation of all plugins complete!"
echo
}
# Installs additional packages that are leveraged from the terminal
terminal_install_pkgs() {
echo "Now checking if there's additional terminal packages needed..."
echo "The following plugins will be installed if not already installed: zsh-autosuggestions"
confirm_user
# Checks for zsh-autosuggestions plugin
if [ ! -d "${HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions" ]; then
echo "Installing zsh-autosuggestions into ${HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions..."
mkdir -p ${HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions
git clone [email protected]:zsh-users/zsh-autosuggestions.git ${HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions
fi
echo "Finished installing terminal plugins!"
echo
}
# Symlinks all needed config files to their respectible places, depending on the flag, TYPE
create_config_symlinks() {
dir_loc=""
if [ "${TYPE}" == "personal" ]; then
echo "Symlinking configs from the personal directory..."
dir_loc="$(pwd)/personal"
elif [ "${TYPE}" == "work" ]; then
echo "Symlinking configs from the work directory..."
dir_loc="$(pwd)/work"
else
echo "That option is not valid here, sorry! Try asking for help. :)"
exit 1
fi
echo "The following files will now be symlinked to this repo: ${HOME}/.gitconfig, ${HOME}/.tmux.conf, ${HOME}/.zshrc, ${HOME}/.zsh_exports, ${HOME}/.vimrc"
confirm_user
ln -sf ${dir_loc}/git/gitconfig ${HOME}/.gitconfig
ln -sf ${dir_loc}/terminal/tmux.conf ${HOME}/.tmux.conf
ln -sf ${dir_loc}/terminal/zshrc ${HOME}/.zshrc
ln -sf ${dir_loc}/terminal/zsh_exports ${HOME}/.zsh_exports
ln -sf ${dir_loc}/vim/vimrc ${HOME}/.vimrc
echo "Finished symlinking configs!"
echo
}
# Removes symlinks that are on the current system
delete_config_symlinks() {
echo "The following symlinks will be removed: ${HOME}/.gitconfig, ${HOME}/.tmux.conf, ${HOME}/.zshrc, ${HOME}/.zsh_exports, ${HOME}/.vimrc"
confirm_user
# If file/symblink is already removed, we will skip that step
echo "Removing symlinks/files mentioned..."
if [ -f "${HOME}/.gitconfig" ]; then
rm ${HOME}/.gitconfig
fi
if [ -f "${HOME}/.tmux.conf" ]; then
rm ${HOME}/.tmux.conf
fi
if [ -f "${HOME}/.zshrc" ]; then
rm ${HOME}/.zshrc
fi
if [ -f "${HOME}/.zsh_exports" ]; then
rm ${HOME}/.zsh_exports
fi
if [ -f "${HOME}/.vimrc" ]; then
rm ${HOME}/.vimrc
fi
echo "Removed all symlinks and/or files!"
echo
}
# Creates symlinks to a specific binary
# Presumes that the binary was already downloaded and verified
create_binary_symlinks() {
echo "Checking that ${MAIN_BIN_PATH} contains ${SPEC_BIN_NAME}..."
echo
if [ ! -f "${MAIN_BIN_PATH}/${SPEC_BIN_NAME}" ]; then
echo "Error, cannot find ${SPEC_BIN_NAME}, exiting..."
echo
else
binaryNameClean=$(echo ${SPEC_BIN_NAME} | cut -d '_' -f 1)
if [ ! -f "${BIN_SYMLINK_PATH}/${binaryNameClean}" ]; then
echo "No existing symlink was found! The following will be made:"
echo "${binaryNameClean} -> ${SPEC_BIN_NAME}"
else
existingBinName=$(basename $(readlink ${BIN_SYMLINK_PATH}/${binaryNameClean}))
if [ "${existingBinName}" == "${SPEC_BIN_NAME}" ]; then
echo "The symlink won't be changed, sine it is already using that binary."
echo "Exiting script..."
exit 0
else
echo "An existing symlink was found for ${binaryNameClean}:"
echo "${existingBinName} -> ${SPEC_BIN_NAME}"
echo
echo "This action will rewrite the symlink to use the specified binary."
fi
fi
confirm_user
ln -sf ${HOME}/CLI_Tools/${SPEC_BIN_NAME} ${BIN_SYMLINK_PATH}/${binaryNameClean}
echo "Successfully made symlink, ${binaryNameClean}!"
fi
}
# Deletes the specified binary symlink
delete_binary_symlink() {
echo "Checking that ${MAIN_BIN_PATH} contains the specified binary..."
binaryNameClean=$(echo ${SPEC_BIN_NAME} | cut -d '_' -f 1)
if [ ! -f "${MAIN_BIN_PATH}/${SPEC_BIN_NAME}" ]; then
echo "Error, cannot find ${SPEC_BIN_NAME}, exiting..."
exit 1
elif [ ! -f "${BIN_SYMLINK_PATH}/${binaryNameClean}" ]; then
echo "There is no symlink for ${binaryNameClean}! Exiting..."
exit 1
fi
symlinkToDelete=$(readlink ${BIN_SYMLINK_PATH}/${binaryNameClean})
if [ $(basename ${symlinkToDelete}) == ${SPEC_BIN_NAME} ]; then
echo "The following symlink will be removed: ${binaryNameClean}"
confirm_user
rm -f $BIN_SYMLINK_PATH/${binaryNameClean}
echo "Symlink removed!"
delete_old_binary ${SPEC_BIN_NAME}
else
echo "Current symlink with ${binaryNameClean} is not established with ${SPEC_BIN_NAME}, exiting..."
exit 1
fi
}
# Deletes the binary that was specified in this function's parameter
delete_old_binary() {
binary_to_delete=$1
if [ -f "${MAIN_BIN_PATH}/${binary_to_delete}" ]; then
echo
echo "Would you like to remove the old binary, ${binary_to_delete}, as well?"
echo "If not, the script will complete and the binary will still be in ${MAIN_BIN_PATH}."
confirm_user
rm -f ${MAIN_BIN_PATH}/${binary_to_delete}
echo "Removed old binary!"
else
echo "${binary_to_delete} is not found, exiting script..."
exit 1
fi
}
# Lists all of the active symlinks for each managed binary
list_binary_symlinks() {
echo
for currBinLink in ${HOME}/CLI_Tools/bin_symlinks/*; do
binName=$(readlink $currBinLink)
echo ${binName##*/}
done
echo
}
### Main
while getopts 'b:o:p:dlh' option; do
case "$option" in
b)
SPEC_BIN_NAME=("$OPTARG")
;;
o)
TYPE=("$OPTARG")
;;
p)
MAIN_BIN_PATH=("$OPTARG")
BIN_SYMLINK_PATH=${MAIN_BIN_PATH}/bin_symlinks
echo "Detected user entered custom path for binaries: ${MAIN_BIN_PATH}"
;;
d)
DELETE_MODE=true
;;
l)
LIST_BINARIES=true
;;
h)
usage
exit 0
;;
\?)
printf "illegal option: -%s\n" "$OPTARG" >&2
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
# Main logic
if [ -n "${DELETE_MODE}" ]; then
if [ -n "${SPEC_BIN_NAME}" ]; then
# We are going to delete the specified binary symlink
echo "Preparing to manage binary symlinks..."
delete_binary_symlink
else
# We are going to delete the all config symlinks from the system
echo "Preparing to deleting current dotfiles on system..."
delete_config_symlinks
fi
elif [ -n "${LIST_BINARIES}" ]; then
# We are going to list all active binaries
echo "Active binaries: "
list_binary_symlinks
elif [ -n "${SPEC_BIN_NAME}" ]; then
# We are going to add a specific binary symlink
echo "Preparing to manage binary symlink..."
create_binary_symlinks
elif [ -n "${TYPE}" ]; then
# We are going to install all config symlinks onto the system
# First, run prechecks and preconfigs
echo "Preparing to install dotfiles on system..."
pre_dot_checks
vim_pre_config
prep_binary_symlink_dirs
# Then create symlinks and installs packages
create_config_symlinks
vim_install_plugins_themes
terminal_install_pkgs
echo "Installation complete! To reload the configuation, start a new terminal session."
echo "To add binary symlinks, run this script with -b flag and specify a binary found in ${MAIN_BIN_PATH}"
elif [[ -z "${TYPE}" ]] || [[ -z "${SPEC_BIN_NAME}" ]]; then
usage
exit 0
fi