forked from DDS-Derek/xiaoya-alist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_in_one.sh
4998 lines (4360 loc) · 173 KB
/
all_in_one.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
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
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# shellcheck shell=bash
# shellcheck disable=SC2086
# shellcheck disable=SC1091
# shellcheck disable=SC2154
# shellcheck disable=SC2004
PATH=${PATH}:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin
export PATH
#
# ——————————————————————————————————————————————————————————————————————————————————
# __ ___ _ _ _
# \ \ / (_) /\ | (_) | |
# \ V / _ __ _ ___ _ _ __ _ / \ | |_ ___| |_
# > < | |/ _` |/ _ \| | | |/ _` | / /\ \ | | / __| __|
# / . \| | (_| | (_) | |_| | (_| | / ____ \| | \__ \ |_
# /_/ \_\_|\__,_|\___/ \__, |\__,_| /_/ \_\_|_|___/\__|
# __/ |
# |___/
#
# Copyright (c) 2024 DDSRem <https://blog.ddsrem.com>
#
# This is free software, licensed under the Mit License.
#
# ——————————————————————————————————————————————————————————————————————————————————
#
DATE_VERSION="v1.6.7-2024_06_28_20_14"
#
# ——————————————————————————————————————————————————————————————————————————————————
Sky_Blue="\e[36m"
Blue="\033[34m"
Green="\033[32m"
Red="\033[31m"
Yellow='\033[33m'
Font="\033[0m"
INFO="[${Green}INFO${Font}]"
ERROR="[${Red}ERROR${Font}]"
WARN="[${Yellow}WARN${Font}]"
function INFO() {
echo -e "${INFO} ${1}"
}
function ERROR() {
echo -e "${ERROR} ${1}"
}
function WARN() {
echo -e "${WARN} ${1}"
}
mirrors=(
"docker.io"
"registry-docker-hub-latest-9vqc.onrender.com"
"docker.fxxk.dedyn.io"
"docker.chenby.cn"
"dockerproxy.com"
"hub.uuuadc.top"
"docker.jsdelivr.fyi"
"docker.registry.cyou"
"dockerhub.anzu.vip"
"docker.luyao.dynv6.net"
)
function root_need() {
if [[ $EUID -ne 0 ]]; then
ERROR '此脚本必须以 root 身份运行!'
exit 1
fi
}
function ___install_docker() {
if ! command -v docker; then
WARN "docker 未安装,脚本尝试自动安装..."
wget -qO- get.docker.com | bash
if command -v docker; then
INFO "docker 安装成功!"
else
ERROR "docker 安装失败,请手动安装!"
exit 1
fi
fi
}
function packages_apt_install() {
if ! command -v ${1}; then
WARN "${1} 未安装,脚本尝试自动安装..."
apt update -y
if apt install -y ${1}; then
INFO "${1} 安装成功!"
else
ERROR "${1} 安装失败,请手动安装!"
exit 1
fi
fi
}
function packages_yum_install() {
if ! command -v ${1}; then
WARN "${1} 未安装,脚本尝试自动安装..."
if yum install -y ${1}; then
INFO "${1} 安装成功!"
else
ERROR "${1} 安装失败,请手动安装!"
exit 1
fi
fi
}
function packages_zypper_install() {
if ! command -v ${1}; then
WARN "${1} 未安装,脚本尝试自动安装..."
zypper refresh
if zypper install ${1}; then
INFO "${1} 安装成功!"
else
ERROR "${1} 安装失败,请手动安装!"
exit 1
fi
fi
}
function packages_apk_install() {
if ! command -v ${1}; then
WARN "${1} 未安装,脚本尝试自动安装..."
if apk add ${1}; then
INFO "${1} 安装成功!"
else
ERROR "${1} 安装失败,请手动安装!"
exit 1
fi
fi
}
function packages_pacman_install() {
if ! command -v ${1}; then
WARN "${1} 未安装,脚本尝试自动安装..."
if pacman -Sy --noconfirm ${1}; then
INFO "${1} 安装成功!"
else
ERROR "${1} 安装失败,请手动安装!"
exit 1
fi
fi
}
function packages_need() {
if [ "$1" == "apt" ]; then
packages_apt_install curl
packages_apt_install wget
___install_docker
elif [ "$1" == "yum" ]; then
packages_yum_install curl
packages_yum_install wget
___install_docker
elif [ "$1" == "zypper" ]; then
packages_zypper_install curl
packages_zypper_install wget
___install_docker
elif [ "$1" == "apk_alpine" ]; then
packages_apk_install curl
packages_apk_install wget
packages_apk_install docker
elif [ "$1" == "pacman" ]; then
packages_pacman_install curl
packages_pacman_install wget
packages_pacman_install docker
else
if ! command -v curl; then
ERROR "curl 未安装,请手动安装!"
exit 1
fi
if ! command -v wget; then
ERROR "wget 未安装,请手动安装!"
exit 1
fi
if ! command -v docker; then
ERROR "docker 未安装,请手动安装!"
exit 1
fi
fi
}
function get_os() {
if command -v getconf > /dev/null 2>&1; then
is64bit="$(getconf LONG_BIT)bit"
else
is64bit="unknow"
fi
_os=$(uname -s)
_os_all=$(uname -a)
if [ "${_os}" == "Darwin" ]; then
OSNAME='macos'
packages_need
DDSREM_CONFIG_DIR=/etc/DDSRem
stty -icanon
# 必须先判断的系统
# 绿联NAS 基于 OpenWRT
elif echo -e "${_os_all}" | grep -Eqi "UGREEN"; then
OSNAME='ugreen'
packages_need
DDSREM_CONFIG_DIR=/etc/DDSRem
# OpenMediaVault 基于 Debian
elif grep -Eqi "openmediavault" /etc/issue || grep -Eqi "openmediavault" /etc/os-release; then
OSNAME='openmediavault'
packages_need "apt"
DDSREM_CONFIG_DIR=/etc/DDSRem
# FreeNAS(TrueNAS CORE)基于 FreeBSD
elif echo -e "${_os_all}" | grep -Eqi "FreeBSD" | grep -Eqi "TRUENAS"; then
OSNAME='truenas core'
packages_need
DDSREM_CONFIG_DIR=/etc/DDSRem
# TrueNAS SCALE 基于 Debian
elif grep -Eqi "Debian" /etc/issue && [ -f /etc/version ]; then
OSNAME='truenas scale'
packages_need
DDSREM_CONFIG_DIR=/etc/DDSRem
elif [ -f /etc/synoinfo.conf ]; then
OSNAME='synology'
packages_need
DDSREM_CONFIG_DIR=/etc/DDSRem
elif [ -f /etc/openwrt_release ]; then
OSNAME='openwrt'
packages_need
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "QNAP" /etc/issue; then
OSNAME='qnap'
packages_need
DDSREM_CONFIG_DIR=/etc/DDSRem
elif [ -f /etc/unraid-version ]; then
OSNAME='unraid'
packages_need
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "LibreELEC" /etc/issue || grep -Eqi "LibreELEC" /etc/*-release; then
OSNAME='libreelec'
DDSREM_CONFIG_DIR=/storage/DDSRem
ERROR "LibreELEC 系统目前不支持!"
exit 1
elif grep -Eqi "openSUSE" /etc/*-release; then
OSNAME='opensuse'
packages_need "zypper"
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "FreeBSD" /etc/*-release; then
OSNAME='freebsd'
packages_need
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "EulerOS" /etc/*-release || grep -Eqi "openEuler" /etc/*-release; then
OSNAME='euler'
packages_need "yum"
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "CentOS" /etc/issue || grep -Eqi "CentOS" /etc/*-release; then
OSNAME='centos'
packages_need "yum"
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "Fedora" /etc/issue || grep -Eqi "Fedora" /etc/*-release; then
OSNAME='fedora'
packages_need "yum"
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "Rocky" /etc/issue || grep -Eqi "Rocky" /etc/*-release; then
OSNAME='rocky'
packages_need "yum"
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "AlmaLinux" /etc/issue || grep -Eqi "AlmaLinux" /etc/*-release; then
OSNAME='almalinux'
packages_need "yum"
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "Arch Linux" /etc/issue || grep -Eqi "Arch Linux" /etc/*-release; then
OSNAME='archlinux'
packages_need "pacman"
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "Amazon Linux" /etc/issue || grep -Eqi "Amazon Linux" /etc/*-release; then
OSNAME='amazon'
packages_need "yum"
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "Debian" /etc/issue || grep -Eqi "Debian" /etc/os-release; then
OSNAME='debian'
packages_need "apt"
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eqi "Ubuntu" /etc/os-release; then
OSNAME='ubuntu'
packages_need "apt"
DDSREM_CONFIG_DIR=/etc/DDSRem
elif grep -Eqi "Alpine" /etc/issue || grep -Eq "Alpine" /etc/*-release; then
OSNAME='alpine'
packages_need "apk_alpine"
DDSREM_CONFIG_DIR=/etc/DDSRem
else
OSNAME='unknow'
packages_need
DDSREM_CONFIG_DIR=/etc/DDSRem
fi
HOSTS_FILE_PATH=/etc/hosts
}
function show_disk_mount() {
df -h | grep -E -v "Avail|loop|boot|overlay|tmpfs|proc" | sort -nr -k 4
}
function judgment_container() {
if docker container inspect "${1}" > /dev/null 2>&1; then
local container_status
container_status=$(docker inspect --format='{{.State.Status}}' "${1}")
case "${container_status}" in
"created")
echo -e "${Blue}已创建${Font}"
;;
"running")
echo -e "${Green}运行中${Font}"
;;
"paused")
echo -e "${Blue}已暂停${Font}"
;;
"restarting")
echo -e "${Blue}重启中${Font}"
;;
"removing")
echo -e "${Blue}删除中${Font}"
;;
"exited")
echo -e "${Yellow}已停止${Font}"
;;
"dead")
echo -e "${Red}不可用${Font}"
;;
*)
echo -e "${Red}未知状态${Font}"
;;
esac
else
echo -e "${Red}未安装${Font}"
fi
}
function return_menu() {
INFO "是否返回菜单继续配置 [Y/n]"
answer=""
t=60
while [[ -z "$answer" && $t -gt 0 ]]; do
printf "\r%2d 秒后将自动退出脚本:" $t
read -r -t 1 -n 1 answer
t=$((t - 1))
done
[[ -z "${answer}" ]] && answer="n"
if [[ ${answer} == [Yy] ]]; then
clear
"${@}"
else
echo -e "\n"
exit 0
fi
}
function docker_pull() {
retries=0
max_retries=3
IMAGE_MIRROR=$(cat "${DDSREM_CONFIG_DIR}/image_mirror.txt")
if docker inspect "${1}" > /dev/null 2>&1; then
INFO "发现旧 ${1} 镜像,删除中..."
docker rmi "${1}" > /dev/null 2>&1
fi
while [ $retries -lt $max_retries ]; do
if docker pull "${IMAGE_MIRROR}/${1}"; then
INFO "${1} 镜像拉取成功!"
break
else
WARN "${1} 镜像拉取失败,正在进行第 $((retries + 1)) 次重试..."
retries=$((retries + 1))
fi
done
if [ $retries -eq $max_retries ]; then
ERROR "镜像拉取失败,已达到最大重试次数!"
ERROR "请进入主菜单选择数字 ${Sky_Blue}9 6${Font} 进入 ${Sky_Blue}Docker镜像源选择${Font} 配置镜像源地址!"
exit 1
else
if [ "${IMAGE_MIRROR}" != "docker.io" ]; then
docker tag "${IMAGE_MIRROR}/${1}" "${1}" > /dev/null 2>&1
docker rmi "${IMAGE_MIRROR}/${1}" > /dev/null 2>&1
fi
return 0
fi
}
function container_update() {
local run_image remove_image IMAGE_MIRROR pull_image
if docker inspect assaflavie/runlike:latest > /dev/null 2>&1; then
local_sha=$(docker inspect --format='{{index .RepoDigests 0}}' assaflavie/runlike:latest | cut -f2 -d:)
remote_sha=$(curl -s "https://hub.docker.com/v2/repositories/assaflavie/runlike/tags/latest" | grep -o '"digest":"[^"]*' | grep -o '[^"]*$' | tail -n1 | cut -f2 -d:)
if [ "$local_sha" != "$remote_sha" ]; then
docker rmi assaflavie/runlike:latest
docker_pull "assaflavie/runlike:latest"
fi
else
docker_pull "assaflavie/runlike:latest"
fi
INFO "获取 ${1} 容器信息中..."
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp assaflavie/runlike "${@}" > "/tmp/container_update_${*}"
run_image=$(docker container inspect -f '{{.Config.Image}}' "${@}")
remove_image=$(docker images -q ${run_image})
local retries=0
local max_retries=3
IMAGE_MIRROR=$(cat "${DDSREM_CONFIG_DIR}/image_mirror.txt")
while [ $retries -lt $max_retries ]; do
if docker pull "${IMAGE_MIRROR}/${run_image}"; then
INFO "${1} 镜像拉取成功!"
break
else
WARN "${1} 镜像拉取失败,正在进行第 $((retries + 1)) 次重试..."
retries=$((retries + 1))
fi
done
if [ $retries -eq $max_retries ]; then
ERROR "镜像拉取失败,已达到最大重试次数!"
return 1
else
if [ "${IMAGE_MIRROR}" != "docker.io" ]; then
pull_image=$(docker images -q "${IMAGE_MIRROR}/${run_image}")
else
pull_image=$(docker images -q "${run_image}")
fi
if ! docker stop "${@}" > /dev/null 2>&1; then
if ! docker kill "${@}" > /dev/null 2>&1; then
docker rmi "${IMAGE_MIRROR}/${run_image}"
ERROR "更新失败,停止 ${*} 容器失败!"
return 1
fi
fi
INFO "停止 ${*} 容器成功!"
if ! docker rm --force "${@}" > /dev/null 2>&1; then
ERROR "更新失败,删除 ${*} 容器失败!"
return 1
fi
INFO "删除 ${*} 容器成功!"
if [ "${pull_image}" != "${remove_image}" ]; then
INFO "删除 ${remove_image} 镜像中..."
docker rmi "${remove_image}" > /dev/null 2>&1
fi
if [ "${IMAGE_MIRROR}" != "docker.io" ]; then
docker tag "${IMAGE_MIRROR}/${1}" "${1}" > /dev/null 2>&1
docker rmi "${IMAGE_MIRROR}/${1}" > /dev/null 2>&1
fi
if bash "/tmp/container_update_${*}"; then
rm -f "/tmp/container_update_${*}"
INFO "${*} 更新成功"
return 0
else
ERROR "更新失败,创建 ${*} 容器失败!"
return 1
fi
fi
}
function wait_emby_start() {
start_time=$(date +%s)
CONTAINER_NAME="$(cat "${DDSREM_CONFIG_DIR}"/container_name/xiaoya_emby_name.txt)"
TARGET_LOG_LINE_SUCCESS="All entry points have started"
while true; do
line=$(docker logs "$CONTAINER_NAME" 2>&1 | tail -n 10)
echo -e "$line"
if [[ "$line" == *"$TARGET_LOG_LINE_SUCCESS"* ]]; then
break
fi
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ "$elapsed_time" -gt 600 ]; then
WARN "Emby 未正常启动超时 10 分钟!"
break
fi
sleep 3
done
}
function wait_jellyfin_start() {
start_time=$(date +%s)
CONTAINER_NAME="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_jellyfin_name.txt)"
while true; do
if [ "$(docker inspect --format='{{json .State.Health.Status}}' "${CONTAINER_NAME}" | sed 's/"//g')" == "healthy" ]; then
break
fi
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ "$elapsed_time" -gt 900 ]; then
WARN "Jellyfin 未正常启动超时 15 分钟!"
break
fi
sleep 10
INFO "等待 Jellyfin 初始化完成中..."
done
}
function wait_xiaoya_start() {
start_time=$(date +%s)
TARGET_LOG_LINE_SUCCESS="success load storage: [/©️"
while true; do
line=$(docker logs "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)" 2>&1 | tail -n 10)
echo -e "$line"
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [[ "$line" == *"$TARGET_LOG_LINE_SUCCESS"* ]]; then
if [ "$elapsed_time" -gt 20 ]; then
break
fi
fi
if [ "$elapsed_time" -gt 300 ]; then
WARN "小雅alist 未正常启动超时 5 分钟!"
break
fi
sleep 3
done
}
function check_quark_cookie() {
if [[ ! -f "${CONFIG_DIR}/quark_cookie.txt" ]] && [[ ! -s "${CONFIG_DIR}/quark_cookie.txt" ]]; then
return 1
fi
local cookie user_agent url headers response status state_url sign_daily_reward sign_daily_reward_mb
cookie=$(head -n1 "${CONFIG_DIR}/quark_cookie.txt")
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) quark-cloud-drive/2.5.20 Chrome/100.0.4896.160 Electron/18.3.5.4-b478491100 Safari/537.36 Channel/pckk_other_ch"
url="https://drive-pc.quark.cn/1/clouddrive/config?pr=ucpro&fr=pc&uc_param_str="
headers="Cookie: $cookie; User-Agent: $user_agent; Referer: https://pan.quark.cn"
response=$(curl -s -D - -H "$headers" "$url")
status=$(echo "$response" | grep -i status | cut -f2 -d: | cut -f1 -d,)
if [ "$status" == "401" ]; then
ERROR "无效夸克 Cookie"
return 1
else
state_url="https://drive-m.quark.cn/1/clouddrive/capacity/growth/info?pr=ucpro&fr=pc&uc_param_str="
response=$(curl -s -H "$headers" "$state_url")
sign_daily_reward=$(echo "$response" | cut -f6 -d\{ | cut -f4 -d: | cut -f1 -d,)
sign_daily_reward_mb=$(echo "$sign_daily_reward 1024 1024" | awk '{printf "%.2f\n", $1 / ($2 * $3)}')
if [ $sign_daily_reward_mb ]; then
INFO "有效夸克 Cookie"
INFO "夸克签到获取 $sign_daily_reward_mb MB"
return 0
else
ERROR "请求失败,请检查 Cookie 或网络连接是否正确。"
return 1
fi
fi
}
function get_config_dir() {
if [ -f ${DDSREM_CONFIG_DIR}/xiaoya_alist_config_dir.txt ]; then
OLD_CONFIG_DIR=$(cat ${DDSREM_CONFIG_DIR}/xiaoya_alist_config_dir.txt)
INFO "已读取小雅Alist配置文件路径:${OLD_CONFIG_DIR} (默认不更改回车继续,如果需要更改请输入新路径)"
read -erp "CONFIG_DIR:" CONFIG_DIR
[[ -z "${CONFIG_DIR}" ]] && CONFIG_DIR=${OLD_CONFIG_DIR}
echo "${CONFIG_DIR}" > ${DDSREM_CONFIG_DIR}/xiaoya_alist_config_dir.txt
else
INFO "请输入配置文件目录(默认 /etc/xiaoya )"
read -erp "CONFIG_DIR:" CONFIG_DIR
[[ -z "${CONFIG_DIR}" ]] && CONFIG_DIR="/etc/xiaoya"
touch ${DDSREM_CONFIG_DIR}/xiaoya_alist_config_dir.txt
echo "${CONFIG_DIR}" > ${DDSREM_CONFIG_DIR}/xiaoya_alist_config_dir.txt
fi
if [ -d "${CONFIG_DIR}" ]; then
INFO "读取配置目录中..."
# 将所有小雅配置文件修正成 linux 格式
find ${CONFIG_DIR} -type f -name "*.txt" -exec sed -i "s/\r$//g" {} \;
# 设置权限
chmod -R 777 ${CONFIG_DIR}
fi
}
function get_media_dir() {
if [ -f ${DDSREM_CONFIG_DIR}/xiaoya_alist_config_dir.txt ]; then
XIAOYA_CONFIG_DIR=$(cat ${DDSREM_CONFIG_DIR}/xiaoya_alist_config_dir.txt)
if [ -s "${XIAOYA_CONFIG_DIR}/emby_config.txt" ]; then
source "${XIAOYA_CONFIG_DIR}/emby_config.txt"
echo "${media_dir}" > ${DDSREM_CONFIG_DIR}/xiaoya_alist_media_dir.txt
INFO "媒体库目录通过 emby_config.txt 获取"
fi
fi
if [ -f ${DDSREM_CONFIG_DIR}/xiaoya_alist_media_dir.txt ]; then
OLD_MEDIA_DIR=$(cat ${DDSREM_CONFIG_DIR}/xiaoya_alist_media_dir.txt)
INFO "已读取媒体库目录:${OLD_MEDIA_DIR} (默认不更改回车继续,如果需要更改请输入新路径)"
read -erp "MEDIA_DIR:" MEDIA_DIR
[[ -z "${MEDIA_DIR}" ]] && MEDIA_DIR=${OLD_MEDIA_DIR}
echo "${MEDIA_DIR}" > ${DDSREM_CONFIG_DIR}/xiaoya_alist_media_dir.txt
else
INFO "请输入媒体库目录(默认 /opt/media )"
read -erp "MEDIA_DIR:" MEDIA_DIR
[[ -z "${MEDIA_DIR}" ]] && MEDIA_DIR="/opt/media"
touch ${DDSREM_CONFIG_DIR}/xiaoya_alist_media_dir.txt
echo "${MEDIA_DIR}" > ${DDSREM_CONFIG_DIR}/xiaoya_alist_media_dir.txt
fi
}
function data_crep() { # container_run_extra_parameters
local MODE="${1}"
local DATA="${2}"
local DIR="${DDSREM_CONFIG_DIR}/data_crep"
if [ "${MODE}" == "read" ] || [ "${MODE}" == "r" ]; then
if [ -f "${DIR}/${DATA}.txt" ]; then
cat ${DIR}/${DATA}.txt | head -n1
else
echo "None"
fi
elif [ "${MODE}" == "write" ] || [ "${MODE}" == "w" ]; then
echo "${extra_parameters}" > ${DIR}/${DATA}.txt
else
return 1
fi
}
function install_xiaoya_alist() {
if [ ! -d "${CONFIG_DIR}" ]; then
mkdir -p "${CONFIG_DIR}"
else
if [ -d "${CONFIG_DIR}"/mytoken.txt ]; then
rm -rf "${CONFIG_DIR}"/mytoken.txt
fi
fi
if [ ! -d "${CONFIG_DIR}/data" ]; then
mkdir -p "${CONFIG_DIR}/data"
fi
files=("mytoken.txt" "myopentoken.txt" "temp_transfer_folder_id.txt")
for file in "${files[@]}"; do
if [ ! -f "${CONFIG_DIR}/${file}" ]; then
touch "${CONFIG_DIR}/${file}"
fi
done
mytokenfilesize=$(cat "${CONFIG_DIR}"/mytoken.txt)
mytokenstringsize=${#mytokenfilesize}
if [ "$mytokenstringsize" -le 31 ]; then
INFO "输入你的阿里云盘 Token(32位长)"
read -erp "TOKEN:" token
token_len=${#token}
if [ "$token_len" -ne 32 ]; then
ERROR "长度不对,阿里云盘 Token是32位长"
ERROR "安装停止,请参考指南配置文件: https://xiaoyaliu.notion.site/xiaoya-docker-69404af849504fa5bcf9f2dd5ecaa75f"
exit 1
else
echo "$token" > "${CONFIG_DIR}"/mytoken.txt
fi
fi
myopentokenfilesize=$(cat "${CONFIG_DIR}"/myopentoken.txt)
myopentokenstringsize=${#myopentokenfilesize}
if [ "$myopentokenstringsize" -le 279 ]; then
INFO "输入你的阿里云盘 Open Token(280位长或者335位长)"
read -erp "OPENTOKEN:" opentoken
opentoken_len=${#opentoken}
if [[ "$opentoken_len" -ne 280 ]] && [[ "$opentoken_len" -ne 335 ]]; then
ERROR "长度不对,阿里云盘 Open Token是280位长或者335位"
ERROR "安装停止,请参考指南配置文件: https://xiaoyaliu.notion.site/xiaoya-docker-69404af849504fa5bcf9f2dd5ecaa75f"
exit 1
else
echo "$opentoken" > "${CONFIG_DIR}"/myopentoken.txt
fi
fi
folderidfilesize=$(cat "${CONFIG_DIR}"/temp_transfer_folder_id.txt)
folderidstringsize=${#folderidfilesize}
if [ "$folderidstringsize" -le 39 ]; then
INFO "输入你的阿里云盘转存目录folder id"
read -erp "FOLDERID:" folderid
folder_id_len=${#folderid}
if [ "$folder_id_len" -ne 40 ]; then
ERROR "长度不对,阿里云盘 folder id是40位长"
ERROR "安装停止,请参考指南配置文件: https://xiaoyaliu.notion.site/xiaoya-docker-69404af849504fa5bcf9f2dd5ecaa75f"
exit 1
else
echo "$folderid" > "${CONFIG_DIR}"/temp_transfer_folder_id.txt
fi
fi
if [ ! -f "${CONFIG_DIR}/pikpak.txt" ]; then
INFO "是否继续配置 PikPak 账号密码 [Y/n](默认 n 不配置)"
read -erp "PikPak_Set:" PikPak_Set
[[ -z "${PikPak_Set}" ]] && PikPak_Set="n"
if [[ ${PikPak_Set} == [Yy] ]]; then
touch ${CONFIG_DIR}/pikpak.txt
INFO "输入你的 PikPak 账号(手机号或邮箱)"
INFO "如果手机号,要\"+区号\",比如你的手机号\"12345678900\"那么就填\"+8612345678900\""
read -erp "PikPak_Username:" PikPak_Username
INFO "输入你的 PikPak 账号密码"
read -erp "PikPak_Password:" PikPak_Password
echo -e "\"${PikPak_Username}\" \"${PikPak_Password}\"" > ${CONFIG_DIR}/pikpak.txt
fi
fi
if [ ! -f "${CONFIG_DIR}/quark_cookie.txt" ] || ! check_quark_cookie; then
INFO "是否配置 夸克 Cookie [Y/n](默认 n 不配置)"
read -erp "Cookie:" choose_cookie
[[ -z "${choose_cookie}" ]] && choose_cookie="n"
if [[ ${choose_cookie} == [Yy] ]]; then
touch ${CONFIG_DIR}/quark_cookie.txt
while true; do
INFO "输入你的 夸克 Cookie"
read -erp "Cookie:" quark_cookie
echo -e "${quark_cookie}" > ${CONFIG_DIR}/quark_cookie.txt
if check_quark_cookie; then
break
fi
done
fi
fi
if command -v ifconfig > /dev/null 2>&1; then
localip=$(ifconfig -a | grep inet | grep -v 172.17 | grep -v 127.0.0.1 | grep -v inet6 | awk '{print $2}' | sed 's/addr://' | head -n1)
else
localip=$(ip address | grep inet | grep -v 172.17 | grep -v 127.0.0.1 | grep -v inet6 | awk '{print $2}' | sed 's/addr://' | head -n1 | cut -f1 -d"/")
fi
INFO "本地IP:${localip}"
if [ "${SET_NET_MODE}" == true ]; then
INFO "是否使用host网络模式 [Y/n](默认 n 不使用)"
read -erp "NET_MODE:" NET_MODE
fi
[[ -z "${NET_MODE}" ]] && NET_MODE="n"
if [ ! -s "${CONFIG_DIR}"/docker_address.txt ]; then
echo "http://$localip:5678" > "${CONFIG_DIR}"/docker_address.txt
fi
docker_command=("docker run" "-itd")
if [[ ${NET_MODE} == [Yy] ]]; then
docker_image="xiaoyaliu/alist:hostmode"
docker_command+=("--network=host")
else
docker_image="xiaoyaliu/alist:latest"
docker_command+=("-p 5678:80" "-p 2345:2345" "-p 2346:2346")
fi
if [[ -f ${CONFIG_DIR}/proxy.txt ]] && [[ -s ${CONFIG_DIR}/proxy.txt ]]; then
proxy_url=$(head -n1 "${CONFIG_DIR}"/proxy.txt)
docker_command+=("--env HTTP_PROXY=$proxy_url" "--env HTTPS_PROXY=$proxy_url" "--env no_proxy=*.aliyundrive.com")
fi
docker_command+=("-v ${CONFIG_DIR}:/data" "-v ${CONFIG_DIR}/data:/www/data" "--restart=always" "--name=$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)" "$docker_image")
docker_pull "$docker_image"
eval "${docker_command[*]}"
wait_xiaoya_start
INFO "安装完成!"
}
function update_xiaoya_alist() {
for i in $(seq -w 3 -1 0); do
echo -en "即将开始更新小雅Alist${Blue} $i ${Font}\r"
sleep 1
done
container_update "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)"
}
function uninstall_xiaoya_alist() {
INFO "是否${Red}删除配置文件${Font} [Y/n](默认 Y 删除)"
read -erp "Clean config:" CLEAN_CONFIG
[[ -z "${CLEAN_CONFIG}" ]] && CLEAN_CONFIG="y"
for i in $(seq -w 3 -1 0); do
echo -en "即将开始卸载小雅Alist${Blue} $i ${Font}\r"
sleep 1
done
IMAGE_NAME="$(docker inspect --format='{{.Config.Image}}' "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)")"
docker stop "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)"
docker rm "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)"
docker rmi "${IMAGE_NAME}"
if [[ ${CLEAN_CONFIG} == [Yy] ]]; then
INFO "清理配置文件..."
if [ -f ${DDSREM_CONFIG_DIR}/xiaoya_alist_config_dir.txt ]; then
OLD_CONFIG_DIR=$(cat ${DDSREM_CONFIG_DIR}/xiaoya_alist_config_dir.txt)
for file in "${OLD_CONFIG_DIR}/mycheckintoken.txt" "${OLD_CONFIG_DIR}/mycmd.txt" "${OLD_CONFIG_DIR}/myruntime.txt"; do
if [ -f "$file" ]; then
mv -f "$file" "/tmp/$(basename "$file")"
fi
done
rm -rf \
${OLD_CONFIG_DIR}/*.txt \
${OLD_CONFIG_DIR}/*.m3u \
${OLD_CONFIG_DIR}/*.m3u8
if [ -d "${OLD_CONFIG_DIR}/xiaoya_backup" ]; then
rm -rf ${OLD_CONFIG_DIR}/xiaoya_backup
fi
for file in /tmp/mycheckintoken.txt /tmp/mycmd.txt /tmp/myruntime.txt; do
if [ -f "$file" ]; then
mv -f "$file" "${OLD_CONFIG_DIR}/$(basename "$file")"
fi
done
fi
fi
INFO "小雅Alist卸载成功!"
}
function judgment_xiaoya_alist_sync_data_status() {
if command -v crontab > /dev/null 2>&1; then
if crontab -l | grep 'xiaoya_data_downloader' > /dev/null 2>&1; then
echo -e "${Green}已创建${Font}"
else
echo -e "${Red}未创建${Font}"
fi
elif [ -f /etc/synoinfo.conf ]; then
if grep 'xiaoya_data_downloader' /etc/crontab > /dev/null 2>&1; then
echo -e "${Green}已创建${Font}"
else
echo -e "${Red}未创建${Font}"
fi
else
echo -e "${Red}未知${Font}"
fi
}
function uninstall_xiaoya_alist_sync_data() {
if command -v crontab > /dev/null 2>&1; then
crontab -l > /tmp/cronjob.tmp
sed -i '/xiaoya_data_downloader/d' /tmp/cronjob.tmp
crontab /tmp/cronjob.tmp
rm -f /tmp/cronjob.tmp
elif [ -f /etc/synoinfo.conf ]; then
sed -i '/xiaoya_data_downloader/d' /etc/crontab
fi
}
function main_xiaoya_alist() {
echo -e "——————————————————————————————————————————————————————————————————————————————————"
echo -e "${Blue}小雅Alist${Font}\n"
echo -e "1、安装"
echo -e "2、更新"
echo -e "3、卸载"
echo -e "4、创建/删除 定时同步更新数据(${Red}功能已弃用,只提供删除${Font}) 当前状态:$(judgment_xiaoya_alist_sync_data_status)"
echo -e "0、返回上级"
echo -e "——————————————————————————————————————————————————————————————————————————————————"
read -erp "请输入数字 [0-4]:" num
case "$num" in
1)
clear
get_config_dir
SET_NET_MODE=true
install_xiaoya_alist
return_menu "main_xiaoya_alist"
;;
2)
clear
update_xiaoya_alist
return_menu "main_xiaoya_alist"
;;
3)
clear
uninstall_xiaoya_alist
return_menu "main_xiaoya_alist"
;;
4)
clear
if command -v crontab > /dev/null 2>&1; then
if crontab -l | grep xiaoya_data_downloader > /dev/null 2>&1; then
for i in $(seq -w 3 -1 0); do
echo -en "即将删除同步定时任务${Blue} $i ${Font}\r"
sleep 1
done
uninstall_xiaoya_alist_sync_data
clear
INFO "已删除"
else
INFO "功能已弃用,目前只提供删除!"
fi
elif [ -f /etc/synoinfo.conf ]; then
if grep 'xiaoya_data_downloader' /etc/crontab > /dev/null 2>&1; then
for i in $(seq -w 3 -1 0); do
echo -en "即将删除同步定时任务${Blue} $i ${Font}\r"
sleep 1
done
uninstall_xiaoya_alist_sync_data
clear
INFO "已删除"
else
INFO "功能已弃用,目前只提供删除!"
fi
else
INFO "功能已弃用,目前只提供删除!"
fi
return_menu "main_xiaoya_alist"
;;
0)
clear
main_return
;;
*)
clear
ERROR '请输入正确数字 [0-4]'
main_xiaoya_alist
;;
esac
}
function get_docker0_url() {
if command -v ifconfig > /dev/null 2>&1; then
docker0=$(ifconfig docker0 | awk '/inet / {print $2}' | sed 's/addr://')
else
docker0=$(ip addr show docker0 | awk '/inet / {print $2}' | cut -d '/' -f 1)
fi
if [ -n "$docker0" ]; then
INFO "docker0 的 IP 地址是:$docker0"
else
WARN "无法获取 docker0 的 IP 地址!"
docker0=$(ip address | grep inet | grep -v 172.17 | grep -v 127.0.0.1 | grep -v inet6 | awk '{print $2}' | sed 's/addr://' | head -n1 | cut -f1 -d"/")
INFO "尝试使用本地IP:${docker0}"
fi
}
function test_xiaoya_status() {
get_docker0_url
INFO "测试xiaoya的联通性..."
if curl -siL http://127.0.0.1:5678/d/README.md | grep -v 302 | grep "x-oss-"; then
xiaoya_addr="http://127.0.0.1:5678"
elif curl -siL http://${docker0}:5678/d/README.md | grep -v 302 | grep "x-oss-"; then
xiaoya_addr="http://${docker0}:5678"
else
if [ -s ${CONFIG_DIR}/docker_address.txt ]; then
docker_address=$(head -n1 ${CONFIG_DIR}/docker_address.txt)
if curl -siL ${docker_address}/d/README.md | grep -v 302 | grep "x-oss-"; then
xiaoya_addr=${docker_address}
else
__xiaoya_connectivity_detection=$(cat ${DDSREM_CONFIG_DIR}/xiaoya_connectivity_detection.txt)
if [ "${__xiaoya_connectivity_detection}" == "false" ]; then
xiaoya_addr=${docker_address}
WARN "您已设置跳过小雅连通性检测"
else
ERROR "请检查xiaoya是否正常运行后再试"
ERROR "小雅日志如下:"
docker logs --tail 8 "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)"
exit 1
fi
fi
else
ERROR "请先配置 ${CONFIG_DIR}/docker_address.txt 后重试"
exit 1
fi
fi
INFO "连接小雅地址为 ${xiaoya_addr}"
}
function test_disk_capacity() {
if [ ! -d "${MEDIA_DIR}" ]; then
mkdir -p "${MEDIA_DIR}"
fi
free_size=$(df -P "${MEDIA_DIR}" | tail -n1 | awk '{print $4}')