-
Notifications
You must be signed in to change notification settings - Fork 11
/
install.sh
executable file
·282 lines (247 loc) · 6.04 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
#!/bin/bash
# print colored text
print_style () {
if [ "$2" == "info" ] ; then COLOR="96m";
elif [ "$2" == "succ" ] ; then COLOR="92m";
elif [ "$2" == "warn" ] ; then COLOR="95m";
elif [ "$2" == "error" ] ; then COLOR="91m";
else COLOR="0m"; #default color
fi
STARTCOLOR="\e[$COLOR";
ENDCOLOR="\e[0m";
printf "$STARTCOLOR%b$ENDCOLOR" "$1";
}
info () {
print_style "$1" "info"
}
succ () {
print_style "$1" "succ"
}
warn () {
print_style "$1" "warn"
}
error () {
print_style "$1" "error"
}
normal () {
print_style "$1" "-"
}
die () {
error "$1" ; exit 1
}
logo () {
warn '======================================\n'
warn ' _____ _ _ _ \n'
warn ' |___ | |_| |__ __ _(_)_ __ ___ \n'
warn ' / /| __| `_ \ \ \ / / | `_ ` _ \ \n'
warn ' / / | |_| | | | \ V /| | | | | | |\n'
warn ' /_/ \__|_| |_| \_/ |_|_| |_| |_|\n'
warn '======================================\n'
}
help () {
logo
echo
echo 'Usage: install.sh <Options>'
echo
echo 'Options:'
echo ' -i -- install'
echo ' -u -- update'
echo ' -b -- remove config files and backup'
echo ' -c -- check dependencies'
echo ' -l -- show the list of supported languages'
echo ' -h -- show help'
echo
exit 0
}
language_support_info () {
info '-------------------------------------------------------------------\n'
info 'Edit ' ; succ '~/.vimrc.language' ; info ' to enable/disable language support you need.\n'
info 'Supported languages:\n'
normal ' - markdown\n'
normal ' - html\n'
normal ' - css\n'
normal ' - js\n'
normal ' - json\n'
normal ' - php\n'
normal ' - python\n'
#normal ' - c/c++\n'
normal ' - go\n'
info '-------------------------------------------------------------------\n'
}
# check dependent
check () {
E=0
info '>> Checking Git ...'
if which git > /dev/null ; then
succ '\t OK!\n'
else
E=1
error '\t NO!\n'
how_to git
fi
info '>> Checking Python ...'
if which python3 > /dev/null ; then
succ '\t OK!\n'
else
E=1
error '\t NO!\n'
how_to python
fi
info '>> Checking cmake ...'
if which cmake > /dev/null ; then
succ '\t OK!\n'
else
E=1
error '\t NO!\n'
how_to cmake
fi
if [ $E -ne 0 ] ; then
warn '>>> The 7th-Vim '
die 'install failed!\n'
fi
}
how_to () {
if [ $1 == git ] ; then
warn 'How to install Git:\n'
info '- for macOS, refer to the following url:\n'
normal 'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git\n'
info '- for Ubuntu\n'
info '$ ' ; normal 'sudo apt-get install -y git-all\n'
info '- for CentOS\n'
info '$ ' ; normal 'sudo yum install -y git-all\n'
elif [ $1 == python ] ; then
warn 'How to install Python:\n'
info '- for macOS\n'
info '$ ' ; normal 'brew install python\n'
info '- for Ubuntu\n'
info '$ ' ; normal 'sudo apt-get install -y python-dev python3-dev\n'
info '- for CentOS\n'
info '$ ' ; normal 'sudo yum install -y python-devel python3-devel\n'
elif [ $1 == cmake ] ; then
warn 'How to install cmake:\n'
info '- for macOS\n'
info '$ ' ; normal 'brew install gcc cmake\n'
info '- for Ubuntu\n'
info '$ ' ; normal 'sudo apt-get install -y cmake\n'
info '- for CentOS\n'
info '$ ' ; normal 'sudo yum install -y automake gcc gcc-c++ cmake\n'
fi
}
create_undo_dir () {
mkdir -p ~/.vim/.undodir
}
install_backup () {
# remove and backup old files
info '>>> Remove and backup old files ...\n'
mkdir -p ~/7th-vim-bak
mv ~/.vimrc ~/7th-vim-bak
mv ~/.vimrc.local ~/7th-vim-bak
mv ~/.vimrc.plugins ~/7th-vim-bak
mv ~/.vimrc.language ~/7th-vim-bak
}
update_backup () {
# remove and backup old files
info '>>> Remove and backup old files ...\n'
mkdir -p ~/7th-vim-bak
mv ~/.vimrc ~/7th-vim-bak
}
load_vimrc () {
# download .vimrc file
info '>>> Download .vimrc file ...\n'
curl -fLo ~/.vimrc \
https://raw.githubusercontent.com/dofy/7th-vim/master/vimrc
# download .vimrc.language file
if [ ! -f ~/.vimrc.language ] ; then
info '>>> Download .vimrc.language file ...\n'
curl -fLo ~/.vimrc.language \
https://raw.githubusercontent.com/dofy/7th-vim/master/vimrc.language
fi
# download .vimrc.plugins file
if [ ! -f ~/.vimrc.plugins ] ; then
info '>>> Download .vimrc.plugins file ...\n'
curl -fLo ~/.vimrc.plugins \
https://raw.githubusercontent.com/dofy/7th-vim/master/vimrc.plugins
fi
# download .vimrc.local file
if [ ! -f ~/.vimrc.local ] ; then
info '>>> Download .vimrc.local file ...\n'
curl -fLo ~/.vimrc.local \
https://raw.githubusercontent.com/dofy/7th-vim/master/vimrc.local
fi
}
append_settings () {
# append settings
curl -f \
https://raw.githubusercontent.com/dofy/7th-vim/master/vimrc.append \
>> ~/.vimrc
}
install_plugin () {
# download vim-plug
info '>>> Download vim-plug ...\n'
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# install plugins
info '>>> Install plugins ...\n'
vim +PlugClean! +PlugUpdate +qal
}
update_plugin () {
# update plugins
info '>>> Update plugins ...\n'
vim +PlugClean! +PlugUpdate +qal
}
install_ycm () {
info '>>> Install YouCompleteMe ...\n'
~/.vim/bundle/YouCompleteMe/install.py --all
}
run_install () {
logo
succ '>>> Thanks for Installing The 7th-Vim\n'
check
create_undo_dir
install_backup
load_vimrc
install_plugin
install_ycm
append_settings
language_support_info
succ '>>> DONE!\n\n'
}
run_update () {
logo
succ '>>> Thanks for Updating The 7th-Vim\n'
create_undo_dir
update_backup
load_vimrc
append_settings
update_plugin
language_support_info
succ '>>> DONE!\n\n'
}
run_backup () {
install_backup
succ '>>> DONE!\n\n'
}
if [ $# -ne 1 ]; then
help
fi
while getopts ":iubcl" opts; do
case $opts in
i)
run_install;;
u)
run_update;;
b)
logo
run_backup;;
c)
logo
check;;
l)
logo
language_support_info;;
:)
help;;
?)
help;;
esac
done