-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
executable file
·297 lines (236 loc) · 5.31 KB
/
setup.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
#!/usr/bin/env bash
# author: cnsworder
# email: [email protected]
# date: 2014-02-14
# version: 1.1
BASE_DIR= $(cd $(dirname ${BASH_SOURCE[0]})) && pwd
ln -s ${BASE_DIR} ~/.config/dev_init
source package.sh
INIT_VIM=false
INIT_EMACS=false
INIT_PACKAGE=false
INIT_XPACKAGE=false
INIT_PYTHON=false
function pre_package() {
if [ -x /usr/bin/pacman ];then
PM=${PM:=pacman}
PM_INSTALL=-S
OS=arch
PM_UPDATE=-Syu
elif [ -x /usr/bin/apt-get ];then
PM=apt-get
PM_INSTALL=install
PM_UPDATE=upgrade
OS=debian
# yes | apt-get update
elif [ -x /usr/bin/yum ]; then
PM=yum
PM_INSTALL=install
PM_UPDATE=update
OS=redhat
elif [ -x /usr/bin/emerge ]; then
PM=emerge
PM_INSTALL=
PM_UPDATE=world
OS=gentoo
elif which brew; then
PM=brew
PM_INSTALL=install
PM_UPDATE=update
OS="Mac OS X"
fi
echo "OS: $OS"
echo "Package Manager: $PM"
}
function update_package() {
yes | ${PM} ${PM_UPDATE}
}
pre_package
HAVE_REAL_PATH=true
if ! which realpath > /dev/null ; then
echo "${PM} ${PM_INSTALL} realpath"
yes | ${PM} ${PM_INSTALL} realpath
if (( $? != 0 )); then
HAVE_REAL_PATh=false
fi
fi
if ${HAVE_REAL_PATH} ; then
THIS_PATH=$(realpath .)
else
THIS_PATH=`pwd`
fi
IS_ROOT=$(id -u)
function init_package() {
echo "Installing packages..."
if [[ "${IS_ROOT}" != "0" ]]; then
return
fi
update_package
yes | ${PM} ${PM_INSTALL} ${PACKAGES}
}
function init_dev() {
if [[ "${IS_ROOT}" != "0" ]]; then
return
fi
update_package
yes | ${PM} ${PM_INSTALL} ${DEV_PACKAGES}
}
function init_xpackage() {
if [[ $# == 1 ]]; then
if [[ "$1" == "gui" ]]; then
echo "Install X Appliaction..."
yes | ${PM} ${PM_INSTALL} ${XPACKAGES}
ln -s ${THIS_PATH}/config/awesome/rc.lua ~/.config/rc.lua
fi
fi
}
function init_vim() {
echo "Configing vim..."
if ! which vim > /dev/null; then
if [[ "${IS_ROOT}" != "0" ]]; then
return
fi
yes | ${PM} ${PM_INSTALL} vim
fi
cd crossvim && ./setup.sh
cd -
}
function init_emacs() {
echo "Configing emacs..."
if ! which emacs > /dev/null; then
if [[ "${IS_ROOT}" != "0" ]]; then
return
fi
yes | ${PM} ${PM_INSTALL} emacs
fi
cd crossemacs && ./setup.sh
cd -
}
function init_python() {
# python
echo "Update python environment..."
if ! which ${PIP} > /dev/null; then
if [[ "${IS_ROOT}" != "0" ]]; then
return
fi
yes | ${PM} ${PM_INSTALL} python-${PIP}
fi
if [ ! -d ~/.pip ]; then
mkdir ~/.pip
elif [ -e ~/.pip/pip.conf ]; then
mv ~/.pip/pip.conf ~/.pip/pip.conf.old
fi
if [[ "${IS_ROOT}" != "0" ]]; then
return
fi
ln -s ${THIS_PATH}/pip/pip.conf ~/.pip/pip.conf
${PIP} install ${PYTHON_PACKAGES}
}
function init_shell() {
echo "Configing Shell, set zsh to default shell..."
if ! which zsh > /dev/null; then
if [[ "${IS_ROOT}" != "0" ]]; then
return
fi
yes | ${PM} ${PM_INSTALL} zsh
fi
# git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
# cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
chsh `which zsh`
cd crossh && ./install.sh
ln -s Xdefaults ~/.Xdefaults
}
function init_sshd() {
echo "Configure ssh server..."
if [[ "${IS_ROOT}" != "0" ]]; then
return
fi
cat << EOF >> /etc/ssh/sshd_conf
UseDNS no
GatewayPorts yes
TCPKeepAlive yes
ClientAliveInterval 60
ClientAliveCountMax 99999
EOF
systemctl restart sshd || service ssh restart
}
function init_ssh() {
echo "Configure ssh ..."
echo "ServerAliveInterval 60" >> ~/.ssh/config
}
function proc() {
echo "Begin Configure..."
if [[ "${INIT_VIM}" == "true" ]]; then
init_vim
fi
if [[ "${INIT_EMACS}" == "true" ]]; then
init_emacs
fi
if [[ "${INIT_PACKAGE}" == "true" ]]; then
init_package
fi
if [[ "${INIT_XPACKAGE}" == "true" ]]; then
init_xpackage
fi
if [[ "${INIT_PYTHON}" == "true" ]]; then
init_python
fi
if [[ "${INIT_SHELL}" == "true" ]]; then
init_shell
fi
echo "Init finish..."
}
function main() {
echo "#####################################"
proc
echo "#####################################"
}
while getopts "vepkxsthda" arg
do
case ${arg} in
v)
INIT_VIM=true
;;
e)
INIT_EMACS=true
;;
p)
INIT_PYTHON=true
;;
k)
INIT_PACKAGE=true
;;
x)
INIT_XPACKAGE=true
;;
s)
INIT_SHELL=true
;;
t)
INIT_SSH=true
init_ssh
;;
h)
INIT_SSHD=true
init_sshd
;;
d)
INIT_DEV=true
init_dev
;;
a)
echo "all will configure..."
INIT_VIM=true
INIT_EMACS=true
INIT_PYTHON=true
INIT_PACKAGE=true
INIT_XPACKAGE=true
INIT_SHELL=false
;;
?)
echo "Unkow option..."
exit -1
;;
esac
done
main