-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·352 lines (283 loc) · 9.85 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
#!/usr/bin/env bash
#
# install.sh - installation for my dotfiles
#
# SYNTAX
#
# ./install.sh [-q|--quiet]
#
# DESCRIPTION
#
# Installs all my dotfiles on your current user's working directory.
#
# This script would not only prepare my dotfiles on your home directory,
# since ZSH plugins and necessary packages will be installed too whether
# there is a valid package manager installed on your current machine.
#
# To prevent errors, installation would ask you to create a backup for your
# old dotfiles, which will be stored at current dotfiles path (see exports).
#
# Relative to configuration, you can modify exports file to adjust some settings
# like dotfiles path. It is important to notice that any changes you make are not
# considered and can provoke errors, so please modify exports by your own risk!
#
# ARGUMENTS
#
# [-q | --quiet] Execute installation with no output messages at
# current shell. This was included to offer a way
# to use this command at bash scripts. You should
# know that dotfiles backup would be done if this
# option has been set to current command
#
# AUTHOR
#
# losedavidpb (https://github.com/losedavidpb)
#
source ./exports
source ./functions
# Flags for options
silent_flag=0
no_deps_flag=0
# Personal customization
terminal_name="termite"
shell_name="zsh"
# List of packages that will be installed based on
# current package manager. It is important to notice
# that installation does not include all managers
declare -a _packages=(
git dos2unix zsh
build-essential neofetch
g++ libgtk-3-dev xinit
gtk-doc-tools gnutls-bin
valac intltool libpcre2-dev
libglib3.0-cil-dev libgnutls28-dev
libgirepository1.0-dev libxml2-utils gperf
)
# List of ZSH plugins that will be installed. Installation
# will be done manually to assure that lots of different
# machines could install it without errors
declare -A _zsh_plugins=(
[zsh-autosuggestions]=https://github.com/zsh-users/zsh-autosuggestions
[zsh-syntax-highlighting]=https://github.com/zsh-users/zsh-syntax-highlighting
[zsh-history-substring-search]=https://github.com/zsh-users/zsh-history-substring-search
)
function _showerr () {
if (( $# == 1 )); then
echo "error: install: $1" 2>&1
exit 1
fi
}
function _main_header () {
echo -e "${BOLD_YELLOW}>>${CLOSE_COLOR} ${BOLD_BLUE} SETUP FOR ${UNDERLINE_CYAN}BASH DOTFILES${CLOSE_COLOR}${CLOSE_COLOR} ${BOLD_YELLOW}<<${CLOSE_COLOR}"
echo -e "${BOLD_BLUE}==============================${CLOSE_COLOR}"
}
function _install_packages () {
for (( i=0; i<${#_packages[@]}; i++ )); do
local package_name=${_packages[$i]}
(( $silent_flag == 0 )) && echo -n ">> Installing package $package_name ... "
case $PACKAGE_MANAGER in
"yum")
yes | sudo yum install $package_name -q &>/dev/null
(( $? == 0 )) || echo "BAD" || exit 1
;;
"pacman")
yes | sudo pacman -Syyuq $package_name &>/dev/null
(( $? == 0 )) || echo "BAD" || exit 1
;;
"emerger")
yes | sudo emerge $package_name &>/dev/null
(( $? == 0 )) || echo "BAD" || exit 1
;;
"zypp")
yes | sudo zypper ar $package_name &>/dev/null
(( $? == 0 )) || echo "BAD" || exit 1
;;
"apt")
sudo apt-get -qq install -y $package_name &>/dev/null
(( $? == 0 )) || echo "BAD" || exit 1
;;
"apt-get")
sudo apt-get -qq install -y $package_name &>/dev/null
(( $? == 0 )) || echo "BAD" || exit 1
;;
"apk")
yes | sudo apk add $package_name &>/dev/null
(( $? == 0 )) || echo "BAD" || exit 1
;;
*) _showerr "package manager not available" ;;
esac
(( $silent_flag == 0 )) && echo "OK"
done
}
function _install_vte_ng () {
(( $silent_flag == 0)) && echo -n ">> Installing package vte ... "
if [[ ! -d vte-ng ]]; then
sudo rm -rf vte-ng &>/dev/null
sudo git clone https://github.com/thestinger/vte-ng.git --quiet >/dev/null
sudo find vte-ng/* -type f -print0 | xargs -0 sudo dos2unix -- &>/dev/null
fi
export LIBRARY_PATH="/usr/include/gtk-3.0:$LIBRARY_PATH"
cd vte-ng && sudo ./autogen.sh &>/dev/null && sudo make -s &>/dev/null && sudo make -s install &>/dev/null
cd ..; (( $silent_flag == 0 )) && echo "OK"
sudo rm -rf vte-ng &>/dev/null
}
function _install_termite () {
(( $silent_flag == 0)) && echo -n ">> Installing package termite ... "
if [[ ! -d termite ]]; then
sudo rm -rf termite &>/dev/null
sudo git clone --recursive https://github.com/thestinger/termite.git --quiet >/dev/null
sudo find termite/* -type f -print0 | xargs -0 sudo dos2unix -- &>/dev/null
fi
cd termite && sudo make -s 2>/dev/null
sudo make -s install 2>/dev/null
sudo ldconfig 2>/dev/null
sudo mkdir -p /lib/terminfo/x 2>/dev/null
sudo rm /lib/terminfo/x/xterm-termite 2>/dev/null
sudo ln -s /usr/local/share/terminfo/x/xterm-termite /lib/terminfo/x/xterm-termite
sudo update-alternatives --install /usr/bin/x-terminal-emulator \
x-terminal-emulator /usr/local/bin/termite 60 &>/dev/null
cd ..; (( $silent_flag == 0 )) && echo "OK"
sudo rm -rf termite &>/dev/null
}
function _install_zsh_plugins () {
(( $silent_flag == 0)) && echo -n ">> Install zsh plugins ... "
for zsh_plugin in "${!_zsh_plugins[@]}"; do
local zsh_plugin_url=${_zsh_plugins[$zsh_plugin]}
sudo rm -rf /usr/share/zsh/plugins/$zsh_plugin 2>/dev/null
sudo mkdir -p /usr/share/zsh/plugins/$zsh_plugin 2>/dev/null
sudo git clone $zsh_plugin_url --quiet &>/dev/null
sudo find ./$zsh_plugin/* -type f -print0 | xargs -0 sudo dos2unix -- &>/dev/null
sudo cp -rf ./$zsh_plugin/* /usr/share/zsh/plugins/$zsh_plugin &>/dev/null
sudo rm -rf $zsh_plugin &>/dev/null
done
(( $silent_flag == 0 )) && echo "OK"
}
function _prepare_dotfiles () {
rm -rf ~/.config/shell/ &>/dev/null
mkdir -p ~/.config/Hyper &>/dev/null
mkdir -p ~/.config/neofetch &>/dev/null
mkdir -p ~/.config/termite &>/dev/null
mkdir -p ~/.config/shell/bash &>/dev/null
mkdir -p ~/.config/shell/zsh &>/dev/null
touch ~/.config/shell/.bash_history &>/dev/null
touch ~/.config/shell/.zhistory &>/dev/null
touch ~/.config/shell/.zcompdump &>/dev/null
rm -rf ~/.bash_history &>/dev/null
rm -rf ~/.zcompdump &>/dev/null
rm -rf ~/.zhistory &>/dev/null
}
function _backup_dotfiles () {
rm -rf ~/.config/shell/old-dotfiles
mkdir -p ~/.config/shell/old-dotfiles
cp -rf ~/.bashrc ~/.config/shell/old-dotfiles/
cp -rf ~/.zshrc ~/.config/shell/old-dotfiles/
tar -czf ~/.config/shell/old-dotfiles.tar ~/.config/shell/old-dotfiles
rm -rf ~/.config/shell/old-dotfiles
}
function _install_dotfiles () {
cp -rf $PWD/bash/*.bash ~/.config/shell/bash
cp -rf $PWD/zsh/*.zsh ~/.config/shell/zsh
cp -rf $PWD/neofetch/ascii_icon ~/.config/neofetch
cp -rf $PWD/exports ~/.config/shell
cp -rf $PWD/aliases ~/.config/shell
cp -rf $PWD/functions ~/.config/shell
ln -sf ~/.config/shell/bash/bashrc.bash ~/.bashrc
ln -sf ~/.config/shell/bash/profile.bash ~/.profile
ln -sf ~/.config/shell/zsh/zshrc.zsh ~/.zshrc
cp -rf $PWD/hyper/hyper.js ~/.config/Hyper/
cp -rf $PWD/neofetch/config.conf ~/.config/neofetch/
cp -rf $PWD/termite/config ~/.config/termite/
}
function _customization () {
local temp_file=$(mktemp)
echo "${BOLD_YELLOW}>>${CLOSE_COLOR} ${BOLD_BLUE} SETUP FOR ${UNDERLINE_CYAN}BASH DOTFILES${CLOSE_COLOR}${CLOSE_COLOR} ${BOLD_YELLOW}<<${CLOSE_COLOR}\n" >> $temp_file
echo "${BOLD_BLUE}==============================${CLOSE_COLOR}\n" >> $temp_file
echo "Select one of the following terminals:" >> $temp_file
local menu_items=('Termite' 'Hyper')
interactive_menu "$temp_file" "0" "${menu_items[@]}"
case "$?" in
0) terminal_name="termite" ;;
1) terminal_name="hyper" ;;
esac
echo "${BOLD_YELLOW}>>${CLOSE_COLOR} ${BOLD_BLUE} SETUP FOR ${UNDERLINE_CYAN}BASH DOTFILES${CLOSE_COLOR}${CLOSE_COLOR} ${BOLD_YELLOW}<<${CLOSE_COLOR}\n" > $temp_file
echo "${BOLD_BLUE}==============================${CLOSE_COLOR}\n" >> $temp_file
echo "Select one of the following shells:" >> $temp_file
menu_items=('Bash' 'ZSH')
interactive_menu "$temp_file" "0" "${menu_items[@]}"
case "$?" in
0) shell_name="bash" ;;
1) shell_name="zsh" ;;
esac
rm $temp_file
}
function _apply_customization () {
case $terminal_name in
"termite") setexport TERMINAL /usr/bin/termite ;;
"hyper") setexport TERMINAL /usr/bin/hyper ;;
esac
case $shell_name in
"bash")
setexport SHELL /usr/bin/bash
setexport SHELL_NAME bash
setexport HISTFILE ~/.config/shell/.bash_history
;;
"zsh")
setexport SHELL /usr/bin/zsh
setexport SHELL_NAME zsh
setexport HISTFILE ~/.config/shell/.zhistory
;;
esac
}
(( $# < 0 || $# > 1 )) && _showerr "invalid number of parameters"
while (( $# > 0 )); do
case $1 in
"-q") silent_flag=1; shift ;;
"--quiet") silent_flag=1; shift ;;
*) _showerr "$1 is not a valid option" ;;
esac
done
[[ $PACKAGE_MANAGER =~ "unkown" ]] && no_deps_flag=1
if (( $silent_flag == 0 )); then
clear; sudo ls /root &>/dev/null; clear
_main_header
fi
_prepare_dotfiles
(( $silent_flag == 0 )) && _customization && clear && _main_header
if (( $silent_flag == 0 )); then
while true; do
read -p "Would you like to create a backup? (y/n): " yesno
if [[ $yesno = "y" ]]; then
echo -n ">> Creating the backup for old .files ... "
_backup_dotfiles &>/dev/null
echo "OK"; break
elif [[ $yesno = "n" ]]; then
break
fi
done
else
_backup_dotfiles &>/dev/null
fi
rm -rf ~/.config/neofetch/*
rm -rf ~/.config/termite/*
(( $silent_flag == 0 )) && echo -n ">> Moving and linking all the bash .files ... "
_install_dotfiles &>/dev/null
(( $silent_flag == 0 )) && echo "OK"
rm -rf ~/.bash_profile &>/dev/null
rm -rf ~/.bash_logout &>/dev/null
if (( $no_deps_flag == 0 )); then
_install_packages
_install_zsh_plugins
_install_vte_ng
_install_termite
fi
_apply_customization
unset _packages _zsh_plugins
unset terminal_name shell_name
unset no_deps_flag
if (( $silent_flag == 0 )); then
echo "Current shell would be reload..."
unset silent_flag
reload-bash
clear; reload-all-bash
fi
unset silent_flag