/
install.sh
executable file
·222 lines (190 loc) · 5.94 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
#!/bin/bash
#History:
# Michael Aug,13,2016
#Program:
#
function need_root() {
if [ $UID != 0 ];then
echo "You must run this script as root"
exit 0
fi
}
function install_supervisor() {
need_root
if [[ -x $(which supervisord) ]];then
return 0
fi
SYSTEMD_FILE="/etc/systemd/system/supervisord.service"
CONFIG_DIR="/etc/supervisor"
LOG_DIR="/var/log/supervisord/"
if [[ ! -x $(which pip) ]];then
apt-get -y install python-pip
fi
if [[ ! -x $(which supervisord) ]];then
pip install supervisor
fi
WHEEL=`dpkg -l | grep 'python-wheel'`
if [ "${WHEEL}" == '' ];then
apt-get -y install python-wheel
fi
SETUPTOOLS=`dpkg -l | grep 'python-setuptools'`
if [ "${SETUPTOOLS}" == '' ];then
apt-get -y install python-setuptools
fi
if [[ -e ${SYSTEMD_FILE} ]];then
mv ${SYSTEMD_FILE} /tmp/
echo "Move the original ${SYSTEMD_FILE} to the /tmp"
fi
cp ./Supervisor/supervisord.service ${SYSTEMD_FILE}
chmod a+x ${SYSTEMD_FILE}
echo "Copy the ${SYSTEMD_FILE}"
systemctl daemon-reload
systemctl enable supervisord
if [ ! -d ${CONFIG_DIR} ];then
cp -r ./Supervisor/supervisor /etc/
else
if [ -d "/tmp/supervisor/" ];then
rm -rf /tmp/supervisor
echo "Delete the /tmp/supervisor"
fi
mv ${CONFIG_DIR} /tmp/
echo "Move the original ${CONFIG_DIR} to the /tmp"
cp -r ./Supervisor/supervisor /etc/
fi
echo "Copy the ${CONFIG_DIR}"
if [ ! -d ${LOG_DIR} ];then
mkdir ${LOG_DIR}
fi
echo "Please run the |sudo systemctl start supervisord| to start the Supervisor"
return $?
}
function install_shadowsocks() {
need_root
# install the supervisor
install_supervisor
# create the shadowsocks user
SHADOWSOCKS_USER=`awk 'BEGIN{FS=":"}{print $1}' /etc/passwd | egrep '^shadowsocks$'`
if [ "${SHADOWSOCKS_USER}" == '' ];then
SHADOWSOCKS_USER='shadowsocks'
useradd ${SHADOWSOCKS_USER}
echo "Create the user ${SHADOWSOCKS_USER}"
fi
# make log dir
LOG_DIR="/var/log/shadowsocks/"
if [ ! -d ${LOG_DIR} ];then
mkdir -p ${LOG_DIR}
chown shadowsocks:shadowsocks ${LOG_DIR}
echo "Make the dir ${LOG_DIR}"
fi
# install shadowsocks
if [[ ! -x $(which ssserver) ]];then
pip install shadowsocks
echo "Install the shadowsocks"
fi
if [ "$#" == 1 -a "$1" == 'client' ];then
# install shadowsocks client
if [[ ! -x $(which sslocal) ]];then
pip install shadowsocks
fi
# config the sslocal
cp ./ShadowSocks/shadowsocks.json /etc/shadowsocks.json
echo "Copy the shadowsock client configure file"
ln -s /etc/supervisor/tasks-available/sslocal.ini /etc/supervisor/tasks-enabled/
echo "Link the Shadowsocks client supervisor configure file"
echo "Shadowsocks client already installed, Please change the configure file" && exit 0
fi
# config the shadowsocks
ln -s /etc/supervisor/tasks-available/shadowsocks.ini /etc/supervisor/tasks-enabled/
echo "Link the shadowsocks configure file"
CONFIG_FILE="/etc/shadowsocks_server.json"
if [ -e ${CONFIG_FILE} ];then
mv ${CONFIG_FILE} /tmp
echo "Move the original ${CONFIG_FILE} to the /tmp"
fi
cp ./ShadowSocks/shadowsocks_server.json ${CONFIG_FILE}
chmod 644 ${CONFIG_FILE}
# change the password
echo "Please change the password in the ${CONFIG_FILE} and restart the shadowsocks"
}
function install_git() {
need_root
if [[ ! -x $(which git) ]];then
apt-get -y install git
fi
if [[ -e "/etc/gitconfig" ]];then
mv "/etc/gitconfig" "/etc/gitconfig.bak"
fi
ln -s "$(pwd)/Git/gitconfig" /etc/gitconfig
}
function install_blog() {
need_root
install_supervisor
REPO_DIR="/var/www/blog"
if [[ ! -d ${REPO_DIR} ]];then
git clone -b master https://github.com/bwangel23/bwangel23.github.io.git ${REPO_DIR}
else
git -C ${REPO_DIR} pull origin master
fi
systemctl restart supervisord.service
AVALIABLE_FILE="/etc/nginx/sites-available/blog.conf"
ENABLE_FILE="/etc/nginx/sites-enabled/blog.conf"
if [[ ! -x $(which nginx) ]];then
sudo apt-get -y install nginx
fi
if [[ -e "${ENABLE_FILE}" ]];then
rm ${ENABLE_FILE} && echo "Delete the ${ENABLE_FILE}"
fi
if [[ -e "${AVALIABLE_FILE}" ]];then
rm ${AVALIABLE_FILE} && echo "Delete the ${AVALIABLE_FILE}"
fi
cp "$(pwd)/Blog/blog.conf" ${AVALIABLE_FILE}
ln -s ${AVALIABLE_FILE} ${ENABLE_FILE}
nginx -s reload 2> /dev/null || nginx
}
function install_docker () {
if [[ ! -d "$HOME/.docker" ]];then
mkdir $HOME/.docker
fi
cp -v "$(pwd)/docker/config.json" $HOME/.docker/
}
function install_bin () {
if [[ ! -d "$HOME/bin" ]];then
mkdir $HOME/bin
fi
for file in $(pwd)/bin/*; do
filename=$(basename $file)
if [[ ! -h "$HOME/bin/${filename}" ]];then
ln -s $(pwd)/bin/${filename} $HOME/bin/
echo "Link the $(pwd)/bin/${filename} to the $HOME/bin/${filename}"
fi
done
}
case "$1" in
supervisor)
install_supervisor && exit 0
echo "supervisor install failed"
;;
shadowsocks)
install_shadowsocks && exit 0
echo "shadowsocks install failed"
;;
shadowsocks-client)
install_shadowsocks "client" && exit 0
echo "shadowsocks client install failed"
;;
git)
install_git && echo "Link the gitconfig"
;;
blog)
install_blog && echo "Install the hexo blog"
;;
docker)
install_docker && echo "Install the docker config file"
;;
bin)
install_bin && echo "Install the custom command"
;;
*)
echo "Usage: $0 {supervisor|shadowsocks|shadowsocks-client|git|blog|docker|bin}"
;;
esac