-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·187 lines (149 loc) · 5.23 KB
/
install
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
#!/bin/bash
############################ SETUP PARAMETERS
# TODO: Makefile
debug_mode=0
############################ ZSH BUNDLES
bundles=(
"bundle/zsh-history-substring-search"
"--squash https://github.com/zsh-users/zsh-history-substring-search.git master"
"bundle/zsh-syntax-highlighting"
"--squash https://github.com/zsh-users/zsh-syntax-highlighting.git master"
"bundle/zsh-auto-fu"
"--squash https://github.com/hchbaw/auto-fu.zsh.git master"
);
############################ BASIC SETUP TOOLS
msg() {
printf '%b' "$1" >&2
}
error() {
msg "\e[31m[✘]\033[0m ${1}${2}"
exit 1
}
success() {
if [[ "$ret" -eq '0' ]]; then
msg "\e[32m[✔]\033[0m ${1}${2}"
else
error "${1}${2}"
fi
}
debug() {
if [ "$debug_mode" -eq '1' ] && [ "$ret" -gt '1' ]; then
msg "An error occured in function \"${FUNCNAME[$i+1]}\" on line ${BASH_LINENO[$i+1]}, we're sorry for that."
fi
}
program_exists() {
local ret='0'
type $1 >/dev/null 2>&1 || { local ret='1'; }
# throw error on non-zero return value
if [ ! "$ret" -eq '0' ]; then
error "$2"
fi
}
############################ SETUP ROUTINE
function uninstall () {
msg "\n\e[36mDo you want to uninstall X4?\033[0m\n[\e[31mn\033[0m] no\t\t[\e[31my\033[0m] yes\t\t[\e[31mENTER\033[0m] skip \nChoose: "
read; echo ""
if [[ $REPLY =~ ^[yY]$ ]]; then
if [[ -L "$HOME/.zshrc" ]]; then
rm -i "$HOME/.zshrc" "$HOME/.zshenv" "$HOME/.zprofile" "$HOME/.*.zwc" "$HOME/.zcompdump" "$HOME/.zdirs" "$HOME/.zlogin" "$HOME/.zlogout"
fi
if [[ -L "$HOME/.bashrc" ]]; then
rm -i "$HOME/.bashrc"
fi
if [[ -L "$HOME.fishrc" ]]; then
rm -i "$HOME/.config/fish/config.fish"
fi
if [[ -L "$HOME/.bcrc" || -L "$HOME/.irbrc" || -L "$HOME/.gemrc" || -L "$HOME/.tmux.conf" ]]; then
rm -i "$HOME/.bcrc"
rm -i "$HOME/.cvsignore"
rm -i "$HOME/.gemrc"
rm -i "$HOME/.irbrc"
rm -i "$HOME/.inputrc"
rm -i "$HOME/.tmux.conf"
rm -i "$HOME/.kde4/Autostart/ssh-add"
fi
ret="$?"
error "$1\n"
fi
success "$2\n"
}
git_subtrees() {
git subtree add --prefix $1
git subtree pull --prefix $2
msg "\e[32m[✔]\033[0m ${2}\n"
}
setup_shell() {
msg "\n\n\e[36mWhich shell do you want to setup?\033[0m]\n[\e[31m1\033[0m] ZSH\t\t [\e[31m2\033[0m] Bash\t [\e[31m3\033[0m] Fish\t [\e[31mENTER\033[0m] skip\nChoose: "
read; echo ""
if [[ $REPLY =~ ^[1]$ ]]; then
chosen_one=$(which zsh)
ln -sfv "$HOME/.X4/zshrc" "$HOME/.zshrc"
ln -sfv "$HOME/.X4/zshenv" "$HOME/.zshenv"
ln -sfv "$HOME/.X4/zprofile" "$HOME/.zprofile"
ln -sfv "$HOME/.X4/zlogin" "$HOME/.zlogin"
ln -sfv "$HOME/.X4/zlogout" "$HOME/.zlogout"
fi
if [[ $REPLY =~ ^[2]$ ]]; then
chosen_one=$(which bash)
ln -sfv "$HOME/.X4/bashrc" "$HOME/.bashrc"
fi
if [[ $REPLY =~ ^[3]$ ]]; then
chosen_one=$(which fish)
ln -sfv "$HOME/.X4/fishrc" "$HOME/.config/fish/config.fish"
fi
ret="$?"
success "$1"
msg "\n\e[36mAdd extra configs to your $chosen_one shell now?\033[0m\n[\e[31my\033[0m] yes\t\t[\e[31mn\033[0m] no\t[\e[31mENTER\033[0m] skip \nChoose: "
read; echo ""
if [[ ! $REPLY -eq "" ]]; then
# Enable custom bc functions
ln -sfv "$HOME/.X4/local/configs/bcrc" "$HOME/.bcrc"
# Install VCS defaults
ln -sfv "$HOME/.X4/local/configs/cvsignore" "$HOME/.cvsignore"
# Enable custom RoR toolset defaults
ln -sfv "$HOME/.X4/local/configs/gemrc" "$HOME/.gemrc"
ln -sfv "$HOME/.X4/local/configs/irbrc" "$HOME/.irbrc"
# Enable custom keybindings
ln -sfv "$HOME/.X4/local/configs/inputrc" "$HOME/.inputrc"
# Enable custom tmux defaults
if [[ "$OSTYPE" == linux* ]]; then
ln -sfv "$HOME/.X4/local/configs/tmux.linux.conf" "$HOME/.tmux.conf"
fi
# Install Konsole themes
mkdir -p `kde4-config --localprefix`/share/apps/konsole/
cp -fv "$HOME/.X4/local/configs/konsole/*" `kde4-config --localprefix`/share/apps/konsole/
# Install ksshaskpass script
ln -sfv "$HOME/.X4/local/scripts/ssh-add" "$HOME/.kde4/Autostart/"
fi
ret="$?"
success "$1"
if [[ $REPLY =~ ^[123]$ ]]; then
msg "\n\e[36mDo you want to make $chosen_one your default shell now?\033[0m\n[\e[31my\033[0m] yes\t\t[\e[31mn\033[0m] no\t[\e[31mENTER\033[0m] skip \nChoose: "
read; echo ""
if [[ $REPLY =~ ^[yY]$ ]]; then
chsh -s $chosen_one
fi
fi
ret="$?"
success "$2\n"
}
function setup_subtrees {
msg "\n\e[36mDo you want to add the bundle git subtrees now?\033[0m\n[\e[31my\033[0m] yes\t\t[\e[31mn\033[0m] no\t\t[\e[31mENTER\033[0m] skip \nChoose: "
read; echo ""
if [[ $REPLY =~ ^[yY]$ ]]; then
cd ~/.X4
for ((i=0; i<${#bundles[@]}; i+=2)) ; do
git_subtrees "${bundles[$i]} ${bundles[$i+1]}" "${bundles[$i]}"
done
cd -
fi
ret="$?"
success "$1\n"
}
############################ MAIN()
msg "Welcome!\n"
uninstall "Successfully uninstalled X4 ...\n" "Skipping uninstaller ..."
setup_shell "Successfully installed chosen dotfile symlinks ...\n"\
"Successfully set default shell to $chosen_one ...\n"
setup_subtrees "Successfully installed all bundle subtrees ..."
success "Thank you master commander!\n"