forked from openwrtcompileshell/OpenwrtCompileScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenwrt.sh
2407 lines (2171 loc) · 78.6 KB
/
openwrt.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
#set -x
#set -u
version="3.0"
SF="Script_File"
OW="Openwrt"
by="ITdesk"
OCS="OpenwrtCompileScript"
cpu_cores=`cat /proc/cpuinfo | grep processor | wc -l`
#颜色调整参考wen55333
red="\033[31m"
green="\033[32m"
yellow="\033[33m"
white="\033[0m"
calculating_time_start() {
startTime=`date +%Y%m%d-%H:%M:%S`
startTime_s=`date +%s`
}
calculating_time_end() {
endTime=`date +%Y%m%d-%H:%M:%S`
endTime_s=`date +%s`
sumTime=$[ $endTime_s - $startTime_s ]
echo -e "$yellow开始时间:$green $startTime ---> $yellow结束时间:$green $endTime $white"
echo -e "耗时:"
#以下代码copy https://blog.csdn.net/weixin_33478575/article/details/116683248
local T=$sumTime
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
(( $D > 0 )) && printf '%d 天 ' $D
(( $H > 0 )) && printf '%d 小时 ' $H
(( $M > 0 )) && printf '%d 分钟 ' $M
(( $D > 0 || $H > 0 || $M > 0 )) && printf 'and '
printf '%d 秒\n' $S
echo ""
}
prompt() {
echo -e "$green 脚本问题反馈:https://github.com/openwrtcompileshell/OpenwrtCompileScript/issues或者加群反馈(群在github有)$white"
echo -e " $yellow温馨提示,最近的编译依赖有变动,如果你最近一直编译失败,建议使用脚本5.其他选项 --- 1.只搭建编译环境功能 $white"
}
source_make_clean() {
clear
echo "--------------------------------------------------------"
echo -e "$green++是否执行make clean清理固件++$white"
echo ""
echo " 1.执行make clean"
echo ""
echo " 2.不执行make clean"
echo ""
echo -e "$yellow 温馨提醒make clean会清理掉之前编译的固件,为了编译成功 $white"
echo -e "$yellow率建议执行make clean,虽然编译时间会比较久$white"
echo "--------------------------------------------------------"
read -p "请输入你的参数(回车默认:make clean):" mk_c
if [[ -z "$mk_c" ]];then
clear && echo -e "$green开始执行make clean $white"
make clean
else
case "$mk_c" in
1)
clear && echo -e "$green开始执行make clean $white"
make clean
;;
2)
clear && echo -e "$green不执行make clean $white"
;;
*)
clear && echo "Error请输入正确的数字 [1-2]" && Time
clear && source_make_clean
;;
esac
fi
}
rely_on() {
sudo apt install -y ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential \
bzip2 ccache cmake cpio curl device-tree-compiler fastjar flex gawk gettext gcc-multilib g++-multilib \
git gperf haveged help2man intltool libc6-dev-i386 libelf-dev libglib2.0-dev libgmp3-dev libltdl-dev \
libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libreadline-dev libssl-dev libtool lrzsz \
mkisofs msmtp nano ninja-build p7zip p7zip-full patch pkgconf python2.7 python3 python3-pip libpython3-dev qemu-utils \
rsync scons squashfs-tools subversion swig texinfo uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev
#sudo apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib antlr3 gperf wget curl swig rsync bison g++ gcc help2man htop ncurses-term ocaml-nox sharutils yui-compressor make cmake
}
#显示编译文件夹
ls_file() {
LF=`ls $HOME/$OW | grep -v $0 | grep -v Script_File`
echo -e "$green$LF$white"
echo ""
}
ls_file_luci(){
clear && cd
echo "***你的openwrt文件夹有以下几个***"
ls_file
read -p "请输入你的文件夹(记得区分大小写):" file
if [[ -e $HOME/$OW/$SF/tmp ]]; then
echo "$file" > $HOME/$OW/$SF/tmp/you_file
else
mkdir -p $HOME/$OW/$SF/tmp
fi
}
#显示config文件夹
ls_my_config() {
LF=`ls My_config`
echo -e "$green$LF$white"
echo ""
}
#倒数专用
Time() {
seconds_left=3
echo ""
echo " ${seconds_left}秒以后执行代码"
echo " 如果不需要执行代码以Ctrl+C 终止即可"
echo ""
while [[ ${seconds_left} -gt 0 ]]; do
echo -n ${seconds_left}
sleep 1
seconds_left=$(($seconds_left - 1))
echo -ne "\r"
done
}
#选项9.更新update_script
update_script() {
clear
cd $HOME/$OW/$SF/$OCS
if [[ "$action1" == "" ]]; then
git fetch --all
git reset --hard origin/master
if [[ $? -eq 0 ]]; then
echo -e "$green>> 脚本源码更新成功回车进入编译菜单$white"
read a
bash $openwrt
else
echo -e "$red>> 脚本源码更新失败,重新执行代码$white"
update_script
fi
else
git fetch --all
git reset --hard origin/master
if [[ $? -eq 0 ]]; then
echo -e "$green>> 脚本源码更新成功$white"
else
echo -e "$red>> 脚本源码更新失败,重新执行代码$white"
update_script
fi
fi
}
#选项5.其他选项
other() {
clear
echo " -------------------------------------"
echo " 【 5.其他选项 】"
echo ""
echo " 1 只搭建编译环境,不进行编译"
echo ""
echo " 2 单独Download DL库 "
echo ""
echo " 3 更新lean软件库 "
echo ""
echo " 4 下载额外的插件 "
echo ""
echo " 0. 回到上一级菜单"
echo ""
echo ""
echo " PS:请先搭建好梯子再进行编译,不然很慢!"
echo " By:ITdesk"
echo " --------------------------------------"
read -p "请输入数字:" other_num
case "$other_num" in
1)
clear
echo "5.1 只搭建编译环境,不进行编译 " && Time
update_system
echo "环境搭建完成,请自行创建文件夹和git"
;;
2)
ls_file_luci
dl_other
;;
3)
update_lean_package
;;
4)
download_package
;;
0)
main_interface
;;
*)
clear && echo "请输入正确的数字 [1-4,0]" && Time
other
;;
esac
}
dl_other() {
dl_download
if [[ $? -eq 0 ]]; then
echo ""
echo -e ">>$green dl已经单独下载完成$white"
else
clear
echo -e "$red dl没有下载成功,重新执行下载代码 $white" && Time
dl_other
fi
}
update_lean_package() {
ls_file_luci
source_make_clean
rm -rf package/lean
source_openwrt_Setting
echo "插件下载完成"
Time
display_git_log_luci
update_feeds
source_config
}
download_package() {
ls_file_luci
if [[ -e package/Extra-plugin ]]; then
echo ""
else
mkdir package/Extra-plugin
fi
download_package_luci
}
download_package2() {
cd $HOME/$OW/$you_file/lede
rm -rf ./tmp
display_git_log_luci
update_feeds
source_config
}
download_package_luci() {
cd $HOME/$OW/$you_file/lede/package/Extra-plugin
clear
echo " -------------------------------------"
echo " 【 5.4额外的插件 】"
echo ""
echo " 1. luci-theme-argon"
echo ""
echo " 2. luci-app-oaf (测试中)"
echo ""
echo " 3. cups 共享打印机"
echo ""
echo " 4. luci-app-netkeeper(闪讯插件)"
echo ""
echo " 99. 自定义下载插件 "
echo ""
echo " 0. 回到上一级菜单"
echo ""
echo " PS:如果你有什么好玩的插件,可以提交给我"
echo " --------------------------------------"
read -p "请输入数字:" download_num
case "$download_num" in
1)
git clone https://github.com/jerrykuku/luci-theme-argon.git
;;
2)
git clone https://github.com/destan19/OpenAppFilter.git
;;
3)
cd $HOME/$OW/$you_file/lede/
if [[ `cat feeds.conf.default | grep "cups" | wc -l` -eq 0 ]]; then
echo "src-git cups https://github.com/TheMMcOfficial/lede-cups.git" >> feeds.conf.default
fi
./scripts/feeds update cups
./scripts/feeds install cups
;;
4)
cd $HOME/$OW/$you_file/lede/
if [[ `cat feeds.conf.default | grep "netkeeper" | wc -l` -eq 0 ]]; then
echo "src-git netkeeper https://github.com/sjz123321/feed-netkeeper.git" >> feeds.conf.default
fi
./scripts/feeds update netkeeper
./scripts/feeds install netkeeper
;;
99)
download_package_customize
;;
0)
other
;;
*)
clear && echo "请输入正确的数字 [1-4,99,0]" && Time
download_package_luci
;;
esac
if [[ $? -eq 0 ]]; then
download_package_customize_Decide
else
clear
echo -e "没有下载成功或者插件已经存在,请检查$red package/Extra-plugin $white里面是否已经存在" && Time
download_package_customize
fi
}
download_package_customize() {
cd $HOME/$OW/$you_file/lede/package/Extra-plugin
clear
echo "--------------------------------------------------------------------------------"
echo "自定义下载插件"
echo ""
echo -e " $green例子:git clone https://github.com/destan19/OpenAppFilter.git (此插件用于过滤应用)$white"
echo "--------------------------------------------------------------------------------"
echo ""
read -p "请输入你要下载的插件地址:" download_url
$download_url
if [[ $? -eq 0 ]]; then
cd $HOME/$OW/$you_file/lede
else
clear
echo -e "没有下载成功或者插件已经存在,请检查$red package/Extra-plugin $white里面是否已经存在" && Time
download_package_customize
fi
download_package_customize_Decide
}
download_package_customize_Decide() {
echo "----------------------------------------"
echo -e "$green是否需要继续下载插件$white"
echo " 1.继续下载插件"
echo " 2.不需要了"
echo "----------------------------------------"
read -p "请输入你的决定:" Decide
case "$Decide" in
1)
cd $HOME/$OW/$you_file/lede/package/Extra-plugin
download_package_luci
;;
2)
download_package2
;;
*)
clear && echo -e"$red Error请输入正确的数字 [1-2]$white" && Time
clear && download_package_customize_Decide
;;
esac
}
#选项4.恢复编译环境
source_RestoreFactory() {
ls_file_luci
echo ""
if [[ -e $HOME/$OW/$you_file ]]; then
cd $HOME/$OW/$you_file/lede
echo -e "危险操作注意:$red所有编译过的文件全部删除,openwrt源代码保存,回车继续$white $green Ctrl+c取消$white" && read a
echo -e ">>$green开始删除$file文件 $white" && Time
echo ""
else
clear && echo "-----文件名错误,请重新输入-----" && Time
source_RestoreFactory
fi
make distclean
ln -s $HOME/$OW/$SF/dl $HOME/$OW/$you_file/lede/dl
echo -e ">>$green $file文件删除完成 $white"
echo -e " 所有编译过的文件全部删除完成,回车可以开始编译 不需要编译Ctrl+c取消,如依旧编译失败,请重新下载源代码" && read a
source_if
display_git_log_luci
}
#选项2.二次编译 与 源码更新合并
source_secondary_compilation() {
ls_file_luci
if [[ -e $HOME/$OW/$you_file ]]; then
cd && cd $HOME/$OW/$you_file/lede
else
clear && echo "-----文件名错误,请重新输入-----" && Time
source_secondary_compilation
fi
echo "开始清理之前的文件"
source_make_clean && rm -rf ./tmp && Time
if [[ `grep -o "PandoraBox" .config | wc -l` == "2" ]]; then
echo "检测到PandoraBox源码,开始更新"
rm -rf package/lean && rm -rf ./feeds
source_lean_package
source_Soft_link
update_feeds
else
source_if
display_git_log_luci
fi
}
#显示git log 提交记录
display_git_log() {
git log -3 --graph --all --branches --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(bold green)(%ai)%C(reset) %C(white)%s%C(reset) %C(yellow) - %an%C(reset)%C(auto) %d%C(reset)'
#参考xueguang668
}
display_git_log_if() {
git_branch=$(git branch -v | grep -o 落后 )
if [[ "$git_branch" == "落后" ]]; then
echo -e "$yellow自动检测:$white $red本地源码已经落后远端,建议更新$white"
else
echo -e "$yellow自动检测:$white $green本地源码与远端一样$white"
fi
}
display_git_log_luci() {
clear
echo "稍等一下,正在取回分支,用于比较现在源码,不会更新请放心,速度看你网络"
git fetch
if [[ $? -eq 0 ]]; then
echo ""
else
echo -e "$red>> 取回分支没有成功,重新执行代码$white" && Time
display_git_log_luci
fi
clear
echo "----------------------------------------"
echo -e " $green显示远端仓库最近三条更新内容$white "
echo "----------------------------------------"
echo ""
display_git_log
echo ""
echo -e "$yellow你所在的文件夹:$white $green $file $white"
display_git_log_if
echo -e "$yellow你现在所用的分支版本:$white`git branch -v`"
echo ""
read -p "是否需要更新源码(1.yes 2.no 3.退到/进到某个版本):" update_source
case "$update_source" in
1)
rm -rf ./feeds && source_update && rm -rf ./tmp && source_openwrt && update_feeds
;;
2)
source_openwrt && update_feeds
;;
3)
git_reset && source_openwrt && update_feeds
;;
*)
clear && echo "Error请输入正确的数字 [1-2]" && Time
display_git_log_luci
;;
esac
if [[ "$?" == "0" ]]; then
source_lean
source_lienol
source_Setting_Public
source_config
make_defconfig
ecc
else
echo -e "$red >>命令错误或者网络不好,重新执行代码$white" && Time
display_git_log_luci
fi
}
git_reset() {
clear
echo "----------------------------------------"
echo -e " $green Git reset 回退到某个版本$white "
echo "----------------------------------------"
echo -e "$green >>例子$white"
echo -e " git reset --hard HEAD^ $green回退到上个版本$white"
echo -e " git reset --hard HEAD~3 $green回退到前3次提交之前,以此类推$white"
echo -e " git reset --hard (commit_id) $green退到/进到 指定commit的sha码(不会的百度)$white"
echo ""
echo -e "$yellow你所在的文件夹:$white $green $file $white"
echo -e "$yellow你现在所用的分支版本:$white`git branch -v`"
echo ""
read -p "请输入你的命令(手动敲别偷懒):" git_reset_read
$git_reset_read
rm -rf ./feeds && rm -rf ./tmp
if [[ "$?" == "0" ]]; then
clear
echo ""
echo -e "$green >>命令执行完成$white"
echo -e "$yellow你现在所用的分支版本:$white`git branch -v`" && Time
else
echo -e "$red >>命令错误或者网络不好,重新执行代码$white" && Time
git_reset
fi
}
source_config() {
clear
echo "----------------------------------------------------------------------"
echo -e "$green选择编译方式$white"
echo ""
echo " 1.以全新的config进行编译 (适合编译新机型)"
echo " 2.继续上次的编译(不对配置做任何操作)"
echo ""
echo -e "$yellow PS:如果源码进行过重大更新,建议直接选择1.以全新config进行编译,以减少报错$white"
echo "----------------------------------------------------------------------"
read -p "请输入你的决定:" config
case "$config" in
1)
rm -rf .config && rm -rf ./tmp
;;
2)
echo ""
;;
*)
clear && echo "Error请输入正确的数字 [1-2]" && Time
source_config
;;
esac
}
Save_My_Config_luci() {
clear && echo "------------------------------------------------"
echo "是否要保存你的配置,以备下次使用(1.是 2.否 )"
echo "注:同一名字的文件会覆盖"
echo "------------------------------------------------"
read -p "请输入你的决定:" save
case "$save" in
1)
save_my_config_yes
;;
2)
;;
*)
clear && echo "请输入正确的数字 [1-2]" && Time
Save_My_Config_luci
;;
esac
}
save_my_config_yes() {
read -p "请输入你的配置名:" mange_config
cp .config My_config/$mange_config
echo "******配置保存完成回车进行编译*******" && read a
}
transfer_my_config() {
clear
echo "你的配置文件如下:"
echo ""
ls_my_config
echo ""
read -p "请输入你要调用的配置名(记得区分大小写):" transfer
if [[ -e `pwd`/My_config/$transfer ]]; then
Time && clear
echo "正在调用"
rm -rf .config
cp My_config/$transfer .config
echo "配置加载完成" && Time
else
clear && echo "调用错误" && Time
transfer_my_config
fi
}
#源码更新
source_update() {
clear
echo "------------------------------------------------------------------"
echo -e "$green***准备开始更新openwrt源代码与软件***$white"
echo ""
echo "有没有改动过源代码,因为改动过源代码可能会导致git pull失效无法更新"
echo "1.是 2.否 "
echo " "
echo "------------------------------------------------------------------"
read -p "请输入你的决定:" git_source
case "$git_source" in
1)
source_update_No_git_pull
;;
2)
source_update_git_pull
;;
*)
clear && echo "Error请输入正确的数字 [1-2]" && Time
source_update
;;
esac
if [[ "$?" == "0" ]]; then
echo -e "$green >>源码更新完成$white" && Time
else
echo -e "$red >>源码更新失败,重新执行代码$white" && Time
source_update
fi
}
source_update_No_git_pull() {
source_branch=$(cat "$HOME/$OW/$SF/tmp/source_branch")
clear
if [[ "$source_branch" == "" ]]; then
git fetch --all
git reset --hard origin/master
else
git fetch --all
git reset --hard origin/$source_branch
if [[ $? -eq 0 ]]; then
echo ""
else
echo -e "$red>> 源码更新失败,重新执行代码$white" && Time
source_update_No_git_pull
fi
fi
}
source_update_git_pull() {
git pull
if [[ $? -eq 0 ]]; then
echo ""
else
echo -e "$red>> 源码更新失败,重新执行代码$white" && Time
source_update_git_pull
fi
}
#选项1.开始搭建编译环境与主菜单
#判断代码
description_if(){
cd
clear
echo "开始检测系统"
curl_if=$(dpkg -l | grep -o "curl" |sed -n '1p' | wc -l)
if [[ "$curl_if" == "0" ]]; then
clear && echo "安装一下脚本用的依赖(注:不是openwrt的依赖而是脚本本身)"
sudo apt update
sudo apt install curl -y
else
clear && echo -e "$green已经安装curl$white"
fi
:<<'COMMENT'
#解决golang下载慢的问题,来源:https://goproxy.cn/
if [[ ! "$GO111MODULE" == "no" ]]; thendescription_if
echo "export GO111MODULE=on" | sudo tee -a /etc/profile
echo "export GOPROXY=https://goproxy.cn" | sudo tee -a /etc/profile
source /etc/profile
fi
COMMENT
if [[ ! -d "$HOME/$OW/$SF/$OCS" ]]; then
echo "开始创建主文件夹"
mkdir -p $HOME/$OW/$SF/dl
mkdir -p $HOME/$OW/$SF/My_config
mkdir -p $HOME/$OW/$SF/tmp
fi
#清理一下之前的编译文件
rm -rf $HOME/$OW/$SF/tmp/*
#判断是否云编译
workspace_home=`echo "$HOME" | grep gitpod | wc -l`
if [[ "$workspace_home" == "1" ]]; then
echo "$yellow请注意云编译已经放弃维护很久了description_if,不保证你能编译成功,太耗时耗力,你如果不信邪你可以回车继续$white"
read a
echo "开始添加云编译系统变量"
Cloud_env=`gp env | grep -o "shfile" | wc -l `
if [[ "$Cloud_env" == "0" ]]; then
eval $(gp env -e openwrt=$THEIA_WORKSPACE_ROOT/Openwrt/Script_File/OpenwrtCompileScript/openwrt.sh)
eval $(gp env -e shfile=$THEIA_WORKSPACE_ROOT/Openwrt/Script_File/OpenwrtCompileScript)
echo -e "系统变量添加完成,老样子启动 bash \$openwrt"
Time
fi
HOME=`echo "$THEIA_WORKSPACE_ROOT"`
else
#添加系统变量
openwrt_shfile_path=$(cat /etc/profile | grep -o shfile | wc -l)
openwrt_script_path=$(cat /etc/profile | grep -o openwrt.sh | wc -l)
if [[ "$openwrt_shfile_path" == "0" ]]; then
echo "export shfile=$HOME/Openwrt/Script_File/OpenwrtCompileScript" | sudo tee -a /etc/profile
echo -e "$green添加openwrt脚本变量成功,以后无论在那个目录输入 cd \$shfile 都可以进到脚本目录$white"
#clear
elif [[ "$openwrt_script_path" == "0" ]]; then
echo "export openwrt=$HOME/Openwrt/Script_File/OpenwrtCompileScript/openwrt.sh" | sudo tee -a /etc/profile
#clear
echo "-----------------------------------------------------------------------"
echo ""
echo -e "$green添加openwrt变量成功,重启系统以后无论在那个目录输入 bash \$openwrt 都可以运行脚本$white"
echo ""
echo ""
echo -e " $green回车重启你的操作系统!!!$white"
echo "-----------------------------------------------------------------------"
read a
Time
rm -rf `pwd`/$OCS
reboot
else
echo "系统变量已经添加"
fi
fi
if [[ -e $HOME/$OW/$SF/$OCS ]]; then
echo "存在"
else
cd $HOME/$OW/$SF/
git clone https://github.com/openwrtcompileshell/OpenwrtCompileScript.git
cd
rm -rf `pwd`/$OCS
cd $HOME/$OW/$SF/$OCS
bash openwrt.sh
fi
:<<'COMMENT'
#win10
check_win10_system=$(cat /proc/version |grep -o [email protected])
check_win10_system01=$(cat /proc/version |grep -o microsoft-standard)
if [[ "$check_win10_system" == "[email protected]" ]]; then
win10
elif [[ "$check_win10_system01" == "microsoft-standard" ]]; then
win10
else
echo "不是win10系统" && clear
fi
clear
if [[ -e $HOME/$OW/$SF/description ]]; then
self_test
main_interface
else
clear
description
echo ""
read -p "请输入密码:" ps
if [[ $ps == $by ]]; then
description >> $HOME/$OW/$SF/description && clear && self_test && main_interface
else
clear && echo "+++++密码错误++++++" && Time && description_if
fi
fi
COMMENT
clear
echo ""
echo -e "$red图形界面编译已停止维护,请参考底下命令行进行编译$white"
}
win10() {
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
if [[ -e /etc/apt/sources.list.back ]]; then
clear && echo -e "$green源码已替换$white"
else
clear
echo "-----------------------------------------------------------------"
echo "+++检测到win10子系统+++"
echo ""
echo " win10子系统已知问题"
echo " 1.IO很慢,编译很慢,不怕耗时间随意"
echo " 2.win10对大小写不敏感,你需要百度如何开启win10子系统大小写敏感"
echo " 3.需要替换子系统的linux源(脚本可以帮你搞定)"
echo "-----------------------------------------------------------------"
echo ""
read -p "是否替换软件源然后进行编译(1.yes,2.no):" win10_select
case "$win10_select" in
1)
clear
echo -e "$green开始替换软件源$white" && Time
sudo cp /etc/apt/sources.list /etc/apt/sources.list.back
sudo rm -rf /etc/apt/sources.list
sudo cp $HOME/$OW/$SF/$OCS/ubuntu18.4_sources.list /etc/apt/sources.list
sudo apt-get update
sudo apt-get install git-core build-essential libssl-dev libncurses5-dev unzip
;;
2)
clear
echo "不做任何操作,即将进入主菜单" && Time
;;
*)
clear && echo "Error请输入正确的数字 [1-2]" && Time
description_if
;;
esac
fi
}
self_test() {
clear
CheckUrl_google=$(curl -I -m 2 -s -w "%{http_code}\n" -o /dev/null www.google.com)
if [[ "$CheckUrl_google" -eq "200" ]]; then
Check_google=`echo -e "$green网络正常$white"`
else
Check_google=`echo -e "$red网络较差$white"`
fi
CheckUrl_baidu=$(curl -I -m 2 -s -w "%{http_code}\n" -o /dev/null www.baidu.com)
if [[ "$CheckUrl_baidu" -eq "200" ]]; then
Check_baidu=`echo -e "$green百度正常$white"`
else
Check_baidu=`echo -e "$red百度无法打开,请修复这个错误$white"`
fi
Root_detection=`id -u` # 学渣代码改良版
if [[ "$Root_detection" -eq "0" ]]; then
Root_run=`echo -e "$red请勿以root运行,请修复这个错误$white"`
else
Root_run=`echo -e "$green非root运行$white"`
fi
clear
echo "稍等一下,正在取回远端脚本源码,用于比较现在脚本源码,速度看你网络"
cd && cd $HOME/$OW/$SF/$OCS
git fetch
if [[ $? -eq 0 ]]; then
echo ""
else
echo -e "$red>> 取回分支没有成功,重新执行代码$white" && Time
self_test
fi
clear
git_branch=$(git branch -v | grep -o 落后 )
if [[ "$git_branch" == "落后" ]]; then
Script_status=`echo -e "$red建议更新$white"`
else
Script_status=`echo -e "$green最新$white"`
fi
echo " -------------------------------------------"
echo " 【 Script Self-Test Program 】"
echo ""
echo " 检测是否root运行: $Root_run "
echo ""
echo " 检测与DL网络情况: $Check_google "
echo " "
echo " 检测百度是否正常: $Check_baidu "
echo " "
echo " 检测脚本是否最新: $Script_status "
echo " "
echo " -------------------------------------------"
echo ""
echo -e "$green 脚本问题反馈:https://github.com/openwrtcompileshell/OpenwrtCompileScript/issues或者加群反馈(群在github有)$white"
echo ""
echo " 请自行决定是否修复红字的错误,以保证编译顺利,你也可以直接回车进入菜单,但有可能会出现编译失败!!!如果都是绿色正常可以忽略此段话"
read a
}
description() {
echo " +++++++++++++++++++++++++++++++++++++++"
echo " ++欢迎使用Openwrt-Compile-Script Ver $version ++"
echo " +++++++++++++++++++++++++++++++++++++++"
echo ""
echo -e " 创建脚本的初衷是因($red I $white)为openwrt编译的时候有些东西太繁琐了,为了简化掉一些操作,使编译更加简单就有了此脚本($red T $white)的诞生,后面觉得好玩就分享给了大家一起玩耍,你需要清楚此脚本仅用于学习,有一定危险性,请勿进行商用,如果商用导致损失或者其他问题,均由使用者自行承担!!!"
echo ""
echo "下面简单给大家描述脚本的作用"
echo -e " 1.协助你更快的搭建编译环境,小白($red d $white)建议学习一下再用会比较好"
echo -e " 2.统一管理你的编译源,全部($red e $white)存放在Openwrt这个文件里面"
echo " 3.你只要启动脚本就可以控制你的源,进行二次编译或者更新"
echo ""
echo -e "缺陷1:小白($red s $white)不太适合,因为他们不了解过程"
echo -e "缺陷2:不能自定义openwrt代码或者修改,此脚本适合做重复的事情($red k $white)"
echo ""
echo "注:请自行将你系统的软件源更换为国内的服务器,不会请百度"
echo ""
echo ""
echo "请阅读完上面的前言,()红字里面的就是密码,此界面只会出现一次,后面就不会了"
}
#主菜单
main_interface() {
clear
echo " -------------------------------------"
echo " 【 Openwrt Compile Script Ver ${version}版 】"
echo ""
echo " 1.搭建编译环境"
echo ""
echo " 2.二次编译固件"
echo ""
echo " 4.恢复编译环境"
echo ""
echo " 5.其他选项"
echo ""
echo " 9.更新脚本"
echo ""
echo " 0. EXIT"
echo ""
echo ""
echo " PS:请先搭建好梯子再进行编译,不然很慢!"
echo " By:ITdesk"
echo " --------------------------------------"
read -p "请输入数字:" num
case "$num" in
1)
system_install
;;
2)
source_secondary_compilation
;;
4)
source_RestoreFactory
;;
5)
other
;;
9)
update_script
;;
99)
cd $HOME/$OW/lean/lede/
n1_builder
;;
0)
exit
;;
*)
clear && echo "请输入正确的数字 [1-5,9,0]" && Time
main_interface
;;
esac
}
system_install() {
clear
echo -e "$green>> 是否要更新系统,首次搭建选择是,其余选否(1.是 2.否)$white"
read -p "请输入你的决定:" system
case "$system" in
1)
update_system
create_file
;;
2)
create_file
;;
*)
clear && echo "请输入正确的数字 [1-2]" && Time
system_install
;;
esac
}
update_system() {
clear
clear && echo -e "$green >>准备更新系统 $white" && Time
sudo apt-get update
clear
javahome=`echo "$JAVA_HOME" | grep gitpod | wc -l`
if [[ "$javahome" == "1" ]]; then
clear
echo -e "$green >>检测到你是gitpod云编译主机,不需要安装依赖,直接创建文件夹即可 $white" && Time
create_file
else
echo -e "$green >>准备安装依赖 $white" && Time
rely_on
if [[ $? -eq 0 ]]; then
echo -e "$green >>安装完成 $white" && Time
else
clear
echo -e "$red 依赖没有更新或安装成功,重新执行代码 $white" && Time
update_system
fi
fi
}
create_file() {
clear
echo "----------------------------------------"
echo -e " $green开始创建文件夹$white"
echo "----------------------------------------"
echo ""
read -p "请输入你要创建的文件夹名(不要中文):" you_file
if [[ -z "$you_file" ]];then
echo -e "$red请不要输入空值!!!$white"
Time
create_file
elif [[ -e $HOME/$OW/$you_file ]]; then
clear
echo -e "$green你输入的$yellow$you_file$green文件夹在$yellow$HOME/$OW$green已存在,请重新输入文件夹名$white" && Time
create_file