forked from ailg666/xy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxy_install_old.sh
2725 lines (2550 loc) · 118 KB
/
xy_install_old.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
PATH=${PATH}:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin
export PATH
Blue="\033[1;34m"
Green="\033[1;32m"
Red="\033[1;31m"
Yellow="\033[1;33m"
NC="\033[0m"
INFO="[${Green}INFO${NC}]"
ERROR="[${Red}ERROR${NC}]"
WARN="[${Yellow}WARN${NC}]"
function INFO() {
echo -e "${INFO} ${1}"
}
function ERROR() {
echo -e "${ERROR} ${1}"
}
function WARN() {
echo -e "${WARN} ${1}"
}
function root_need() {
if [[ $EUID -ne 0 ]]; then
ERROR '此脚本必须以 root 身份运行!'
exit 1
fi
}
function ___install_docker() {
if ! which docker; then
WARN "docker 未安装,脚本尝试自动安装..."
wget -qO- get.docker.com | bash
if which docker; then
INFO "docker 安装成功!"
else
ERROR "docker 安装失败,请手动安装!"
exit 1
fi
fi
}
install_package() {
local package=$1
local install_cmd="$2 $package"
if ! which $package > /dev/null 2>&1; then
WARN "$package 未安装,脚本尝试自动安装..."
if eval "$install_cmd"; then
INFO "$package 安装成功!"
else
ERROR "$package 安装失败,请手动安装!"
exit 1
fi
fi
}
# 用grep -Eqi "QNAP" /etc/issue判断威联通系统
packages_need() {
local update_cmd
local install_cmd
if [ -f /etc/debian_version ]; then
update_cmd="apt update -y"
install_cmd="apt install -y"
elif [ -f /etc/redhat-release ]; then
install_cmd="yum install -y"
elif [ -f /etc/SuSE-release ]; then
update_cmd="zypper refresh"
install_cmd="zypper install"
elif [ -f /etc/alpine-release ]; then
install_cmd="apk add"
elif [ -f /etc/arch-release ]; then
update_cmd="pacman -Sy --noconfirm"
install_cmd="pacman -S --noconfirm"
else
ERROR "不支持的操作系统."
exit 1
fi
[ -n "$update_cmd" ] && eval "$update_cmd"
install_package "curl" "$install_cmd"
if ! which wget; then
install_package "wget" "$install_cmd"
fi
___install_docker
}
function check_space() {
free_size=$(df -P "$1" | tail -n1 | awk '{print $4}')
free_size_G=$((free_size / 1024 / 1024))
if [ "$free_size_G" -lt "$2" ]; then
ERROR "空间剩余容量不够:${free_size_G}G 小于最低要求${2}G"
exit 1
else
INFO "磁盘可用空间:${free_size_G}G"
fi
}
function get_emby_image() {
cpu_arch=$(uname -m)
case $cpu_arch in
"x86_64" | *"amd64"*)
emby_image="emby/embyserver:4.8.0.56"
;;
"aarch64" | *"arm64"* | *"armv8"* | *"arm/v8"*)
emby_image="emby/embyserver_arm64v8:4.8.0.56"
;;
"armv7l")
emby_image="emby/embyserver_arm32v7:4.8.0.56"
;;
*)
ERROR "不支持你的CPU架构:$cpu_arch"
exit 1
;;
esac
if ! docker images --format '{{.Repository}}:{{.Tag}}' | grep -q ${emby_image}; then
for i in {1..3}; do
if docker_pull $emby_image; then
INFO "${emby_image}镜像拉取成功!"
break
fi
done
fi
docker images --format '{{.Repository}}:{{.Tag}}' | grep -q ${emby_image} || (ERROR "${emby_image}镜像拉取失败,请手动安装emby,无需重新运行本脚本,小雅媒体库在${media_dir}!" && exit 1)
}
function get_jellyfin_image() {
cpu_arch=$(uname -m)
case $cpu_arch in
"x86_64" | *"amd64"*)
linux_version=$(uname -r | cut -d"." -f1)
if [ "${linux_version}" -lt 5 ];then
[[ "${f4_select}" == [56] ]] && emby_image="jellyfin/jellyfin:10.9.6" || emby_image="nyanmisaka/jellyfin:240220-amd64-legacy"
else
[[ "${f4_select}" == [56] ]] && emby_image="jellyfin/jellyfin:10.9.6" || emby_image="nyanmisaka/jellyfin:latest"
fi
;;
*)
ERROR "不支持你的CPU架构:$cpu_arch"
exit 1
;;
esac
for i in {1..3}; do
if docker_pull $emby_image; then
INFO "${emby_image}镜像拉取成功!"
break
fi
done
docker images --format '{{.Repository}}:{{.Tag}}' | grep -q ${emby_image} || (ERROR "${emby_image}镜像拉取失败,请手动安装emby,无需重新运行本脚本,小雅媒体库在${media_dir}!" && exit 1)
}
function get_emby_happy_image() {
cpu_arch=$(uname -m)
case $cpu_arch in
"x86_64" | *"amd64"*)
emby_image="amilys/embyserver:4.8.0.56"
;;
"aarch64" | *"arm64"* | *"armv8"* | *"arm/v8"*)
emby_image="amilys/embyserver_arm64v8:4.8.6.0"
;;
*)
ERROR "不支持你的CPU架构:$cpu_arch"
exit 1
;;
esac
for i in {1..3}; do
if docker_pull $emby_image; then
INFO "${emby_image}镜像拉取成功!"
break
fi
done
docker images --format '{{.Repository}}:{{.Tag}}' | grep -q ${emby_image} || (ERROR "${emby_image}镜像拉取失败,请手动安装emby,无需重新运行本脚本,小雅媒体库在${img_mount}!" && exit 1)
}
function get_config_path() {
images=("ailg/alist" "xiaoyaliu/alist" "ailg/g-box")
results=()
for image in "${images[@]}"; do
while IFS= read -r line; do
container_name=$(echo $line | awk '{print $NF}')
if command -v jq > /dev/null 2>&1; then
config_dir=$(docker inspect $container_name | jq -r '.[].Mounts[] | select(.Destination=="/data") | .Source')
else
# config_dir=$(docker inspect --format '{{ (index .Mounts 0).Source }}' "$container_name")
config_dir=$(docker inspect --format '{{range .Mounts}}{{if eq .Destination "/data"}}{{.Source}}{{end}}{{end}}' "$container_name")
fi
results+=("$container_name $config_dir")
done < <(docker ps -a | grep "$image")
done
if [ ${#results[@]} -eq 0 ]; then
#read -p "没有找到任何符合条件的容器,请输入docker_name: " docker_name
read -erp "请输入alist/g-box的配置目录路径:(直接回车将使用/etc/xiaoya目录) " config_dir
config_dir=${config_dir:-"/etc/xiaoya"}
check_path $config_dir
elif [ ${#results[@]} -eq 1 ]; then
docker_name=$(echo "${results[0]}" | awk '{print $1}')
config_dir=$(echo "${results[0]}" | awk '{print $2}')
else
for i in "${!results[@]}"; do
printf "[ %-1d ] 容器名: \033[1;33m%-20s\033[0m 配置路径: \033[1;33m%s\033[0m\n" $((i+1)) $(echo "${results[$i]}" | awk '{print $1}') $(echo "${results[$i]}" | awk '{print $2}')
done
t=15
while [[ -z "$choice" && $t -gt 0 ]]; do
printf "\r找到多个alist相关容器,请选择配置目录所在的正确容器(默认选择第一个正在运行的容器):(%2d 秒后将默认确认):" $t
read -r -t 1 -n 1 choice
[ $? -eq 0 ] && break
t=$((t - 1))
done
choice=${choice:-1}
docker_name=$(echo "${results[$((choice-1))]}" | awk '{print $1}')
config_dir=$(echo "${results[$((choice-1))]}" | awk '{print $2}')
fi
echo -e "\033[1;37m你选择的alist容器是:\033[1;35m$docker_name\033[0m"
echo -e "\033[1;37m你选择的配置目录是:\033[1;35m$config_dir\033[0m"
}
function get_jf_media_path() {
jf_name=${1}
if command -v jq; then
media_dir=$(docker inspect $jf_name | jq -r '.[].Mounts[] | select(.Destination=="/media_jf") | .Source')
else
media_dir=$(docker inspect $jf_name | awk '/"Destination": "\/media_jf"/{print a} {a=$0}' | awk -F\" '{print $4}')
fi
if [[ -n $media_dir ]]; then
media_dir=$(dirname "$media_dir")
echo -e "\033[1;37m找到您的小雅姐夫媒体库路径是: \033[1;35m\n$media_dir\033[0m"
echo -e "\n"
read -erp "确认请按任意键,或者按N/n手动输入路径:" f12_select_2
if [[ $f12_select_2 == [Nn] ]]; then
echo -e "\033[1;35m请输入您的小雅姐夫媒体库路径:\033[0m"
read -r media_dir
check_path $media_dir
fi
echo -e "\n"
else
echo -e "\033[1;35m请输入您的小雅姐夫媒体库路径:\033[0m"
read -r media_dir
check_path $media_dir
fi
}
function get_emby_media_path() {
emby_name=${1:-emby}
if command -v jq; then
media_dir=$(docker inspect $emby_name | jq -r '.[].Mounts[] | select(.Destination=="/media") | .Source')
else
media_dir=$(docker inspect $emby_name | awk '/"Destination": "\/media"/{print a} {a=$0}' | awk -F\" '{print $4}')
fi
if [[ -n $media_dir ]]; then
media_dir=$(dirname "$media_dir")
echo -e "\033[1;37m找到您原来的小雅emby媒体库路径是: \033[1;35m\n$media_dir\033[0m"
echo -e "\n"
read -erp "确认请按任意键,或者按N/n手动输入路径:" f12_select_1
if [[ $f12_select_1 == [Nn] ]]; then
echo -e "\033[1;35m请输入您的小雅emby媒体库路径:\033[0m"
read -r media_dir
check_path $media_dir
fi
echo -e "\n"
else
echo -e "\033[1;35m请输入您的小雅emby媒体库路径:\033[0m"
read -r media_dir
check_path $media_dir
fi
}
meta_select() {
echo -e "———————————————————————————————————— \033[1;33mA I 老 G\033[0m —————————————————————————————————"
echo -e "\n"
echo -e "\033[1;32m1、config.mp4 —— 小雅姐夫的配置目录数据\033[0m"
echo -e "\n"
echo -e "\033[1;35m2、all.mp4 —— 除pikpak之外的所有小雅元数据\033[0m"
echo -e "\n"
echo -e "\033[1;32m3、pikpak.mp4 —— pikpak元数据(需魔法才能观看)\033[0m"
echo -e "\n"
echo -e "\033[1;32m4、全部安装\033[0m"
echo -e "\n"
echo -e "——————————————————————————————————————————————————————————————————————————————————"
echo -e "请选择您\033[1;31m需要安装\033[0m的元数据(输入序号,多项用逗号分隔):"
read -r f8_select
if ! [[ $f8_select =~ ^[1-4]([\,\,][1-4])*$ ]]; then
echo "输入的序号无效,请输入1到3之间的数字。"
exit 1
fi
if ! [[ $f8_select == "4" ]]; then
files=("config_jf.mp4" "all_jf.mp4" "pikpak_jf.mp4")
for i in {1..3}; do
file=${files[$i - 1]}
if ! [[ $f8_select == *$i* ]]; then
sed -i "/aria2c.*$file/d" /tmp/update_meta_jf.sh
sed -i "/7z.*$file/d" /tmp/update_meta_jf.sh
else
if [[ -f $media_dir/temp/$file ]] && ! [[ -f $media_dir/temp/$file.aria2 ]]; then
WARN "${Yellow}${file}文件已在${media_dir}/temp目录存在,是否要重新解压?$NC"
read -erp "请选择:(是-按任意键,否-按N/n键)" yn
if [[ $yn == [Nn] ]]; then
sed -i "/7z.*$file/d" /tmp/update_meta_jf.sh
sed -i "/aria2c.*$file/d" /tmp/update_meta_jf.sh
else
remote_size=$(curl -sL -D - -o /dev/null --max-time 5 "$docker_addr/d/ailg_jf/${file}" | grep "Content-Length" | cut -d' ' -f2)
local_size=$(du -b $media_dir/temp/$file | cut -f1)
[[ $remote_size == "$local_size" ]] && sed -i "/aria2c.*$file/d" /tmp/update_meta_jf.sh
fi
fi
fi
done
fi
}
get_emby_status() {
emby_list=()
emby_order=()
if command -v mktemp > /dev/null; then
temp_file=$(mktemp)
else
temp_file="/tmp/tmp_img"
fi
docker ps -a | grep -E "${search_img}" | awk '{print $1}' > "$temp_file"
while read -r container_id; do
if docker inspect --format '{{ range .Mounts }}{{ println .Source .Destination }}{{ end }}' $container_id | grep -qE "/xiaoya$ /media|\.img /media\.img"; then
container_name=$(docker ps -a --format '{{.Names}}' --filter "id=$container_id")
host_path=$(docker inspect --format '{{ range .Mounts }}{{ println .Source }}{{ end }}' $container_id | grep -E "/xiaoya$|\.img\b")
emby_list+=("$container_name:$host_path")
emby_order+=("$container_name")
fi
done < "$temp_file"
rm "$temp_file"
if [ ${#emby_list[@]} -ne 0 ]; then
echo -e "\033[1;37m默认会关闭以下您已安装的小雅emby/jellyfin容器,并删除名为emby/jellyfin_xy的容器!\033[0m"
for index in "${!emby_order[@]}"; do
name=${emby_order[$index]}
for entry in "${emby_list[@]}"; do
if [[ $entry == $name:* ]]; then
host_path=${entry#*:}
printf "[ %-1d ] 容器名: \033[1;33m%-20s\033[0m 媒体库路径: \033[1;33m%s\033[0m\n" $((index + 1)) $name $host_path
fi
done
done
fi
}
#镜像代理的内容抄的DDSRem大佬的,适当修改了一下
function docker_pull() {
if ! [[ "$skip_choose_mirror" == [Yy] ]]; then
mirrors=()
[ -z "${config_dir}" ] && get_config_path
INFO "正在从${config_dir}/docker_mirrors.txt文件获取代理点配置……"
while IFS= read -r line; do
mirrors+=("$line")
done < "${config_dir}/docker_mirrors.txt"
if command -v timeout > /dev/null 2>&1;then
for mirror in "${mirrors[@]}"; do
INFO "正在从${mirror}代理点为您下载镜像……"
#local_sha=$(timeout 300 docker pull "${mirror}/${1}" 2>&1 | grep 'Digest: sha256' | awk -F':' '{print $3}')
if command -v mktemp > /dev/null; then
tempfile=$(mktemp)
else
tempfile="/tmp/tmp_sha"
fi
timeout 300 docker pull "${mirror}/${1}" | tee "$tempfile"
local_sha=$(grep 'Digest: sha256' "$tempfile" | awk -F':' '{print $3}')
echo -e "local_sha:${local_sha}"
rm "$tempfile"
if [ -n "${local_sha}" ]; then
sed -i "\#${1}#d" "${config_dir}/ailg_sha.txt"
echo "${1} ${local_sha}" >> "${config_dir}/ailg_sha.txt"
[[ "${mirror}" == "docker.io" ]] && return 0
break
else
WARN "${1} 镜像拉取失败,正在进行重试..."
fi
done
else
for mirror in "${mirrors[@]}"; do
INFO "正在从${mirror}代理点为您下载镜像……"
timeout=200
(docker pull "${mirror}/${1}" 2>&1 | tee /dev/stderr | grep 'Digest: sha256' | awk -F':' '{print $3}' > "/tmp/tmp_sha") &
pid=$!
count=0
while kill -0 $pid 2>/dev/null; do
sleep 5
count=$((count+5))
if [ $count -ge $timeout ]; then
echo "Command timed out"
kill $pid
break
fi
done
local_sha=$(cat "/tmp/tmp_sha")
rm "/tmp/tmp_sha"
if [ -n "${local_sha}" ]; then
INFO "${1} 镜像拉取成功!"
sed -i "\#${1}#d" "${config_dir}/ailg_sha.txt"
echo "${1} ${local_sha}" >> "${config_dir}/ailg_sha.txt"
echo -e "local_sha:${local_sha}"
[[ "${mirror}" == "docker.io" ]] && return 0
break
else
WARN "${1} 镜像拉取失败,正在进行重试..."
fi
done
fi
if [ -n "$(docker images -q "${mirror}/${1}")" ]; then
docker tag "${mirror}/${1}" "${1}"
docker rmi "${mirror}/${1}"
return 0
else
ERROR "已尝试docker_mirrors.txt中所有镜像代理拉取失败,程序将退出,请检查网络后再试!"
WARN "如需重测速选择代理,请手动删除${config_dir}/docker_mirrors.txt文件后重新运行脚本!"
if [[ "${1}" == "ailg/g-box:hostmode" ]]; then
return 1
else
exit 1
fi
fi
else
tempfile="/tmp/tmp_sha"
docker pull "${1}" | tee "$tempfile"
local_sha=$(grep 'Digest: sha256' "$tempfile" | awk -F':' '{print $3}')
echo -e "local_sha:${local_sha}"
rm "$tempfile"
if [ -n "${local_sha}" ]; then
sed -i "\#${1}#d" "${config_dir}/ailg_sha.txt"
echo "${1} ${local_sha}" >> "${config_dir}/ailg_sha.txt"
return 0
else
WARN "${1} 镜像拉取失败,正在进行重试..."
return 1
fi
fi
}
update_ailg() {
[ -z "${config_dir}" ] && get_config_path
if [[ -n "$1" ]];then
update_img="$1"
fi
#local name_img
#name_img=$(echo "${update_img}" | awk -F'[/:]' '{print $2}')
#local tag_img
#tag_img=$(echo "${update_img}" | awk -F'[/:]' '{print $3}')
if [ -f $config_dir/ailg_sha.txt ]; then
local_sha=$(grep -E "${update_img}" "$config_dir/ailg_sha.txt" | awk '{print $2}')
else
local_sha=$(docker inspect -f'{{index .RepoDigests 0}}' "${update_img}" | cut -f2 -d:)
fi
for i in {1..3}; do
remote_sha=$(curl -sSLf https://gbox.ggbond.org/ailg_sha_remote.txt | grep -E "${update_img}" | awk '{print $2}')
[ -n "${remote_sha}" ] && break
done
#remote_sha=$(curl -s -m 20 "https://hub.docker.com/v2/repositories/ailg/${name_img}/tags/${tag_img}" | grep -oE '[0-9a-f]{64}' | tail -1)
#[ -z "${remote_sha}" ] && remote_sha=$(docker exec $docker_name cat "/${name_img}_${tag_img}_sha.txt")
if [ ! "$local_sha" == "$remote_sha" ]; then
docker rmi "${update_img}"
retries=0
max_retries=3
while [ $retries -lt $max_retries ]; do
if docker_pull "${update_img}"; then
INFO "${update_img} 镜像拉取成功!"
break
else
WARN "${update_img} 镜像拉取失败,正在进行第 $((retries + 1)) 次重试..."
retries=$((retries + 1))
fi
done
if [ $retries -eq $max_retries ]; then
ERROR "镜像拉取失败,已达到最大重试次数!"
if [[ "$update_img" == "ailg/g-box:hostmode" ]]; then
return 1
else
exit 1
fi
fi
elif [ -z "$local_sha" ] && [ -z "$remote_sha" ]; then
docker_pull "${update_img}"
fi
}
function user_select1() {
docker_name="$(docker ps -a | grep -E 'ailg/g-box' | awk '{print $NF}' | head -n1)"
if [ -n "${docker_name}" ]; then
WARN "您已安装g-box,包含老G版alist的所有功能,无需再安装老G版的alist!继续安装将自动卸载已安装的g-box容器!"
read -erp "是否卸载G-Box继续安装老G版alist?(确认按Y/y,否则按任意键返回!):" ow_install
if [[ $ow_install == [Yy] ]]; then
# config_dir=$(docker inspect --format '{{ (index .Mounts 0).Source }}' "${docker_name}")
config_dir=$(docker inspect --format '{{range .Mounts}}{{if eq .Destination "/data"}}{{.Source}}{{end}}{{end}}' "${docker_name}")
INFO "正在停止和删除${docker_name}容器……"
docker rm -f $docker_name
INFO "$docker_name 容器已删除"
else
main
return
fi
fi
echo -e "———————————————————————————————————— \033[1;33mA I 老 G\033[0m —————————————————————————————————"
echo -e "\n"
echo -e "\033[1;32m1、host版 - 无🍉十全大补瓜🍉第三方播放器(不再更新!)$NC"
echo -e "\n"
echo -e "\033[1;35m2、latest版 - 也是host网络模式!适配小雅emby/jellyfin速装版 有🍉十全大补瓜🍉第三方播放器,未装G-Box可装!$NC"
echo -e "\n"
echo -e "——————————————————————————————————————————————————————————————————————————————————"
while :;do
read -erp "请选择您要安装的版本(输入1-2,按b返回上级或按q退出):" ver_alist
case "$ver_alist" in
1)
host="host"
_update_img="ailg/alist:hostmode"
break
;;
2)
host=""
_update_img="ailg/alist:latest"
break
;;
[Bb])
clear
main
break
;;
[Qq])
exit
;;
*)
ERROR "输入错误,按任意键重新输入!"
read -rn 1
continue
;;
esac
done
if [[ $st_alist =~ "已安装" ]]; then
WARN "您的小雅ALIST老G版已安装,是否需要重装?"
read -erp "请选择:(确认重装按Y/y,否则按任意键返回!)" re_setup
if [[ $re_setup == [Yy] ]]; then
check_env
[ -z "${config_dir}" ] && get_config_path
INFO "小雅ALIST老G版配置路径为:$config_dir"
INFO "正在停止和删除旧的小雅alist容器"
docker stop $docker_name
docker rm $docker_name
INFO "$docker_name 容器已删除"
update_ailg "${_update_img}"
else
main
return
fi
else
check_env
INFO "正在检查和删除已安装的小雅alist"
rm_alist
INFO "原有小雅alist容器已删除"
if [[ -n "$config_dir" ]]; then
INFO "你原来小雅alist的配置路径是:${Blue}${config_dir}${NC},可使用原有配置继续安装!"
read -erp "确认请按任意键,或者按N/n手动输入路径:" user_select_0
if [[ $user_select_0 == [Nn] ]]; then
echo -e "\033[1;35m请输入您的小雅ALIST配置文件路径:\033[0m"
read -r config_dir
check_path $config_dir
INFO "小雅ALIST老G版配置路径为:$config_dir"
update_ailg "${_update_img}"
fi
else
read -erp "请输入小雅alist的安装路径,使用默认的/etc/xiaoya可直接回车:" config_dir
[[ -z $config_dir ]] && config_dir="/etc/xiaoya"
check_path $config_dir
INFO "小雅ALIST老G版配置路径为:$config_dir"
INFO "正在更新${_update_img}镜像……"
update_ailg "${_update_img}"
fi
fi
curl -o /tmp/update_new_jf.sh https://gbox.ggbond.org/update_new_jf.sh
for i in {1..5}; do
grep -q "长度不对" /tmp/update_new_jf.sh && break
echo -e "文件获取失败,正在进行第${i}次重试……"
rm -f /tmp/update_new_jf.sh >/dev/null 2>&1
curl -o /tmp/update_new_jf.sh https://gbox.ggbond.org/update_new_jf.sh
done
grep -q "长度不对" /tmp/update_new_jf.sh || {
echo -e "文件获取失败,检查网络后重新运行脚本!"
rm -f /tmp/update_new_jf.sh
exit 1
}
echo "http://127.0.0.1:6908" > $config_dir/emby_server.txt
echo "http://127.0.0.1:6909" > $config_dir/jellyfin_server.txt
bash -c "$(cat /tmp/update_new_jf.sh)" -s $config_dir $host
[ $? -eq 0 ] && INFO "${Blue}哇塞!你的小雅ALIST老G版安装完成了!$NC" || ERROR "哎呀!翻车失败了!"
}
function user_select2() {
if [[ $st_alist =~ "未安装" ]] && [[ $st_gbox =~ "未安装" ]]; then
ERROR "请先安装小雅ALIST老G版或G-Box,再执行本安装!"
main
return
fi
if [[ $st_jf =~ "已安装" ]]; then
WARN "您的小雅姐夫已安装,是否需要重装?"
read -erp "请选择:(确认重装按Y/y,否则按任意键返回!)" re_setup
if [[ $re_setup == [Yy] ]]; then
check_env
[ -z "${config_dir}" ] && get_config_path
get_jf_media_path "jellyfin_xy"
docker stop $jf_name
docker rm $jf_name
else
main
return
fi
else
[ -z "${config_dir}" ] && get_config_path
echo -e "\033[1;35m请输入您的小雅姐夫媒体库路径:\033[0m"
read -r media_dir
check_path $media_dir
fi
if [ -s $config_dir/docker_address.txt ]; then
docker_addr=$(head -n1 $config_dir/docker_address.txt)
else
echo "请先配置 $config_dir/docker_address.txt,以便获取docker 地址"
exit
fi
mkdir -p $media_dir/xiaoya
mkdir -p $media_dir/temp
curl -o /tmp/update_meta_jf.sh https://gbox.ggbond.org/update_meta_jf.sh
meta_select
chmod 777 /tmp/update_meta_jf.sh
docker run -i --security-opt seccomp=unconfined --rm --net=host -v /tmp:/tmp -v $media_dir:/media -v $config_dir:/etc/xiaoya -e LANG=C.UTF-8 ailg/ggbond:latest /tmp/update_meta_jf.sh
#dir=$(find $media_dir -type d -name "*config*" -print -quit)
mv "$media_dir/jf_config" "$media_dir/confg"
chmod -R 777 $media_dir/confg
chmod -R 777 $media_dir/xiaoya
host=$(echo $docker_addr | cut -f1,2 -d:)
host_ip=$(grep -oP '\d+\.\d+\.\d+\.\d+' $config_dir/docker_address.txt)
if ! [[ -f /etc/nsswitch.conf ]]; then
echo -e "hosts:\tfiles dns\nnetworks:\tfiles" > /etc/nsswitch.conf
fi
docker run -d --name jellyfin_xy -v /etc/nsswitch.conf:/etc/nsswitch.conf \
-v $media_dir/config_jf:/config \
-v $media_dir/xiaoya:/media_jf \
--user 0:0 \
-e JELLYFIN_CACHE_DIR=/config/cache \
-e HEALTHCHECK_URL=http://localhost:6909/health \
-p 6909:8096 \
-p 6920:8920 \
-p 1909:1900/udp \
-p 7369:7359/udp \
--privileged --add-host="xiaoya.host:${host_ip}" --restart always nyanmisaka/jellyfin:240220-amd64-legacy
INFO "${Blue}小雅姐夫安装完成,正在为您重启小雅alist!$NC"
echo "${host}:6909" > $config_dir/jellyfin_server.txt
docker restart xiaoya_jf
start_time=$(date +%s)
TARGET_LOG_LINE_SUCCESS="success load storage: [/©️"
while true; do
line=$(docker logs "xiaoya_jf" 2>&1 | tail -n 10)
echo $line
if [[ "$line" == *"$TARGET_LOG_LINE_SUCCESS"* ]]; then
break
fi
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ "$elapsed_time" -gt 300 ]; then
echo "小雅alist未正常启动超时 5分钟,请检查小雅alist的安装!"
break
fi
sleep 3
done
INFO "请登陆${Blue} $host:2346 ${NC}访问小雅姐夫,用户名:${Blue} ailg ${NC},密码:${Blue} 5678 ${NC}"
}
function user_select3() {
user_select1
start_time=$(date +%s)
TARGET_LOG_LINE_SUCCESS="success load storage: [/©️"
while true; do
line=$(docker logs "xiaoya_jf" 2>&1 | tail -n 10)
echo $line
if [[ "$line" == *"$TARGET_LOG_LINE_SUCCESS"* ]]; then
break
fi
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ "$elapsed_time" -gt 300 ]; then
echo "小雅alist未正常启动超时 5分钟,程序将退出,请检查小雅alist的安装,或重启小雅alist后重新运行脚本!"
exit
fi
sleep 3
done
user_select2
}
check_loop_support() {
if [ ! -e /dev/loop-control ]; then
if ! lsmod | awk '$1 == "loop"'; then
if ! command -v modprobe &> /dev/null; then
echo "modprobe command not found."
return 1
else
if modprobe loop; then
if ! mknod -m 660 /dev/loop-control c 10 237; then
ERROR "您的系统环境不支持直接挂载loop回循设备,无法安装速装版emby/jellyfin,请手动启用该功能后重新运行脚本安装!或用DDS大佬脚本安装原版小雅emby!" && exit 1
fi
else
ERROR "您的系统环境不支持直接挂载loop回循设备,无法安装速装版emby/jellyfin,请手动启用该功能后重新运行脚本安装!或用DDS大佬脚本安装原版小雅emby!" && exit 1
fi
fi
fi
fi
if ls -al /dev/loop7 > /dev/null 2>&1; then
if losetup /dev/loop7; then
imgs=("emby-ailg.img" "emby-ailg-lite.img" "jellyfin-ailg.img" "jellyfin-ailg-lite.img" "emby-ailg-115.img" "emby-ailg-lite-115.img" "media.img" "/")
contains=false
for img in "${imgs[@]}"; do
if [ "$img" = "/" ]; then
if losetup /dev/loop7 | grep -q "^/$"; then
contains=true
break
fi
else
if losetup /dev/loop7 | grep -q "$img"; then
contains=true
break
fi
fi
done
if [ "$contains" = false ]; then
ERROR "您系统的/dev/loop7设备已被占用,可能是你没有用脚本卸载手动删除了emby的img镜像文件!"
ERROR "请手动卸载后重装运行脚本安装!不会就删掉爬虫容后重启宿主机设备,再运行脚本安装!" && exit 1
fi
else
for i in {1..3}; do
curl -o /tmp/loop_test.img https://gbox.ggbond.org/loop_test.img
if [ -f /tmp/loop_test.img ] && [ $(stat -c%s /tmp/loop_test.img) -gt 1024000 ]; then
break
else
rm -f /tmp/loop_test.img
fi
done
if [ ! -f /tmp/loop_test.img ] || [ $(stat -c%s /tmp/loop_test.img) -le 1024000 ]; then
ERROR "测试文件下载失败,请检查网络后重新运行脚本!" && exit 1
fi
if ! losetup -o 35 /dev/loop7 /tmp/loop_test.img > /dev/null 2>&1; then
ERROR "您的系统环境不支持直接挂载loop回循设备,无法安装速装版emby/jellyfin,建议排查losetup命令后重新运行脚本安装!或用DDS大佬脚本安装原版小雅emby!"
rm -rf /tmp/loop_test.img
exit 1
else
mkdir -p /tmp/loop_test
if ! mount /dev/loop7 /tmp/loop_test; then
ERROR "您的系统环境不支持直接挂载loop回循设备,无法安装速装版emby/jellyfin,建议排查mount命令后重新运行脚本安装!或用DDS大佬脚本安装原版小雅emby!"
rm -rf /tmp/loop_test /tmp/loop_test.img
exit 1
else
umount /tmp/loop_test
losetup -d /dev/loop7
rm -rf /tmp/loop_test /tmp/loop_test.img
return 0
fi
fi
fi
fi
}
check_qnap() {
if grep -Eqi "QNAP" /etc/issue > /dev/null 2>&1; then
INFO "检测到您是QNAP威联通系统,正在尝试更新安装环境,以便速装emby/jellyfin……"
if ! command -v opkg &> /dev/null; then
wget -O - http://bin.entware.net/x64-k3.2/installer/generic.sh | sh
echo 'export PATH=$PATH:/opt/bin:/opt/sbin' >> ~/.profile
source ~/.profile
fi
[ -f /bin/mount ] && mv /bin/mount /bin/mount.bak
[ -f /bin/umount ] && mv /bin/umount /bin/umount.bak
[ -f /usr/local/sbin/losetup ] && mv /usr/local/sbin/losetup /usr/local/sbin/losetup.bak
opkg update
for pkg in mount-utils losetup; do
success=false
for i in {1..3}; do
if opkg install $pkg; then
success=true
break
else
INFO "尝试安装 $pkg 失败,重试中 ($i/3)..."
fi
done
if [ "$success" = false ]; then
INFO "$pkg 安装失败,恢复备份文件并退出脚本。"
[ -f /bin/mount.bak ] && mv /bin/mount.bak /bin/mount
[ -f /bin/umount.bak ] && mv /bin/umount.bak /bin/umount
[ -f /usr/local/sbin/losetup.bak ] && mv /usr/local/sbin/losetup.bak /usr/local/sbin/losetup
exit 1
fi
done
if [ -f /opt/bin/mount ] && [ -f /opt/bin/umount ] && [ -f /opt/sbin/losetup ]; then
cp /opt/bin/mount /bin/mount
cp /opt/bin/umount /bin/umount
cp /opt/sbin/losetup /usr/local/sbin/losetup
INFO "已完成安装环境更新!"
else
INFO "安装文件缺失,恢复备份文件并退出脚本。"
[ -f /bin/mount.bak ] && mv /bin/mount.bak /bin/mount
[ -f /bin/umount.bak ] && mv /bin/umount.bak /bin/umount
[ -f /usr/local/sbin/losetup.bak ] && mv /usr/local/sbin/losetup.bak /usr/local/sbin/losetup
exit 1
fi
fi
}
function user_select4() {
down_img() {
if [[ ! -f $image_dir/$emby_ailg ]] || [[ -f $image_dir/$emby_ailg.aria2 ]]; then
update_ailg ailg/ggbond:latest
docker exec $docker_name ali_clear -1 > /dev/null 2>&1
docker run --rm --net=host -v $image_dir:/image ailg/ggbond:latest \
aria2c -o /image/$emby_ailg --auto-file-renaming=false --allow-overwrite=true -c -x6 "$docker_addr/d/ailg_jf/${down_path}/$emby_ailg"
fi
local_size=$(du -b $image_dir/$emby_ailg | cut -f1)
for i in {1..3}; do
if [[ -f $image_dir/$emby_ailg.aria2 ]] || [[ $remote_size -gt "$local_size" ]]; then
docker exec $docker_name ali_clear -1 > /dev/null 2>&1
docker run --rm --net=host -v $image_dir:/image ailg/ggbond:latest \
aria2c -o /image/$emby_ailg --auto-file-renaming=false --allow-overwrite=true -c -x6 "$docker_addr/d/ailg_jf/${down_path}/$emby_ailg"
local_size=$(du -b $image_dir/$emby_ailg | cut -f1)
else
break
fi
done
[[ -f $image_dir/$emby_ailg.aria2 ]] || [[ $remote_size != "$local_size" ]] && ERROR "文件下载失败,请检查网络后重新运行脚本!" && WARN "未下完的文件存放在${image_dir}目录,以便您续传下载,如不再需要请手动清除!" && exit 1
}
check_qnap
check_loop_support
while :; do
clear
echo -e "———————————————————————————————————— \033[1;33mA I 老 G\033[0m —————————————————————————————————"
echo -e "\n"
echo -e "A、安装小雅EMBY老G速装版会$Red删除原小雅emby/jellyfin容器,如需保留请退出脚本停止原容器进行更名!$NC"
echo -e "\n"
echo -e "B、完整版与小雅emby原版一样,Lite版无PikPak数据(适合无梯子用户),请按需选择!"
echo -e "\n"
echo -e "C、${Yellow}老G速装版会随emby/jellyfin启动自动挂载镜像,感谢DDSRem大佬提供的解决思路!${NC}"
echo -e "\n"
echo -e "D、${Yellow}老G速装版新增jellyfin最新版10.9.6,建议16G以上内存安装!${NC}"
echo -e "\n"
echo -e "——————————————————————————————————————————————————————————————————————————————————"
echo -e "\n"
echo -e "\033[1;32m1、小雅EMBY老G速装 - 115完整版\033[0m"
echo -e "\n"
echo -e "\033[1;35m2、小雅EMBY老G速装 - 115-Lite版\033[0m"
echo -e "\n"
echo -e "\033[1;32m3、小雅JELLYFIN老G速装 - 10.8.13 - 完整版\033[0m"
echo -e "\n"
echo -e "\033[1;35m4、小雅JELLYFIN老G速装 - 10.8.13 - Lite版\033[0m"
echo -e "\n"
echo -e "\033[1;32m5、小雅JELLYFIN老G速装 - 10.9.6 - 完整版\033[0m"
echo -e "\n"
echo -e "\033[1;35m6、小雅JELLYFIN老G速装 - 10.9.6 - Lite版\033[0m"
echo -e "\n"
echo -e "\033[1;35m7、小雅EMBY老G速装 - Lite版\033[0m"
echo -e "\n"
echo -e "——————————————————————————————————————————————————————————————————————————————————"
read -erp "请输入您的选择(1-7,按b返回上级菜单或按q退出):" f4_select
case "$f4_select" in
1)
emby_ailg="emby-ailg-115.mp4"
emby_img="emby-ailg-115.img"
space_need=160
break
;;
2)
emby_ailg="emby-ailg-lite-115.mp4"
emby_img="emby-ailg-lite-115.img"
space_need=140
break
;;
3)
emby_ailg="jellyfin-ailg.mp4"
emby_img="jellyfin-ailg.img"
space_need=160
break
;;
4)
emby_ailg="jellyfin-ailg-lite.mp4"
emby_img="jellyfin-ailg-lite.img"
space_need=130
break
;;
5)
emby_ailg="jellyfin-10.9.6-ailg.mp4"
emby_img="jellyfin-10.9.6-ailg.img"
space_need=160
break
;;
6)
emby_ailg="jellyfin-10.9.6-ailg-lite.mp4"
emby_img="jellyfin-10.9.6-ailg-lite.img"
space_need=130
break
;;
7)
emby_ailg="emby-ailg-lite.mp4"
emby_img="emby-ailg-lite.img"
space_need=125
break
;;
[Bb])
clear
main
break
;;
[Qq])
exit
;;
*)
ERROR "输入错误,按任意键重新输入!"
read -rn 1
continue
;;
esac
done
if [[ $st_alist =~ "未安装" ]] && [[ $st_gbox =~ "未安装" ]]; then
ERROR "请先安装G-Box/小雅ALIST老G版,再执行本安装!"
read -erp '按任意键返回主菜单'
main
return
fi
umask 000
check_env
[ -z "${config_dir}" ] && get_config_path
INFO "正在为您清理阿里云盘空间……"
docker exec $docker_name ali_clear -1 > /dev/null 2>&1
echo -e "\033[1;35m请输入您的小雅emby/jellyfin镜像存放路径(请确保大于${space_need}G剩余空间!):\033[0m"
read -r image_dir
echo -e "\033[1;35m请输入镜像下载后需要扩容的空间(单位:GB,默认60G可直接回车,请确保大于${space_need}G剩余空间!):\033[0m"
read -r expand_size
expand_size=${expand_size:-60}
check_path $image_dir
check_path $image_dir
if [ -f "${image_dir}/${emby_ailg}" ] || [ -f "${image_dir}/${emby_img}" ]; then
echo "镜像文件已存在,跳过空间检查"
else
check_space $image_dir $space_need
fi
if [[ "${f4_select}" == [127] ]]; then
search_img="emby/embyserver|amilys/embyserver"
del_name="emby"
loop_order="/dev/loop7"
down_path="emby"
get_emby_image
init="run"
emd_name="xiaoya-emd"
entrypoint_mount="entrypoint_emd"
elif [[ "${f4_select}" == [3456] ]]; then
search_img="nyanmisaka/jellyfin|jellyfin/jellyfin"
del_name="jellyfin_xy"
loop_order="/dev/loop6"
down_path="jellyfin"
get_jellyfin_image
init="run_jf"
emd_name="xiaoya-emd-jf"
entrypoint_mount="entrypoint_emd_jf"
fi
get_emby_status
# for name in "${!emby_list[@]}"; do
# if [[ "${name}" == "${del_name}" ]]; then
# read -erp "$(echo -e "\033[1;36m是否保留名为${del_name}的容器!按Y/y保留,按其他任意键将删除!\033[0m\n请输入:") " del_emby
# [[ "${del_emby}" == [Yy] ]] && del_emby=false || del_emby=true
# fi
# done
docker ps -a | grep 'ddsderek/xiaoya-emd' | awk '{print $1}' | xargs docker stop
if [ ${#emby_list[@]} -ne 0 ]; then
for entry in "${emby_list[@]}"; do
op_emby=${entry%%:*}
host_path=${entry#*:}
docker stop "${op_emby}"
INFO "${op_emby}容器已关闭!"