forked from rubyangxg/jd-qinglong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
476 lines (441 loc) · 14.8 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#!/usr/bin/env bash
stty erase ^H
PORT=0
#判断当前端口是否被占用,没被占用返回0,反之1
function Listening() {
TCPListeningnum=$(netstat -an | grep ":$1 " | awk '$1 == "tcp" && $NF == "LISTEN" {print $0}' | wc -l)
UDPListeningnum=$(netstat -an | grep ":$1 " | awk '$1 == "udp" && $NF == "0.0.0.0:*" {print $0}' | wc -l)
((Listeningnum = TCPListeningnum + UDPListeningnum))
if [ $Listeningnum == 0 ]; then
echo "0"
else
echo "1"
fi
}
case $(uname -m) in
x86_64) is_x86=1 ;;
aarch64) is_x86=0 ;;
esac
synology=0
if [[ $(uname -a) == *synology* ]]; then
synology=1
fi
#指定区间随机数
function random_range() {
shuf -i $1-$2 -n1
}
#得到随机端口
function get_random_port() {
templ=0
while [ $PORT == 0 ]; do
temp1=$(random_range $1 $2)
if [ $(Listening $temp1) == 0 ]; then
PORT=$temp1
fi
done
echo "port=$PORT"
}
TIME() {
[[ -z "$1" ]] && {
echo -ne " "
} || {
case $1 in
r) export Color="\e[31;1m" ;;
g) export Color="\e[32;1m" ;;
b) export Color="\e[34;1m" ;;
y) export Color="\e[33;1m" ;;
z) export Color="\e[35;1m" ;;
l) export Color="\e[36;1m" ;;
esac
[[ $# -lt 2 ]] && echo -e "\e[36m\e[0m ${1}" || {
echo -e "\e[36m\e[0m ${Color}${2}\e[0m"
}
}
}
[[ ! "$USER" == "root" ]] && {
echo
TIME y "警告:请使用root用户操作!~~"
echo
exit 1
}
if [[ $synology == 1 ]]; then
echo
TIME y "你是群晖nas"
echo
elif [[ "$(. /etc/os-release && echo "$ID")" == "centos" ]]; then
export Aptget="yum"
yum -y update
yum install -y sudo wget curl psmisc net-tools
export XITONG="cent_os"
elif [[ "$(. /etc/os-release && echo "$ID")" == "ubuntu" ]]; then
export Aptget="apt-get"
apt-get -y update
apt-get install -y sudo wget curl psmisc net-tools
export XITONG="ubuntu_os"
elif [[ "$(. /etc/os-release && echo "$ID")" == "debian" || "$(. /etc/os-release && echo "$ID")" == "Deepin" ]]; then
export Aptget="apt"
apt-get -y update
apt-get install -y sudo wget curl psmisc net-tools
export XITONG="debian_os"
else
echo
TIME y "本一键安装docker脚本只支持(centos、ubuntu和debian)!"
echo
exit 1
fi
ignore_install_docker=0
if [[ $(docker --version | grep -c "version") -ge '1' ]]; then
echo
if [[ $synology == 1 ]]; then
TIME y "已安装docker,进行下一步"
ignore_install_docker=1
else
TIME y "检测到docker存在,是否重新安装?"
echo
TIME g "重新安装会把您现有的所有容器及镜像全部删除,请慎重!"
echo
while :; do
read -p " [输入[ N/n ]回车跳过安装docker,输入[ Y/y ]回车重新安装docker]: " ANDK
case $ANDK in
[Yy])
TIME g "正在御载老版本docker"
export CHONGXIN="YES"
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)
sudo "${Aptget}" remove -y docker docker-engine docker.io containerd runc
sudo "${Aptget}" remove -y docker
sudo "${Aptget}" remove -y docker-ce
sudo "${Aptget}" remove -y docker-ce-cli
sudo "${Aptget}" remove -y docker-ce-rootless-extras
sudo "${Aptget}" remove -y docker-scan-plugin
sudo "${Aptget}" remove -y --auto-remove docker
sudo rm -rf /var/lib/docker
sudo rm -rf /etc/docker
sudo rm -rf /lib/systemd/system/{docker.service,docker.socket}
rm /var/lib/dpkg/info/$nomdupaquet* -f
break
;;
[Nn])
echo
TIME r "跳过安装docker!"
echo
sleep 1
ignore_install_docker=1
break
;;
*)
echo
TIME b "提示:请输入正确的选择!"
echo
;;
esac
done
fi
fi
if [ $ignore_install_docker == 0 ]; then
echo
TIME y "正在安装docker,请耐心等候..."
echo
if [[ ${XITONG} == "cent_os" ]]; then
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum -y update
sudo yum install -y docker-ce
sudo yum install -y docker-ce-cli
sudo yum install -y containerd.io
fi
if [[ ${XITONG} == "ubuntu_os" ]]; then
if [ $is_x86 == 1 ]; then
sudo apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
if [[ $? -ne 0 ]]; then
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
fi
sudo apt-key fingerprint 0EBFCD88
if [[ $(sudo apt-key fingerprint 0EBFCD88 | grep -c "0EBF CD88") == '0' ]]; then
TIME r "密匙验证出错,或者没下载到密匙了,请检查网络,或者源有问题"
sleep 5
exit 1
sleep 5
fi
sudo add-apt-repository -y "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce
sudo apt-get install -y docker-ce-cli
sudo apt-get install -y containerd.io
else
sudo apt-get update
sudo apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg -f --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
fi
fi
if [[ ${XITONG} == "debian_os" ]]; then
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add -
if [[ $? -ne 0 ]]; then
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add -
fi
sudo apt-key fingerprint 0EBFCD88
if [[ $(sudo apt-key fingerprint 0EBFCD88 | grep -c "0EBF CD88") == '0' ]]; then
TIME r "密匙验证出错,或者没下载到密匙了,请检查网络,或者上游有问题"
sleep 5
exit 1
sleep 5
fi
sudo add-apt-repository -y "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce
sudo apt-get install -y docker-ce-cli
sudo apt-get install -y containerd.io
fi
sudo rm -fr /etc/systemd/system/docker.service.d
sed -i 's#ExecStart=/usr/bin/dockerd -H fd://#ExecStart=/usr/bin/dockerd#g' /lib/systemd/system/docker.service
sudo systemctl daemon-reload
sudo rm -fr docker.sh
if [[ $(docker --version | grep -c "version") == '0' ]]; then
TIME y "docker安装失败"
sleep 2
exit 1
else
# 1.创建一个目录
sudo mkdir -p /etc/docker
# 2.编写配置文件
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.ccs.tencentyun.com"
]
}
EOF
TIME y ""
TIME g "docker安装成功,正在启动docker,请稍后..."
sudo systemctl restart docker
sudo systemctl start docker
sudo systemctl enable docker.service
sleep 12
TIME y ""
TIME g "测试docker拉取镜像是否成功"
TIME y ""
sudo docker run hello-world | tee build.log
if [[ $(docker ps -a | grep -c "hello-world") -ge '1' ]] && [[ $(grep -c "docs.docker" build.log) -ge '1' ]]; then
echo
TIME g "测试镜像拉取成功,正在删除测试镜像..."
echo
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)
echo
TIME y "测试镜像删除完毕,docker安装成功!"
echo
else
echo
TIME y "docker虽然安装成功但是拉取镜像失败,这个原因很多是因为以前的docker没御载完全造成的,或者容器网络问题"
echo
TIME y "重启服务器后,用 sudo docker run hello-world 命令测试吧,能拉取成功就成了"
echo
sleep 2
exit 1
fi
fi
rm -fr build.log
fi
dir='jd-qinglong'
TIME y "请指定保存数据的目录,已存在的请指定名字,回车默认jd-qinglong"
read input
if [ -z "${input}" ]; then
input=$dir
fi
dir=$input
if [ ! -d $dir ]; then
mkdir $dir
fi
cd $dir || exit
rm -f adbot/adbot
file=env.properties
if [ ! -f "$file" ]; then
wget -O env.properties https://ghproxy.com/https://raw.githubusercontent.com/rubyangxg/jd-qinglong/master/env.template.properties
else
echo "env.properties已存在"
fi
sudo docker rm -f webapp
if [ $is_x86 == 1 ]; then
sudo docker pull rubyangxg/jd-qinglong
else
sudo docker pull rubyangxg/jd-qinglong:arm
fi
ad_port1=5701
TIME y "请设置阿东网页登录端口:(数字80~65535),回车默认5701"
while [ 1 ]; do
read input
if [ -z "${input}" ]; then
input=5701
fi
if [ $input -gt 79 -a $input -lt 65536 ]; then
grep_port=$(netstat -tlpn | grep "\b$input\b")
if [ -n "$grep_port" ]; then
get_random_port 5701 5800
ad_port1=$PORT
echo -e "端口 $input 已被占用,生成随机端口$ad_port1,配置成功\n"
else
echo -e "端口 $input 未被使用,配置成功\n"
ad_port1=$input
fi
break
else
TIME r "别瞎搞,请输入端口:(数字80~65535)"
fi
done
ad_port2=9527
grep_port=$(netstat -tlpn | grep "\b$ad_port2\b")
if [ -n "$grep_port" ]; then
get_random_port 9527 9600
ad_port2=$PORT
TIME -e "端口 9527 已被占用,生成随机端口$ad_port2,配置成功\n"
fi
#echo "请设置阿东网页管理(内部使用)端口:(数字5702~65535),回车默认5702"
#while [ 1 ]; do
# read input
# if [ -z "${input}" ]; then
# input=5702
# fi
# if [ $input -gt 5701 -a $input -lt 65536 ]; then
# grep_port=$(netstat -tlpn | grep "\b$input\b")
# if [ -n "$grep_port" ]; then
# get_random_port 5702 5800
# ad_port2=$PORT
# echo -e "端口 $input 已被占用,生成随机端口$ad_port2,配置成功\n"
# else
# echo -e "端口 $input 未被使用,配置成功\n"
# ad_port2=$input
# fi
# break
# else
# echo "别瞎搞,请输入端口:(数字5702~65535)"
# fi
#done
adbotDir="$(pwd)"/adbot
if [ $synology == 1 ]; then
if [ ! -d $adbotDir ]; then
mkdir $adbotDir
fi
fi
if [ $is_x86 == 1 ]; then
docker run -d -p $ad_port1:8080 -p $ad_port2:8090 --name=webapp -e TZ=Asia/Shanghai --privileged=true -v "$(pwd)"/env.properties:/env.properties:rw -v "$(pwd)"/adbot:/adbot --restart always rubyangxg/jd-qinglong
else
docker run -d -p $ad_port1:8080 -p $ad_port2:8090 --name=webapp -e TZ=Asia/Shanghai -e "SPRING_PROFILES_ACTIVE=arm" --privileged=true -v "$(pwd)"/env.properties:/env.properties:rw -v "$(pwd)"/adbot:/adbot --restart always rubyangxg/jd-qinglong:arm
fi
while [ 1 ]; do
if [ -f "./adbot/adbot" ]; then
sleep 1s
echo "阿东启动成功"
break
else
echo "等待阿东启动完成,生成必要文件"
sleep 1s
fi
done
json='{"server_groups":[{"name":"webapp","disabled":false,"json":false,"urls":["ws://localhost:'$ad_port1'/ws/cq/"],"event_filter":[],"regex_filter":"","regex_replace":"","extra_header":{"User-Agent":["GMC"]}},{"name":"webapp_admin","disabled":false,"json":false,"urls":["ws://localhost:'$ad_port2'/ws/cq/"],"event_filter":[],"regex_filter":"","regex_replace":"","extra_header":{"User-Agent":["GMC"]}}]}'
echo $json >./adbot/gmc_config.json
cd adbot || exit
chmod +x adbot
echo "请创建一个机器人管理页面用户名:(字母数字下划线),回车默认admin"
while [ 1 ]; do
read input
if [ -z "${input}" ]; then
input="admin"
fi
if [[ $input =~ ^[A-Za-z0-9_]+$ ]]; then
username=$input
break
else
echo "别瞎搞,请输入用户名:(字母数字下划线),回车默认随机字符"
fi
done
echo "请设置机器人管理页面密码:(字母数字下划线),回车默认adbotadmin"
while [ 1 ]; do
read input
if [ -z "${input}" ]; then
input="adbotadmin"
fi
if [[ $input =~ ^[A-Za-z0-9_]+$ ]]; then
password=$input
break
else
echo "别瞎搞,请输入密码:(字母数字下划线),回车默认随机字符"
fi
done
killall adbot
port=8100
echo "请设置机器人管理页面登录端口:(数字80~65535),回车默认8100"
while [ 1 ]; do
read input
if [ -z "${input}" ]; then
input=8100
fi
if [ $input -gt 79 -a $input -lt 65536 ]; then
grep_port=$(netstat -tlpn | grep "\b$input\b")
if [ -n "$grep_port" ]; then
get_random_port 8100 8200
port=$PORT
echo -e "端口 $input 已被占用,生成随机端口$port,配置成功\n"
else
echo -e "端口 $input 未被使用,配置成功\n"
port=$input
fi
break
else
echo "别瞎搞,请输入端口:(数字80~65535)"
fi
done
echo "机器人管理页面用户名是$username"
echo "机器人管理页面密码是$password"
echo "机器人管理页面端口是$port"
echo "阿东网页登录端口$ad_port1"
sed -i "s#^username=.*#username=$username#g" ./start-adbot.sh
sed -i "s#^password=.*#password=$password#g" ./start-adbot.sh
sed -i "s#^port=.*#port=$port#g" ./start-adbot.sh
chmod +x ./start-adbot.sh
bash ./start-adbot.sh restart
hasError1=1
for i in {1..10}; do
urlstatus=$(curl -s -m 5 -IL http://localhost:$ad_port1/ping | grep 200)
if [ "$urlstatus" == "" ]; then
echo "检查是否可访问阿东页面...第 $i 次(共10次),如果机器太慢可能会检查超时,请自行确认服务正常。"
sleep 5s
else
hasError1=0
break
fi
done
hasError2=1
for i in {1..10}; do
urlstatus=$(curl -u $username:$password -s -m 5 -IL http://localhost:$port | grep 200)
if [ "$urlstatus" == "" ]; then
echo "检查是否可访问机器人管理页面...第 $i 次(共10次)"
sleep 6s
else
hasError2=0
break
fi
done
if [ $hasError1 == 1 -o $hasError2 == 1 ]; then
echo "出错了,请联系作者,查看日志docker logs -f webapp"
else
sed -i '/^ADONG.URL.*/d' ../env.properties
sed -i '$aADONG.URL=http://localhost:'$ad_port1'' ../env.properties
echo "恭喜你安装完成,阿东网页:http://localhost:$ad_port1,阿东机器人登录入口:http://localhost:$port,外部访问请打开防火墙并且开放 $ad_port1 和 $port 端口!"
fi
#bash <(curl -s -L https://ghproxy.com/https://raw.githubusercontent.com/rubyangxg/jd-qinglong/master/install.sh)
#sed -e '0,/localhost:[0-9]\+/ s/localhost:[0-9]\+/localhost:1245/' ./adbot/gmc_config.json
#tac ./adbot/gmc_config.json | sed -e '0,/localhost:[0-9]\+/{s/localhost:[0-9]\+/localhost:1245/}' | tac | tee a.json