-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·257 lines (205 loc) · 6.09 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
#!/bin/bash
os=$(uname)
bad_echo() {
echo -e "# -> \033[0;31m$1\033[0m"
}
nice_echo() {
echo -e "# -> \033[0;36m$1\033[0m"
}
msg_header() {
echo "# --------------------------------------------------------"
nice_echo "[+] $1"
echo "# --------------------------------------------------------"
echo "#"
}
msg_footer() {
nice_echo "[+] Exit from $1()"
echo "#"
}
backup() {
backup=$HOME/backup/dotfiles
if [ ! -d $backup ]; then
mkdir -p $backup
fi
if [ -e "$HOME/$1" ]; then
now=`date +%Y%m%d_%s`
[ ! -L "$HOME/$1" ] && cp -fpR "$HOME/$1" "$backup/$1.$now";
fi
}
append() {
cat $1 >> $2
}
isExist() {
if which $1 >/dev/null 2>&1;then
nice_echo "[+] $1 exist"
return 0
else
bad_echo "[-] $1 not exist"
return 1
fi
}
install() {
isExist $1
if [ "$?" -ne 0 ]; then
nice_echo "[+] install $1..."
if [ $os == 'Darwin' ];then
brew install $1
elif [ $os == 'Linux' ];then
if which apt-get >/dev/null; then
sudo apt-get update
sudo apt-get install -y $1
else
bad_echo "[-] Sorry, please install $1 by yourself!"
fi
fi
fi
}
#==============================================================================#
#==============================================================================#
# backup & link dot files
backup_copy() {
msg_header "Update config files"
backup .vimrc
backup .zshrc
backup .gitconfig
backup .tmux.conf
backup .ycm_extra_conf.py
cp -rf $(pwd)/vim/basic.vimrc $HOME/.vimrc
#cp -rf $(pwd)/configs/zshrc $HOME/.zshrc
cp -rf $(pwd)/configs/gitconfig $HOME/.gitconfig
cp -rf $(pwd)/configs/tmux.conf $HOME/.tmux.conf
cp -rf $(pwd)/configs/agignore $HOME/.agignore
if [ $os == 'Linux' ];then
backup .bashrc
cp -rf $(pwd)/configs/bashrc $HOME/.bashrc
elif [ $os == 'Darwin' ];then
backup .bash_profile
cp -rf $(pwd)/configs/bashrc $HOME/.bash_profile
fi
if [ ! -d $HOME/.vim/skeleton ]; then
mkdir -p $HOME/.vim/skeleton
fi
cp -rf $(pwd)/vim/skeleton/* $HOME/.vim/skeleton/
msg_footer backup_copy
}
requirement() {
msg_header "Install some requirements"
if [ $os == 'Darwin' ];then
isExist brew
if [ "$?" -ne 0 ]; then
nice_echo "[+] Downloading brew first ..."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
brew install git git-gui wget proxychains-ng cmake ranger screenfetch the_silver_searcher
elif [ $os == 'Linux' ];then
if which apt-get >/dev/null; then
sudo apt-get remove -y vim-common
sudo apt update
sudo apt-get install -y vim
sudo apt-get install -y git gitk wget curl
sudo apt-get install -y build-essential cmake
sudo apt-get install -y python-dev python3-dev python-setuptools python3-setuptools python-pip python3-pip ppa-purge
sudo apt-get install -y tree proxychains ranger screenfetch silversearcher-ag
else
bad_echo "[-] Sorry, please install some packages by yourself!"
fi
fi
msg_footer requirement
}
vim() {
msg_header "Install some tools about vim"
cp -rf $(pwd)/vim/ycm_extra_conf.py $HOME/.vim/.ycm_extra_conf.py
# Vundle
if [ ! -d $HOME/.vim/bundle ];then
nice_echo "[+] Downloading bundle..."
git clone https://github.com/VundleVim/Vundle.vim.git $HOME/.vim/bundle/Vundle.vim
fi
# Powerline fonts
if [ ! -d $HOME/.vim/fonts ];then
nice_echo "[+] Downloading essential fonts..."
git clone https://github.com/powerline/fonts.git $HOME/.vim/fonts
$HOME/.vim/fonts/install.sh
fi
# ctags
install ctags
# cscope
install cscope
msg_footer vim
}
zsh() {
msg_header "Install some tools about zsh"
# oh-my-zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# autojump
install autojump
msg_footer zsh
}
tmux() {
msg_header "Install some tools about Tmux"
# tmux
install tmux
msg_footer tmux
}
web() {
msg_header "Install some tools about web"
if [ $os == 'Darwin' ];then
# yarn
curl -o- -L https://yarnpkg.com/install.sh | bash
elif [ $os == 'Linux' ];then
# yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install --no-install-recommends yarn
# nvm & nodejs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
bad_echo "[-] Please manual install nodejs use: nvm install --lts!"
fi
msg_footer web
}
spacemacs() {
mv $HOME/.emacs.d $HOME/.emacs.d.bak
mv $HOME/.emacs $HOME/.emacs.bak
git clone https://github.com/syl20bnr/spacemacs $HOME/.emacs.d
msg_footer spacemacs
}
setEnv() {
msg_header "Set some environment variables"
if [ ! -d $HOME/bin ]; then
mkdir $HOME/bin
fi
cp -f $(pwd)/configs/emacs_alias.sh $HOME/bin/
if [ $os == 'Linux' ];then
#append $(pwd)/configs/env_for_linux >> $HOME/.zshrc
append $(pwd)/configs/env_for_linux $HOME/.bashrc
elif [ $os == 'Darwin' ];then
#append $(pwd)/configs/env_for_mac $HOME/.zshrc
append $(pwd)/configs/env_for_mac $HOME/.bash_profile
fi
msg_footer "setEnv"
}
main() {
option=$1
backup_copy
setEnv
if [ "$option" == "init" ]; then
requirement
vim
zsh
tmux
#web
fi
if [ "$option" == "web" ]; then
web
fi
nice_echo "[+] Install Success !"
echo "# --------------------------------------------------------"
}
#==============================================================================#
#==============================================================================#
# main
if [ $# != 1 ]; then
echo "Usage:"
echo "./install init|config|web"
exit -1
fi
main $1