forked from xiaoyaDev/xiaoya-alist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
1887 lines (1622 loc) · 63.7 KB
/
main.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
#
# ——————————————————————————————————————————————————————————————————————————————————
# __ ___ _ _ _
# \ \ / (_) /\ | (_) | |
# \ V / _ __ _ ___ _ _ __ _ / \ | |_ ___| |_
# > < | |/ _` |/ _ \| | | |/ _` | / /\ \ | | / __| __|
# / . \| | (_| | (_) | |_| | (_| | / ____ \| | \__ \ |_
# /_/ \_\_|\__,_|\___/ \__, |\__,_| /_/ \_\_|_|___/\__|
# __/ |
# |___/
#
# Copyright (c) 2023 DDSRem <https://blog.ddsrem.com>
#
# This is free software, licensed under the Mit License.
#
# ——————————————————————————————————————————————————————————————————————————————————
#
# bash -c "$(curl http://docker.xiaoya.pro/update_new.sh | awk '{gsub("/etc/xiaoya", "/ssd/data/docker/xiaoya/xiaoya"); print}')"
#
# bash -c "$(curl http://docker.xiaoya.pro/emby_plus.sh \
# | awk '{gsub("emby/embyserver:4.8.0.56", "amilys/embyserver:4.8.0.56"); print}' \
# | awk '{gsub("emby/embyserver_arm64v8:4.8.0.56", "amilys/embyserver:4.8.0.56"); print}' \
# | awk '{gsub("--name emby", "--name xiaoya-emby"); print}')"
#
# bash -c "$(curl -s https://xiaoyahelper.zengge99.eu.org/aliyun_clear.sh| tail -n +2)" -s 3 -tg
#
# docker run -d -p 4567:4567 -p 5344:80 -e ALIST_PORT=5344 --restart=always -v /etc/xiaoya:/data --name=xiaoya-tvbox haroldli/xiaoya-tvbox
# bash -c "$(curl -fsSL https://d.har01d.cn/update_xiaoya.sh)"
#
# bash -c "$(curl http://docker.xiaoya.pro/update_new.sh)"
#
# find ./ -name "*.strm" -exec sed \-i "s#http://127.0.0.1:5678#自己的地址#g; s# #%20#g; s#|#%7C#g" {} \;
#
# bash -c "$(curl http://docker.xiaoya.pro/emby.sh)" -s /媒体库目录
#
# bash -c "$(curl http://docker.xiaoya.pro/resilio.sh)" -s /媒体库目录
#
# 0 6 * * * bash -c "$(curl http://docker.xiaoya.pro/sync_emby_config.sh)" -s /媒体库目录
#
# ——————————————————————————————————————————————————————————————————————————————————
#
# The functions that the script can call are 'INFO' 'WARN' 'ERROR'
# INFO function use(log output): INFO "xxxx"
# WARN function use(log output): WARN "xxxx"
# ERROR function use(log output): ERROR "xxxx"
#
# ——————————————————————————————————————————————————————————————————————————————————
#
DATE_VERSION="v1.0.7-2024_01_28_21_12"
#
# ——————————————————————————————————————————————————————————————————————————————————
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}"
}
DDSREM_CONFIG_DIR=/etc/DDSRem
function root_need() {
if [[ $EUID -ne 0 ]]; then
ERRO '此脚本必须以 root 身份运行!'
exit 1
fi
}
function packages_need() {
if ! which docker; then
ERROR "docker 未安装,请手动安装!"
exit 1
fi
if ! which curl; then
ERROR "curl 未安装,请手动安装!"
exit 1
fi
if ! which wget; then
ERROR "wget 未安装,请手动安装!"
exit 1
fi
}
function get_os() {
is64bit=$(getconf LONG_BIT)
_os=$(uname -s)
_os_all=$(uname -a)
if [ "${_os}" == "Darwin" ]; then
OSNAME='macos'
elif [ -f /etc/synoinfo.conf ]; then
OSNAME='synology'
elif [ -f /etc/openwrt_release ]; then
OSNAME='openwrt'
elif grep -Eqi "QNAP" /etc/issue; then
OSNAME='qnap'
elif grep -Eqi "openmediavault" /etc/issue || grep -Eqi "openmediavault" /etc/os-release; then
OSNAME='openmediavault'
elif echo -e "${_os_all}" | grep -Eqi "UnRaid"; then
OSNAME='unraid'
elif grep -Eqi "openSUSE" /etc/*-release; then
OSNAME='opensuse'
elif grep -Eqi "FreeBSD" /etc/*-release; then
OSNAME='freebsd'
elif grep -Eqi "EulerOS" /etc/*-release || grep -Eqi "openEuler" /etc/*-release; then
OSNAME='euler'
elif grep -Eqi "CentOS" /etc/issue || grep -Eqi "CentOS" /etc/*-release; then
OSNAME='rhel'
elif grep -Eqi "Fedora" /etc/issue || grep -Eqi "Fedora" /etc/*-release; then
OSNAME='rhel'
elif grep -Eqi "Rocky" /etc/issue || grep -Eqi "Rocky" /etc/*-release; then
OSNAME='rhel'
elif grep -Eqi "AlmaLinux" /etc/issue || grep -Eqi "AlmaLinux" /etc/*-release; then
OSNAME='rhel'
elif grep -Eqi "Amazon Linux" /etc/issue || grep -Eqi "Amazon Linux" /etc/*-release; then
OSNAME='amazon'
elif grep -Eqi "Debian" /etc/issue || grep -Eqi "Debian" /etc/os-release; then
OSNAME='debian'
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eqi "Ubuntu" /etc/os-release; then
OSNAME='ubuntu'
elif grep -Eqi "Alpine" /etc/issue || grep -Eq "Alpine" /etc/*-release; then
OSNAME='alpine'
else
OSNAME='unknow'
fi
}
function TODO() {
WARN "此功能未完成,请耐心等待开发者开发"
}
function judgment_container() {
if docker container inspect "${1}" > /dev/null 2>&1; then
echo -e "${Green}已安装${Font}"
else
echo -e "${Red}未安装${Font}"
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
}
function get_media_dir() {
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="/etc/xiaoya"
touch ${DDSREM_CONFIG_DIR}/xiaoya_alist_media_dir.txt
echo "${MEDIA_DIR}" > ${DDSREM_CONFIG_DIR}/xiaoya_alist_media_dir.txt
fi
}
function install_xiaoya_alist() {
INFO "小白全部回车即可完成安装!"
get_config_dir
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
touch "${CONFIG_DIR}"/mytoken.txt
touch "${CONFIG_DIR}"/myopentoken.txt
touch "${CONFIG_DIR}"/temp_transfer_folder_id.txt
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
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"/")
INFO "本地IP:${localip}"
INFO "是否使用host网络模式 [Y/n](默认 n 不使用)"
read -erp "NET_MODE:" NET_MODE
[[ -z "${NET_MODE}" ]] && NET_MODE="n"
if [[ ${NET_MODE} == [Yy] ]]; then
if [ ! -s "${CONFIG_DIR}"/docker_address.txt ]; then
echo "http://$localip:5678" > "${CONFIG_DIR}"/docker_address.txt
fi
docker pull xiaoyaliu/alist:hostmode
if [[ -f ${CONFIG_DIR}/proxy.txt ]] && [[ -s ${CONFIG_DIR}/proxy.txt ]]; then
proxy_url=$(head -n1 "${CONFIG_DIR}"/proxy.txt)
docker run -itd \
--env HTTP_PROXY="$proxy_url" \
--env HTTPS_PROXY="$proxy_url" \
--env no_proxy="*.aliyundrive.com" \
--network=host \
-v "${CONFIG_DIR}:/data" \
--restart=always \
--name="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)" \
xiaoyaliu/alist:hostmode
else
docker run -itd \
--network=host \
-v "${CONFIG_DIR}:/data" \
--restart=always \
--name="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)" \
xiaoyaliu/alist:hostmode
fi
fi
if [[ ${NET_MODE} == [Nn] ]]; then
if [ ! -s "${CONFIG_DIR}"/docker_address.txt ]; then
echo "http://$localip:5678" > "${CONFIG_DIR}"/docker_address.txt
fi
docker pull xiaoyaliu/alist:latest
if [[ -f ${CONFIG_DIR}/proxy.txt ]] && [[ -s ${CONFIG_DIR}/proxy.txt ]]; then
proxy_url=$(head -n1 "${CONFIG_DIR}"/proxy.txt)
docker run -itd \
-p 5678:80 \
-p 2345:2345 \
-p 2346:2346 \
--env HTTP_PROXY="$proxy_url" \
--env HTTPS_PROXY="$proxy_url" \
--env no_proxy="*.aliyundrive.com" \
-v "${CONFIG_DIR}:/data" \
--restart=always \
--name="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)" \
xiaoyaliu/alist:latest
else
docker run -itd \
-p 5678:80 \
-p 2345:2345 \
-p 2346:2346 \
-v "${CONFIG_DIR}:/data" \
--restart=always \
--name="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)" \
xiaoyaliu/alist:latest
fi
fi
INFO "安装完成!"
}
function update_xiaoya_alist() {
for i in $(seq -w 3 -1 0); do
echo -en "即将开始更新小雅Alist${Blue} $i ${Font}\r"
sleep 1
done
docker pull containrrr/watchtower:latest
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower:latest \
--run-once \
--cleanup \
"$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)"
docker rmi containrrr/watchtower:latest
INFO "更新成功!"
}
function uninstall_xiaoya_alist() {
INFO "是否删除配置文件 [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
docker stop "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)"
docker rm "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)"
if docker inspect xiaoyaliu/alist:latest > /dev/null 2>&1; then
docker rmi xiaoyaliu/alist:latest
elif docker inspect xiaoyaliu/alist:hostmode > /dev/null 2>&1; then
docker rmi xiaoyaliu/alist:hostmode
fi
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)
rm -rf "${OLD_CONFIG_DIR}"
fi
fi
INFO "卸载成功!"
}
function main_xiaoya_alist() {
echo -e "——————————————————————————————————————————————————————————————————————————————————"
echo -e "${Blue}小雅Alist${Font}\n"
echo -e "1、安装"
echo -e "2、更新"
echo -e "3、卸载"
echo -e "4、返回上级"
echo -e "——————————————————————————————————————————————————————————————————————————————————"
read -erp "请输入数字 [1-4]:" num
case "$num" in
1)
clear
install_xiaoya_alist
;;
2)
clear
update_xiaoya_alist
;;
3)
clear
uninstall_xiaoya_alist
;;
4)
clear
main_return
;;
*)
clear
ERROR '请输入正确数字 [1-4]'
main_xiaoya_alist
;;
esac
}
function test_xiaoya_status() {
if [ -s "${CONFIG_DIR}"/docker_address.txt ]; then
docker_addr=$(head -n1 "${CONFIG_DIR}"/docker_address.txt)
else
ERROR "请先配置 ${CONFIG_DIR}/docker_address.txt 后重试"
exit 1
fi
INFO "测试xiaoya的联通性.......尝试连接 ${docker_addr}"
wget -4 -q -T 5 -O /tmp/test.md "${docker_addr}/README.md"
test_size=$(du -k /tmp/test.md | cut -f1)
if [[ "$test_size" -eq 196 ]] || [[ "$test_size" -eq 65 ]] || [[ "$test_size" -eq 0 ]]; then
ERROR "请检查xiaoya是否正常运行后再试"
exit 1
else
INFO "xiaoya容器正常工作"
fi
rm -rf /tmp/test.md
}
function pull_run_glue() {
if docker inspect xiaoyaliu/glue:latest > /dev/null 2>&1; then
local_sha=$(docker inspect --format='{{index .RepoDigests 0}}' xiaoyaliu/glue:latest | cut -f2 -d:)
remote_sha=$(curl -s "https://hub.docker.com/v2/repositories/xiaoyaliu/glue/tags/latest" | grep -o '"digest":"[^"]*' | grep -o '[^"]*$' | tail -n1 | cut -f2 -d:)
if [ ! "$local_sha" == "$remote_sha" ]; then
docker rmi xiaoyaliu/glue:latest
fi
fi
if [ -n "${extra_parameters}" ]; then
docker run -it \
--security-opt seccomp=unconfined \
--rm \
--net=host \
-v "${MEDIA_DIR}:/media" \
-v "${CONFIG_DIR}:/etc/xiaoya" \
"${extra_parameters}" \
-e LANG=C.UTF-8 \
xiaoyaliu/glue:latest \
"${@}"
else
docker run -it \
--security-opt seccomp=unconfined \
--rm \
--net=host \
-v "${MEDIA_DIR}:/media" \
-v "${CONFIG_DIR}:/etc/xiaoya" \
-e LANG=C.UTF-8 \
xiaoyaliu/glue:latest \
"${@}"
fi
docker rmi xiaoyaliu/glue:latest
}
function pull_run_ddsderek_glue() {
if docker inspect ddsderek/xiaoya-glue:latest > /dev/null 2>&1; then
local_sha=$(docker inspect --format='{{index .RepoDigests 0}}' ddsderek/xiaoya-glue:latest | cut -f2 -d:)
remote_sha=$(curl -s "https://hub.docker.com/v2/repositories/ddsderek/xiaoya-glue/tags/latest" | grep -o '"digest":"[^"]*' | grep -o '[^"]*$' | tail -n1 | cut -f2 -d:)
if [ ! "$local_sha" == "$remote_sha" ]; then
docker rmi ddsderek/xiaoya-glue:latest
fi
fi
if [ -n "${extra_parameters}" ]; then
docker run -it \
--security-opt seccomp=unconfined \
--rm \
--net=host \
-v "${MEDIA_DIR}:/media" \
-v "${CONFIG_DIR}:/etc/xiaoya" \
"${extra_parameters}" \
-e LANG=C.UTF-8 \
ddsderek/xiaoya-glue:latest \
"${@}"
else
docker run -it \
--security-opt seccomp=unconfined \
--rm \
--net=host \
-v "${MEDIA_DIR}:/media" \
-v "${CONFIG_DIR}:/etc/xiaoya" \
-e LANG=C.UTF-8 \
ddsderek/xiaoya-glue:latest \
"${@}"
fi
docker rmi ddsderek/xiaoya-glue:latest
}
function set_emby_server_infuse_api_key() {
if command -v ifconfig > /dev/null 2>&1; then
docker0=$(ifconfig docker0 | grep "inet " | awk '{print $2}' | sed 's/addr://' | head -n1)
else
docker0=$(ip addr show docker0 | grep "inet " | awk '{print $2}' | sed 's/addr://' | head -n1 | cut -f1 -d/)
fi
echo "http://$docker0:6908" > "${CONFIG_DIR}"/emby_server.txt
echo "e825ed6f7f8f44ffa0563cddaddce14d" > "${CONFIG_DIR}"/infuse_api_key.txt
}
function download_unzip_xiaoya_all_emby() {
get_config_dir
get_media_dir
test_xiaoya_status
mkdir -p "${MEDIA_DIR}/temp"
rm -rf "${MEDIA_DIR}/config"
free_size=$(df -P "${MEDIA_DIR}" | tail -n1 | awk '{print $4}')
free_size=$((free_size))
free_size_G=$((free_size / 1024 / 1024))
if [ "$free_size" -le 63886080 ]; then
ERROR "空间剩余容量不够:${free_size_G}G 小于最低要求140G"
exit 1
else
INFO "磁盘容量:${free_size_G}G"
fi
mkdir -p "${MEDIA_DIR}/xiaoya"
mkdir -p "${MEDIA_DIR}/config"
chmod 755 "${MEDIA_DIR}"
chown root:root "${MEDIA_DIR}"
if command -v ifconfig > /dev/null 2>&1; then
docker0=$(ifconfig docker0 | grep "inet " | awk '{print $2}' | sed 's/addr://' | head -n1)
else
docker0=$(ip addr show docker0 | grep "inet " | awk '{print $2}' | sed 's/addr://' | head -n1 | cut -f1 -d/)
fi
INFO "开始下载解压..."
pull_run_glue '/update_all.sh'
set_emby_server_infuse_api_key
INFO "设置目录权限..."
chmod -R 777 "${MEDIA_DIR}"
INFO "下载解压完成!"
}
function unzip_xiaoya_all_emby() {
get_config_dir
get_media_dir
test_xiaoya_status
mkdir -p "${MEDIA_DIR}"/temp
rm -rf "${MEDIA_DIR}"/config
free_size=$(df -P "${MEDIA_DIR}" | tail -n1 | awk '{print $4}')
free_size=$((free_size))
free_size_G=$((free_size / 1024 / 1024))
if [ "$free_size" -le 63886080 ]; then
ERROR "空间剩余容量不够:${free_size_G}G 小于最低要求140G"
exit 1
else
INFO "磁盘容量:${free_size_G}G"
fi
mkdir -p "${MEDIA_DIR}"/xiaoya
mkdir -p "${MEDIA_DIR}"/config
chmod 755 "${MEDIA_DIR}"
chown root:root "${MEDIA_DIR}"
if command -v ifconfig > /dev/null 2>&1; then
docker0=$(ifconfig docker0 | grep "inet " | awk '{print $2}' | sed 's/addr://' | head -n1)
else
docker0=$(ip addr show docker0 | grep "inet " | awk '{print $2}' | sed 's/addr://' | head -n1 | cut -f1 -d/)
fi
INFO "开始解压..."
pull_run_glue '/unzip.sh'
set_emby_server_infuse_api_key
INFO "设置目录权限..."
chmod -R 777 "${MEDIA_DIR}"
INFO "解压完成!"
}
function download_xiaoya_emby() {
get_config_dir
get_media_dir
test_xiaoya_status
mkdir -p "${MEDIA_DIR}"/temp
free_size=$(df -P "${MEDIA_DIR}" | tail -n1 | awk '{print $4}')
free_size=$((free_size))
free_size_G=$((free_size / 1024 / 1024))
INFO "磁盘容量:${free_size_G}G"
mkdir -p "${MEDIA_DIR}"/xiaoya
mkdir -p "${MEDIA_DIR}"/config
chmod 755 "${MEDIA_DIR}"
chown root:root "${MEDIA_DIR}"
INFO "开始下载 ${1} ..."
docker_addr=$(head -n1 "${CONFIG_DIR}"/docker_address.txt)
extra_parameters="--workdir=/media/temp"
pull_run_glue aria2c -o "${1}" --auto-file-renaming=false -c -x6 "${docker_addr}/d/元数据/${1}"
INFO "设置目录权限..."
chmod 777 "${MEDIA_DIR}"/temp/"${1}"
INFO "下载完成!"
}
function unzip_xiaoya_emby() {
get_config_dir
get_media_dir
free_size=$(df -P "${MEDIA_DIR}" | tail -n1 | awk '{print $4}')
free_size=$((free_size))
free_size_G=$((free_size / 1024 / 1024))
INFO "磁盘容量:${free_size_G}G"
mkdir -p "${MEDIA_DIR}"/xiaoya
mkdir -p "${MEDIA_DIR}"/config
chmod 755 "${MEDIA_DIR}"
chown root:root "${MEDIA_DIR}"
INFO "开始解压 ${1} ..."
docker_addr=$(head -n1 "${CONFIG_DIR}"/docker_address.txt)
if [ "${1}" == "config.mp4" ]; then
extra_parameters="--workdir=/media"
pull_run_glue 7z x -aoa -mmt=16 temp/config.mp4
INFO "设置目录权限..."
chmod 777 "${MEDIA_DIR}"/config
else
extra_parameters="--workdir=/media/xiaoya"
pull_run_glue 7z x -aoa -mmt=16 /media/temp/"${1}"
INFO "设置目录权限..."
chmod 777 "${MEDIA_DIR}"/xiaoya
fi
INFO "解压完成!"
}
function main_download_unzip_xiaoya_emby() {
echo -e "——————————————————————————————————————————————————————————————————————————————————"
echo -e "${Blue}下载/解压 元数据${Font}\n"
echo -e "1、下载并解压 全部元数据"
echo -e "2、解压 全部元数据"
echo -e "3、下载 all.mp4"
echo -e "4、解压 all.mp4"
echo -e "5、下载 config.mp4"
echo -e "6、解压 config.mp4"
echo -e "7、下载 pikpak.mp4"
echo -e "8、解压 pikpak.mp4"
echo -e "9、返回上级"
echo -e "——————————————————————————————————————————————————————————————————————————————————"
read -erp "请输入数字 [1-9]:" num
case "$num" in
1)
clear
download_unzip_xiaoya_all_emby
;;
2)
clear
unzip_xiaoya_all_emby
;;
3)
clear
download_xiaoya_emby "all.mp4"
;;
4)
clear
unzip_xiaoya_emby "all.mp4"
;;
5)
clear
download_xiaoya_emby "config.mp4"
;;
6)
clear
unzip_xiaoya_emby "config.mp4"
;;
7)
clear
download_xiaoya_emby "pikpak.mp4"
;;
8)
clear
unzip_xiaoya_emby "pikpak.mp4"
;;
9)
clear
main_xiaoya_all_emby
;;
*)
clear
ERROR '请输入正确数字 [1-9]'
main_download_unzip_xiaoya_emby
;;
esac
}
function install_emby_embyserver() {
cpu_arch=$(uname -m)
INFO "开始安装Emby容器....."
case $cpu_arch in
"x86_64" | *"amd64"*)
if [ -n "${extra_parameters}" ]; then
docker run -itd \
--name="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)" \
-v "${MEDIA_DIR}/config:/config" \
-v "${MEDIA_DIR}/xiaoya:/media" \
-v /etc/nsswitch.conf:/etc/nsswitch.conf \
--add-host="xiaoya.host:$xiaoya_host" \
--net=host \
--privileged=true \
"${extra_parameters}" \
-e PUID=0 \
-e PGID=0 \
--restart=always \
emby/embyserver:4.8.0.56
else
docker run -itd \
--name="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)" \
-v "${MEDIA_DIR}/config:/config" \
-v "${MEDIA_DIR}/xiaoya:/media" \
-v /etc/nsswitch.conf:/etc/nsswitch.conf \
--add-host="xiaoya.host:$xiaoya_host" \
--net=host \
--privileged=true \
-e PUID=0 \
-e PGID=0 \
--restart=always \
emby/embyserver:4.8.0.56
fi
;;
"aarch64" | *"arm64"* | *"armv8"* | *"arm/v8"*)
if [ -n "${extra_parameters}" ]; then
docker run -itd \
--name="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)" \
-v "${MEDIA_DIR}/config:/config" \
-v "${MEDIA_DIR}/xiaoya:/media" \
-v /etc/nsswitch.conf:/etc/nsswitch.conf \
--add-host="xiaoya.host:$xiaoya_host" \
--net=host \
--privileged=true \
"${extra_parameters}" \
-e PUID=0 \
-e PGID=0 \
--restart=always \
emby/embyserver_arm64v8:4.8.0.56
else
docker run -itd \
--name="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)" \
-v "${MEDIA_DIR}/config:/config" \
-v "${MEDIA_DIR}/xiaoya:/media" \
-v /etc/nsswitch.conf:/etc/nsswitch.conf \
--add-host="xiaoya.host:$xiaoya_host" \
--net=host \
--privileged=true \
-e PUID=0 \
-e PGID=0 \
--restart=always \
emby/embyserver_arm64v8:4.8.0.56
fi
;;
*)
ERROR "目前只支持amd64和arm64架构,你的架构是:$cpu_arch"
exit 1
;;
esac
}
function install_amilys_embyserver() {
cpu_arch=$(uname -m)
INFO "开始安装Emby容器....."
case $cpu_arch in
"x86_64" | *"amd64"*)
if [ -n "${extra_parameters}" ]; then
docker run -itd \
--name "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)" \
-v "${MEDIA_DIR}/config:/config" \
-v "${MEDIA_DIR}/xiaoya:/media" \
-v /etc/nsswitch.conf:/etc/nsswitch.conf \
--add-host="xiaoya.host:$xiaoya_host" \
--net=host \
--privileged=true \
"${extra_parameters}" \
-e PUID=0 \
-e PGID=0 \
--restart=always \
amilys/embyserver:4.8.0.56
else
docker run -itd \
--name "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)" \
-v "${MEDIA_DIR}/config:/config" \
-v "${MEDIA_DIR}/xiaoya:/media" \
-v /etc/nsswitch.conf:/etc/nsswitch.conf \
--add-host="xiaoya.host:$xiaoya_host" \
--net=host \
--privileged=true \
-e PUID=0 \
-e PGID=0 \
--restart=always \
amilys/embyserver:4.8.0.56
fi
;;
*)
ERROR "目前只支持amd64架构,你的架构是:$cpu_arch"
exit 1
;;
esac
}
function choose_emby_image() {
INFO "请选择使用的Emby镜像 [ 1:amilys/embyserver | 2:emby/embyserver ](默认 2)"
read -erp "IMAGE:" IMAGE
[[ -z "${IMAGE}" ]] && IMAGE="2"
if [[ ${IMAGE} == [1] ]]; then
install_amilys_embyserver
elif [[ ${IMAGE} == [2] ]]; then
install_emby_embyserver
else
ERROR "输入无效,请重新选择"
choose_emby_image
fi
}
function install_emby_xiaoya_all_emby() {
if ! grep xiaoya.host /etc/hosts; then
echo -e "127.0.0.1\txiaoya.host\n" >> /etc/hosts
xiaoya_host="127.0.0.1"
else
xiaoya_host=$(grep xiaoya.host /etc/hosts | awk '{print $1}' | head -n1)
fi
container_run_extra_parameters=$(cat ${DDSREM_CONFIG_DIR}/container_run_extra_parameters.txt)
if [ "${container_run_extra_parameters}" == "true" ]; then
INFO "请输入其他参数(默认 无 )"
read -erp "Extra parameters:" extra_parameters
fi
if [ "$1" == "official" ]; then
install_emby_embyserver
else
choose_emby_image
fi
set_emby_server_infuse_api_key
sleep 5
INFO "重启小雅容器中..."
docker restart \
"$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_alist_name.txt)" \
"$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)"
INFO "Emby安装完成!"
}
function docker_address_xiaoya_all_emby() {
get_config_dir
get_media_dir
pull_run_ddsderek_glue "/docker_address.sh"
INFO "替换DOCKER_ADDRESS完成!"
}
function uninstall_xiaoya_all_emby() {
INFO "是否删除配置文件 [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 "即将开始卸载小雅Emby全家桶${Blue} $i ${Font}\r"
sleep 1
done
docker stop "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)"
docker rm "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)"
cpu_arch=$(uname -m)
case $cpu_arch in
"x86_64" | *"amd64"*)
if docker inspect amilys/embyserver:4.8.0.56 > /dev/null 2>&1; then
docker rmi amilys/embyserver:4.8.0.56
elif docker inspect emby/embyserver:4.8.0.56 > /dev/null 2>&1; then
docker rmi emby/embyserver:4.8.0.56
fi
;;
"aarch64" | *"arm64"* | *"armv8"* | *"arm/v8"*)
docker rmi emby/embyserver_arm64v8:4.8.0.56
;;
esac
if [[ ${CLEAN_CONFIG} == [Yy] ]]; then
INFO "清理配置文件..."
if [ -f ${DDSREM_CONFIG_DIR}/xiaoya_alist_media_dir.txt ]; then
OLD_MEDIA_DIR=$(cat ${DDSREM_CONFIG_DIR}/xiaoya_alist_media_dir.txt)
rm -rf "${OLD_MEDIA_DIR}"
fi
fi
INFO "卸载成功!"
}
function install_resilio() {
if [ -f ${DDSREM_CONFIG_DIR}/resilio_config_dir.txt ]; then
OLD_CONFIG_DIR=$(cat ${DDSREM_CONFIG_DIR}/resilio_config_dir.txt)
INFO "已读取Resilio-Sync配置文件路径:${OLD_CONFIG_DIR} (默认不更改回车继续,如果需要更改请输入新路径)"
read -erp "CONFIG_DIR:" CONFIG_DIR
[[ -z "${CONFIG_DIR}" ]] && CONFIG_DIR=${OLD_CONFIG_DIR}
echo "${CONFIG_DIR}" > ${DDSREM_CONFIG_DIR}/resilio_config_dir.txt
else
INFO "请输入配置文件目录(默认 /etc/xiaoya/resilio )"
read -erp "CONFIG_DIR:" CONFIG_DIR
[[ -z "${CONFIG_DIR}" ]] && CONFIG_DIR="/etc/xiaoya/resilio"
touch ${DDSREM_CONFIG_DIR}/resilio_config_dir.txt
echo "${CONFIG_DIR}" > ${DDSREM_CONFIG_DIR}/resilio_config_dir.txt
fi
INFO "请输入后台管理端口(默认 8888 )"
read -erp "HT_PORT:" HT_PORT
[[ -z "${HT_PORT}" ]] && HT_PORT="8888"
container_run_extra_parameters=$(cat ${DDSREM_CONFIG_DIR}/container_run_extra_parameters.txt)
if [ "${container_run_extra_parameters}" == "true" ]; then
INFO "请输入其他参数(默认 无 )"
read -erp "Extra parameters:" extra_parameters
fi
get_media_dir
if [ ! -d "${MEDIA_DIR}"/config_sync ]; then
mkdir -p "${MEDIA_DIR}"/config_sync
chmod 777 "${MEDIA_DIR}"/config_sync
cp -r "${MEDIA_DIR}"/config/* "${MEDIA_DIR}"/config_sync/
fi
INFO "开始安装resilio..."
if [ -n "${extra_parameters}" ]; then
docker run -d \
--name="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_resilio_name.txt)" \
-e PUID=0 \
-e PGID=0 \
-e TZ=Asia/Shanghai \
-p "${HT_PORT}":8888 \
-p 55555:55555 \
-v "${CONFIG_DIR}:/config" \
-v "${CONFIG_DIR}/downloads:/downloads" \
-v "${MEDIA_DIR}:/sync" \
"${extra_parameters}" \
--restart=always \
linuxserver/resilio-sync:latest
else
docker run -d \
--name="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_resilio_name.txt)" \