-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·144 lines (119 loc) · 2.82 KB
/
bootstrap.sh
File metadata and controls
executable file
·144 lines (119 loc) · 2.82 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
#!/bin/bash
DOTFILES_ROOT=$(pwd -P)
ARGS=$(getopt -a --options m:iur --long "module:,install,uninstall,remove" -- "$@")
MODULE=""
INSTALL=false
UNINSTALL=false
REMOVE=false
eval set -- "$ARGS"
set -e
while true; do
case "$1" in
-m | --module)
MODULE="${2}"
shift 2
;;
-i | --install)
INSTALL=true
shift
;;
-u | --uninstall)
UNINSTALL=true
shift
;;
-r | --remove)
REMOVE=true
shift
;;
--)
break
;;
esac
done
echo ''
# Now look for arguments set after the -- in the call to this script
shift $((OPTIND - 1))
EXTRA_ARGS=("$@")
# Skip the "--" argument
if [[ ${#EXTRA_ARGS[@]} -gt 0 ]]; then
unset "EXTRA_ARGS[0]"
fi
info() {
# shellcheck disable=SC2059
printf "\r [ \033[00;34m..\033[0m ] $1\n"
}
user() {
# shellcheck disable=SC2059
printf "\r [ \033[0;33m??\033[0m ] $1\n"
}
success() {
# shellcheck disable=SC2059
printf "\r\033[2K [ \033[00;32mOK\033[0m ] $1\n"
}
fail() {
# shellcheck disable=SC2059
printf "\r\033[2K [\033[0;31mFAIL\033[0m] $1\n"
echo ''
exit
}
find_shell() {
if command -v "${1}" >/dev/null 2>&1 && grep "$(command -v "${1}")" /etc/shells >/dev/null; then
command -v "$1"
else
echo "/bin/$1"
fi
}
update_module_config() {
if [[ $REMOVE == true ]]; then
sed -i "/$MODULE/d" ~/.dotFileModules &&
stow -D "${MODULE}"
if [[ $? -eq 0 ]]; then
success "Successfully removed and unstowed $MODULE module"
else
fail "Failed to remove and unstow $MODULE module"
fi
# Swap shell back to bash if we are removing zsh module
if [[ ${MODULE} == "zsh" ]]; then
BASH="$(find_shell bash)"
command -v chsh >/dev/null 2>&1 &&
chsh -s "$BASH" &&
success "set $("$BASH" --version) at $BASH as default shell"
fi
else
if (! grep -q "^${MODULE}$" "$HOME"/.dotFileModules) && [[ "${MODULE}" != "zsh" ]]; then
echo "${MODULE}" >>"${HOME}"/.dotFileModules
fi
stow "${MODULE}"
if [[ $? -eq 0 ]]; then
success "Successfully stowed $MODULE module"
if [[ ${MODULE} == "zsh" ]]; then
zsh
zinit self-update
fi
else
fail "Failed to stow $MODULE module"
fi
fi
}
install_module_dependencies() {
if [[ -f ./"${MODULE}"/install.sh ]]; then
./"${MODULE}"/install.sh "${EXTRA_ARGS[@]}"
if [[ $? -eq 0 ]]; then
success "Successfully installed dependencies for $MODULE module"
else
fail "Failed to install dependencies for $MODULE module"
fi
fi
}
if [[ ${MODULE} == "zsh" ]]; then
ZSH="$(find_shell zsh)"
test "$(expr "$SHELL" : '.*/\(.*\)')" != "ZSH" &&
command -v chsh >/dev/null 2>&1 &&
chsh -s "$ZSH" &&
success "set $("$ZSH" --version) at $ZSH as default shell"
fi
if [[ $INSTALL == true ]]; then
install_module_dependencies
fi
update_module_config
source "$HOME"/.zshrc