Repository navigation
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·1092 lines (953 loc) · 41 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·1092 lines (953 loc) · 41 KB
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
#!/usr/bin/env bash
#
# Copyright (C) 2025 ZqinKing
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
set -e
set -o errexit
set -o errtrace
# 定义错误处理函数
error_handler() {
echo "Error occurred in script at line: ${BASH_LINENO[0]}, command: '${BASH_COMMAND}'"
}
# 设置trap捕获ERR信号
trap 'error_handler' ERR
BASE_PATH=$(cd $(dirname $0) && pwd)
REPO_URL=$1
REPO_BRANCH=$2
BUILD_DIR=$3
COMMIT_HASH=$4
FEEDS_CONF="feeds.conf.default"
GOLANG_REPO="https://github.com/sbwml/packages_lang_golang"
GOLANG_BRANCH="25.x"
THEME_SET="argon"
LAN_ADDR="192.168.1.1"
clone_repo() {
if [[ ! -d $BUILD_DIR ]]; then
echo "克隆仓库: $REPO_URL 分支: $REPO_BRANCH"
if ! git clone --depth 1 -b $REPO_BRANCH $REPO_URL $BUILD_DIR; then
echo "错误:克隆仓库 $REPO_URL 失败" >&2
exit 1
fi
fi
}
clean_up() {
cd $BUILD_DIR
if [[ -f $BUILD_DIR/.config ]]; then
\rm -f $BUILD_DIR/.config
fi
if [[ -d $BUILD_DIR/tmp ]]; then
\rm -rf $BUILD_DIR/tmp
fi
if [[ -d $BUILD_DIR/logs ]]; then
\rm -rf $BUILD_DIR/logs/*
fi
mkdir -p $BUILD_DIR/tmp
echo "1" >$BUILD_DIR/tmp/.build
}
reset_feeds_conf() {
git reset --hard origin/$REPO_BRANCH
git clean -f -d
git pull
if [[ $COMMIT_HASH != "none" ]]; then
git checkout $COMMIT_HASH
fi
}
update_feeds() {
# 删除注释行
sed -i '/^#/d' "$BUILD_DIR/$FEEDS_CONF"
# 检查并添加 small-package 源
if ! grep -q "small-package" "$BUILD_DIR/$FEEDS_CONF"; then
# 确保文件以换行符结尾
[ -z "$(tail -c 1 "$BUILD_DIR/$FEEDS_CONF")" ] || echo "" >>"$BUILD_DIR/$FEEDS_CONF"
echo "src-git small8 https://github.com/kenzok8/small-package" >>"$BUILD_DIR/$FEEDS_CONF"
fi
# 添加bpf.mk解决更新报错
if [ ! -f "$BUILD_DIR/include/bpf.mk" ]; then
touch "$BUILD_DIR/include/bpf.mk"
fi
# 切换nss-packages源
# if grep -q "nss_packages" "$BUILD_DIR/$FEEDS_CONF"; then
# sed -i '/nss_packages/d' "$BUILD_DIR/$FEEDS_CONF"
# [ -z "$(tail -c 1 "$BUILD_DIR/$FEEDS_CONF")" ] || echo "" >>"$BUILD_DIR/$FEEDS_CONF"
# echo "src-git nss_packages https://github.com/LiBwrt/nss-packages.git" >>"$BUILD_DIR/$FEEDS_CONF"
# fi
# 更新 feeds
./scripts/feeds clean
./scripts/feeds update -a
}
remove_unwanted_packages() {
local luci_packages=(
"luci-app-passwall" "luci-app-ddns-go" "luci-app-rclone" "luci-app-ssr-plus"
"luci-app-vssr" "luci-app-daed" "luci-app-dae" "luci-app-alist" "luci-app-homeproxy"
"luci-app-haproxy-tcp" "luci-app-openclash" "luci-app-mihomo" "luci-app-appfilter"
"luci-app-msd_lite"
)
local packages_net=(
"haproxy" "xray-core" "xray-plugin" "dns2socks" "alist" "hysteria"
"mosdns" "adguardhome" "ddns-go" "naiveproxy" "shadowsocks-rust"
"sing-box" "v2ray-core" "v2ray-geodata" "v2ray-plugin" "tuic-client"
"chinadns-ng" "ipt2socks" "tcping" "trojan-plus" "simple-obfs" "shadowsocksr-libev"
"dae" "daed" "mihomo" "geoview" "tailscale" "open-app-filter" "msd_lite"
)
local packages_utils=(
"cups"
)
local small8_packages=(
"ppp" "firewall" "dae" "daed" "daed-next" "libnftnl" "nftables" "dnsmasq" "luci-app-alist"
"alist" "opkg" "smartdns" "luci-app-smartdns"
)
for pkg in "${luci_packages[@]}"; do
if [[ -d ./feeds/luci/applications/$pkg ]]; then
\rm -rf ./feeds/luci/applications/$pkg
fi
if [[ -d ./feeds/luci/themes/$pkg ]]; then
\rm -rf ./feeds/luci/themes/$pkg
fi
done
for pkg in "${packages_net[@]}"; do
if [[ -d ./feeds/packages/net/$pkg ]]; then
\rm -rf ./feeds/packages/net/$pkg
fi
done
for pkg in "${packages_utils[@]}"; do
if [[ -d ./feeds/packages/utils/$pkg ]]; then
\rm -rf ./feeds/packages/utils/$pkg
fi
done
for pkg in "${small8_packages[@]}"; do
if [[ -d ./feeds/small8/$pkg ]]; then
\rm -rf ./feeds/small8/$pkg
fi
done
if [[ -d ./package/istore ]]; then
\rm -rf ./package/istore
fi
# ipq60xx不支持NSS offload mnet_rx
# if grep -q "nss_packages" "$BUILD_DIR/$FEEDS_CONF"; then
# rm -rf "$BUILD_DIR/feeds/nss_packages/wwan"
# fi
# 临时放一下,清理脚本
if [ -d "$BUILD_DIR/target/linux/qualcommax/base-files/etc/uci-defaults" ]; then
find "$BUILD_DIR/target/linux/qualcommax/base-files/etc/uci-defaults/" -type f -name "99*.sh" -exec rm -f {} +
fi
}
update_golang() {
if [[ -d ./feeds/packages/lang/golang ]]; then
echo "正在更新 golang 软件包..."
\rm -rf ./feeds/packages/lang/golang
if ! git clone --depth 1 -b $GOLANG_BRANCH $GOLANG_REPO ./feeds/packages/lang/golang; then
echo "错误:克隆 golang 仓库 $GOLANG_REPO 失败" >&2
exit 1
fi
fi
}
install_small8() {
./scripts/feeds install -p small8 -f xray-core xray-plugin dns2tcp dns2socks haproxy hysteria \
naiveproxy shadowsocks-rust sing-box v2ray-core v2ray-geodata v2ray-geoview v2ray-plugin \
tuic-client chinadns-ng ipt2socks tcping trojan-plus simple-obfs shadowsocksr-libev \
luci-app-passwall v2dat mosdns luci-app-mosdns adguardhome luci-app-adguardhome ddns-go \
luci-app-ddns-go taskd luci-lib-xterm luci-lib-taskd luci-app-store quickstart \
luci-app-quickstart luci-app-istorex luci-app-cloudflarespeedtest netdata luci-app-netdata \
lucky luci-app-lucky luci-app-openclash luci-app-homeproxy luci-app-amlogic nikki luci-app-nikki \
tailscale luci-app-tailscale oaf open-app-filter luci-app-oaf easytier luci-app-easytier \
msd_lite luci-app-msd_lite cups luci-app-cupsd
}
install_fullconenat() {
if [ ! -d $BUILD_DIR/package/network/utils/fullconenat-nft ]; then
./scripts/feeds install -p small8 -f fullconenat-nft
fi
if [ ! -d $BUILD_DIR/package/network/utils/fullconenat ]; then
./scripts/feeds install -p small8 -f fullconenat
fi
}
check_default_settings() {
local settings_dir="$BUILD_DIR/package/emortal/default-settings"
if [ ! -d "$settings_dir" ]; then
echo "目录 $settings_dir 不存在,正在从 immortalwrt 仓库克隆..."
local tmp_dir
tmp_dir=$(mktemp -d)
if git clone --depth 1 --filter=blob:none --sparse https://github.com/immortalwrt/immortalwrt.git "$tmp_dir"; then
pushd "$tmp_dir" > /dev/null
git sparse-checkout set package/emortal/default-settings
# 确保目标父目录存在
mkdir -p "$(dirname "$settings_dir")"
# 移动 default-settings 目录
mv package/emortal/default-settings "$settings_dir"
popd > /dev/null
rm -rf "$tmp_dir"
echo "default-settings 克隆并移动成功。"
else
echo "错误:克隆 immortalwrt 仓库失败" >&2
rm -rf "$tmp_dir"
exit 1
fi
fi
}
install_feeds() {
./scripts/feeds update -i
for dir in $BUILD_DIR/feeds/*; do
# 检查是否为目录并且不以 .tmp 结尾,并且不是软链接
if [ -d "$dir" ] && [[ ! "$dir" == *.tmp ]] && [ ! -L "$dir" ]; then
if [[ $(basename "$dir") == "small8" ]]; then
install_small8
install_fullconenat
else
./scripts/feeds install -f -ap $(basename "$dir")
fi
fi
done
}
fix_default_set() {
# 修改默认主题
if [ -d "$BUILD_DIR/feeds/luci/collections/" ]; then
find "$BUILD_DIR/feeds/luci/collections/" -type f -name "Makefile" -exec sed -i "s/luci-theme-bootstrap/luci-theme-$THEME_SET/g" {} \;
fi
install -Dm544 "$BASE_PATH/patches/990_set_argon_primary" "$BUILD_DIR/package/base-files/files/etc/uci-defaults/990_set_argon_primary"
install -Dm544 "$BASE_PATH/patches/991_custom_settings" "$BUILD_DIR/package/base-files/files/etc/uci-defaults/991_custom_settings"
install -Dm544 "$BASE_PATH/patches/992_set-wifi-uci.sh" "$BUILD_DIR/package/base-files/files/etc/uci-defaults/992_set-wifi-uci.sh"
if [ -f "$BUILD_DIR/package/emortal/autocore/files/tempinfo" ]; then
if [ -f "$BASE_PATH/patches/tempinfo" ]; then
\cp -f "$BASE_PATH/patches/tempinfo" "$BUILD_DIR/package/emortal/autocore/files/tempinfo"
fi
fi
}
fix_miniupnpd() {
local miniupnpd_dir="$BUILD_DIR/feeds/packages/net/miniupnpd"
local patch_file="999-chanage-default-leaseduration.patch"
if [ -d "$miniupnpd_dir" ] && [ -f "$BASE_PATH/patches/$patch_file" ]; then
install -Dm644 "$BASE_PATH/patches/$patch_file" "$miniupnpd_dir/patches/$patch_file"
fi
}
change_dnsmasq2full() {
if ! grep -q "dnsmasq-full" $BUILD_DIR/include/target.mk; then
sed -i 's/dnsmasq/dnsmasq-full/g' ./include/target.mk
fi
}
fix_mk_def_depends() {
sed -i 's/libustream-mbedtls/libustream-openssl/g' $BUILD_DIR/include/target.mk 2>/dev/null
if [ -f $BUILD_DIR/target/linux/qualcommax/Makefile ]; then
sed -i 's/wpad-openssl/wpad-mesh-openssl/g' $BUILD_DIR/target/linux/qualcommax/Makefile
fi
}
update_default_lan_addr() {
local CFG_PATH="$BUILD_DIR/package/base-files/files/bin/config_generate"
if [ -f $CFG_PATH ]; then
sed -i 's/192\.168\.[0-9]*\.[0-9]*/'$LAN_ADDR'/g' $CFG_PATH
fi
}
remove_something_nss_kmod() {
local ipq_mk_path="$BUILD_DIR/target/linux/qualcommax/Makefile"
local target_mks=("$BUILD_DIR/target/linux/qualcommax/ipq60xx/target.mk" "$BUILD_DIR/target/linux/qualcommax/ipq807x/target.mk")
for target_mk in "${target_mks[@]}"; do
if [ -f "$target_mk" ]; then
sed -i 's/kmod-qca-nss-crypto//g' "$target_mk"
fi
done
if [ -f "$ipq_mk_path" ]; then
sed -i '/kmod-qca-nss-drv-eogremgr/d' "$ipq_mk_path"
sed -i '/kmod-qca-nss-drv-gre/d' "$ipq_mk_path"
sed -i '/kmod-qca-nss-drv-map-t/d' "$ipq_mk_path"
sed -i '/kmod-qca-nss-drv-match/d' "$ipq_mk_path"
sed -i '/kmod-qca-nss-drv-mirror/d' "$ipq_mk_path"
sed -i '/kmod-qca-nss-drv-tun6rd/d' "$ipq_mk_path"
sed -i '/kmod-qca-nss-drv-tunipip6/d' "$ipq_mk_path"
sed -i '/kmod-qca-nss-drv-vxlanmgr/d' "$ipq_mk_path"
sed -i '/kmod-qca-nss-drv-wifi-meshmgr/d' "$ipq_mk_path"
sed -i '/kmod-qca-nss-macsec/d' "$ipq_mk_path"
sed -i 's/automount //g' "$ipq_mk_path"
sed -i 's/cpufreq //g' "$ipq_mk_path"
fi
}
update_affinity_script() {
local affinity_script_dir="$BUILD_DIR/target/linux/qualcommax"
if [ -d "$affinity_script_dir" ]; then
find "$affinity_script_dir" -name "set-irq-affinity" -exec rm -f {} \;
find "$affinity_script_dir" -name "smp_affinity" -exec rm -f {} \;
install -Dm755 "$BASE_PATH/patches/smp_affinity" "$affinity_script_dir/base-files/etc/init.d/smp_affinity"
fi
}
# 通用函数,用于修正 Makefile 中的哈希值
fix_hash_value() {
local makefile_path="$1"
local old_hash="$2"
local new_hash="$3"
local package_name="$4"
if [ -f "$makefile_path" ]; then
sed -i "s/$old_hash/$new_hash/g" "$makefile_path"
echo "已修正 $package_name 的哈希值。"
fi
}
# 应用所有哈希值修正
apply_hash_fixes() {
fix_hash_value \
"$BUILD_DIR/package/feeds/packages/smartdns/Makefile" \
"860a816bf1e69d5a8a2049483197dbebe8a3da2c9b05b2da68c85ef7dee7bdde" \
"582021891808442b01f551bc41d7d95c38fb00c1ec78a58ac3aaaf898fbd2b5b" \
"smartdns"
fix_hash_value \
"$BUILD_DIR/package/feeds/packages/smartdns/Makefile" \
"320c99a65ca67a98d11a45292aa99b8904b5ebae5b0e17b302932076bf62b1ec" \
"43e58467690476a77ce644f9dc246e8a481353160644203a1bd01eb09c881275" \
"smartdns"
}
update_ath11k_fw() {
local makefile="$BUILD_DIR/package/firmware/ath11k-firmware/Makefile"
local new_mk="$BASE_PATH/patches/ath11k_fw.mk"
local url="https://raw.githubusercontent.com/VIKINGYFY/immortalwrt/refs/heads/main/package/firmware/ath11k-firmware/Makefile"
if [ -d "$(dirname "$makefile")" ]; then
echo "正在更新 ath11k-firmware Makefile..."
if ! curl -fsSL -o "$new_mk" "$url"; then
echo "错误:从 $url 下载 ath11k-firmware Makefile 失败" >&2
exit 1
fi
if [ ! -s "$new_mk" ]; then
echo "错误:下载的 ath11k-firmware Makefile 为空文件" >&2
exit 1
fi
mv -f "$new_mk" "$makefile"
fi
}
fix_mkpkg_format_invalid() {
if [[ $BUILD_DIR =~ "imm-nss" ]]; then
if [ -f $BUILD_DIR/feeds/small8/v2ray-geodata/Makefile ]; then
sed -i 's/VER)-\$(PKG_RELEASE)/VER)-r\$(PKG_RELEASE)/g' $BUILD_DIR/feeds/small8/v2ray-geodata/Makefile
fi
if [ -f $BUILD_DIR/feeds/small8/luci-lib-taskd/Makefile ]; then
sed -i 's/>=1\.0\.3-1/>=1\.0\.3-r1/g' $BUILD_DIR/feeds/small8/luci-lib-taskd/Makefile
fi
if [ -f $BUILD_DIR/feeds/small8/luci-app-openclash/Makefile ]; then
sed -i 's/PKG_RELEASE:=beta/PKG_RELEASE:=1/g' $BUILD_DIR/feeds/small8/luci-app-openclash/Makefile
fi
if [ -f $BUILD_DIR/feeds/small8/luci-app-quickstart/Makefile ]; then
sed -i 's/PKG_VERSION:=0\.8\.16-1/PKG_VERSION:=0\.8\.16/g' $BUILD_DIR/feeds/small8/luci-app-quickstart/Makefile
sed -i 's/PKG_RELEASE:=$/PKG_RELEASE:=1/g' $BUILD_DIR/feeds/small8/luci-app-quickstart/Makefile
fi
if [ -f $BUILD_DIR/feeds/small8/luci-app-store/Makefile ]; then
sed -i 's/PKG_VERSION:=0\.1\.27-1/PKG_VERSION:=0\.1\.27/g' $BUILD_DIR/feeds/small8/luci-app-store/Makefile
sed -i 's/PKG_RELEASE:=$/PKG_RELEASE:=1/g' $BUILD_DIR/feeds/small8/luci-app-store/Makefile
fi
fi
}
add_ax6600_led() {
local athena_led_dir="$BUILD_DIR/package/emortal/luci-app-athena-led"
local repo_url="https://github.com/NONGFAH/luci-app-athena-led.git"
echo "正在添加 luci-app-athena-led..."
rm -rf "$athena_led_dir" 2>/dev/null
if ! git clone --depth=1 "$repo_url" "$athena_led_dir"; then
echo "错误:从 $repo_url 克隆 luci-app-athena-led 仓库失败" >&2
exit 1
fi
if [ -d "$athena_led_dir" ]; then
chmod +x "$athena_led_dir/root/usr/sbin/athena-led"
chmod +x "$athena_led_dir/root/etc/init.d/athena_led"
else
echo "错误:克隆操作后未找到目录 $athena_led_dir" >&2
exit 1
fi
}
change_cpuusage() {
local luci_rpc_path="$BUILD_DIR/feeds/luci/modules/luci-base/root/usr/share/rpcd/ucode/luci"
local qualcommax_sbin_dir="$BUILD_DIR/target/linux/qualcommax/base-files/sbin"
local filogic_sbin_dir="$BUILD_DIR/target/linux/mediatek/filogic/base-files/sbin"
# Modify LuCI RPC script to prefer our custom cpuusage script
if [ -f "$luci_rpc_path" ]; then
sed -i "s#const fd = popen('top -n1 | awk \\\'/^CPU/ {printf(\"%d%\", 100 - \$8)}\\\'')#const cpuUsageCommand = access('/sbin/cpuusage') ? '/sbin/cpuusage' : 'top -n1 | awk \\\'/^CPU/ {printf(\"%d%\", 100 - \$8)}\\\''#g" "$luci_rpc_path"
sed -i '/cpuUsageCommand/a \\t\t\tconst fd = popen(cpuUsageCommand);' "$luci_rpc_path"
fi
# Remove old script if it exists from a previous build
local old_script_path="$BUILD_DIR/package/base-files/files/sbin/cpuusage"
if [ -f "$old_script_path" ]; then
rm -f "$old_script_path"
fi
# Install platform-specific cpuusage scripts
install -Dm755 "$BASE_PATH/patches/cpuusage" "$qualcommax_sbin_dir/cpuusage"
install -Dm755 "$BASE_PATH/patches/hnatusage" "$filogic_sbin_dir/cpuusage"
}
update_tcping() {
local tcping_path="$BUILD_DIR/feeds/small8/tcping/Makefile"
local url="https://raw.githubusercontent.com/xiaorouji/openwrt-passwall-packages/refs/heads/main/tcping/Makefile"
if [ -d "$(dirname "$tcping_path")" ]; then
echo "正在更新 tcping Makefile..."
if ! curl -fsSL -o "$tcping_path" "$url"; then
echo "错误:从 $url 下载 tcping Makefile 失败" >&2
exit 1
fi
fi
}
set_custom_task() {
local sh_dir="$BUILD_DIR/package/base-files/files/etc/init.d"
cat <<'EOF' >"$sh_dir/custom_task"
#!/bin/sh /etc/rc.common
# 设置启动优先级
START=99
boot() {
# 重新添加缓存请求定时任务
sed -i '/drop_caches/d' /etc/crontabs/root
echo "15 3 * * * sync && echo 3 > /proc/sys/vm/drop_caches" >>/etc/crontabs/root
# 删除现有的 wireguard_watchdog 任务
sed -i '/wireguard_watchdog/d' /etc/crontabs/root
# 获取 WireGuard 接口名称
local wg_ifname=$(wg show | awk '/interface/ {print $2}')
if [ -n "$wg_ifname" ]; then
# 添加新的 wireguard_watchdog 任务,每10分钟执行一次
echo "*/15 * * * * /usr/bin/wireguard_watchdog" >>/etc/crontabs/root
uci set system.@system[0].cronloglevel='9'
uci commit system
/etc/init.d/cron restart
fi
# 应用新的 crontab 配置
crontab /etc/crontabs/root
}
EOF
chmod +x "$sh_dir/custom_task"
}
# 应用 Passwall 相关调整
apply_passwall_tweaks() {
# 清理 Passwall 的 chnlist 规则文件
local chnlist_path="$BUILD_DIR/feeds/small8/luci-app-passwall/root/usr/share/passwall/rules/chnlist"
if [ -f "$chnlist_path" ]; then
> "$chnlist_path"
fi
# 调整 Xray 最大 RTT 和 保留记录数量
local xray_util_path="$BUILD_DIR/feeds/small8/luci-app-passwall/luasrc/passwall/util_xray.lua"
if [ -f "$xray_util_path" ]; then
sed -i 's/maxRTT = "1s"/maxRTT = "2s"/g' "$xray_util_path"
sed -i 's/sampling = 3/sampling = 5/g' "$xray_util_path"
fi
}
install_opkg_distfeeds() {
local emortal_def_dir="$BUILD_DIR/package/emortal/default-settings"
local distfeeds_conf="$emortal_def_dir/files/99-distfeeds.conf"
if [ -d "$emortal_def_dir" ] && [ ! -f "$distfeeds_conf" ]; then
cat <<'EOF' >"$distfeeds_conf"
src/gz openwrt_base https://downloads.immortalwrt.org/releases/24.10-SNAPSHOT/packages/aarch64_cortex-a53/base/
src/gz openwrt_luci https://downloads.immortalwrt.org/releases/24.10-SNAPSHOT/packages/aarch64_cortex-a53/luci/
src/gz openwrt_packages https://downloads.immortalwrt.org/releases/24.10-SNAPSHOT/packages/aarch64_cortex-a53/packages/
src/gz openwrt_routing https://downloads.immortalwrt.org/releases/24.10-SNAPSHOT/packages/aarch64_cortex-a53/routing/
src/gz openwrt_telephony https://downloads.immortalwrt.org/releases/24.10-SNAPSHOT/packages/aarch64_cortex-a53/telephony/
EOF
sed -i "/define Package\/default-settings\/install/a\\
\\t\$(INSTALL_DIR) \$(1)/etc\\n\
\t\$(INSTALL_DATA) ./files/99-distfeeds.conf \$(1)/etc/99-distfeeds.conf\n" $emortal_def_dir/Makefile
sed -i "/exit 0/i\\
[ -f \'/etc/99-distfeeds.conf\' ] && mv \'/etc/99-distfeeds.conf\' \'/etc/opkg/distfeeds.conf\'\n\
sed -ri \'/check_signature/s@^[^#]@#&@\' /etc/opkg.conf\n" $emortal_def_dir/files/99-default-settings
fi
}
update_nss_pbuf_performance() {
local pbuf_path="$BUILD_DIR/package/kernel/mac80211/files/pbuf.uci"
if [ -d "$(dirname "$pbuf_path")" ] && [ -f $pbuf_path ]; then
sed -i "s/auto_scale '1'/auto_scale 'off'/g" $pbuf_path
sed -i "s/scaling_governor 'performance'/scaling_governor 'schedutil'/g" $pbuf_path
fi
}
set_build_signature() {
local file="$BUILD_DIR/feeds/luci/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/10_system.js"
if [ -d "$(dirname "$file")" ] && [ -f $file ]; then
sed -i "s/(\(luciversion || ''\))/(\1) + (' \/ build by ZqinKing')/g" "$file"
fi
}
update_nss_diag() {
local file="$BUILD_DIR/package/kernel/mac80211/files/nss_diag.sh"
if [ -d "$(dirname "$file")" ] && [ -f "$file" ]; then
\rm -f "$file"
install -Dm755 "$BASE_PATH/patches/nss_diag.sh" "$file"
fi
}
update_menu_location() {
local samba4_path="$BUILD_DIR/feeds/luci/applications/luci-app-samba4/root/usr/share/luci/menu.d/luci-app-samba4.json"
if [ -d "$(dirname "$samba4_path")" ] && [ -f "$samba4_path" ]; then
sed -i 's/nas/services/g' "$samba4_path"
fi
local tailscale_path="$BUILD_DIR/feeds/small8/luci-app-tailscale/root/usr/share/luci/menu.d/luci-app-tailscale.json"
if [ -d "$(dirname "$tailscale_path")" ] && [ -f "$tailscale_path" ]; then
sed -i 's/services/vpn/g' "$tailscale_path"
fi
}
fix_compile_coremark() {
local file="$BUILD_DIR/feeds/packages/utils/coremark/Makefile"
if [ -d "$(dirname "$file")" ] && [ -f "$file" ]; then
sed -i 's/mkdir \$/mkdir -p \$/g' "$file"
fi
}
update_homeproxy() {
local repo_url="https://github.com/immortalwrt/homeproxy.git"
local target_dir="$BUILD_DIR/feeds/small8/luci-app-homeproxy"
if [ -d "$target_dir" ]; then
echo "正在更新 homeproxy..."
rm -rf "$target_dir"
if ! git clone --depth 1 "$repo_url" "$target_dir"; then
echo "错误:从 $repo_url 克隆 homeproxy 仓库失败" >&2
exit 1
fi
fi
}
update_dnsmasq_conf() {
local file="$BUILD_DIR/package/network/services/dnsmasq/files/dhcp.conf"
if [ -d "$(dirname "$file")" ] && [ -f "$file" ]; then
sed -i '/dns_redirect/d' "$file"
fi
}
# 更新版本
update_package() {
local dir=$(find "$BUILD_DIR/package" \( -type d -o -type l \) -name "$1")
if [ -z "$dir" ]; then
return 0
fi
local branch="$2"
if [ -z "$branch" ]; then
branch="releases"
fi
local mk_path="$dir/Makefile"
if [ -f "$mk_path" ]; then
# 提取repo
local PKG_REPO=$(grep -oE "^PKG_GIT_URL.*github.com(/[-_a-zA-Z0-9]{1,}){2}" "$mk_path" | awk -F"/" '{print $(NF - 1) "/" $NF}')
if [ -z "$PKG_REPO" ]; then
PKG_REPO=$(grep -oE "^PKG_SOURCE_URL.*github.com(/[-_a-zA-Z0-9]{1,}){2}" "$mk_path" | awk -F"/" '{print $(NF - 1) "/" $NF}')
if [ -z "$PKG_REPO" ]; then
echo "错误:无法从 $mk_path 提取 PKG_REPO" >&2
return 1
fi
fi
local PKG_VER
if ! PKG_VER=$(curl -fsSL "https://api.github.com/repos/$PKG_REPO/$branch" | jq -r '.[0] | .tag_name // .name'); then
echo "错误:从 https://api.github.com/repos/$PKG_REPO/$branch 获取版本信息失败" >&2
return 1
fi
if [ -n "$3" ]; then
PKG_VER="$3"
fi
local COMMIT_SHA
if ! COMMIT_SHA=$(curl -fsSL "https://api.github.com/repos/$PKG_REPO/tags" | jq -r '.[] | select(.name=="'$PKG_VER'") | .commit.sha' | cut -c1-7); then
echo "错误:从 https://api.github.com/repos/$PKG_REPO/tags 获取提交哈希失败" >&2
return 1
fi
if [ -n "$COMMIT_SHA" ]; then
sed -i 's/^PKG_GIT_SHORT_COMMIT:=.*/PKG_GIT_SHORT_COMMIT:='$COMMIT_SHA'/g' "$mk_path"
fi
PKG_VER=$(echo "$PKG_VER" | grep -oE "[\.0-9]{1,}")
local PKG_NAME=$(awk -F"=" '/PKG_NAME:=/ {print $NF}' "$mk_path" | grep -oE "[-_:/\$\(\)\?\.a-zA-Z0-9]{1,}")
local PKG_SOURCE=$(awk -F"=" '/PKG_SOURCE:=/ {print $NF}' "$mk_path" | grep -oE "[-_:/\$\(\)\?\.a-zA-Z0-9]{1,}")
local PKG_SOURCE_URL=$(awk -F"=" '/PKG_SOURCE_URL:=/ {print $NF}' "$mk_path" | grep -oE "[-_:/\$\(\)\{\}\?\.a-zA-Z0-9]{1,}")
local PKG_GIT_URL=$(awk -F"=" '/PKG_GIT_URL:=/ {print $NF}' "$mk_path")
local PKG_GIT_REF=$(awk -F"=" '/PKG_GIT_REF:=/ {print $NF}' "$mk_path")
PKG_SOURCE_URL=${PKG_SOURCE_URL//\$\(PKG_GIT_URL\)/$PKG_GIT_URL}
PKG_SOURCE_URL=${PKG_SOURCE_URL//\$\(PKG_GIT_REF\)/$PKG_GIT_REF}
PKG_SOURCE_URL=${PKG_SOURCE_URL//\$\(PKG_NAME\)/$PKG_NAME}
PKG_SOURCE_URL=$(echo "$PKG_SOURCE_URL" | sed "s/\${PKG_VERSION}/$PKG_VER/g; s/\$(PKG_VERSION)/$PKG_VER/g")
PKG_SOURCE=${PKG_SOURCE//\$\(PKG_NAME\)/$PKG_NAME}
PKG_SOURCE=${PKG_SOURCE//\$\(PKG_VERSION\)/$PKG_VER}
local PKG_HASH
if ! PKG_HASH=$(curl -fsSL "$PKG_SOURCE_URL""$PKG_SOURCE" | sha256sum | cut -b -64); then
echo "错误:从 $PKG_SOURCE_URL$PKG_SOURCE 获取软件包哈希失败" >&2
return 1
fi
sed -i 's/^PKG_VERSION:=.*/PKG_VERSION:='$PKG_VER'/g' "$mk_path"
sed -i 's/^PKG_HASH:=.*/PKG_HASH:='$PKG_HASH'/g' "$mk_path"
echo "更新软件包 $1 到 $PKG_VER $PKG_HASH"
fi
}
# 添加系统升级时的备份信息
function add_backup_info_to_sysupgrade() {
local conf_path="$BUILD_DIR/package/base-files/files/etc/sysupgrade.conf"
if [ -f "$conf_path" ]; then
cat >"$conf_path" <<'EOF'
/etc/AdGuardHome.yaml
/etc/easytier
/etc/lucky/
EOF
fi
}
# 更新启动顺序
function update_script_priority() {
# 更新qca-nss驱动的启动顺序
local qca_drv_path="$BUILD_DIR/package/feeds/nss_packages/qca-nss-drv/files/qca-nss-drv.init"
if [ -d "${qca_drv_path%/*}" ] && [ -f "$qca_drv_path" ]; then
sed -i 's/START=.*/START=88/g' "$qca_drv_path"
fi
# 更新pbuf服务的启动顺序
local pbuf_path="$BUILD_DIR/package/kernel/mac80211/files/qca-nss-pbuf.init"
if [ -d "${pbuf_path%/*}" ] && [ -f "$pbuf_path" ]; then
sed -i 's/START=.*/START=89/g' "$pbuf_path"
fi
# 更新mosdns服务的启动顺序
local mosdns_path="$BUILD_DIR/package/feeds/small8/luci-app-mosdns/root/etc/init.d/mosdns"
if [ -d "${mosdns_path%/*}" ] && [ -f "$mosdns_path" ]; then
sed -i 's/START=.*/START=94/g' "$mosdns_path"
fi
}
update_mosdns_deconfig() {
local mosdns_conf="$BUILD_DIR/feeds/small8/luci-app-mosdns/root/etc/config/mosdns"
if [ -d "${mosdns_conf%/*}" ] && [ -f "$mosdns_conf" ]; then
sed -i 's/8000/300/g' "$mosdns_conf"
sed -i 's/5335/5336/g' "$mosdns_conf"
fi
}
fix_quickstart() {
local file_path="$BUILD_DIR/feeds/small8/luci-app-quickstart/luasrc/controller/istore_backend.lua"
local url="https://gist.githubusercontent.com/puteulanus/1c180fae6bccd25e57eb6d30b7aa28aa/raw/istore_backend.lua"
# 下载新的istore_backend.lua文件并覆盖
if [ -f "$file_path" ]; then
echo "正在修复 quickstart..."
if ! curl -fsSL -o "$file_path" "$url"; then
echo "错误:从 $url 下载 istore_backend.lua 失败" >&2
exit 1
fi
fi
}
update_oaf_deconfig() {
local conf_path="$BUILD_DIR/feeds/small8/open-app-filter/files/appfilter.config"
local uci_def="$BUILD_DIR/feeds/small8/luci-app-oaf/root/etc/uci-defaults/94_feature_3.0"
local disable_path="$BUILD_DIR/feeds/small8/luci-app-oaf/root/etc/uci-defaults/99_disable_oaf"
if [ -d "${conf_path%/*}" ] && [ -f "$conf_path" ]; then
sed -i \
-e "s/record_enable '1'/record_enable '0'/g" \
-e "s/disable_hnat '1'/disable_hnat '0'/g" \
-e "s/auto_load_engine '1'/auto_load_engine '0'/g" \
"$conf_path"
fi
if [ -d "${uci_def%/*}" ] && [ -f "$uci_def" ]; then
sed -i '/\(disable_hnat\|auto_load_engine\)/d' "$uci_def"
# 禁用脚本
cat >"$disable_path" <<-EOF
#!/bin/sh
[ "\$(uci get appfilter.global.enable 2>/dev/null)" = "0" ] && {
/etc/init.d/appfilter disable
/etc/init.d/appfilter stop
}
EOF
chmod +x "$disable_path"
fi
}
add_timecontrol() {
local timecontrol_dir="$BUILD_DIR/package/luci-app-timecontrol"
local repo_url="https://github.com/sirpdboy/luci-app-timecontrol.git"
# 删除旧的目录(如果存在)
rm -rf "$timecontrol_dir" 2>/dev/null
echo "正在添加 luci-app-timecontrol..."
if ! git clone --depth 1 "$repo_url" "$timecontrol_dir"; then
echo "错误:从 $repo_url 克隆 luci-app-timecontrol 仓库失败" >&2
exit 1
fi
}
add_gecoosac() {
local gecoosac_dir="$BUILD_DIR/package/openwrt-gecoosac"
local repo_url="https://github.com/lwb1978/openwrt-gecoosac.git"
# 删除旧的目录(如果存在)
rm -rf "$gecoosac_dir" 2>/dev/null
echo "正在添加 openwrt-gecoosac..."
if ! git clone --depth 1 "$repo_url" "$gecoosac_dir"; then
echo "错误:从 $repo_url 克隆 openwrt-gecoosac 仓库失败" >&2
exit 1
fi
}
update_adguardhome() {
local adguardhome_dir="$BUILD_DIR/package/feeds/small8/luci-app-adguardhome"
local repo_url="https://github.com/ZqinKing/luci-app-adguardhome.git"
echo "正在更新 luci-app-adguardhome..."
rm -rf "$adguardhome_dir" 2>/dev/null
if ! git clone --depth 1 "$repo_url" "$adguardhome_dir"; then
echo "错误:从 $repo_url 克隆 luci-app-adguardhome 仓库失败" >&2
exit 1
fi
}
update_geoip() {
local geodata_path="$BUILD_DIR/package/feeds/small8/v2ray-geodata/Makefile"
if [ -d "${geodata_path%/*}" ] && [ -f "$geodata_path" ]; then
local GEOIP_VER=$(awk -F"=" '/GEOIP_VER:=/ {print $NF}' $geodata_path | grep -oE "[0-9]{1,}")
if [ -n "$GEOIP_VER" ]; then
local base_url="https://github.com/v2fly/geoip/releases/download/${GEOIP_VER}"
# 下载旧的geoip.dat和新的geoip-only-cn-private.dat文件的校验和
local old_SHA256
if ! old_SHA256=$(wget -qO- "$base_url/geoip.dat.sha256sum" | awk '{print $1}'); then
echo "错误:从 $base_url/geoip.dat.sha256sum 获取旧的 geoip.dat 校验和失败" >&2
return 1
fi
local new_SHA256
if ! new_SHA256=$(wget -qO- "$base_url/geoip-only-cn-private.dat.sha256sum" | awk '{print $1}'); then
echo "错误:从 $base_url/geoip-only-cn-private.dat.sha256sum 获取新的 geoip-only-cn-private.dat 校验和失败" >&2
return 1
fi
# 更新Makefile中的文件名和校验和
if [ -n "$old_SHA256" ] && [ -n "$new_SHA256" ]; then
if grep -q "$old_SHA256" "$geodata_path"; then
sed -i "s|=geoip.dat|=geoip-only-cn-private.dat|g" "$geodata_path"
sed -i "s/$old_SHA256/$new_SHA256/g" "$geodata_path"
fi
fi
fi
fi
}
update_lucky() {
# 从补丁文件名中提取版本号
local version
version=$(find "$BASE_PATH/patches" -name "lucky_*.tar.gz" -printf "%f\n" | head -n 1 | sed -n 's/^lucky_\(.*\)_Linux.*$/\1/p')
if [ -z "$version" ]; then
echo "Warning: 未找到 lucky 补丁文件,跳过更新。" >&2
return 1
fi
local makefile_path="$BUILD_DIR/feeds/small8/lucky/Makefile"
if [ ! -f "$makefile_path" ]; then
echo "Warning: lucky Makefile not found. Skipping." >&2
return 1
fi
echo "正在更新 lucky Makefile..."
# 使用本地补丁文件,而不是下载
local patch_line="\\t[ -f \$(TOPDIR)/../patches/lucky_${version}_Linux_\$(LUCKY_ARCH)_wanji.tar.gz ] && install -Dm644 \$(TOPDIR)/../patches/lucky_${version}_Linux_\$(LUCKY_ARCH)_wanji.tar.gz \$(PKG_BUILD_DIR)/\$(PKG_NAME)_\$(PKG_VERSION)_Linux_\$(LUCKY_ARCH).tar.gz"
# 确保 Build/Prepare 部分存在,然后在其后添加我们的行
if grep -q "Build/Prepare" "$makefile_path"; then
sed -i "/Build\\/Prepare/a\\$patch_line" "$makefile_path"
# 删除任何现有的 wget 命令
sed -i '/wget/d' "$makefile_path"
echo "lucky Makefile 更新完成。"
else
echo "Warning: lucky Makefile 中未找到 'Build/Prepare'。跳过。" >&2
fi
}
fix_rust_compile_error() {
if [ -f "$BUILD_DIR/feeds/packages/lang/rust/Makefile" ]; then
sed -i 's/download-ci-llvm=true/download-ci-llvm=false/g' "$BUILD_DIR/feeds/packages/lang/rust/Makefile"
fi
}
update_smartdns() {
# smartdns 仓库地址
local SMARTDNS_REPO="https://github.com/ZqinKing/openwrt-smartdns.git"
local SMARTDNS_DIR="$BUILD_DIR/feeds/packages/net/smartdns"
# luci-app-smartdns 仓库地址
local LUCI_APP_SMARTDNS_REPO="https://github.com/pymumu/luci-app-smartdns.git"
local LUCI_APP_SMARTDNS_DIR="$BUILD_DIR/feeds/luci/applications/luci-app-smartdns"
echo "正在更新 smartdns..."
rm -rf "$SMARTDNS_DIR"
if ! git clone --depth=1 "$SMARTDNS_REPO" "$SMARTDNS_DIR"; then
echo "错误:从 $SMARTDNS_REPO 克隆 smartdns 仓库失败" >&2
exit 1
fi
install -Dm644 "$BASE_PATH/patches/100-smartdns-optimize.patch" "$SMARTDNS_DIR/patches/100-smartdns-optimize.patch"
sed -i '/define Build\/Compile\/smartdns-ui/,/endef/s/CC=\$(TARGET_CC)/CC="\$(TARGET_CC_NOCACHE)"/' "$SMARTDNS_DIR/Makefile"
echo "正在更新 luci-app-smartdns..."
rm -rf "$LUCI_APP_SMARTDNS_DIR"
if ! git clone --depth=1 "$LUCI_APP_SMARTDNS_REPO" "$LUCI_APP_SMARTDNS_DIR"; then
echo "错误:从 $LUCI_APP_SMARTDNS_REPO 克隆 luci-app-smartdns 仓库失败" >&2
exit 1
fi
}
update_diskman() {
local path="$BUILD_DIR/feeds/luci/applications/luci-app-diskman"
local repo_url="https://github.com/lisaac/luci-app-diskman.git"
if [ -d "$path" ]; then
echo "正在更新 diskman..."
cd "$BUILD_DIR/feeds/luci/applications" || return # 显式路径避免歧义
\rm -rf "luci-app-diskman" # 直接删除目标目录
if ! git clone --filter=blob:none --no-checkout "$repo_url" diskman; then
echo "错误:从 $repo_url 克隆 diskman 仓库失败" >&2
exit 1
fi
cd diskman || return
git sparse-checkout init --cone
git sparse-checkout set applications/luci-app-diskman || return # 错误处理
git checkout --quiet # 静默检出避免冗余输出
mv applications/luci-app-diskman ../luci-app-diskman || return # 添加错误检查
cd .. || return
\rm -rf diskman
cd "$BUILD_DIR"
sed -i 's/fs-ntfs /fs-ntfs3 /g' "$path/Makefile"
sed -i '/ntfs-3g-utils /d' "$path/Makefile"
fi
}
add_quickfile() {
local repo_url="https://github.com/sbwml/luci-app-quickfile.git"
local target_dir="$BUILD_DIR/package/emortal/quickfile"
if [ -d "$target_dir" ]; then
rm -rf "$target_dir"
fi
echo "正在添加 luci-app-quickfile..."
if ! git clone --depth 1 "$repo_url" "$target_dir"; then
echo "错误:从 $repo_url 克隆 luci-app-quickfile 仓库失败" >&2
exit 1
fi
local makefile_path="$target_dir/quickfile/Makefile"
if [ -f "$makefile_path" ]; then
sed -i '/\t\$(INSTALL_BIN) \$(PKG_BUILD_DIR)\/quickfile-\$(ARCH_PACKAGES)/c\
\tif [ "\$(ARCH_PACKAGES)" = "x86_64" ]; then \\\
\t\t\$(INSTALL_BIN) \$(PKG_BUILD_DIR)\/quickfile-x86_64 \$(1)\/usr\/bin\/quickfile; \\\
\telse \\\
\t\t\$(INSTALL_BIN) \$(PKG_BUILD_DIR)\/quickfile-aarch64_generic \$(1)\/usr\/bin\/quickfile; \\\
\tfi' "$makefile_path"
fi
}
# 设置 Nginx 默认配置
set_nginx_default_config() {
local nginx_config_path="$BUILD_DIR/feeds/packages/net/nginx-util/files/nginx.config"
if [ -f "$nginx_config_path" ]; then
# 使用 cat 和 heredoc 覆盖写入 nginx.config 文件
cat > "$nginx_config_path" <<EOF
config main 'global'
option uci_enable 'true'
config server '_lan'
list listen '443 ssl default_server'
list listen '[::]:443 ssl default_server'
option server_name '_lan'
list include 'restrict_locally'
list include 'conf.d/*.locations'
option uci_manage_ssl 'self-signed'
option ssl_certificate '/etc/nginx/conf.d/_lan.crt'
option ssl_certificate_key '/etc/nginx/conf.d/_lan.key'
option ssl_session_cache 'shared:SSL:32k'
option ssl_session_timeout '64m'
option access_log 'off; # logd openwrt'
config server 'http_only'
list listen '80'
list listen '[::]:80'
option server_name 'http_only'
list include 'conf.d/*.locations'
option access_log 'off; # logd openwrt'
EOF
fi
local nginx_template="$BUILD_DIR/feeds/packages/net/nginx-util/files/uci.conf.template"
if [ -f "$nginx_template" ]; then
# 检查是否已存在配置,避免重复添加
if ! grep -q "client_body_in_file_only clean;" "$nginx_template"; then
sed -i "/client_max_body_size 128M;/a\\
\tclient_body_in_file_only clean;\\
\tclient_body_temp_path /mnt/tmp;" "$nginx_template"
fi
fi
local luci_support_script="$BUILD_DIR/feeds/packages/net/nginx/files-luci-support/60_nginx-luci-support"
if [ -f "$luci_support_script" ]; then
# 检查是否已经为 ubus location 应用了修复
if ! grep -q "client_body_in_file_only off;" "$luci_support_script"; then
echo "正在为 Nginx ubus location 配置应用修复..."
sed -i "/ubus_parallel_req 2;/a\\ client_body_in_file_only off;\\n client_max_body_size 1M;" "$luci_support_script"
fi
fi
}
update_uwsgi_limit_as() {
# 更新 uwsgi 的 limit-as 配置,将其值更改为 8192
local cgi_io_ini="$BUILD_DIR/feeds/packages/net/uwsgi/files-luci-support/luci-cgi_io.ini"
local webui_ini="$BUILD_DIR/feeds/packages/net/uwsgi/files-luci-support/luci-webui.ini"
if [ -f "$cgi_io_ini" ]; then
# 将 luci-cgi_io.ini 文件中的 limit-as 值更新为 8192
sed -i 's/^limit-as = .*/limit-as = 8192/g' "$cgi_io_ini"
fi
if [ -f "$webui_ini" ]; then
# 将 luci-webui.ini 文件中的 limit-as 值更新为 8192
sed -i 's/^limit-as = .*/limit-as = 8192/g' "$webui_ini"
fi
}
remove_tweaked_packages() {
local target_mk="$BUILD_DIR/include/target.mk"
if [ -f "$target_mk" ]; then
# 检查目标行是否未被注释
if grep -q "^DEFAULT_PACKAGES += \$(DEFAULT_PACKAGES.tweak)" "$target_mk"; then
# 如果未被注释,则添加注释
sed -i 's/DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.tweak)/# DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.tweak)/g' "$target_mk"
fi
fi
}
update_argon() {
local repo_url="https://github.com/ZqinKing/luci-theme-argon.git"
local dst_theme_path="$BUILD_DIR/feeds/luci/themes/luci-theme-argon"
local tmp_dir
tmp_dir=$(mktemp -d)
echo "正在更新 argon 主题..."
if ! git clone --depth 1 "$repo_url" "$tmp_dir"; then
echo "错误:从 $repo_url 克隆 argon 主题仓库失败" >&2
rm -rf "$tmp_dir"
exit 1