-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.sh
executable file
·1442 lines (1292 loc) · 68 KB
/
common.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
function __error_msg() {
echo -e "\033[31m[ERROR]\033[0m $*"
}
function __success_msg() {
echo -e "\033[32m[SUCCESS]\033[0m $*"
}
function __warning_msg() {
echo -e "\033[33m[WARNING]\033[0m $*"
}
function __info_msg() {
echo -e "\033[36m[INFO]\033[0m $*"
}
function __red_color() {
echo -e "\033[31m$*\033[0m"
}
function __green_color() {
echo -e "\033[32m$*\033[0m"
}
function __yellow_color() {
echo -e "\033[33m$*\033[0m"
}
function __blue_color() {
echo -e "\033[34m$*\033[0m"
}
function __magenta_color() {
echo -e "\033[35m$*\033[0m"
}
function __cyan_color() {
echo -e "\033[36m$*\033[0m"
}
function __white_color() {
echo -e "\033[37m$*\033[0m"
}
################################################################################################################
# 环境变量
################################################################################################################
function parse_settings() {
source build/$MATRIX_TARGET/settings.ini
if [[ -n "$INPUTS_SOURCE_BRANCH" ]]; then
[[ $INPUTS_SOURCE_BRANCH =~ (default|DEFAULT|Default) ]] && SOURCE_BRANCH="$SOURCE_BRANCH" || SOURCE_BRANCH="$INPUTS_SOURCE_BRANCH"
[[ $INPUTS_CONFIG_FILE =~ (default|DEFAULT|Default) ]] && CONFIG_FILE="$CONFIG_FILE" || CONFIG_FILE="$INPUTS_CONFIG_FILE"
[[ $INPUTS_BIOS_MODE =~ (default|DEFAULT|Default) ]] && BIOS_MODE="$BIOS_MODE" || BIOS_MODE="$INPUTS_BIOS_MODE"
[[ $INPUTS_ENABLE_CCACHE =~ (default|DEFAULT|Default) ]] && ENABLE_CCACHE="$ENABLE_CCACHE" || ENABLE_CCACHE="$INPUTS_ENABLE_CCACHE"
[[ $INPUTS_UPLOAD_FIRMWARE =~ (default|DEFAULT|Default) ]] && UPLOAD_FIRMWARE="$UPLOAD_FIRMWARE" || UPLOAD_FIRMWARE="$INPUTS_UPLOAD_FIRMWARE"
[[ $INPUTS_UPLOAD_RELEASE =~ (default|DEFAULT|Default) ]] && UPLOAD_RELEASE="$UPLOAD_RELEASE" || UPLOAD_RELEASE="$INPUTS_UPLOAD_RELEASE"
ENABLE_SSH="$INPUTS_ENABLE_SSH"
fi
if [[ $NOTICE_TYPE =~ (TG|telegram|Telegram|TELEGRAM) ]]; then
NOTICE_TYPE="TG"
elif [[ $NOTICE_TYPE =~ (PUSH|pushplus|Pushplus|PUSHPLUS) ]]; then
NOTICE_TYPE="PUSH"
else
NOTICE_TYPE="false"
fi
if [[ $PACKAGES_REPO =~ (default|DEFAULT|Default) || -z $PACKAGES_REPO ]]; then
PACKAGES_REPO="roacn/openwrt-packages"
fi
local package_repo_owner=`echo "$PACKAGES_REPO" | awk -F/ '{print $1}'` 2>/dev/null
if [[ $package_repo_owner == $GITHUB_ACTOR ]]; then
ENABLE_PACKAGES_UPDATE="true"
update_packages
else
ENABLE_PACKAGES_UPDATE="false"
fi
case "$SOURCE_ABBR" in
lede|Lede|LEDE)
SOURCE_URL="https://github.com/coolsnowwolf/lede"
SOURCE="lede"
SOURCE_OWNER="Lean's"
LUCI_EDITION="18.06"
;;
openwrt|Openwrt|OpenWrt|OpenWRT|OPENWRT|official|Official|OFFICIAL)
SOURCE_URL="https://github.com/openwrt/openwrt"
SOURCE="official"
SOURCE_OWNER="openwrt's"
LUCI_EDITION="$(echo $SOURCE_BRANCH |sed 's/openwrt-//g')"
;;
lienol|Lienol|LIENOL)
SOURCE_URL="https://github.com/Lienol/openwrt"
SOURCE="lienol"
SOURCE_OWNER="Lienol's"
LUCI_EDITION="$(echo $SOURCE_BRANCH)"
;;
immortalwrt|Immortalwrt|IMMORTALWRT|mortal|immortal)
SOURCE_URL="https://github.com/immortalwrt/immortalwrt"
SOURCE="Immortalwrt"
SOURCE_OWNER="Immortalwrt's"
LUCI_EDITION="$(echo $SOURCE_BRANCH |sed 's/openwrt-//g')"
;;
*)
__error_msg "不支持$SOURCE_ABBR源码"
exit 1
;;
esac
# 基础设置
echo "SOURCE_BRANCH=$SOURCE_BRANCH" >> $GITHUB_ENV
echo "CONFIG_FILE=$CONFIG_FILE" >> $GITHUB_ENV
echo "FIRMWARE_TYPE=$FIRMWARE_TYPE" >> $GITHUB_ENV
echo "BIOS_MODE=$BIOS_MODE" >> $GITHUB_ENV
echo "ENABLE_CCACHE=$ENABLE_CCACHE" >> $GITHUB_ENV
echo "ENABLE_SSH=$ENABLE_SSH" >> $GITHUB_ENV
echo "UPLOAD_CONFIG=$UPLOAD_CONFIG" >> $GITHUB_ENV
echo "UPLOAD_FIRMWARE=$UPLOAD_FIRMWARE" >> $GITHUB_ENV
echo "UPLOAD_RELEASE=$UPLOAD_RELEASE" >> $GITHUB_ENV
echo "NOTICE_TYPE=$NOTICE_TYPE" >> $GITHUB_ENV
echo "DIY_PART_SH=$DIY_PART_SH" >> $GITHUB_ENV
echo "PACKAGES_REPO=$PACKAGES_REPO" >> $GITHUB_ENV
echo "PACKAGES_BRANCH=$PACKAGES_BRANCH" >> $GITHUB_ENV
echo "REPOSITORY=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
echo "SOURCE=$SOURCE" >> $GITHUB_ENV
echo "SOURCE_URL=$SOURCE_URL" >> $GITHUB_ENV
echo "SOURCE_OWNER=$SOURCE_OWNER" >> $GITHUB_ENV
echo "LUCI_EDITION=$LUCI_EDITION" >> $GITHUB_ENV
echo "ENABLE_PACKAGES_UPDATE=$ENABLE_PACKAGES_UPDATE" >> $GITHUB_ENV
echo "ENABLE_REPO_UPDATE=false" >> $GITHUB_ENV
echo "GITHUB_API=zzz_api" >> $GITHUB_ENV
# 日期时间
echo "COMPILE_DATE_MD=$(date +%m.%d)" >> $GITHUB_ENV
echo "COMPILE_DATE_HM=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV
echo "COMPILE_DATE_HMS=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
echo "COMPILE_DATE_CN=$(date +%Y年%m月%d日%H时%M分)" >> $GITHUB_ENV
echo "COMPILE_DATE_STAMP=$(date -d "$(date +'%Y-%m-%d %H:%M:%S')" +%s)" >> $GITHUB_ENV
# 路径
HOME_PATH="$GITHUB_WORKSPACE/openwrt"
echo "HOME_PATH=$HOME_PATH" >> $GITHUB_ENV
echo "BIN_PATH=$HOME_PATH/bin" >> $GITHUB_ENV
echo "AUTOUPDATE_PATH=$HOME_PATH/bin/autoupdate" >> $GITHUB_ENV
echo "FEEDS_PATH=$HOME_PATH/feeds" >> $GITHUB_ENV
echo "BUILD_PATH=$HOME_PATH/build" >> $GITHUB_ENV
echo "COMMON_PATH=$HOME_PATH/build/common" >> $GITHUB_ENV
echo "MATRIX_TARGET_PATH=$HOME_PATH/build/$MATRIX_TARGET" >> $GITHUB_ENV
echo "CONFIG_PATH=$HOME_PATH/build/$MATRIX_TARGET/config" >> $GITHUB_ENV
# 文件
echo "DIFFCONFIG_TXT=$HOME_PATH/diffconfig.txt" >> $GITHUB_ENV
echo "RELEASE_MD=$HOME_PATH/release.md" >> $GITHUB_ENV
echo "RELEASEINFO_MD=$HOME_PATH/build/$MATRIX_TARGET/release/releaseinfo.md" >> $GITHUB_ENV
echo "SETTINGS_INI=$HOME_PATH/build/$MATRIX_TARGET/settings.ini" >> $GITHUB_ENV
echo "FILES_TO_CLEAR=$HOME_PATH/default_clear" >> $GITHUB_ENV
echo "CONFFLICTIONS=$HOME_PATH/confflictions" >> $GITHUB_ENV
# 源码files文件夹
# https://github.com/coolsnowwolf/lede/tree/master/package/base-files/files
echo "FILES_PATH=$HOME_PATH/package/base-files/files" >> $GITHUB_ENV
echo "FILE_DEFAULT_UCI=$HOME_PATH/package/base-files/files/etc/default_uci" >> $GITHUB_ENV
echo "FILES_TO_DELETE=$HOME_PATH/package/base-files/files/etc/default_delete" >> $GITHUB_ENV
echo "FILES_TO_KEEP=$HOME_PATH/package/base-files/files/lib/upgrade/keep.d/base-files-essential" >> $GITHUB_ENV
echo "FILENAME_DEFAULT_UCI=default_uci" >> $GITHUB_ENV
echo "FILENAME_DEFAULT_SETTINGS=default_settings" >> $GITHUB_ENV
echo "FILENAME_DEFAULT_RUNONCE=default_settings_runonce" >> $GITHUB_ENV
echo "FILENAME_CONFIG_GEN=config_generate" >> $GITHUB_ENV
echo "FILENAME_TO_DELETE=default_delete" >> $GITHUB_ENV
local cpu_name=$(cat /proc/cpuinfo | grep name | cut -d: -f2 | uniq | sed 's/^[[:space:]]\+//')
echo "::notice title=GithubCPU::$cpu_name"
echo "::notice title=编译时间::$(date +'%Y-%m-%d %H:%M:%S')"
echo "::notice title=源码链接::$SOURCE_URL"
echo "::notice title=源码分支::$SOURCE_BRANCH"
echo "::notice title=固件类型::$FIRMWARE_TYPE"
echo "::notice title=LUCI版本::$LUCI_EDITION"
}
################################################################################################################
# 编译开始通知
################################################################################################################
function notice_begin() {
if [[ "$NOTICE_TYPE" == "TG" ]]; then
curl -k --data chat_id="$TELEGRAM_CHAT_ID" --data "text=✨主人✨:您正在使用【$REPOSITORY】仓库【$MATRIX_TARGET】文件夹编译【$SOURCE-$LUCI_EDITION】固件,请耐心等待...... 😋" "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage"
elif [[ "$NOTICE_TYPE" == "PUSH" ]]; then
curl -k --data token="$PUSH_PLUS_TOKEN" --data title="开始编译【$SOURCE-$MATRIX_TARGET】" --data "content=✨主人✨:您正在使用【$REPOSITORY】仓库【$MATRIX_TARGET】文件夹编译【$SOURCE-$LUCI_EDITION】固件,请耐心等待...... 😋" "http://www.pushplus.plus/send"
fi
}
################################################################################################################
# 编译完成通知
################################################################################################################
function notice_end() {
if [[ "$NOTICE_TYPE" == "TG" ]]; then
curl -k --data chat_id="$TELEGRAM_CHAT_ID" --data "text=🎉 我亲爱的✨主人✨:您使用【$REPOSITORY】仓库【$MATRIX_TARGET】文件夹编译的【$FIRMWARE_NAME_PREFIX】固件顺利编译完成了!💐 https://github.com/$GITHUB_REPOSITORY/releases" "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage"
elif [[ "$NOTICE_TYPE" == "PUSH" ]]; then
curl -k --data token="$PUSH_PLUS_TOKEN" --data title="【$SOURCE-$TARGET_PROFILE】编译成功" --data "content=🎉 我亲爱的✨主人✨:您使用【$REPOSITORY】仓库【$MATRIX_TARGET】文件夹编译的【$FIRMWARE_NAME_PREFIX】固件顺利编译完成了!💐 https://github.com/$GITHUB_REPOSITORY/releases" "http://www.pushplus.plus/send"
fi
}
################################################################################################################
# 初始化编译环境
################################################################################################################
function init_environment() {
sudo -E apt-get -qq update -y
#sudo -E apt-get -qq full-upgrade -y
sudo -E apt-get -qq install -y ack antlr3 aria2 asciidoc autoconf automake autopoint binutils bison \
build-essential bzip2 ccache clang cmake cpio curl device-tree-compiler fastjar flex g++-multilib gawk \
gcc-multilib gettext git git-core gperf haveged help2man intltool lib32stdc++6 libc6-dev-i386 libelf-dev \
libfuse-dev libglib2.0-dev libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev \
libpcap0.8-dev libpython3-dev libreadline-dev libssl-dev libtool libz-dev llvm lrzsz mkisofs msmtp \
nano ninja-build p7zip p7zip-full patch pkgconf python2.7 python3 python3-pip qemu-utils rename rsync \
scons squashfs-tools subversion swig texinfo tree uglifyjs unzip upx upx-ucl vim wget xmlto xxd zlib1g-dev
#sudo -E apt-get -qq autoremove -y --purge
#sudo -E apt-get -qq clean
sudo timedatectl set-timezone "$TZ"
# "/"目录创建文件夹$MATRIX_TARGET
sudo mkdir -p /$MATRIX_TARGET
sudo chown $USER:$GROUPS /$MATRIX_TARGET
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
}
################################################################################################################
# 下载源码
################################################################################################################
function git_clone_source() {
# 在每matrix.target目录下下载源码
git clone -b $SOURCE_BRANCH $SOURCE_URL openwrt > /dev/null 2>&1
ln -sf /$MATRIX_TARGET/openwrt $HOME_PATH
# 将build等文件夹复制到openwrt文件夹下
cd $GITHUB_WORKSPACE
cp -rf $(find ./ -maxdepth 1 -type d ! -path './openwrt' ! -path './') $HOME_PATH/
# 下载common仓库
sudo rm -rf $COMMON_PATH && git clone -b main --depth 1 https://github.com/stanlyshi/common $COMMON_PATH
chmod -Rf +x $BUILD_PATH
}
################################################################################################################
# 插件源仓库更新
################################################################################################################
function update_packages() {
local gitdate=$(curl -H "Authorization: token $REPO_TOKEN" -s "https://api.github.com/repos/$PACKAGES_REPO/actions/runs" | jq -r '.workflow_runs[0].created_at')
local gitdate_timestamp=$(date -d "$gitdate" +%s)
local gitdate_hms="$(date -d "$gitdate" '+%Y-%m-%d %H:%M:%S')"
echo "github latest merge upstream timestamp: $gitdate_timestamp, time: $gitdate_hms"
local now_hms="$(date '+%Y-%m-%d %H:%M:%S')"
local now_timestamp=$(date -d "$now_hms" +%s)
echo "time now timestamp: $now_timestamp, time: $now_hms"
if [[ $(($gitdate_timestamp+1800)) < $now_timestamp ]]; then
curl -X POST https://api.github.com/repos/$PACKAGES_REPO/dispatches \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "Authorization: token $REPO_TOKEN" \
--data "{\"event_type\": \"updated by ${GITHUB_REPOSITORY##*/}\"}"
fi
__info_msg "packages url: https://github.com/$PACKAGES_REPO"
}
################################################################################################################
# 加载源,补丁和自定义设置
################################################################################################################
function do_diy() {
cd $HOME_PATH
# 添加插件源、更新插件源
update_feeds
# 执行公共脚本
diy_public
# 执行私有脚本
if [[ $SOURCE =~ (lede|Lede|LEDE) ]]; then
diy_lede
elif [[ $SOURCE =~ (openwrt|Openwrt|OpenWrt|OpenWRT|OPENWRT|official|Official|OFFICIAL) ]]; then
diy_openwrt
elif [[ $SOURCE =~ (lienol|Lienol|LIENOL) ]]; then
diy_lienol
elif [[ $SOURCE =~ (immortalwrt|Immortalwrt|IMMORTALWRT|mortal|immortal) ]]; then
diy_immortalwrt
fi
# 执行diy_part.sh脚本
/bin/bash "$MATRIX_TARGET_PATH/$DIY_PART_SH"
# 再次更新插件源,并安装插件源
./scripts/feeds update -a > /dev/null 2>&1 && ./scripts/feeds install -a > /dev/null 2>&1
# 修改golang版本
rm -rf feeds/packages/lang/golang
git clone https://github.com/sbwml/packages_lang_golang -b 22.x feeds/packages/lang/golang
# 修改.config文件
modify_config
# 编译机型CPU架构、内核版本等信息,替换内核等
firmware_settings
}
################################################################################################################
# 插件源
################################################################################################################
function update_feeds() {
echo "--------------common_update_feeds start--------------"
echo
cd $HOME_PATH
# 添加插件源
__yellow_color "开始添加插件源..."
local packages_url="https://github.com/$PACKAGES_REPO.git"
local packages_branch="$PACKAGES_BRANCH"
local packages="pkg$GITHUB_ACTOR"
__info_msg "源码:$SOURCE 插件源仓库:$packages_url 插件源分支:$packages_branch 插件源文件夹:$packages"
sed -i "/${packages}/d; /#/d; /^$/d; /ssrplus/d; /helloworld/d; /passwall/d; /OpenClash/d" "feeds.conf.default"
# 当插件源添加至 feeds.conf.default 首行时,优先安装自己添加的插件源
#sed -i "1i src-git $packages $packages_url;$packages_branch" "feeds.conf.default"
# 当插件源添加至 feeds.conf.default 结尾时,重复插件,先删除相应文件,操作完毕后,再一次运行./scripts/feeds update -a,即可更新对应的.index与target.index文件
if [[ -z "$packages_branch" ]]; then
cat >> "feeds.conf.default" <<-EOF
src-git $packages $packages_url
EOF
else
cat >> "feeds.conf.default" <<-EOF
src-git $packages $packages_url;$packages_branch
EOF
fi
# 更新插件源
__yellow_color "开始更新插件源..."
./scripts/feeds clean
./scripts/feeds update -a > /dev/null 2>&1
sudo rm -rf $FEEDS_PATH/$packages/{LICENSE,*README*,*readme*,.git,.github,.gitignore} > /dev/null 2>&1
# 删除自己插件源不用的文件
local files_to_delete=(".git" ".github")
for X in $files_to_delete[*]; do
find $FEEDS_PATH -maxdepth 3 -type d -name "$X" | grep "$packages" | xargs sudo rm -rf {}
done
# 删除源码中重复插件及依赖
for X in $(ls $FEEDS_PATH/$packages); do
find $FEEDS_PATH -maxdepth 3 -type d -name "$X" | grep -v "$packages" | xargs sudo rm -rf {}
done
# 设置中文语言包(官方:zh_Hans,Lede:zh-cn;对缺失相应文件的插件进行补充)
__yellow_color "开始设置中文语言包..."
for e in $(ls -d $FEEDS_PATH/$packages/luci-*/po); do
if [[ -d $e/zh-cn && ! -d $e/zh_Hans ]]; then
rm -rf $e/zh_Hans && ln -s zh-cn $e/zh_Hans 2>/dev/null
elif [[ -d $e/zh_Hans && ! -d $e/zh-cn ]]; then
rm -rf $e/zh-cn && ln -s zh_Hans $e/zh-cn 2>/dev/null
fi
done
echo
echo "--------------common_update_feeds end--------------"
}
################################################################################################################
# 各源码库的公共脚本(文件检测、添加插件源、diy、files、patch等,以及Openwrt编译完成后的首次运行设置)
################################################################################################################
function diy_public() {
echo "--------------common_diy_public start--------------"
echo
cd $HOME_PATH
__yellow_color "开始检测文件是否存在..."
# 检查.config文件是否存在
if [ -z "$(ls -A "$CONFIG_PATH/$CONFIG_FILE" 2>/dev/null)" ]; then
__error_msg "编译脚本的[$MATRIX_TARGET配置文件夹内缺少$CONFIG_FILE文件],请在[$MATRIX_TARGET/config/]文件夹内补齐"
exit 1
fi
# 检查diy_part.sh文件是否存在
if [ -z "$(ls -A "$MATRIX_TARGET_PATH/$DIY_PART_SH" 2>/dev/null)" ]; then
__error_msg "编译脚本的[$MATRIX_TARGET文件夹内缺少$DIY_PART_SH文件],请在[$MATRIX_TARGET]文件夹内补齐"
exit 1
fi
__yellow_color "开始替换diy文件夹内文件..."
# 替换编译前源码中对应目录文件
sudo rm -rf $MATRIX_TARGET_PATH/diy/{*README*,*readme*} > /dev/null 2>&1
if [ -n "$(ls -A "$MATRIX_TARGET_PATH/diy" 2>/dev/null)" ]; then
cp -rf $MATRIX_TARGET_PATH/diy/* $HOME_PATH > /dev/null 2>&1
fi
__yellow_color "开始替换files文件夹内文件..."
# 替换编译后固件中对应目录文件(备用)
sudo rm -rf $MATRIX_TARGET_PATH/files/{*README*,*readme*} > /dev/null 2>&1
if [ -n "$(ls -A "$MATRIX_TARGET_PATH/files" 2>/dev/null)" ]; then
cp -rf $MATRIX_TARGET_PATH/files $HOME_PATH > /dev/null 2>&1
fi
__yellow_color "开始执行补丁文件..."
# 打补丁
sudo rm -rf $MATRIX_TARGET_PATH/patches/{*README*,*readme*} > /dev/null 2>&1
if [ -n "$(ls -A "$MATRIX_TARGET_PATH/patches" 2>/dev/null)" ]; then
find "$MATRIX_TARGET_PATH/patches" -type f -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 --forward --no-backup-if-mismatch"
fi
#__yellow_color "开始添加openwrt.sh(或openwrt.lxc.sh)..."
# openwrt.sh
#[[ ! -d "$FILES_PATH/usr/bin" ]] && mkdir -p $FILES_PATH/usr/bin
#if [[ "$FIRMWARE_TYPE" == "lxc" ]]; then
# wget https://raw.githubusercontent.com/stanlyshi/pve/main/openwrt.lxc.sh -O /usr/bin/openwrt $FILES_PATH/usr/bin/openwrt && sudo chmod +x $FILES_PATH/usr/bin/openwrt
#else
# wget https://raw.githubusercontent.com/stanlyshi/luci-app-autoupdate/main/root/usr/bin/autoupdate -O $FILES_PATH/usr/bin/openwrt && sudo chmod +x $FILES_PATH/usr/bin/openwrt
#fi
__yellow_color "开始设置自动更新插件..."
# 自动更新插件(luci-app-autoupdate)
if [[ $FIRMWARE_TYPE == "lxc" ]]; then
find $HOME_PATH/feeds -type d -name "luci-app-autoupdate" | xargs -i sudo rm -rf {}
find $HOME_PATH/package -type d -name "luci-app-autoupdate" | xargs -i sudo rm -rf {}
if [[ -n "$(grep "luci-app-autoupdate" $HOME_PATH/include/target.mk)" ]]; then
sed -i 's/luci-app-autoupdate//g' $HOME_PATH/include/target.mk
fi
__info_msg "lxc固件,删除自动更新插件"
else
find $HOME_PATH/feeds -type d -name "luci-app-autoupdate" | xargs -i sudo rm -rf {}
find $HOME_PATH/package -type d -name "luci-app-autoupdate" | xargs -i sudo rm -rf {}
git clone https://github.com/stanlyshi/luci-app-autoupdate $HOME_PATH/package/luci-app-autoupdate 2>/dev/null
if [[ `grep -c "luci-app-autoupdate" $HOME_PATH/include/target.mk` -eq '0' ]]; then
sed -i 's/DEFAULT_PACKAGES:=/DEFAULT_PACKAGES:=luci-app-autoupdate luci-app-ttyd /g' $HOME_PATH/include/target.mk
fi
if [[ -d "$HOME_PATH/package/luci-app-autoupdate" ]]; then
__info_msg "增加定时更新固件的插件成功"
else
__error_msg "插件源码下载失败"
fi
# autoupdate插件版本
if [[ -f "$HOME_PATH/package/luci-app-autoupdate/root/usr/bin/autoupdate" ]]; then
AUTOUPDATE_VERSION=$(grep -Eo "Version=V[0-9.]+" "$HOME_PATH/package/luci-app-autoupdate/root/usr/bin/autoupdate" |grep -Eo [0-9.]+)
echo "AUTOUPDATE_VERSION=$AUTOUPDATE_VERSION" >> $GITHUB_ENV
__info_msg "luci-app-autoupdate版本:$AUTOUPDATE_VERSION"
fi
fi
# "默认设置文件..."
# https://github.com/coolsnowwolf/lede/blob/master/package/lean/default-settings/files/zzz-default-settings
export ZZZ_PATH="$(find "$HOME_PATH/package" -type f -name "*-default-settings" | grep files)"
if [[ -n "$ZZZ_PATH" ]]; then
echo "ZZZ_PATH=$ZZZ_PATH" >> $GITHUB_ENV
fi
__yellow_color "开始修改IP设置..."
# 修改源码中IP设置
local def_ipaddress="$(grep "ipaddr:-" "$FILES_PATH/bin/$FILENAME_CONFIG_GEN" | grep -v 'addr_offset' | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")"
local new_ipaddress="$(grep -E "^uci set network.lan.ipaddr" $MATRIX_TARGET_PATH/$DIY_PART_SH | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")"
if [[ -n "$def_ipaddress" && -n "$new_ipaddress" ]]; then
sed -i "s/${def_ipaddress}/${new_ipaddress}/g" $FILES_PATH/bin/$FILENAME_CONFIG_GEN
__info_msg "IP地址从[$def_ipaddress]替换为[$new_ipaddress]"
else
__info_msg "使用默认IP地址:$def_ipaddress"
fi
__yellow_color "开始执行其它设置..."
# Openwrt初次运行初始化设置
# default_uci文件,UCI基础设置
echo "#!/bin/sh" > $FILES_PATH/etc/$FILENAME_DEFAULT_UCI && sudo chmod +x $FILES_PATH/etc/$FILENAME_DEFAULT_UCI
cp -rf $COMMON_PATH/custom/$FILENAME_DEFAULT_RUNONCE $FILES_PATH/etc/init.d/$FILENAME_DEFAULT_RUNONCE && sudo chmod +x $FILES_PATH/etc/init.d/$FILENAME_DEFAULT_RUNONCE
cp -rf $COMMON_PATH/custom/$FILENAME_DEFAULT_SETTINGS $FILES_PATH/etc/$FILENAME_DEFAULT_SETTINGS && sudo chmod +x $FILES_PATH/etc/$FILENAME_DEFAULT_SETTINGS
cat >> $FILES_PATH/etc/$FILENAME_DEFAULT_SETTINGS <<-EOF
rm -rf /etc/init.d/$FILENAME_DEFAULT_RUNONCE
rm -rf /etc/$FILENAME_DEFAULT_UCI
rm -rf /etc/$FILENAME_TO_DELETE
rm -rf /etc/$FILENAME_DEFAULT_SETTINGS
exit 0
EOF
# default_delete文件,Openwrt固件升级时需要删除的文件
echo "#!/bin/sh" > $FILES_PATH/etc/$FILENAME_TO_DELETE && sudo chmod +x "$FILES_PATH/etc/$FILENAME_TO_DELETE"
# base-files-essential文件,Openwrt固件升级时需要保留的文件
if [[ -z "$(grep "background" $FILES_TO_KEEP)" ]]; then
cat >> "$FILES_TO_KEEP" <<-EOF
/www/luci-static/argon/background/
/etc/smartdns/custom.conf
EOF
fi
echo
echo "--------------common_diy_public end--------------"
}
################################################################################################################
# LEDE源码库的私有脚本(LEDE源码对应的修改,请在此处)
################################################################################################################
function diy_lede() {
echo "--------------common_diy_lede start--------------"
echo
cd $HOME_PATH
if [[ -n "$ZZZ_PATH" ]]; then
#__info_msg "去除防火墙规则"
#sed -i '/to-ports 53/d' $ZZZ_PATH
__info_msg "设置密码为空"
sed -i '/CYXluq4wUazHjmCDBCqXF/d' $ZZZ_PATH
fi
# 修复后台管理页面无法打开,降级openssl到1.1.1版本
#if [[ "$FIRMWARE_TYPE" == "lxc" ]]; then
# __info_msg "修复lxc固件openssl"
# sudo rm -rf "$HOME_PATH/include/openssl-module.mk"
# sudo rm -rf "$HOME_PATH/package/libs/openssl"
# cp -rf "$HOME_PATH/build/common/share/include/openssl-engine.mk" "$HOME_PATH/include/openssl-engine.mk"
# cp -rf "$HOME_PATH/build/common/share/package/libs/openssl" "$HOME_PATH/package/libs/openssl"
#fi
echo
echo "--------------common_diy_lede end--------------"
}
################################################################################################################
# 官方源码库的私有脚本(官方源码对应的修改,请在此处)
################################################################################################################
function diy_openwrt() {
echo "--------------common_diy_openwrt start--------------"
echo
cd $HOME_PATH
echo "Reserved for Future Use."
echo
echo "--------------common_diy_openwrt end--------------"
}
################################################################################################################
# LIENOL源码库的私有脚本(LIENOL源码对应的修改,请在此处)
################################################################################################################
function diy_lienol() {
echo "--------------common_diy_lienol start--------------"
echo
cd $HOME_PATH
echo "Reserved for Future Use."
echo
echo "--------------common_diy_lienol end--------------"
}
################################################################################################################
# IMMORTALWRT源码库的私有脚本(IMMORTALWRT源码对应的修改,请在此处)
################################################################################################################
function diy_immortalwrt() {
echo "--------------common_diy_immortalwrt start--------------"
echo
cd $HOME_PATH
echo "Reserved for Future Use."
echo
echo "--------------common_diy_immortalwrt end--------------"
}
################################################################################################################
# 修改.config文件配置
################################################################################################################
function modify_config() {
echo "--------------common_modify_config start--------------"
echo
cd $HOME_PATH
rm -rf $CONFFLICTIONS && touch $CONFFLICTIONS
__yellow_color "开始处理.config文件..."
# 复制自定义.config文件
cp -rf $CONFIG_PATH/$CONFIG_FILE $HOME_PATH/.config
make defconfig > /dev/null 2>&1
# 缓存加速
if [[ $ENABLE_CCACHE =~ (fast|Fast|FAST) ]]; then
__info_msg "快速缓存加速,如编译出错,请尝试删除缓存,或切换为普通加速,或关闭缓存加速"
sed -i '/CONFIG_DEVEL/d' $HOME_PATH/.config > /dev/null 2>&1
sed -i '/CONFIG_CCACHE/d' $HOME_PATH/.config > /dev/null 2>&1
sed -i '$a CONFIG_DEVEL=y' $HOME_PATH/.config > /dev/null 2>&1
sed -i '$a CONFIG_CCACHE=y' $HOME_PATH/.config > /dev/null 2>&1
elif [[ $ENABLE_CCACHE =~ (true|True|TRUE|normal|Normal|NORMAL) ]]; then
__info_msg "普通缓存加速,如编译出错,请尝试删除缓存,或关闭缓存加速"
sed -i '/CONFIG_DEVEL/d' $HOME_PATH/.config > /dev/null 2>&1
sed -i '/CONFIG_CCACHE/d' $HOME_PATH/.config > /dev/null 2>&1
else
__info_msg "关闭缓存加速,希望快速编译,请在settings.ini中开启缓存加速"
sed -i '/CONFIG_DEVEL/d' $HOME_PATH/.config > /dev/null 2>&1
sed -i '/CONFIG_CCACHE/d' $HOME_PATH/.config > /dev/null 2>&1
fi
# lxc模式下编译.tar.gz固件
if [[ "$FIRMWARE_TYPE" == "lxc" ]]; then
sed -Ei 's/.*(CONFIG_TARGET_ROOTFS_TARGZ).*/\1=y/g' $HOME_PATH/.config
__info_msg "lxc固件,添加对openwrt-generic-rootfs.tar.gz文件编译"
fi
# https连接,检测修正,主要针对官方源码
# CONFIG_PACKAGE_ca-bundle=y 默认已经选择
# liubustream-mbedtls、liubustream-openssl、libustream-wolfssl,三者在后面设置
if [[ $SOURCE =~ (openwrt|Openwrt|OpenWrt|OpenWRT|OPENWRT|official|Official|OFFICIAL) ]]; then
sed -Ei 's/.*(CONFIG_PACKAGE_ca-certificates).*/\1=y/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_libustream-openssl).*/\1=y/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_libustream-mbedtls).*/# \1 is not set/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_libustream-wolfssl).*/# \1 is not set/g' $HOME_PATH/.config
__info_msg "官方源码,已经设置为支持https连接"
fi
# 官方源码:'状态'、'网络'、'系统'等主菜单,在默认情况下是未选中状态,进行修正
if [[ $SOURCE =~ (openwrt|Openwrt|OpenWrt|OpenWRT|OPENWRT|official|Official|OFFICIAL) ]]; then
sed -Ei 's/.*(CONFIG_PACKAGE_luci-mod-admin-full).*/\1=y/g' $HOME_PATH/.config
#sed -Ei 's/.*(CONFIG_PACKAGE_luci-mod-dsl).*/\1=y/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_luci-mod-network).*/\1=y/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_luci-mod-status).*/\1=y/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_luci-mod-system).*/\1=y/g' $HOME_PATH/.config
__info_msg "官方源码,'状态'、'系统'等主菜单检测设置"
fi
# Lede源码:修复lxc固件openssl无法打开后台管理界面,以wolfssl替代openssl(仅lede源码需要修改,官方不需要)
if [[ $FIRMWARE_TYPE == "lxc" && $SOURCE =~ (lede|Lede|LEDE) ]]; then
# 依赖关系
# LuCI -> Collections -> [ ] luci-ssl(依赖libustream-mbedtls)
# LuCI -> Collections -> [ ] luci-ssl-openssl(依赖libustream-openssl)
# Utilities -> [ ] cache-domains-mbedtls(依赖libustream-mbedtls)
# Utilities -> [ ] cache-domains-openssl(依赖libustream-openssl)
# Utilities -> cache-domains-wolfssl(依赖libustream-wolfssl)
# 库
# Libraries -> [ ] libustream-mbedtls(库文件,三选一,依赖libmbedtls)
# Libraries -> [ ] libustream-openssl(库文件,三选一,依赖libopenssl)
# Libraries -> [*] libustream-wolfssl(库文件,三选一,依赖libwolfssl)
# Libraries -> SSL -> [*] libmbedtls(库文件,自动勾选,无需关注)
# Libraries -> SSL -> [*] libopenssl(库文件,自动勾选,无需关注)
# Libraries -> SSL -> [*] libwolfssl(库文件,自动勾选,无需关注)
# 插件
# LuCI->Applications -> [ ] luci-app-cshark(依赖Network->cshark,cshark依赖libustream-mbedtls)
sed -Ei 's/.*(CONFIG_PACKAGE_libustream-wolfssl).*/\1=y/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_libustream-mbedtls).*/# \1 is not set/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_libustream-openssl).*/# \1 is not set/g' $HOME_PATH/.config
sed -i '/CONFIG_PACKAGE_luci-ssl-openssl=y/d' $HOME_PATH/.config
sed -i '/CONFIG_PACKAGE_luci-ssl=y/d' $HOME_PATH/.config
sed -i '/CONFIG_PACKAGE_luci-app-cshark=y/d' $HOME_PATH/.config
#sed -i '$a # CONFIG_PACKAGE_luci-ssl-openssl is not set' $HOME_PATH/.config
#sed -i '$a # CONFIG_PACKAGE_luci-ssl is not set' $HOME_PATH/.config
#sed -i '$a # CONFIG_PACKAGE_luci-app-cshark is not set' $HOME_PATH/.config
if [[ `grep -c "CONFIG_PACKAGE_cache-domains-mbedtls=y" $HOME_PATH/.config` -ge '1' || `grep -c "CONFIG_PACKAGE_cache-domains-openssl=y" $HOME_PATH/.config` -ge '1' ]]; then
sed -Ei 's/.*(CONFIG_PACKAGE_cache-domains-wolfssl).*/\1=y/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_cache-domains-mbedtls).*/# \1 is not set/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_cache-domains-openssl).*/# \1 is not set/g' $HOME_PATH/.config
echo "__error_msg \"lxc固件下,您选择cache-domains-mbedtls或cache-domains-openssl,与cache-domains-wolfssl库有冲突,替换为cache-domains-wolfssl\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
else
# 非lede源码lxc模式的其它固件:openwrt的所有固件、lede普通固件
# 非强制使用openssl,由.config决定,只解决冲突
if [[ `grep -c "CONFIG_PACKAGE_libustream-openssl=y" $HOME_PATH/.config` -ge '1' ]]; then
if [[ `grep -c "CONFIG_PACKAGE_libustream-mbedtls=y" $HOME_PATH/.config` -ge '1' ]]; then
sed -Ei 's/.*(CONFIG_PACKAGE_libustream-mbedtls).*/# \1 is not set/g' $HOME_PATH/.config
echo "__error_msg \"您同时选择libustream-mbedtls和libustream-openssl,库有冲突,只能二选一,已删除libustream-mbedtls库\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
# libustream-wolfssl可能处于=y或=m状态
if [[ `grep -c "CONFIG_PACKAGE_libustream-wolfssl=y" $HOME_PATH/.config` -ge '1' || `grep -c "CONFIG_PACKAGE_libustream-wolfssl=m" $HOME_PATH/.config` -ge '1' ]]; then
sed -Ei 's/.*(CONFIG_PACKAGE_libustream-wolfssl).*/# \1 is not set/g' $HOME_PATH/.config
echo "__error_msg \"您同时选择libustream-wolfssl和libustream-openssl,库有冲突,只能二选一,已删除libustream-wolfssl库\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
# luci-ssl(依赖于旧的libustream-mbedtls),替换为luci-ssl-openssl(依赖于libustream-openssl)
if [[ `grep -c "CONFIG_PACKAGE_luci-ssl=y" $HOME_PATH/.config` -ge '1' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-ssl=y/# CONFIG_PACKAGE_luci-ssl is not set/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_luci-ssl-openssl).*/\1=y/g' $HOME_PATH/.config
echo "__error_msg \"您选择luci-ssl(依赖于旧的libustream-mbedtls),与libustream-openssl库有冲突,替换为luci-ssl-openssl(依赖于libustream-openssl)\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
# cache-domains-mbedtls(依赖于旧的libustream-mbedtls),cache-domains-wolfssl(依赖于libustream-wolfssl)
# 替换为cache-domains-openssl(依赖于libustream-openssl)
if [[ `grep -c "CONFIG_PACKAGE_cache-domains-mbedtls=y" $HOME_PATH/.config` -ge '1' || `grep -c "CONFIG_PACKAGE_cache-domains-wolfssl=y" $HOME_PATH/.config` -ge '1' ]]; then
sed -i '/CONFIG_PACKAGE_cache-domains-mbedtls/d' $HOME_PATH/.config
sed -i '/CONFIG_PACKAGE_cache-domains-wolfssl/d' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_cache-domains-openssl).*/\1=y/g' $HOME_PATH/.config
echo "__error_msg \"您选择cache-domains-mbedtls或cache-domains-wolfssl,与cache-domains-openssl库有冲突,替换为cache-domains-openssl\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
fi
fi
if [[ `grep -c "CONFIG_TARGET_x86=y" $HOME_PATH/.config` -eq '1' || `grep -c "CONFIG_TARGET_rockchip=y" $HOME_PATH/.config` -eq '1' || `grep -c "CONFIG_TARGET_bcm27xx=y" $HOME_PATH/.config` -eq '1' ]]; then
#sed -Ei 's/.*(CONFIG_TARGET_IMAGES_GZIP).*/\1=y/g' $HOME_PATH/.config
#sed -Ei 's/.*(CONFIG_PACKAGE_snmpd).*/\1=y/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_openssh-sftp-server).*/\1=y/g' $HOME_PATH/.config
if [[ `grep -c "CONFIG_TARGET_ROOTFS_PARTSIZE=" $HOME_PATH/.config` -eq '1' ]]; then
local partsize="$(grep -Eo "CONFIG_TARGET_ROOTFS_PARTSIZE=[0-9]+" $HOME_PATH/.config |cut -f2 -d=)"
if [[ "$partsize" -lt "400" ]];then
sed -i '/CONFIG_TARGET_ROOTFS_PARTSIZE/d' $HOME_PATH/.config
sed -i '$a CONFIG_TARGET_ROOTFS_PARTSIZE=400' $HOME_PATH/.config
fi
fi
fi
if [[ `grep -c "CONFIG_TARGET_mxs=y" $HOME_PATH/.config` -eq '1' || `grep -c "CONFIG_TARGET_sunxi=y" $HOME_PATH/.config` -eq '1' || `grep -c "CONFIG_TARGET_zynq=y" $HOME_PATH/.config` -eq '1' ]]; then
#sed -Ei 's/.*(CONFIG_TARGET_IMAGES_GZIP).*/\1=y/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_PACKAGE_openssh-sftp-server).*/\1=y/g' $HOME_PATH/.config
if [[ `grep -c "CONFIG_TARGET_ROOTFS_PARTSIZE=" $HOME_PATH/.config` -eq '1' ]]; then
local partsize="$(grep -Eo "CONFIG_TARGET_ROOTFS_PARTSIZE=[0-9]+" $HOME_PATH/.config |cut -f2 -d=)"
if [[ "$partsize" -lt "400" ]];then
sed -i '/CONFIG_TARGET_ROOTFS_PARTSIZE/d' $HOME_PATH/.config
sed -i '$a CONFIG_TARGET_ROOTFS_PARTSIZE=400' $HOME_PATH/.config
fi
fi
fi
if [[ `grep -c "CONFIG_TARGET_armvirt=y" $HOME_PATH/.config` -eq '1' || `grep -c "CONFIG_TARGET_armsr=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -Ei 's/.*(CONFIG_PACKAGE_luci-app-autoupdate).*/# \1 is not set/g' $HOME_PATH/.config
sed -Ei 's/.*(CONFIG_TARGET_ROOTFS_TARGZ).*/\1=y/g' $HOME_PATH/.config
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-app-adblock=y" $HOME_PATH/.config` -eq '1' ]]; then
if [[ `grep -c "CONFIG_PACKAGE_luci-app-adblock-plus=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-app-adblock=y/# CONFIG_PACKAGE_luci-app-adblock is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_adblock=y/# CONFIG_PACKAGE_adblock is not set/g' $HOME_PATH/.config
sed -i '/luci-i18n-adblock/d' $HOME_PATH/.config
echo "__error_msg \"您同时选择luci-app-adblock-plus和luci-app-adblock,插件有依赖冲突,只能二选一,已删除luci-app-adblock\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-app-dockerman=y" $HOME_PATH/.config` -eq '1' ]]; then
# 修复官方源码dockerman未选中文语言包
sed -Ei 's/.*(CONFIG_PACKAGE_luci-i18n-dockerman-zh-cn).*/\1=y/g' $HOME_PATH/.config
# 修复官方源码dockerman无法启动(没有关联选中dockerd)
sed -Ei 's/.*(CONFIG_PACKAGE_dockerd).*/\1=y/g' $HOME_PATH/.config
# 解决Lede源码插件双选冲突(取消luci-app-docker选中状态)
if [[ `grep -c "CONFIG_PACKAGE_luci-app-docker=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-app-docker=y/# CONFIG_PACKAGE_luci-app-docker is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_luci-i18n-docker-zh-cn=y/# CONFIG_PACKAGE_luci-i18n-docker-zh-cn is not set/g' $HOME_PATH/.config
echo "__error_msg \"您同时选择luci-app-docker和luci-app-dockerman,插件有冲突,相同功能插件只能二选一,已删除luci-app-docker\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-app-dockerman=y" $HOME_PATH/.config` -eq '0' ]]; then
if [[ `grep -c "CONFIG_PACKAGE_luci-app-docker=y" $HOME_PATH/.config` -eq '0' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-lib-docker=y/# CONFIG_PACKAGE_luci-lib-docker is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_luci-i18n-dockerman-zh-cn=y/# CONFIG_PACKAGE_luci-i18n-dockerman-zh-cn is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_docker=y/# CONFIG_PACKAGE_docker is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_dockerd=y/# CONFIG_PACKAGE_dockerd is not set/g' $HOME_PATH/.config
fi
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-app-ipsec-server=y" $HOME_PATH/.config` -eq '1' ]]; then
if [[ `grep -c "CONFIG_PACKAGE_luci-app-ipsec-vpnd=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-app-ipsec-vpnd=y/# CONFIG_PACKAGE_luci-app-ipsec-vpnd is not set/g' $HOME_PATH/.config
echo "__error_msg \"您同时选择luci-app-ipsec-vpnd和luci-app-ipsec-server,插件有冲突,相同功能插件只能二选一,已删除luci-app-ipsec-vpnd\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-app-qbittorrent=y" $HOME_PATH/.config` -eq '1' ]]; then
if [[ `grep -c "CONFIG_PACKAGE_luci-app-qbittorrent-simple=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-app-qbittorrent-simple=y/# CONFIG_PACKAGE_luci-app-qbittorrent-simple is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_luci-i18n-qbittorrent-simple-zh-cn=y/# CONFIG_PACKAGE_luci-i18n-qbittorrent-simple-zh-cn is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_qbittorrent=y/# CONFIG_PACKAGE_qbittorrent is not set/g' $HOME_PATH/.config
echo "__error_msg \"您同时选择luci-app-qbittorrent和luci-app-qbittorrent-simple,插件有冲突,相同功能插件只能二选一,已删除luci-app-qbittorrent-simple\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-app-samba4=y" $HOME_PATH/.config` -eq '1' ]]; then
if [[ `grep -c "CONFIG_PACKAGE_luci-app-samba=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-app-samba=y/# CONFIG_PACKAGE_luci-app-samba is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_luci-i18n-samba-zh-cn=y/# CONFIG_PACKAGE_luci-i18n-samba-zh-cn is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_samba36-server=y/# CONFIG_PACKAGE_samba36-server is not set/g' $HOME_PATH/.config
echo "__error_msg \"您同时选择luci-app-samba和luci-app-samba4,插件有冲突,相同功能插件只能二选一,已删除luci-app-samba\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-app-cshark=y" $HOME_PATH/.config` -eq '1' ]]; then
if [[ `grep -c "CONFIG_PACKAGE_luci-app-ssr-plus=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-app-cshark=y/# CONFIG_PACKAGE_luci-app-cshark is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_cshark=y/# CONFIG_PACKAGE_cshark is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_libustream-mbedtls=y/# CONFIG_PACKAGE_libustream-mbedtls is not set/g' $HOME_PATH/.config
echo "__error_msg \"您同时选择luci-app-ssr-plus和luci-app-cshark,插件有依赖冲突,只能二选一,已删除luci-app-cshark\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-app-turboacc_INCLUDE_SHORTCUT_FE=y" $HOME_PATH/.config` -eq '1' ]]; then
if [[ `grep -c "CONFIG_PACKAGE_luci-app-turboacc_INCLUDE_SHORTCUT_FE_CM=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-app-turboacc_INCLUDE_SHORTCUT_FE=y/# CONFIG_PACKAGE_luci-app-turboacc_INCLUDE_SHORTCUT_FE is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_kmod-fast-classifier=y/# CONFIG_PACKAGE_kmod-fast-classifier is not set/g' $HOME_PATH/.config
echo "__error_msg \"luci-app-turboacc同时选择Include Shortcut-FE CM和Include Shortcut-FE,有冲突,只能二选一,已删除Include Shortcut-FE\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-app-unblockneteasemusic=y" $HOME_PATH/.config` -eq '1' ]]; then
if [[ `grep -c "CONFIG_PACKAGE_luci-app-unblockmusic=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-app-unblockmusic=y/# CONFIG_PACKAGE_luci-app-unblockmusic is not set/g' $HOME_PATH/.config
echo "__error_msg \"您选择了luci-app-unblockmusic,会和luci-app-unblockneteasemusic冲突导致编译错误,已删除luci-app-unblockmusic\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-app-unblockneteasemusic-go=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-app-unblockneteasemusic-go=y/# CONFIG_PACKAGE_luci-app-unblockneteasemusic-go is not set/g' $HOME_PATH/.config
echo "__error_msg \"您选择了luci-app-unblockneteasemusic-go,会和luci-app-unblockneteasemusic冲突导致编译错误,已删除luci-app-unblockneteasemusic-go\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-theme-argon=y" $HOME_PATH/.config` -eq '1' ]]; then
if [[ `grep -c "CONFIG_PACKAGE_luci-theme-argon_new=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-theme-argon_new=y/# CONFIG_PACKAGE_luci-theme-argon_new is not set/g' $HOME_PATH/.config
echo "__error_msg \"您同时选择luci-theme-argon和luci-theme-argon_new,插件有冲突,相同功能插件只能二选一,已删除luci-theme-argon_new\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-theme-argonne=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -i 's/CONFIG_PACKAGE_luci-theme-argonne=y/# CONFIG_PACKAGE_luci-theme-argonne is not set/g' $HOME_PATH/.config
echo "__error_msg \"您同时选择luci-theme-argon和luci-theme-argonne,插件有冲突,相同功能插件只能二选一,已删除luci-theme-argonne\"" >> $CONFFLICTIONS
echo "" >> $CONFFLICTIONS
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-app-argon-config=y" $HOME_PATH/.config` -eq '0' ]]; then
sed -Ei 's/.*(CONFIG_PACKAGE_luci-app-argon-config).*/\1=y/g' $HOME_PATH/.config
fi
else
sed -Ei 's/.*(CONFIG_PACKAGE_luci-app-argon-config).*/# \1 is not set/g' $HOME_PATH/.config
fi
if [[ `grep -c "CONFIG_PACKAGE_luci-app-zerotier=y" $HOME_PATH/.config` -eq '0' ]]; then
sed -Ei 's/.*(CONFIG_PACKAGE_zerotier).*/# \1 is not set/g' $HOME_PATH/.config
fi
if [[ `grep -c "CONFIG_PACKAGE_dnsmasq=y" $HOME_PATH/.config` -eq '1' || `grep -c "CONFIG_PACKAGE_dnsmasq-dhcpv6=y" $HOME_PATH/.config` -eq '1' ]]; then
if [[ `grep -c "CONFIG_PACKAGE_dnsmasq-full=y" $HOME_PATH/.config` -eq '1' ]]; then
sed -i 's/CONFIG_PACKAGE_dnsmasq=y/# CONFIG_PACKAGE_dnsmasq is not set/g' $HOME_PATH/.config
sed -i 's/CONFIG_PACKAGE_dnsmasq-dhcpv6=y/# CONFIG_PACKAGE_dnsmasq-dhcpv6 is not set/g' $HOME_PATH/.config
fi
fi
if [[ -s $CONFFLICTIONS ]]; then
chmod +x $CONFFLICTIONS && source $CONFFLICTIONS
fi
echo
echo "--------------common_modify_config end--------------"
}
################################################################################################################
# 编译机型CPU机型架构、内核版本、固件名称、固件自动更新相关信息等(依赖于make defconfig,须在生成.config之后)
################################################################################################################
function firmware_settings() {
echo "--------------firmware_settings start--------------"
echo
cd $HOME_PATH
# x86、ramips...
TARGET_BOARD="$(awk -F '[="]+' '/CONFIG_TARGET_BOARD/{print $2}' $HOME_PATH/.config)"
# 64、generic、legacy、mt7621...
TARGET_SUBTARGET="$(awk -F '[="]+' '/CONFIG_TARGET_SUBTARGET/{print $2}' $HOME_PATH/.config)"
# x86_64、i386_pentium4、i386_pentium-mmx、mipsel_24kc...
ARCHITECTURE="$(awk -F '[="]+' '/CONFIG_TARGET_ARCH_PACKAGES/{print $2}' $HOME_PATH/.config)"
# 机型架构
__yellow_color "开始获取固件机型架构信息..."
if [ `grep -c "CONFIG_TARGET_x86_64=y" .config` -eq '1' ]; then
TARGET_PROFILE="x86-64"
elif [[ `grep -c "CONFIG_TARGET_x86=y" .config` == '1' && `grep -c "CONFIG_TARGET_x86_64=y" .config` == '0' ]]; then
TARGET_PROFILE="x86-32"
elif [[ -n "$(grep -Eo 'CONFIG_TARGET.*armsr.*armv8.*=y' $HOME_PATH/.config)" ]]; then
TARGET_PROFILE="Armvirt_64"
elif [[ -n "$(grep -Eo 'CONFIG_TARGET.*armvirt.*64.*=y' $HOME_PATH/.config)" ]]; then
TARGET_PROFILE="Armvirt_64"
elif [[ -n "$(grep -Eo 'CONFIG_TARGET.*DEVICE.*=y' $HOME_PATH/.config)" ]]; then
TARGET_PROFILE="$(grep -Eo "CONFIG_TARGET.*DEVICE.*=y" $HOME_PATH/.config | sed -r 's/.*DEVICE_(.*)=y/\1/')"
else
TARGET_PROFILE="$(awk -F '[="]+' '/TARGET_PROFILE/{print $2}' $HOME_PATH/.config | sed 's/DEVICE_//')"
fi
TARGET_DEVICE="$TARGET_PROFILE"
# 修改TARGET_PROFILE
if [[ $TARGET_PROFILE =~ (phicomm_k3|phicomm-k3) ]]; then
TARGET_PROFILE="phicomm-k3"
elif [[ $TARGET_PROFILE =~ (k2p|phicomm_k2p|phicomm-k2p) ]]; then
TARGET_PROFILE="phicomm-k2p"
elif [[ $TARGET_PROFILE =~ (xiaomi_mi-router-3g-v2|xiaomi_mir3g_v2) ]]; then
TARGET_PROFILE="xiaomi_mir3g-v2"
elif [[ $TARGET_PROFILE == "xiaomi_mi-router-3g" ]]; then
TARGET_PROFILE="xiaomi_mir3g"
elif [[ $TARGET_PROFILE == "xiaomi_mi-router-3-pro" ]]; then
TARGET_PROFILE="xiaomi_mir3p"
fi
__info_msg "CPU架构:$ARCHITECTURE"
# 内核版本
__yellow_color "开始获取内核版本信息、替换内核等..."
KERNEL_PATCHVER="$(grep "KERNEL_PATCHVER" "$HOME_PATH/target/linux/$TARGET_BOARD/Makefile" |grep -Eo "[0-9]+\.[0-9]+")"
# 内核替换
if [[ -n "$NEW_KERNEL_PATCHVER" ]]; then
if [[ "$NEW_KERNEL_PATCHVER" == "0" ]]; then
__info_msg "编译固件内核:[ $KERNEL_PATCHVER ]"
elif [[ `ls -1 "$HOME_PATH/target/linux/$TARGET_BOARD" |grep -c "kernel-$NEW_KERNEL_PATCHVER"` -eq '1' ]]; then
sed -i "s/${KERNEL_PATCHVER}/${NEW_KERNEL_PATCHVER}/g" $HOME_PATH/target/linux/$TARGET_BOARD/Makefile
KERNEL_PATCHVER=$NEW_KERNEL_PATCHVER
__success_msg "内核[ $NEW_KERNEL_PATCHVER ]更换完成"
else
__error_msg "没发现与$TARGET_PROFILE机型对应[ $NEW_KERNEL_PATCHVER ]内核,使用默认内核[ $KERNEL_PATCHVER ]编译"
fi
else
__info_msg "编译固件内核:[ $KERNEL_PATCHVER ]"
fi
local kernel_version_file="kernel-$KERNEL_PATCHVER"
if [[ -f "$HOME_PATH/include/$kernel_version_file" ]]; then
LINUX_KERNEL=$(egrep -o "$KERNEL_PATCHVER\.[0-9]+" $HOME_PATH/include/$kernel_version_file)
[[ -z $LINUX_KERNEL ]] && LINUX_KERNEL="unknown"
else
LINUX_KERNEL=$(egrep -o "$KERNEL_PATCHVER\.[0-9]+" $HOME_PATH/include/kernel-version.mk)
[[ -z $LINUX_KERNEL ]] && LINUX_KERNEL="unknown"
fi
echo "::notice title=内核版本::$LINUX_KERNEL"
echo "::notice title=固件机型::$TARGET_PROFILE"
# BIOS引导模式
if [[ $BIOS_MODE =~ (uefi|UEFI|Uefi) ]]; then
sed -i '/CONFIG_GRUB_IMAGES/d' $HOME_PATH/.config > /dev/null 2>&1
sed -i '$a # CONFIG_GRUB_IMAGES is not set' $HOME_PATH/.config > /dev/null 2>&1
sed -i '/CONFIG_GRUB_EFI_IMAGES/d' $HOME_PATH/.config > /dev/null 2>&1
sed -i '$a CONFIG_GRUB_EFI_IMAGES=y' $HOME_PATH/.config > /dev/null 2>&1
__info_msg "编译uefi固件"
elif [[ $BIOS_MODE =~ (legacy|LEGACY|Legacy) ]]; then
sed -i '/CONFIG_GRUB_IMAGES/d' $HOME_PATH/.config > /dev/null 2>&1
sed -i '$a CONFIG_GRUB_IMAGES=y' $HOME_PATH/.config > /dev/null 2>&1
sed -i '/CONFIG_GRUB_EFI_IMAGES/d' $HOME_PATH/.config > /dev/null 2>&1
sed -i '$a # CONFIG_GRUB_EFI_IMAGES is not set' $HOME_PATH/.config > /dev/null 2>&1
__info_msg "编译legacy固件"
elif [[ $BIOS_MODE =~ (both|BOTH|Both|all|ALL|All) ]]; then
sed -i '/CONFIG_GRUB_IMAGES/d' $HOME_PATH/.config > /dev/null 2>&1
sed -i '$a CONFIG_GRUB_IMAGES=y' $HOME_PATH/.config > /dev/null 2>&1
sed -i '/CONFIG_GRUB_EFI_IMAGES/d' $HOME_PATH/.config > /dev/null 2>&1
sed -i '$a CONFIG_GRUB_EFI_IMAGES=y' $HOME_PATH/.config > /dev/null 2>&1
__info_msg "编译uefi及legacy固件"
else
__info_msg "编译uefi、legacy固件由.config文件决定"
fi
# 固件相关
__yellow_color "开始设置固件名称、后缀等相关信息..."
# 固件路径
FIRMWARE_PATH=$HOME_PATH/bin/targets/$TARGET_BOARD/$TARGET_SUBTARGET
__info_msg "固件保存路径:$FIRMWARE_PATH"
# 固件版本 如:lede-x86-64-202310011001
FIRMWARE_BRIEF="$SOURCE-$TARGET_PROFILE-$COMPILE_DATE_HM"
# 固件名称前缀 如:lede-18.06-x86-64,方便自动更新固件搜寻可更新固件
FIRMWARE_NAME_PREFIX="$SOURCE-$LUCI_EDITION-$TARGET_PROFILE"
# 固件名称(简写,x86区分legacy、uefi)如:lede-18.06-x86-64-202310101010
FIRMWARE_NAME="$FIRMWARE_NAME_PREFIX-$COMPILE_DATE_HM"
# 固件名称与后缀
case "$TARGET_BOARD" in
x86)
ROOTFS_EXT=".tar.gz"
FIRMWARE_EXT=".img.gz"
# 18.06-lede-x86-64-1695553941-legacy
# FIRMWARE_NAME_LEGACY="$FIRMWARE_NAME-legacy"
# 18.06-lede-x86-64-1695553941-uefi
# FIRMWARE_NAME_UEFI="$FIRMWARE_NAME-uefi"
# 18.06-lede-x86-64-1695647548-rootfs
# FIRMWARE_NAME_ROOTFS="$FIRMWARE_NAME-rootfs"
echo "ROOTFS_EXT=$ROOTFS_EXT" >> $GITHUB_ENV
;;
ramips | reltek | ath* | ipq* | bcm47xx | bmips | kirkwood | mediatek)
FIRMWARE_EXT=".bin"
FIRMWARE_NAME="$FIRMWARE_NAME-sysupgrade"
;;
rockchip | bcm27xx | mxs | sunxi | zynq)
FIRMWARE_EXT=".img.gz"
;;
mvebu)
case "$TARGET_SUBTARGET" in
cortexa53 | cortexa72)
FIRMWARE_EXT=".img.gz"
;;
esac
;;
bcm53xx)
FIRMWARE_EXT=".trx"
;;
octeon | oxnas | pistachio)
FIRMWARE_EXT=".tar"
;;
*)
FIRMWARE_EXT=".bin"