-
Notifications
You must be signed in to change notification settings - Fork 1
/
config
661 lines (634 loc) · 12.8 KB
/
config
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
#!/bin/env bash
black="\e[30m"
red="\033[31m"
green="\033[32m"
yellow="\033[33m"
blue="\033[34m"
purple="\033[35m"
cyan="\033[36m"
white="\033[37m"
background="\033[0m"
token="\u0037\u0037\u0038\u0037\u0030\u0036\u0034\u0034\u0066\u0061\u0032\u0033\u0063\u0031"
GithubMirror="https://mirrors.chenby.cn/"
AFHOME=$AFYZHOME
if [ -x /usr/local/NodeJS/bin/node ]
then
if [ ! -d $HOME/.local/share/pnpm ];then
mkdir -p $HOME/.local/share/pnpm
fi
export PATH=$PATH:/usr/local/NodeJS/bin
export PATH=$PATH:/root/.local/share/pnpm
export PNPM_HOME=/root/.local/share/pnpm
export PUPPETEER_SKIP_DOWNLOAD=true
fi
function MenuTips(){
echo "当前时期 $(date +"%Y-%m-%d %H:%M")"
}
function gitclone(){
if [ -d "$2" ]
then
echo -e ${red}目标路径已经存在${background}
return 1
fi
if echo "$1" | grep -q gitee
then
git clone --depth=1 "$1" "$2"
return 0
fi
if CheckNetwork
then
MirrorNum=("gh-proxy" "ghproxy" "gh" "kkgithub" "github" "error")
else
MirrorNum=("github")
fi
for i in ${MirrorNum[@]}
do
case ${i} in
github)
if git clone --depth=1 "$1" "$2"
then
return 0
else
rm -rf "$2"
fi
;;
gh-proxy)
GitUrl=$(echo "$1" | sed 's|https://github.com|https://gh-proxy.com/https://github.com|g')
if git clone --depth=1 "${GitUrl}" "$2"
then
return 0
else
rm -rf "$2"
fi
;;
gitclone)
GitUrl=$(echo "$1" | sed 's|https://github.com|https://gitclone.com/github.com|g')
if git clone --depth=1 "${GitUrl}" "$2"
then
return 0
else
rm -rf "$2"
fi
;;
kkgithub)
GitUrl=$(echo "$1" | sed 's|https://github.com|https://kkgithub.com|g')
if git clone --depth=1 "${GitUrl}" "$2"
then
return 0
else
rm -rf "$2"
fi
;;
gh)
GitUrl=$(echo "$1" | sed 's|https://github.com|https://gh.arcticfox.top/https://github.com|g')
if git clone --depth=1 "${GitUrl}" "$2"
then
return 0
else
rm -rf "$2"
fi
;;
ghproxy)
GitUrl=$(echo "$1" | sed 's|https://github.com|https://mirror.ghproxy.com/https://github.com|g')
if git clone --depth=1 "${GitUrl}" "$2"
then
return 0
else
rm -rf "$2"
fi
;;
error)
echo -e ${yellow}仓库克隆 ${red}失败${background}
exit 1
;;
esac
done
}
function IncrementCounter(){
if [ -z ${count} ]
then
count=0
fi
((count++))
case ${count} in
3)
count=0
return 1
esac
return 0
}
function Download(){
file="$1"
URL="$2"
local i=0
DownloadStart(){
echo -e ${blue}[${green}*${blue}] ${cyan}正在下载 ${yellow}${file}${cyan}${background}
until ${Command}
do
if ! IncrementCounter
then
echo -e ${blue}[${red}*${blue}] ${cyan}错误次数过多 ${yellow}退出${background}
return 1
fi
echo -e ${blue}[${red}*${blue}] ${cyan}下载失败 ${yellow}三秒后重试${background}
sleep 3s
done
echo -e ${blue}[${green}*${blue}] ${cyan}下载完成.${background}
return 0
}
if $(command -v wget > /dev/null 2>&1) && $(wget --help | grep -q show-progress)
then
Command="wget --quiet --show-progress --output-document="${file}" --continue "${URL}""
DownloadStart
elif $(command -v curl > /dev/null 2>&1) && $(wget --help | grep -q progress-bar)
then
Command="curl --output "${file}" --progress-bar --location --continue-at - "${URL}""
DownloadStart
elif $(command -v wget > /dev/null 2>&1)
then
Command="wget --output-document="${file}" --continue "${URL}""
DownloadStart
else
echo -e ${blue}[${red}*${blue}] ${cyan}无下载器.${background}
return 1
fi
}
function MenuSize(){
local HEIGHT=$(($(tput lines) - 5))
local WIDTH=$(($(tput cols) - 5))
local OPTION=$((${HEIGHT} - 7))
if (( $HEIGHT <= 3 ));then
echo -e ${blue}[${red}*${blue}] ${cyan}您的屏幕高度过低.${background}
echo -e ${blue}[${red}*${blue}] ${cyan}考虑缩小终端字体.${background}
exit
fi
if (( $WIDTH <= 0 ));then
echo -e ${blue}[${red}*${blue}] ${cyan}您的屏幕宽度过窄.${background}
echo -e ${blue}[${red}*${blue}] ${cyan}考虑缩小终端字体.${background}
exit
fi
echo ${HEIGHT} ${WIDTH} ${OPTION}
}
function MsgboxSize(){
local HEIGHT=$(($(tput lines) - 15))
local WIDTH=$(($(tput cols) - 5))
if (( $HEIGHT <= 0 ));then
echo -e ${blue}[${red}*${blue}] ${cyan}您的屏幕高度过低.${background}
echo -e ${blue}[${red}*${blue}] ${cyan}考虑缩小终端字体.${background}
exit
fi
if (( $WIDTH <= 0 ));then
echo -e ${blue}[${red}*${blue}] ${cyan}您的屏幕宽度过窄.${background}
echo -e ${blue}[${red}*${blue}] ${cyan}考虑缩小终端字体.${background}
exit
fi
echo ${HEIGHT} ${WIDTH}
}
Arch(){
case `uname -m` in
aarch64|arm64)
echo arm64
;;
x86_64|x64|amd64)
echo x64
;;
*)
echo -e ${blue}[${red}*${blue}] ${cyan}不支持的架构.${background}
until read
do
echo -e ${blue}[${red}*${blue}] ${cyan}不支持的架构.${background}
done
esac
}
function ErrorReturn(){
echo -en "
${white}————————————————————
脚本运行出现${red}错误$white,请及时${blue}截图${white},保存报错信息,
以与便开发者,${green}更好的${white}和${green}更快的${cyan}解决${white}问题.
${white}————————————————————${background}"
exit 1
}
function SelectRegion(){
Tips(){
echo && echo -en "
———————————————————
${cyan}请问您的设备所在位置是?
${green}1${white}. 中国大陆 ${background}
${green}2${white}. 其他位置 ${background}
———————————————————
${cyan}请输入数字 ${white}[1-2]:${background} "
}
read -p "$(Tips)" num
case ${num} in
1)
return 0
;;
2)
return 1
;;
*)
echo -e ${blue}[${red}*${blue}] ${cyan}输入错误 ${yellow}保持默认 ${purple}中国大陆.${background}
return 0
esac
}
function CheckNetwork(){
IpinfoIo=$(curl -sL ipinfo.io/json)
if [ -z "${IpinfoIo}" ]
then
if SelectRegion
then
return 0
else
return 1
fi
else
if echo ${IpinfoIo} | grep -q error
then
token=$(echo -e ${token})
if curl -sL ipinfo.io/json?token=${token} | jq .country | grep -q "CN"
then
return 0
else
return 1
fi
else
if echo ${IpinfoIo} | jq .country | grep -q "CN"
then
return 0
else
return 1
fi
fi
fi
}
function Update(){
if [ -z ${Update} ]
then
Command=$@
${Command}
Update=true
fi
}
function TUISoftware(){
if [ -x "$(command -v whiptail)" ];then
echo whiptail
elif [ -x "$(command -v dialog)" ];then
echo dialog
else
echo -e ${red}没有TUI软件${background}
exit 1
fi
}
function Session(){
jq .SelectManageSession $AFHOME/config.json | sed 's|"||g'
}
function Stop(){
CheckStatus "$1" "$2" "$3"
case $? in
1)
ManageSessionPKG=tmux
;;
2)
ManageSessionPKG=screen
;;
3)
ManageSessionPKG=pm2
;;
4)
ManageSessionPKG=kill
;;
esac
case ${ManageSessionPKG} in
tmux|screen|pm2)
if ManageSession ${ManageSessionPKG} stop "$1"
then
return 0
else
return 1
fi
;;
kill)
PID=$(ps all | sed '/grep/d' | sed '/dialog/d' | sed '/whiptail/d' | grep "$2" | awk '{print $1}')
kill -9 ${PID}
;;
esac
}
function Restart(){
CheckStatus "$1" "$2" "$3"
case $? in
1)
ManageSessionPKG=tmux
;;
2)
ManageSessionPKG=screen
;;
3)
ManageSessionPKG=pm2
;;
4)
ManageSessionPKG=kill
;;
esac
case ${ManageSessionPKG} in
tmux|screen|pm2)
if ManageSession ${ManageSessionPKG} restart "$3"
then
return 0
else
return 1
fi
;;
kill)
PID=$(ps all | sed '/grep/d' | sed '/dialog/d' | sed '/whiptail/d' | grep "$2" | awk '{print $1}')
kill -9 ${PID}
START "$1" "$3"
;;
esac
}
function Log(){
CheckStatus "$1" "$2" "$3"
case $? in
1)
ManageSessionPKG=tmux
;;
2)
ManageSessionPKG=screen
;;
3)
ManageSessionPKG=pm2
;;
4)
ManageSessionPKG=kill
;;
esac
case ${ManageSessionPKG} in
tmux|screen|pm2)
if ManageSession ${ManageSessionPKG} log "$3"
then
return 0
else
return 1
fi
;;
kill)
echo "$1 [前台] 启动"
return 1
;;
esac
}
function PsAll(){
ps all | sed '/grep/d' | sed '/dialog/d' | sed '/whiptail/d' | grep -q "$1"
}
function CheckStatus(){
if tmux ls 2>&1 | grep -q "$1"
then
return 1
elif screen -ls 2>&1 | grep -q "$1"
then
return 2
elif pm2 list 2>&1 | sed '/stopped/d' | grep -q "$3"
then
return 3
elif PsAll "$2"
then
return 4
else
return 0
fi
}
function StartType(){
CheckStatus "$1" "$2" "$3"
case $? in
1)
$(TUISoftware) --title "AF-IdentifyType" \
--msgbox "$3 已在 [Tmux] 中启动" \
$(MsgboxSize)
return 1
;;
2)
$(TUISoftware) --title "AF-IdentifyType" \
--msgbox "$3 已在 [Screen] 中启动" \
$(MsgboxSize)
return 2
;;
3)
$(TUISoftware) --title "AF-IdentifyType" \
--msgbox "$3 已在 [Pm2] 中启动" \
$(MsgboxSize)
return 3
;;
4)
$(TUISoftware) --title "AF-IdentifyType" \
--msgbox "$3 已在 [前台] 中启动" \
$(MsgboxSize)
return 4
;;
esac
}
function ManageSession(){
case "$1" in
tmux)
case "$2" in
start)
tmux new -s "$3" -d "$4" > /dev/null
return $?
;;
stop)
tmux kill-session -t "$3" > /dev/null
return $?
;;
restart)
tmux kill-session -t "$3" && tmux new -s "$3" -d "$4" > /dev/null
return $?
;;
log)
tmux attach -t "$3" > /dev/null
return $?
;;
list)
tmux ls | grep -q "$3"
return $?
;;
esac
;;
screen)
case "$2" in
start)
screen -S "$3" -d -m bash -c "$4"
return $?
;;
stop)
Session=$(screen -ls | grep "$3" | awk '{print $1}')
screen -X -S ${Session} quit
return $?
;;
restart)
Session=$(screen -ls | grep "$3" | awk '{print $1}')
screen -X -S ${Session} quit && screen -S ${Session} -d -m bash -c "$4"
return $?
;;
log)
Session=$(screen -ls | grep "$3" | awk '{print $1}')
screen -r ${Session}
return $?
;;
list)
screen -ls | grep -q "$3"
return $?
;;
esac
;;
pm2)
case $2 in
start)
pm2 start --name $3 "$4"
return $?
;;
stop)
pm2 stop "$3"
return $?
;;
restart)
pm2 stop "$3" && pm2 start --name $3 "$4"
return $?
;;
log)
pm2 logs "$3" | sed '/PM2/d'
return $?
;;
list)
pm2 list
return $?
;;
esac
;;
esac
}
function CheckRedisServer(){
function PedisCliPing(){
if [ "$(redis-cli ping 2>&1)" == "PONG" ]
then
return 0
else
return 1
fi
}
if $(PedisCliPing)
then
echo -e ${cyan}Redis-Server${yellow} 已经启动${background}
else
echo -e ${cyan}Redis-Server${yellow} 正在启动${background}
$(nohup redis-server > /dev/null 2>&1 &)
until PedisCliPing
do
sleep 0.2s
done
echo -e ${cyan}Redis-Server${yellow} 启动成功${background}
fi
}
function CheckSignApi(){
local file="config/config/bot.yaml"
SignApi=$(grep sign_api_addr ${file} | sed 's|sign_api_addr: ||g')
if [ -n ${SignApi} ]
then
echo -e ${yellow}正在检查签名可用性${background}
if curl -sL ${SignApi} | tee grep com.tencent.mobileqq
then
echo
echo -e ${green}签名可用${background}
else
echo
echo -e ${red}签名不可达${background}
fi
fi
}
function START(){
CheckRedisServer
local Command="$1"
${Command}
Pm2List=$(pm2 list 2>&1)
if echo ${Pm2List} | grep -q "$2"
then
if ! $(pm2 list 2>&1 | grep "$2" | grep -q stopped)
then
pm2 delete "$2" > /dev/null 2>&1
START "$1" "$2"
fi
fi
}
function ProgressBar(){
{
i=0
while CheckStatus "$1" "$2" "$3"
do
echo $((i++))
if echo ${i} | grep -q 100
then
return 1
fi
done
return 0
} | $(TUISoftware) --gauge "${BotName} [正在启动]" $(MsgboxSize) 0
}
function CheckPath(){
local Name=$@
for i in ${Name[@]}
do
if [ -d "$HOME/${i}/node_modules" ]
then
export BotPath="$HOME/${i}"
cd "$HOME/${i}"
return 0
elif [ -d "$HOME/.fox@bot/${i}/node_modules" ]
then
export BotPath="$HOME/.fox@bot/${i}"
cd "$HOME/.fox@bot/${i}"
return 0
elif [ -d "$HOME/fox@bot/${i}/node_modules" ]
then
export BotPath="$HOME/fox@bot/${i}/node_modules"
cd "$HOME/fox@bot/${i}"
return 0
elif grep -q true ../config.json
then
if $(command -v jq > /dev/null)
then
BotPath=$(jq -r ".BotPath" ../config.json)
if [ -e ${BotPath}/package.json ]
then
cd "${BotPath}"
export BotPath=${BotPath}
fi
fi
fi
done
return 1
}
function CheckInstall(){
case $1 in
YN|Yunzai-Next)
if CheckPath Yunzai-Next Yunzai-Bot yunzai-bot yunzaijs
then
return 0
else
return 1
fi
;;
MZ|Miao-Yunzai)
if CheckPath Miao-Yunzai
then
return 0
else
return 1
fi
;;
TZ|TRSS-Yunzai)
if CheckPath TRSS-Yunzai Yunzai
then
return 0
else
return 1
fi
;;
esac
}