-
Notifications
You must be signed in to change notification settings - Fork 64
/
inst.sh
executable file
·1777 lines (1420 loc) · 120 KB
/
inst.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
#!/usr/bin/env bash
## free, bootstrap script for inst.sh by minlearn (https://github.com/minlearn/inst/)
## meant to work/tested under debian family linux with bash > 4, ubuntu less than 20.04
## usage: wget -qO- inst.sh | bash [ -s - -o [...] -t debian|your.gzhttp/httpslocation|port:blknameforncrestore [-d]]
## for win,download and install cygwin installler and grub2win installer and setup them
#[[ ! "$(bash --version | head -n 1 | grep -o '[1-9]'| head -n 1)" -ge '4' ]] && echo "Error:bash must be at least 4!" && exit 1
[[ "$(uname -a)" =~ "inux" && "$(uname -a)" =~ "entos" ]] && echo "requires debian or ubuntu" && exit 1
#[[ "$(uname -a)" =~ "inux" && "$(uname -a)" =~ "ebian" && $(echo $(lsb_release -sr) | awk -F '.' '{print($1)}') -ge '11' ]] && echo "requires debian 10 or below,ubt 18 or below" && exit 1
#[[ "$(uname -a)" =~ "inux" && "$(uname -a)" =~ "buntu" && $(echo $(lsb_release -sr) | awk -F '.' '{print($1)}') -ge '20' ]] && echo "requires debian 10 or below,ubt 18 or below" && exit 1
# [[ ! "$(uname -a)" =~ "inux" ]] && echo "unsupported os" && exit 1
[[ "$(uname)" == "Darwin" ]] && tmptmpBUILD='1'
[[ -f /cygdrive/c/cygwin64/bin/uname && ( "$(/cygdrive/c/cygwin64/bin/uname -o)" == "Cygwin" || "$(/cygdrive/c/cygwin64/bin/uname -o)" == "Msys") ]] && tmptmpBUILD='11'
[[ "$(command -v systemd-detect-virt)" && "$(systemd-detect-virt)" == "openvz" ]] && tmptmpCTVIRTTECH='1'
# for wget -qO- xxx| bash -s - subsitute manner
[[ "$tmptmpBUILD" != "1" && "$tmptmpBUILD" != "11" ]] && [ "$(id -u)" != 0 ] && exec sudo bash -c "`cat -`" -a "$@"
# for bash <(wget -qO- xxx) -t subsitute manner we should:
# [ "$(id -u)" != 0 ] && exec sudo bash -c "`cat "$0"`" -a "$@"
[[ "$tmptmpBUILD" != "1" && "$tmptmpBUILD" != "11" ]] && [[ "$EUID" -ne '0' ]] && echo "Error:This script must be run as root!" && exit 1
# =================================================================
# globals
# =================================================================
forcemaintainmode='0' # 0:all put in maintain,1,just devdeskos in maintain
export autoDEBMIRROR0=https://github.com/minlearn/inst/raw/master
export autoDEBMIRROR1=https://gitee.com/minlearn/inst/raw/master
export FORCEDEBMIRROR='' # force apply a fixed mirror/targetddurl selection to force override autoselectdebmirror results based on -t -m args given
export tmpTARGETMODE='0' # 0:WGETDD INSTMODE ONLY 1:CLOUDDDINSTALL+BUILD MIXTURE,2,3,nc install mode,defaultly it sholudbe 0, 4 inplace dd mode for debianctmu(lxcct,or kvmct) or debiandemu
export tmpTARGET='' # dummy(for -d only),debianbase,onekeydevdesk,devdeskos,lxcdebtpl,lxcdebiantpl,qemudebtpl,qemudebiantpl,devdeskosfull,debian,debian10restore,debianct,debiandemu,debianctmu
# part I: settings related instmode,most usually are auto informed,not customable
export setNet='0' # auto informed by judging if forcenetcfgstring are feed
export AutoNet='' # auto informed by judging ifsetnet and if netcfgfile has the static keyword, has value 1,2
export FORCE1STNICNAME='' # sometimes 1stnicnames are fixed,we force set this to avoid exceptions
export FORCENETCFGSTR='' # sometimes gateway and defroute and not in the same subnet,they shoud be manual explict set, azure use the hostname and dsm use the mac
export FORCEPASSWORD='0' # this password can be password to be embeded into target, or password that is originally embeded into the src (windows os) image,0: auto
export FORCENETCFGV6ONLY='' # force ipv6only stack probe in netcfg overall possiblities
export FORCEMIRRORIMGSIZE='' # force apply a fixed mirror/targetddimgsize to force checktargeturl results based on -s args given
export FORCEMIRRORIMGNOSEG='' # force apply the imgfile in both debmirrorsrc and imgmirrorsrc as non-seg git repo style,set to 1 to use common one-piece style
export FORCE1STHDNAME='' # sometimes 1sthdname that being installed to are fixed,we force set this to avoid exceptions
export FORCEGRUBTYPE='' # do we use this?
export FORCEINSTCTL='0' # instcontrol,0:auto(with autohdexp,autonetcfginject,autoreboot),1:pure dd,without auto hd exp,2:pure dd,without networkcfg injection,3:hold without reboot,4: without pre clean just umount
export tmpINSTSERIAL='0' # 0 with serial console output support
export tmpINSTSSHONLY='0'
# part II: customables related with buildmode,initrfs,01-core,clients,lxcapps
export tmpBUILD='0' # 0:linux,1:unix,osx,2,lxc
export tmpBUILDGENE='0' # 0:biosmbr,1:biosgpt,2:uefigpt,used both in buildtime(0or1or2,0and1and2) and insttime(0or1or2)
export tmpBUILDPUTPVEINIFS='0' # put pve building prodcure inside initramfs? defaultly no
export tmpHOST='' # (blank)0,az,servarica(sr),(kimsurf/ovh/sys)ks,orc,bwg10g512m,mbp,pd
export tmpHOSTMODEL='0' # 0:kvm,1:hv,2:xen,>2:bearmetal,auto informed,not customable,0:awlays bothmode,1-98:instonlymode,99,mixed build mode
export HOSTMODLIST='0'
export tmpHOSTARCH='0' # 0,x86-64,1,arm64,used both in buildtime(0or1singlearchonlymode,0and1fullarchmode) and insttime(0or1singlearchonlymode)
export tmpCTVIRTTECH='0' # 0,no virt tech,1,lxc,2,kvm
export custIMGSIZE='10'
export custUSRANDPASS='tdl'
export tmpTGTNICNAME='eth0'
export tmpTGTNICIP='111.111.111.111' # pve only,input target nic public ip(127.0.0.1 and 127.0.1.1 forbidden,enter to use defaults 111.111.111.111)
export tmpWIFICONNECT='CMCC-xxx,11111111,wlan0' # input target wifi connecting settings(in valid hotspotname,hotspotpasswd,wifinicname form,passwd 8-63 long,enter to leave blank)
export GENCLIENTS='y' # linux,win,osx
export GENCLIENTSWINOSX='n'
export PACKCLIENTS='n'
export tmpEBDCLIENTURL='xxx.com' # input target ip or domain that will be embeded into client
export PACKCONTAINERS='' # list for defaultly packmode into 01-core
export GENCONTAINERS='' # list for mergemode into 01-core
# part III: debug and ci/cd extra addons, debug and ci cant coexists in a single subtitute
export tmpDEBUG='0' # 0,debug=manualmode in instmode, or special initramfsgen and localinst boot test in buildmode
export tmpDRYRUNREMASTER='0' # 0,use dryrunmode,wont mod grub? exists but dreprecated, we use ctlc sigint to do it
export tmpINSTWITHMANUAL='0' # 0,enter manual mode, for debugging purpose,will force reboot to a network-console
export tmpBUILDINSTTEST='0' # inst test after initramfs gened
export tmpBUILDADDONS='0' # full build mode,with split post addon actions,0,no addons,1,normal buildaddons for 1keyddbuild 2,buildaddons for lxc*build standalone
# =================================================================
# Below are function libs
# =================================================================
function prehint0(){
[ -d /sys/firmware/efi ] && echo -n u, || echo -n b,;
[[ "$tmptmpBUILD" != "11" && "$tmptmpBUILD" != "1" ]] && { [[ "$(find /sys/class/net/ -type l ! -lname '*/devices/virtual/net/*' | wc -l)" -lt 2 ]] && echo -n "i:1," || echo -n "i:>1,"; } || echo -n "i:d,"
[[ "$tmptmpBUILD" != "11" && "$tmptmpBUILD" != "1" ]] && { [[ "$(lsblk -e 7 -e 11 -d | tail -n+2 | wc -l)" -lt 2 ]] && echo -n "p:1" || echo -n "p:>1"; } || echo -n "p:d"
}
function prehint4(){
[[ "$tmptmpBUILD" != "1" && "$tmptmpBUILD" != "11" && "$tmptmpCTVIRTTECH" != "1" ]] && {
DEFAULTWORKINGNIC="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.*' |head -n1 |sed 's/proto.*\|onlink.*//g' |awk '{print $NF}')";
[[ -z "$DEFAULTWORKINGNIC" ]] && { DEFAULTWORKINGNIC="$(ip -6 -brief route show default |head -n1 |grep -o 'dev .*'|sed 's/proto.*\|onlink.*\|metric.*//g' |awk '{print $NF}')"; };
[[ -n "$DEFAULTWORKINGNIC" ]] && { DEFAULTWORKINGIPSUBV4="$(ip addr |grep ''${DEFAULTWORKINGNIC}'' |grep 'global' |grep 'brd' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/[0-9]\{1,2\}')";[[ -z "$DEFAULTWORKINGIPSUBV4" ]] && DEFAULTWORKINGIPSUBV4="$(ip addr |grep ''${DEFAULTWORKINGNIC}'' |grep 'global' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/[0-9]\{1,2\}')"; };
DEFAULTWORKINGGATEV4="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}')";
[[ -n "$DEFAULTWORKINGIPSUBV4" ]] && [[ -n "$DEFAULTWORKINGGATEV4" ]] && echo -n $DEFAULTWORKINGIPSUBV4,$DEFAULTWORKINGGATEV4 || echo -n 'no default working ipv4';
};
[[ "$tmptmpBUILD" != "1" && "$tmptmpCTVIRTTECH" != "11" && "$tmptmpCTVIRTTECH" == "1" ]] && {
DEFAULTWORKINGNIC="$(awk '$2 == 00000000 { print $1 }' /proc/net/route)";
[[ -n "$DEFAULTWORKINGNIC" ]] && DEFAULTWORKINGIPSUBV4="$(ip addr show dev ''${DEFAULTWORKINGNIC}'' | sed -nE '/global/s/.*inet (.+) brd.*$/\1/p' | head -n 1)";
DEFAULTWORKINGGATEV4="locallink";
[[ -n "$DEFAULTWORKINGIPSUBV4" ]] && [[ -n "$DEFAULTWORKINGGATEV4" ]] && echo -n $DEFAULTWORKINGIPSUBV4,$DEFAULTWORKINGGATEV4 || echo -n 'no default working ipv4';
};
[[ "$tmptmpBUILD" == "11" ]] && {
DEFAULTWORKINGNICIDX="$(netsh int ipv4 show route | grep --text -F '0.0.0.0/0' | awk '$6 ~ /\./ {print $5}')";
[[ -z "$DEFAULTWORKINGNICIDX" ]] && { DEFAULTWORKINGNICIDX="$(netsh int ipv6 show route | grep --text -F '::/0' | awk '$6 ~ /:/ {print $5}')"; };
[[ -n "$DEFAULTWORKINGNICIDX" ]] && DEFAULTWORKINGIPV4=`echo $(wmic nicconfig where "InterfaceIndex='$DEFAULTWORKINGNICIDX'" get IPAddress /format:list|sed 's/\r//g'|sed 's/IPAddress={//g'|sed 's/\("\|}\)//g'|cut -d',' -f1)`;
DEFAULTWORKINGGATEV4=`echo $(wmic nicconfig where "InterfaceIndex='$DEFAULTWORKINGNICIDX'" get DefaultIPGateway /format:list|sed 's/\r//g'|sed 's/DefaultIPGateway={//g'|sed 's/\("\|}\)//g'|cut -d',' -f1)`;
DEFAULTWORKINGMASKV4=`echo $(wmic nicconfig where "InterfaceIndex='$DEFAULTWORKINGNICIDX'" get IPSubnet /format:list|sed 's/\r//g'|sed 's/IPSubnet={//g'|sed 's/\("\|}\)//g'|cut -d',' -f1)`;
[[ -n "$DEFAULTWORKINGIPV4" ]] && [[ -n "$DEFAULTWORKINGGATEV4" ]] && echo -n $DEFAULTWORKINGIPV4,$DEFAULTWORKINGGATEV4 || echo -n 'no default working ipv4';
};
[[ "$tmptmpBUILD" == "1" ]] && {
DEFAULTWORKINGNIC="$(netstat -nr -f inet|grep default|awk '{print $4}')";
[[ -z "$DEFAULTWORKINGNIC" ]] && { DEFAULTWORKINGNIC="$(netstat -nr -f inet6|grep default|awk '{print $4}' |head -n1)"; };
[[ -n "$DEFAULTWORKINGNIC" ]] && DEFAULTWORKINGIPSUBV4="$(ifconfig ''${DEFAULTWORKINGNIC}'' |grep -Fv inet6|grep inet|awk '{print $2}')";
DEFAULTWORKINGGATEV4="$(netstat -nr -f inet|grep default|grep ''${DEFAULTWORKINGNIC}'' |awk '{print $2}')";
[[ -n "$DEFAULTWORKINGIPSUBV4" ]] && [[ -n "$DEFAULTWORKINGGATEV4" ]] && echo -n $DEFAULTWORKINGIPSUBV4,$DEFAULTWORKINGGATEV4 || echo -n 'no default working ipv4';
};
}
function prehint61(){
[[ "$tmptmpBUILD" != "1" && "$tmptmpBUILD" != "11" ]] && {
DEFAULTWORKINGNIC="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.*' |head -n1 |sed 's/proto.*\|onlink.*//g' |awk '{print $NF}')";
[[ -z "$DEFAULTWORKINGNIC" ]] && { DEFAULTWORKINGNIC="$(ip -6 -brief route show default |head -n1 |grep -o 'dev .*'|sed 's/proto.*\|onlink.*\|metric.*//g' |awk '{print $NF}')"; };
[[ -n "$DEFAULTWORKINGNIC" ]] && DEFAULTWORKINGIPSUBV6="$(ip -6 -brief address show scope global|grep ''${DEFAULTWORKINGNIC}'' |awk -F ' ' '{ print $3}')";
[[ -n "$DEFAULTWORKINGIPSUBV6" ]] && echo -n $DEFAULTWORKINGIPSUBV6 || echo -n 'no default working v6ip';
};
[[ "$tmptmpBUILD" == "11" ]] && {
DEFAULTWORKINGNICIDX="$(netsh int ipv6 show route | grep --text -F '::/0' | awk '$6 ~ /:/ {print $5}')";
[[ -n "$DEFAULTWORKINGNICIDX" ]] && DEFAULTWORKINGIPV6=`echo $(wmic nicconfig where "InterfaceIndex='$DEFAULTWORKINGNICIDX'" get IPAddress /format:list|sed 's/\r//g'|sed 's/IPAddress={//g'|sed 's/\("\|}\)//g'|cut -d',' -f2)`;
[[ -n "$DEFAULTWORKINGIPV6" ]] && echo -n $DEFAULTWORKINGIPV6 || echo -n 'no default working v6ip';
};
[[ "$tmptmpBUILD" == "1" ]] && {
DEFAULTWORKINGNIC="$(netstat -nr -f inet6|grep default|awk '{print $4}' |head -n1)";
[[ -n "$DEFAULTWORKINGNIC" ]] && DEFAULTWORKINGIPSUBV6="$(ifconfig ''${DEFAULTWORKINGNIC}'' |grep inet6|head -n1|awk '{print $2}'|sed 's/%.*//g')";
[[ -n "$DEFAULTWORKINGIPSUBV6" ]] && echo -n $DEFAULTWORKINGIPSUBV6 || echo -n 'no default working v6ip';
};
}
function prehint62(){
[[ "$tmptmpBUILD" != "1" && "$tmptmpBUILD" != "11" ]] && {
DEFAULTWORKINGNIC="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.*' |head -n1 |sed 's/proto.*\|onlink.*//g' |awk '{print $NF}')";
[[ -z "$DEFAULTWORKINGNIC" ]] && { DEFAULTWORKINGNIC="$(ip -6 -brief route show default |head -n1 |grep -o 'dev .*'|sed 's/proto.*\|onlink.*\|metric.*//g' |awk '{print $NF}')"; };
[[ -n "$DEFAULTWORKINGNIC" ]] && DEFAULTWORKINGGATEV6="$(ip -6 -brief route show default|grep ''${DEFAULTWORKINGNIC}'' |awk -F ' ' '{ print $3}')";
[[ -n "$DEFAULTWORKINGGATEV6" ]] && echo -n $DEFAULTWORKINGGATEV6 || echo -n 'no default working v6gate';
};
[[ "$tmptmpBUILD" == "11" ]] && {
DEFAULTWORKINGNICIDX="$(netsh int ipv6 show route | grep --text -F '::/0' | awk '$6 ~ /:/ {print $5}')";
[[ -n "$DEFAULTWORKINGNICIDX" ]] && DEFAULTWORKINGGATEV6=`echo $(wmic nicconfig where "InterfaceIndex='$DEFAULTWORKINGNICIDX'" get DefaultIPGateway /format:list|sed 's/\r//g'|sed 's/DefaultIPGateway={//g'|sed 's/\("\|}\)//g'|cut -d',' -f2)`;
[[ -n "$DEFAULTWORKINGGATEV6" ]] && echo -n $DEFAULTWORKINGGATEV6 || echo -n 'no default working v6gate';
};
[[ "$tmptmpBUILD" == "1" ]] && {
DEFAULTWORKINGNIC="$(netstat -nr -f inet6|grep default|awk '{print $4}' |head -n1)";
[[ -n "$DEFAULTWORKINGNIC" ]] && DEFAULTWORKINGGATEV6="$(netstat -nr -f inet6|grep default|grep ''${DEFAULTWORKINGNIC}'' |awk '{ print $2}'|sed 's/%.*//g')";
[[ -n "$DEFAULTWORKINGGATEV6" ]] && echo -n $DEFAULTWORKINGGATEV6 || echo -n 'no default working v6gate';
};
}
function Outbanner(){
RD=$(echo "\033[01;31m")
CL=$(echo "\033[m")
[[ "$1" == 'wizardmode' ]] && echo -e "
██${RD}╗${CL}███${RD}╗${CL} ██${RD}╗${CL}███████${RD}╗${CL}████████${RD}╗${CL} \033[1;31m!!THIS SCIRPT MAY WIPE ALL DATA!!\033[0m \033[32m`[[ "$tmpTARGETMODE" != '1' && "$tmpBUILD" != '1' ]] && echo -n $(wget --no-check-certificate --no-verbose --content-on-error=on --timeout=1 --tries=2 -qO- 'https://counter.minlearn.org/api/dsrkafuu:demo'|grep -Eo [0-9]*[0-9])`\033[0m
██${RD}║${CL}████${RD}╗${CL} ██${RD}║${CL}██${RD}╔════╝╚══${CL}██${RD}╔══╝${CL} https://github.com/minlearn/inst
██${RD}║${CL}██${RD}╔${CL}██${RD}╗${CL} ██${RD}║${CL}███████${RD}╗${CL} ██${RD}║${CL}
██${RD}║${CL}██${RD}║╚${CL}██${RD}╗${CL}██${RD}║╚════${CL}██${RD}║${CL} ██${RD}║${CL} [`prehint0`][`prehint4`]
██${RD}║${CL}██${RD}║ ╚${CL}████${RD}║${CL}███████${RD}║${CL} ██${RD}║${CL} [`prehint61`]
${RD}╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝${CL} [`prehint62`]
`printf "=%0.s" {1..74}`
"
}
function CheckDependence(){
[[ "$tmpBUILD" == "11" || "$tmpBUILD" == "1" ]] && echo -en "[ \033[32m non linux,assume preinstalled \033[0m ]" && return;
FullDependence='0';
lostdeplist="";
lostpkglist="";
for BIN_DEP in `[[ "$tmpBUILD" -ne '0' ]] && echo "$1" |sed 's/,/\n/g' || echo "$1" |sed 's/,/\'$'\n''/g'`
do
if [[ -n "$BIN_DEP" ]]; then
Founded='1';
for BIN_PATH in `[[ "$tmpBUILD" -ne '0' ]] && echo "$PATH" |sed 's/:/\n/g' || echo "$PATH" |sed 's/:/\'$'\n''/g'`
do
ls $BIN_PATH/$BIN_DEP >/dev/null 2>&1;
if [ $? == '0' ]; then
Founded='0';
break;
fi
done
# detailed log under buildmode
[[ "$tmpTARGET" == 'devdeskos' && "$tmpTARGETMODE" == '1' && "$tmpBUILD" != '1' ]] && echo -en "\033[s[ \033[32m ${BIN_DEP:0:10}";
if [ "$Founded" == '0' ]; then
[[ "$tmpTARGET" == 'devdeskos' && "$tmpTARGETMODE" == '1' && "$tmpBUILD" != '1' ]] && echo -en ",ok \033[0m ]\033[u";
:;
else
FullDependence='1';
[[ "$tmpTARGET" == 'devdeskos' && "$tmpTARGETMODE" == '1' && "$tmpBUILD" != '1' ]] && echo -en ",\033[31m miss \033[0m] ";
# simple log under instmode
#[[ "$tmpTARGETMODE" == '0' ]] && echo -en "[ \033[32m $BIN_DEP,\033[31m miss \033[0m] ";
lostdeplist+=" $BIN_DEP";
fi
fi
done
[[ $lostdeplist =~ "sudo" ]] && lostpkglist+=" sudo"; \
[[ $lostdeplist =~ "curl" ]] && lostpkglist+=" curl"; \
[[ $lostdeplist =~ "ar" ]] && lostpkglist+=" binutils"; \
[[ $lostdeplist =~ "cpio" ]] && lostpkglist+=" cpio"; \
[[ $lostdeplist =~ "xzcat" ]] && lostpkglist+=" xz-utils"; \
[[ $lostdeplist =~ "md5sum" || $lostdeplist =~ "sha1sum" || $lostdeplist =~ "sha256sum" || $lostdeplist =~ "df" ]] && lostpkglist+=" coreutils"; \
[[ $lostdeplist =~ "losetup" ]] && lostpkglist+=" util-linux"; \
[[ $lostdeplist =~ "fdisk" ]] && lostpkglist+=" fdisk"; \
[[ $lostdeplist =~ "parted" ]] && lostpkglist+=" parted"; \
[[ $lostdeplist =~ "mkfs.fat" ]] && lostpkglist+=" dosfstools"; \
[[ $lostdeplist =~ "squashfs" ]] && lostpkglist+=" squashfs-tools"; \
[[ $lostdeplist =~ "sqlite3" ]] && lostpkglist+=" sqlite3"; \
[[ $lostdeplist =~ "unzip" ]] && lostpkglist+=" unzip"; \
[[ $lostdeplist =~ "zip" ]] && lostpkglist+=" zip"; \
[[ $lostdeplist =~ "7z" ]] && lostpkglist+=" p7zip"; \
[[ $lostdeplist =~ "openssl" ]] && lostpkglist+=" openssl"; \
[[ $lostdeplist =~ "virt-what" ]] && lostpkglist+=" virt-what"; \
[[ $lostdeplist =~ "rsync" ]] && lostpkglist+=" rsync";
[[ "$tmpTARGETMODE" == '0' && "$tmpBUILD" != '1' ]] && [[ ! -f /usr/sbin/grub-reboot && ! -f /usr/sbin/grub2-reboot ]] && FullDependence='1' && lostdeplist+="grub2-common" && lostpkglist+=" grub2-common"
[[ "$tmpTARGETMODE" == '0' && "$tmpBUILD" != '1' ]] && [[ "$FORCENETCFGV6ONLY" == '1' ]] && [[ ! -f /usr/bin/subnetcalc ]] && FullDependence='1' && lostdeplist+="subnetcalc" && lostpkglist+=" subnetcalc"
# [[ "$tmpBUILDGENE" == '1' && "$tmpTARGET" == 'devdeskos' && "$tmpTARGETMODE" == '1' ]] && [[ ! -f /usr/lib/grub/x86_64-efi/acpi.mod ]] && FullDependence='1' && lostdeplist+="grub-efi" && lostpkglist+=" grub-efi"
if [ "$FullDependence" == '1' ]; then
echo -en "[ \033[32m deps missing! perform autoinstall \033[0m ] ";
apt-get update --allow-releaseinfo-change --allow-unauthenticated --allow-insecure-repositories -y -qq >/dev/null 2>&1
# use reinstall but not install, cause some pkgs maybe already there, but indeedly broken in bin/deps level(the bin were wrong delt)
# dont use apt-get update && apt-get reinstall here,cause apt-get update may fail but actually run
apt-get reinstall --no-install-recommends -y -qq `echo -n "$lostpkglist"` >/dev/null 2>&1
[[ $? == '0' ]] && echo -en "[ \033[32m done. \033[0m ]" || { echo;echo -en "\033[31m $lostdeplist missing !error happen while autoinstall! please fix to run 'apt-get update && apt-get install $lostpkglist ' to install them\033[0m";exit 1; }
else
# simple log under instmode
[[ "$tmpTARGETMODE" != '1' ]] && echo -en "[ \033[32m all,ok \033[0m ]";
fi
}
function test_mirror() {
SAMPLES=3
BYTES=511999 #1mb
TIMEOUT=1
TESTFILE="/_build/1mtest"
for s in $(seq 1 $SAMPLES) ; do
# CheckPass1
downloaded=$(curl -k -L -r 0-$BYTES --max-time $TIMEOUT --silent --output /dev/null --write-out %{size_download} ${1}${TESTFILE})
if [ "$downloaded" == "0" ] ; then
break
else
# CheckPass2
time=$(curl -k -L -r 0-$BYTES --max-time $TIMEOUT --silent --output /dev/null --write-out %{time_total} ${1}${TESTFILE})
echo $time
fi
done
}
function mean() {
len=$#
echo $* | tr " " "\n" | sort -n | head -n $(((len+1)/2)) | tail -n 1
}
osxbash_set_avar() { eval "$1_$2=\$3"; }
_get_avar() { eval "_AVAR=\$$1_$2"; }
osxbash_get_avar() { _get_avar "$@" && printf "%s\n" "$_AVAR"; }
function SelectDEBMirror(){
[ $# -ge 1 ] || exit 1
[[ "$tmpBUILD" != "1" ]] && {
declare -A MirrorTocheck
MirrorTocheck=(["Debian0"]="" ["Debian1"]="" ["Debian2"]="")
echo "$1" |sed 's/\ //g' |grep -q '^http://\|^https://\|^ftp://' && MirrorTocheck[Debian0]=$(echo "$1" |sed 's/\ //g');
echo "$2" |sed 's/\ //g' |grep -q '^http://\|^https://\|^ftp://' && MirrorTocheck[Debian1]=$(echo "$2" |sed 's/\ //g');
#echo "$3" |sed 's/\ //g' |grep -q '^http://\|^https://\|^ftp://' && MirrorTocheck[Debian2]=$(echo "$3" |sed 's/\ //g');
for mirror in `[[ "$tmpBUILD" -ne '0' ]] && echo "${!MirrorTocheck[@]}" |sed 's/\ /\n/g' |sort -n |grep "^Debian" || echo "${!MirrorTocheck[@]}" |sed 's/\ /\'$'\n''/g' |sort -n |grep "^Debian"`
do
CurMirror="${MirrorTocheck[$mirror]}"
[ -n "$CurMirror" ] || continue
mean=$(mean $(test_mirror $CurMirror))
if [ "$mean" != "-nan" -a "$mean" != "" ] ; then
printf '%-60s %.5f\\n' $CurMirror $mean
# else
# printf '%-60s failed, ignoring\\n' $CurMirror 1>&2
fi
done
}
[[ "$tmpBUILD" == "1" ]] && {
osxbash_set_avar MirrorTocheck 1 $1
osxbash_set_avar MirrorTocheck 2 $2
osxbash_set_avar MirrorTocheck 3 $3
for mirror in 1 2 3;do
CurMirror=`osxbash_get_avar MirrorTocheck "$mirror"`
[ -n "$CurMirror" ] || continue
mean=$(mean $(test_mirror $CurMirror))
if [ "$mean" != "-nan" -a "$mean" != "" ] ; then
printf '%-60s %.5f\\n' $CurMirror $mean
# else
# printf '%-60s failed, ignoring\\n' $CurMirror 1>&2
fi
done
}
}
function CheckTargeturl(){
IMGSIZE=''
UNZIP=''
# $1 is always given as a effective url,no need to valicated anymore,just curl its header
IMGHEADERCHECK="$(curl -k -IsL "$1")";
# check imagesize
#[[ -n "$IMGSIZE" && -z "$FORCEMIRRORIMGSIZE" ]] && TARGETDDIMGSIZE=$IMGSIZE
#[[ -n "$IMGSIZE" && -n "$FORCEMIRRORIMGSIZE" ]] && TARGETDDIMGSIZE=$FORCEMIRRORIMGSIZE
#IMGSIZE="$(echo "$IMGHEADERCHECK" | grep 'Content-Length'|awk '{print $2}')" || IMGSIZE=20
IMGSIZE=20
[[ "$IMGSIZE" == '' ]] && echo -en " \033[31m Didnt got img size,or img too small,is there sth wrong? exit! \033[0m " && exit 1;
[[ "$tmpTARGET" =~ ":10000" ]] && IMGTYPECHECK="nc" || IMGTYPECHECK="$(echo "$IMGHEADERCHECK"|grep -E -o '200|302'|head -n 1)";
[[ "$IMGTYPECHECK" != '' ]] && {
[[ "$tmpTARGETMODE" == '4' && "$tmpBUILD" != '1' ]] && [[ "$tmpTARGET" == "debianct" || "$tmpTARGET" == "debianctmu" ]] && [[ "$IMGTYPECHECK" == '200' || "$IMGTYPECHECK" == '302' ]] && UNZIP='2' && { sleep 3 && echo -en "[ \033[32m inbuilt \033[0m ]"; }
[[ "$tmpTARGETMODE" == '0' && "$tmpBUILD" != '1' ]] && [[ "$tmpTARGET" == "devdeskos" || "$tmpTARGET" == "debian10r" ]] && [[ "$IMGTYPECHECK" == '200' || "$IMGTYPECHECK" == '302' ]] && sleep 3 && UNZIP='2' && echo -en "[ \033[32m inbuilt \033[0m ]"
[[ "$tmpTARGETMODE" == '0' && "$IMGTYPECHECK" == 'nc' ]] && sleep 3 && UNZIP='1' && echo -en "[ \033[32m nc \033[0m ]"
[[ "$tmpTARGETMODE" == '0' && "$tmpBUILD" != '1' ]] && [[ "$tmpTARGET" != "devdeskos" && "$tmpTARGET" != "debian10r" ]] && [[ "$IMGTYPECHECK" == '200' || "$IMGTYPECHECK" == '302' ]] && {
# begin pass1:check imagetype
IMGTYPECHECKPASS_DRTREF="$(echo "$IMGHEADERCHECK"|grep -E -o 'github|raw|qcow2|gzip|x-gzip|x-xz|zstd'|head -n 1)";
# github tricks,cause it has raw word in its typecheck info
[[ "$IMGTYPECHECKPASS_DRTREF" == 'github' ]] && UNZIP='1' && sleep 3 && echo -en "[ \033[32m github \033[0m ]";
[[ "$IMGTYPECHECKPASS_DRTREF" == 'raw' ]] && UNZIP='0' && sleep 3 && echo -en "[ \033[32m raw \033[0m ]";
[[ "$IMGTYPECHECKPASS_DRTREF" == 'gzip' ]] && UNZIP='1' && sleep 3 && echo -en "[ \033[32m gzip \033[0m ]";
[[ "$IMGTYPECHECKPASS_DRTREF" == 'x-gzip' ]] && UNZIP='1' && sleep 3 && echo -en "[ \033[32m x-gzip \033[0m ]";
[[ "$IMGTYPECHECKPASS_DRTREF" == 'gunzip' ]] && UNZIP='1' && sleep 3 && echo -en "[ \033[32m gunzip \033[0m ]";
[[ "$IMGTYPECHECKPASS_DRTREF" == 'x-xz' ]] && UNZIP='2' && sleep 3 && echo -en "[ \033[32m xz \033[0m ]";
[[ "$IMGTYPECHECKPASS_DRTREF" == 'zstd' ]] && UNZIP='3' && sleep 3 && echo -en "[ \033[32m zstd \033[0m ]";
[[ "$IMGTYPECHECKPASS_DRTREF" == 'qcow2' ]] && UNZIP='4' && sleep 3 && echo -en "[ \033[32m qcow2 \033[0m ]";
[[ "$IMGTYPECHECKPASS_DRTREF" == '' || "$UNZIP" == '' ]] && {
# begin pass2:simply check ext
EXTCHECKPASS="$([[ $1 =~ '.' ]] && echo ${1##*.})"
[[ "$EXTCHECKPASS" == '' ]] && { UNZIP='0' && sleep 3 && echo -en "[ \033[32m noext \033[0m ]"; } || { [[ "$EXTCHECKPASS" == 'raw' ]] && UNZIP='0' && sleep 3 && echo -en "[ \033[32m raw \033[0m ]";[[ "$EXTCHECKPASS" == 'gz' || "$EXTCHECKPASS" == 'gzip' ]] && UNZIP='1' && sleep 3 && echo -en "[ \033[32m gzip \033[0m ]";[[ "$EXTCHECKPASS" == 'xz' ]] && UNZIP='2' && sleep 3 && echo -en "[ \033[32m xz \033[0m ]";[[ "$EXTCHECKPASS" == 'zstd' ]] && UNZIP='3' && sleep 3 && echo -en "[ \033[32m zstd \033[0m ]";[[ "$EXTCHECKPASS" == 'qcow2' || "$EXTCHECKPASS" == 'img' ]] && UNZIP='4' && sleep 3 && echo -en "[ \033[32m qcow2 \033[0m ]"; }
}
#after 2 passe,no need to check IMGTYPECHECKPASS_DRTREF anymore
# IMGTYPECHECKPASS_DRTREF forced to 1 level only which may fail,we simply failover it as a warning instead of a error
# inbuilt targets has fixed unzip but non inbuilt ones dont,we simply failover to unzip 1 instead of a error
[[ "$UNZIP" == '' ]] && UNZIP='1' && echo -en "[ \033[32m failover \033[0m ]";
}
}
[[ "$tmpTARGETMODE" == '0' && "$tmpBUILD" != '1' ]] && [[ "$IMGTYPECHECK" == '' ]] && echo -en " \033[31m targeturl broken, will exit! \033[0m " && { [[ "$tmpTARGET" == "debian10r" ]] && echo -en " \033[31m debian10r image src may in maintain mode for 10-60m! \033[0m " && forcemaintainmode='1';exit 1; }
}
ipNum()
{
local IFS='.';
read ip1 ip2 ip3 ip4 <<<"$1";
echo $((ip1*(1<<24)+ip2*(1<<16)+ip3*(1<<8)+ip4));
}
SelectMax(){
ii=0;
for IPITEM in `route -n |awk -v OUT=$1 '{print $OUT}' |grep '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'`
do
NumTMP="$(ipNum $IPITEM)";
eval "arrayNum[$ii]='$NumTMP,$IPITEM'";
ii=$[$ii+1];
done
echo ${arrayNum[@]} |sed 's/\s/\n/g' |sort -n -k 1 -t ',' |tail -n1 |cut -d',' -f2;
}
prefixlen2subnetmask(){
echo `subnetcalc $TMPIPSUBV6 2>/dev/null |grep Netmask|cut -d "=" -f 2|sed 's/ //g'`
}
parsenetcfg(){
# never use
interface=''
# 1): setnet=1
# 2): setnet!=1 and netcfgfile containes static (autonet=1=still static)
# 3): setnet!=1 and netcfgfile dont containes static (autonet=2=dhcp)
[[ -n "$FORCENETCFGSTR" || "$FORCENETCFGV6ONLY" == '1' || ( "$tmpBUILD" == '11' || "$tmpBUILD" == '1' ) || "$tmpCTVIRTTECH" == '1' ]] && setNet='1';
# networkmanager
[[ "$setNet" != '1' ]] && [[ -f '/etc/network/interfaces' ]] && {
[[ -z "$(sed -n '/iface.*inet static/p' /etc/network/interfaces)" ]] && AutoNet='2' || AutoNet='1';[[ -n "$(sed -n '/iface.*inet manual/p' /etc/network/interfaces)" ]] && [[ -n "$(sed -n '/iface.*inet static/p' /etc/network/interfaces)" ]] && AutoNet='2'
[[ -d /etc/network/interfaces.d ]] && {
ICFGN="$(find /etc/network/interfaces.d -type f -name '*' |wc -l)" || ICFGN='0';
[[ "$ICFGN" -ne '0' ]] && {
for NetCFG in `ls -1 /etc/network/interfaces.d/*`
do
[[ -z "$(cat $NetCFG | sed -n '/iface.*inet static/p')" ]] && AutoNet='2' || AutoNet='1';[[ -n "$(cat $NetCFG | sed -n '/iface.*inet manual/p' /etc/network/interfaces)" ]] && [[ -n "$(cat $NetCFG | sed -n '/iface.*inet static/p' /etc/network/interfaces)" ]] && AutoNet='2'
[[ "$AutoNet" -eq '0' ]] && break;
done
}
}
}
# netplan
[[ "$setNet" != '1' ]] && [[ -f '/etc/netplan/00-installer-config.yaml' ]] && {
[[ -z "$(sed -n '/dhcp4: false\|- \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}.../p' /etc/netplan/00-installer-config.yaml)" ]] && AutoNet='2' || AutoNet='1'
}
# we have force1stnicname
if [[ -n "$FORCE1STNICNAME" ]]; then
IFETH=`[[ \`echo $FORCE1STNICNAME|grep -Eo ":"\` ]] && echo $FORCE1STNICNAME || echo \`ip addr show $FORCE1STNICNAME|grep link/ether | awk '{print $2}'\``
IFETHMAC=`echo $IFETH`
else
#IFETH="auto"
# no more auto, alwaysly force1stnicname and force mac
DEFAULTNIC="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.*' |head -n1 |sed 's/proto.*\|onlink.*//g' |awk '{print $NF}')";
FORCE1STNICNAME=`echo \`ip addr show $DEFAULTNIC|grep link/ether | awk '{print $2}'\``
IFETH=`echo $FORCE1STNICNAME`
IFETHMAC=`echo $IFETH`
fi
# for printing a default nicname,when -n given,has actual effect for setnet!=1,has no effect for setnet=1
[[ "$tmpBUILD" != "11" && "$tmpBUILD" != "1" && "$tmpCTVIRTTECH" != "1" ]] && {
DEFAULTNIC="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.*' |head -n1 |sed 's/proto.*\|onlink.*//g' |awk '{print $NF}')";
[[ -z "$DEFAULTNIC" ]] && { DEFAULTNIC="$(ip -6 -brief route show default |head -n1 |grep -o 'dev .*'|sed 's/proto.*\|onlink.*\|metric.*//g' |awk '{print $NF}')"; }
# [[ -z "$DEFAULTNIC" ]] || { echo "Error! get default nic failed";exit 1; }
}
[[ "$tmpBUILD" != "11" && "$tmpBUILD" != "1" && "$tmpCTVIRTTECH" == "1" ]] && {
DEFAULTNIC="$(awk '$2 == 00000000 { print $1 }' /proc/net/route)";
# [[ -z "$DEFAULTNIC" ]] || { echo "Error! get default nic failed";exit 1; }
}
# for win we force 1stnicname alwaysly, and defaultnic=forcenic, allinone
if [[ "$tmpBUILD" == '11' && -z "$FORCE1STNICNAME" ]]; then
FORCE1STNICIDX="$(netsh int ipv4 show route | grep --text -F '0.0.0.0/0' | awk '$6 ~ /\./ {print $5}')";[[ -z "$FORCE1STNICIDX" ]] && { FORCE1STNICIDX="$(netsh int ipv6 show route | grep --text -F '::/0' | awk '$6 ~ /:/ {print $5}')";FORCE1STNICNAME=`echo $(wmic nicconfig where "InterfaceIndex='$FORCE1STNICIDX'" get MACAddress /format:list|sed 's/\r//g'|sed 's/MACAddress=//g')`; } || { FORCE1STNICNAME=`echo $(wmic nicconfig where "InterfaceIndex='$FORCE1STNICIDX'" get MACAddress /format:list|sed 's/\r//g'|sed 's/MACAddress=//g')`; }
DEFAULTNIC="$FORCE1STNICIDX";
IFETH=`echo $FORCE1STNICNAME`
IFETHMAC=`echo $IFETH`
fi
if [[ "$tmpBUILD" == '1' && -z "$FORCE1STNICNAME" ]]; then
DEFAULTNIC="$(netstat -nr -f inet|grep default|awk '{print $4}')";[[ -z "$DEFAULTNIC" ]] && { DEFAULTNIC="$(netstat -nr -f inet6|grep default|awk '{print $4}' |head -n1)"; }
FORCE1STNICNAME=`echo $(ifconfig ''${DEFAULTNIC}'' | awk '/ether/{print $2}')`
IFETH=`echo $FORCE1STNICNAME`
IFETHMAC=`echo $IFETH`
fi
[[ "$setNet" == '1' ]] && {
# FORCENETCFGSTR=10.211.55.105/24,10.211.55.1
# FORCENETCFGSTR=10.211.55.105,255.255.255.0,10.211.55.1
# FORCENETCFGSTR=fdb2:2c26:f4e4:0:a756:35e5:2cab:4463/64,fe80::21c:42ff:fe00:18
# FORCENETCFGSTR=fdb2:2c26:f4e4:0:1270:98bd:5b9:eda7,ffff:ffff:ffff:ffff::,fe80::21c:42ff:fe00:18
[[ `echo "$FORCENETCFGSTR" | grep -Eo ,|wc -l` == 1 ]] && {
FIPSUB=`echo "$FORCENETCFGSTR" | awk -F ',' '{ print $1}'`;
FIP="$(echo -n "$FIPSUB" |cut -d'/' -f1)";
FCIDR="/$(echo -n "$FIPSUB" |cut -d'/' -f2)";
[[ `echo $FIP|grep -Eo ":"` ]] && FMASK=`echo \`subnetcalc $FIPSUB 2>/dev/null |grep Netmask|cut -d "=" -f 2|sed 's/ //g'\`` || FMASK="$(echo -n '128.0.0.0/1,192.0.0.0/2,224.0.0.0/3,240.0.0.0/4,248.0.0.0/5,252.0.0.0/6,254.0.0.0/7,255.0.0.0/8,255.128.0.0/9,255.192.0.0/10,255.224.0.0/11,255.240.0.0/12,255.248.0.0/13,255.252.0.0/14,255.254.0.0/15,255.255.0.0/16,255.255.128.0/17,255.255.192.0/18,255.255.224.0/19,255.255.240.0/20,255.255.248.0/21,255.255.252.0/22,255.255.254.0/23,255.255.255.0/24,255.255.255.128/25,255.255.255.192/26,255.255.255.224/27,255.255.255.240/28,255.255.255.248/29,255.255.255.252/30,255.255.255.254/31,255.255.255.255/32' |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'${FCIDR}'' |cut -d'/' -f1)";
FGATE=`echo "$FORCENETCFGSTR" | awk -F ',' '{ print $2}'`;
[[ `echo $FIP|grep -Eo ":"` && -f /etc/resolv.conf ]] && { [[ ! -f /etc/resolv.conf.old ]] && { cp -f /etc/resolv.conf /etc/resolv.conf.old && > /etc/resolv.conf && echo -e 'nameserver 2001:67c:2b0::4\nnameserver 2001:67c:2b0::6' >/dev/null 2>&1 >> /etc/resolv.conf; } || { cp -f /etc/resolv.conf /etc/resolv.conf.bak && > /etc/resolv.conf && echo -e 'nameserver 2001:67c:2b0::4\nnameserver 2001:67c:2b0::6' >/dev/null 2>&1 >> /etc/resolv.conf; }; } || { [[ -f /etc/resolv.conf.old ]] && cp -f /etc/resolv.conf.old /etc/resolv.conf; }
}
[[ `echo "$FORCENETCFGSTR" | grep -Eo ,|wc -l` == 2 ]] && {
#NAME=`echo "$FORCENETCFGSTR" | awk -F ',' '{ print $1}' | awk -F ':' '{ print $2}'`
FIP=`echo "$FORCENETCFGSTR" | awk -F ',' '{ print $1}'`
#CIDR=`echo "$FORCENETCFGSTR" | awk -F ',' '{ print $3}' | awk -F ':' '{ print $2}'`
#MAC=`echo "$FORCENETCFGSTR" | awk -F ',' '{ print $4}' | awk -F ':' '{ print $2}'`
FMASK=`echo "$FORCENETCFGSTR" | awk -F ',' '{ print $2}'`
FGATE=`echo "$FORCENETCFGSTR" | awk -F ',' '{ print $3}'`
[[ `echo $FIP|grep -Eo ":"` && -f /etc/resolv.conf ]] && { [[ ! -f /etc/resolv.conf.old ]] && { cp -f /etc/resolv.conf /etc/resolv.conf.old && > /etc/resolv.conf && echo -e 'nameserver 2001:67c:2b0::4\nnameserver 2001:67c:2b0::6' >/dev/null 2>&1 >> /etc/resolv.conf; } || { cp -f /etc/resolv.conf /etc/resolv.conf.bak && > /etc/resolv.conf && echo -e 'nameserver 2001:67c:2b0::4\nnameserver 2001:67c:2b0::6' >/dev/null 2>&1 >> /etc/resolv.conf; }; } || { [[ -f /etc/resolv.conf.old ]] && cp -f /etc/resolv.conf.old /etc/resolv.conf; }
#STATICROUTE=`echo "$FORCENETCFGSTR" | awk -F ',' '{ print $7}' | awk -F ':' '{ print $2}'`
#DNS1=`echo "$FORCENETCFGSTR" | awk -F ',' '{ print $8}' | awk -F ':' '{ print $2}'`
#DNS2=`echo "$FORCENETCFGSTR" | awk -F ',' '{ print $9}' | awk -F ':' '{ print $2}'`
}
# force ipv6 also force ipv6 staticnetcfg
[[ "$FORCENETCFGV6ONLY" == '1' && -z "$FORCENETCFGSTR" ]] && { [[ -n "$DEFAULTNIC" ]] && TMPIPSUBV6="$(ip -6 -brief address show scope global|grep ''${DEFAULTNIC}'' |awk -F ' ' '{ print $3}')";
FIP="$(echo -n "$TMPIPSUBV6" |cut -d'/' -f1)";
TMPCIDRV6="$(echo -n "$TMPIPSUBV6" |cut -d'/' -f2)";
FGATE="$(ip -6 -brief route show default|grep ''${DEFAULTNIC}'' |awk -F ' ' '{ print $3}')";
[[ -n "$TMPCIDRV6" ]] && FMASK="$(prefixlen2subnetmask)"; } && FORCENETCFGSTR="$FIP,$FMASK,$FGATE" && { [[ -f /etc/resolv.conf && ! -f /etc/resolv.conf.old ]] && { cp -f /etc/resolv.conf /etc/resolv.conf.old && > /etc/resolv.conf && echo -e 'nameserver 2001:67c:2b0::4\nnameserver 2001:67c:2b0::6' >/dev/null 2>&1 >> /etc/resolv.conf; } || { cp -f /etc/resolv.conf /etc/resolv.conf.bak && > /etc/resolv.conf && echo -e 'nameserver 2001:67c:2b0::4\nnameserver 2001:67c:2b0::6' >/dev/null 2>&1 >> /etc/resolv.conf; }; }
# force ct will force staticnetcfg
[[ "$tmpCTVIRTTECH" == '1' && -z "$FORCENETCFGSTR" ]] && { [[ -n "$DEFAULTNIC" ]] && TMPIPSUBV4="$(ip addr show dev ''${DEFAULTNIC}'' | sed -nE '/global/s/.*inet (.+) brd.*$/\1/p' | head -n 1)";
FIP="$(echo -n "$TMPIPSUBV4" |cut -d'/' -f1)";
TMPCIDRV4="$(echo -n "$TMPIPSUBV4" |grep -o '/[0-9]\{1,2\}')";
FGATE="locallink";
[[ -n "$TMPCIDRV4" ]] && FMASK="$(echo -n '128.0.0.0/1,192.0.0.0/2,224.0.0.0/3,240.0.0.0/4,248.0.0.0/5,252.0.0.0/6,254.0.0.0/7,255.0.0.0/8,255.128.0.0/9,255.192.0.0/10,255.224.0.0/11,255.240.0.0/12,255.248.0.0/13,255.252.0.0/14,255.254.0.0/15,255.255.0.0/16,255.255.128.0/17,255.255.192.0/18,255.255.224.0/19,255.255.240.0/20,255.255.248.0/21,255.255.252.0/22,255.255.254.0/23,255.255.255.0/24,255.255.255.128/25,255.255.255.192/26,255.255.255.224/27,255.255.255.240/28,255.255.255.248/29,255.255.255.252/30,255.255.255.254/31,255.255.255.255/32' |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'${TMPCIDRV4}'' |cut -d'/' -f1)"; } && { FORCENETCFGSTR="$FIP,$FMASK,$FGATE";echo -e "auto lo\niface lo inet loopback\n\nauto $DEFAULTNIC\niface $DEFAULTNIC inet static\naddress $TMPIPSUBV4\nup route add $(ip route show default 0.0.0.0/0 | sed -E 's/^(.*dev [^ ]+).*$/\1/')\n\nhostname $(hostname)" >/dev/null 2>&1 >> $remasteringdir/ctrnet;echo -e "nameserver 8.8.8.8\nnameserver 2001:4860:4860::8888" >/dev/null 2>&1 >> $remasteringdir/ctrdns; }
# win force v4v6 FORCENETCFGSTR too
[[ "$tmpBUILD" == '11' && -z "$FORCENETCFGSTR" ]] && { [[ -n "$DEFAULTNIC" ]] && FIP=`echo $(wmic nicconfig where "InterfaceIndex='$FORCE1STNICIDX'" get IPAddress /format:list|sed 's/\r//g'|sed 's/IPAddress={//g'|sed 's/\("\|}\)//g'|cut -d',' -f1)`;
FGATE=`echo $(wmic nicconfig where "InterfaceIndex='$FORCE1STNICIDX'" get DefaultIPGateway /format:list|sed 's/\r//g'|sed 's/DefaultIPGateway={//g'|sed 's/\("\|}\)//g'|cut -d',' -f1)`;
FMASK=`echo $(wmic nicconfig where "InterfaceIndex='$FORCE1STNICIDX'" get IPSubnet /format:list|sed 's/\r//g'|sed 's/IPSubnet={//g'|sed 's/\("\|}\)//g'|cut -d',' -f1)`; } && FORCENETCFGSTR="$FIP,$FMASK,$FGATE"
[[ "$tmpBUILD" == '11' && -n "$FORCENETCFGSTR" ]] && { FORCENETCFGSTR="$FIP,$FMASK,$FGATE"; }
[[ "$tmpBUILD" == '1' && -z "$FORCENETCFGSTR" ]] && { [[ -n "$DEFAULTNIC" ]] && FIP=`echo $(ifconfig ''${DEFAULTNIC}'' |grep -Fv inet6|grep inet|awk '{print $2}')`;
FGATE=`echo $(netstat -nr -f inet|grep default|grep ''${DEFAULTNIC}'' |awk '{print $2}')`;
FMASKTMP=`echo $(ifconfig ''${DEFAULTNIC}''|grep netmask|awk '{print $4}'|sed s/0x//g)`
FMASK=`printf '%d.%d.%d.%d\n' $(echo ''${FMASKTMP}'' | sed 's/../0x& /g')`; } && FORCENETCFGSTR="$FIP,$FMASK,$FGATE"
[[ "$tmpBUILD" == '1' && -n "$FORCENETCFGSTR" ]] && { FORCENETCFGSTR="$FIP,$FMASK,$FGATE"; }
}
[[ "$setNet" != '1' ]] && {
[[ -n "$DEFAULTNIC" ]] && { IPSUBV4="$(ip addr |grep ''${DEFAULTNIC}'' |grep 'global' |grep 'brd' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/[0-9]\{1,2\}')";[[ -z "$IPSUBV4" ]] && IPSUBV4="$(ip addr |grep ''${DEFAULTWORKINGNIC}'' |grep 'global' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/[0-9]\{1,2\}')"; };
IPV4="$(echo -n "$IPSUBV4" |cut -d'/' -f1)";
CIDRV4="$(echo -n "$IPSUBV4" |grep -o '/[0-9]\{1,2\}')";
GATEV4="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}')";
[[ -n "$CIDRV4" ]] && MASKV4="$(echo -n '128.0.0.0/1,192.0.0.0/2,224.0.0.0/3,240.0.0.0/4,248.0.0.0/5,252.0.0.0/6,254.0.0.0/7,255.0.0.0/8,255.128.0.0/9,255.192.0.0/10,255.224.0.0/11,255.240.0.0/12,255.248.0.0/13,255.252.0.0/14,255.254.0.0/15,255.255.0.0/16,255.255.128.0/17,255.255.192.0/18,255.255.224.0/19,255.255.240.0/20,255.255.248.0/21,255.255.252.0/22,255.255.254.0/23,255.255.255.0/24,255.255.255.128/25,255.255.255.192/26,255.255.255.224/27,255.255.255.240/28,255.255.255.248/29,255.255.255.252/30,255.255.255.254/31,255.255.255.255/32' |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'${CIDRV4}'' |cut -d'/' -f1)";
#[[ -n "$GATEV4" ]] && [[ -n "$MASKV4" ]] && [[ -n "$IPV4" ]] || {
# echo "\`ip command\` Failed to get gatev4,maskv4,ipv4 settings, will try using \`route command\`."
#[[ -z $IPV4 ]] && IPV4="$(ifconfig |grep 'Bcast' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1)";
#[[ -z $GATEV4 ]] && GATEV4="$(SelectMax 2)";
#[[ -z $MASKV4 ]] && MASKV4="$(SelectMax 3)";
#}
[[ -n "$DEFAULTNIC" ]] && IPSUBV6="$(ip -6 -brief address show scope global|grep ''${DEFAULTNIC}'' |awk -F ' ' '{ print $3}')";
IPV6="$(echo -n "$IPSUBV6" |cut -d'/' -f1)";
CIDRV6="$(echo -n "$IPSUBV6" |cut -d'/' -f2)";
GATEV6="$(ip -6 -brief route show default|grep ''${DEFAULTNIC}'' |awk -F ' ' '{ print $3}')";
# the subnetcalc deps didnt be called yet ?
[[ -n "$CIDRV6" ]] && MASKV6="$(prefixlen2subnetmask)"
# if not force ipv6 stack probe, try non-force auto ipv6/ipv4 stack probe methods,ipv4 always has priority over ipv6 by default
[[ "$FORCENETCFGV6ONLY" != '1' ]] && {
[[ -n "$GATEV4" && -n "$MASKV4" && -n "$IPV4" ]] && { IP=$IPV4;MASK=$MASKV4;GATE=$GATEV4;[[ -f /etc/resolv.conf.old ]] && cp -f /etc/resolv.conf.old /etc/resolv.conf; } || {
# if reach || here,there maybe no ipv4 stacks
[[ -n "$GATEV6" && -n "$MASKV6" && -n "$IPV6" ]] && { IP=$IPV6;MASK=$MASKV6;GATE=$GATEV6;[[ -f /etc/resolv.conf && ! -f /etc/resolv.conf.old ]] && { cp -f /etc/resolv.conf /etc/resolv.conf.old && > /etc/resolv.conf && echo -e 'nameserver 2001:67c:2b0::4\nnameserver 2001:67c:2b0::6' >/dev/null 2>&1 >> /etc/resolv.conf; } || { cp -f /etc/resolv.conf /etc/resolv.conf.bak && > /etc/resolv.conf && echo -e 'nameserver 2001:67c:2b0::4\nnameserver 2001:67c:2b0::6' >/dev/null 2>&1 >> /etc/resolv.conf; }; } # || exit 1;
# if reach && here,there may still be useful ipv6 stacks
}
# final give up both stack(there maybe no any ipstacks)
[[ -n "$GATE" && -n "$MASK" && -n "$IP" ]] || {
echo "Error! get netcfg auto ipv4/ipv6 stack settings failed. please speficty static netcfg settings";
exit 1;
}
}
}
# buildmode, set auto net hints
[[ "$FORCE1STNICNAME" == "" && "$setNet" == '1' && "$AutoNet" != '1' && "$AutoNet" != '2' ]] && echo -en "[ \033[32m force,static \033[0m ]" && echo -en "[ \033[32m $DEFAULTNIC:$FIP,$FMASK,$FGATE \033[0m ]"
[[ "$FORCE1STNICNAME" != "" && "$setNet" == '1' && "$AutoNet" != '1' && "$AutoNet" != '2' ]] && echo -en "[ \033[32m force,static \033[0m ]" && echo -en "[ \033[32m `[[ "$tmpBUILD" == '11' || "$tmpBUILD" == '1' ]] && echo $DEFAULTNIC:$FIP,$FMASK,$FGATE || echo $FORCE1STNICNAME:$FIP,$FMASK,$FGATE` \033[0m ]"
[[ "$setNet" != '1' && "$AutoNet" != '1' && "$AutoNet" == '2' ]] && echo -en "[ \033[32m auto,dhcp \033[0m ]" && echo -en "[ \033[32m $DEFAULTNIC:$IP,$MASK,$GATE \033[0m ]"
[[ "$setNet" != '1' && "$AutoNet" == '1' && "$AutoNet" != '2' ]] && echo -en "[ \033[32m auto,static \033[0m ]" && echo -en "[ \033[32m $DEFAULTNIC:$IP,$MASK,$GATE \033[0m ]"
}
parsediskcfg(){
#maybe we can force bootdir and efi bootorder here, just in the plan
[[ "$tmpBUILD" != "1" && "$tmpBUILD" != "11" ]] && [[ "$tmpTARGETMODE" != "1" ]] && [[ ! -d /boot ]] && echo -ne "Error! \nNo boot directory mounted.\n" && exit 1;
[[ "$tmpBUILD" != "1" && "$tmpBUILD" != "11" ]] && [[ "$tmpTARGETMODE" != "1" ]] && [[ -z `find /boot -name grub.cfg -o -name grub.conf` ]] && echo -ne "Error! \nNo grubcfg files in the boot directory.\n" && exit 1;
# try lookingfor the full working grub(file+dir+ver); simple case : only one grub gen(bios) and grub cfg
if [[ "$tmpBUILDGENE" != "2" ]] && [[ "$tmpBUILD" != "1" && "$tmpBUILD" != "11" ]] && [[ "$tmpTARGETMODE" != "1" ]]; then
WORKINGGRUB=`find /boot/grub* -maxdepth 1 -mindepth 1 -name grub.cfg -o -name grub.conf`
[[ -z "$GRUBDIR" ]] && [[ `echo $WORKINGGRUB|wc -l` == 1 ]] && GRUBTYPE='0' && GRUBDIR=${WORKINGGRUB%/*}/ && GRUBFILE=${WORKINGGRUB##*/}
fi
# try lookingfor the full working grub(file+dir+ver); complicated cases : one(efi) or two grub gen(bios and efi) coexists and one or two grub cfgs
if [[ "$tmpBUILDGENE" == "2" ]] && [[ "$tmpBUILD" != "1" && "$tmpBUILD" != "11" ]] && [[ "$tmpTARGETMODE" != "1" ]]; then
WORKINGGRUB=`find /boot -name grub.cfg -o -name grub.conf`
# we must use echo "$WORKINGGRUB" but not $WORKINGGRUB or lines will be ingored
[[ -z "$GRUBDIR" ]] && [[ `echo "$WORKINGGRUB"|wc -l` == 1 ]] && GRUBTYPE='1' && GRUBDIR=${WORKINGGRUB%/*}/ && GRUBFILE=${WORKINGGRUB##*/};
# we must use grep -vq && but not grep -q ||,or ...
# it seems that grep -vq are not portable(results may vary though under same stuation)
[[ -z "$GRUBDIR" ]] && [[ `echo "$WORKINGGRUB"|wc -l` == 2 ]] && GRUBTYPE='2' && echo "$WORKINGGRUB" | while read line; do cat $line | grep -Eo -q configfile || { GRUBDIR=${line%/*}/;GRUBFILE=${line##*/}; };done
fi
if [[ "$tmpBUILD" == "11" ]] && [[ "$tmpTARGETMODE" != "1" ]]; then
GRUBTYPE='11' && GRUBDIR=/cygdrive/c/grub2/ && GRUBFILE=grub.cfg
fi
if [[ "$tmpBUILD" == "1" ]] && [[ "$tmpTARGETMODE" != "1" ]]; then
GRUBTYPE='10' && GRUBDIR=$topdir/$remasteringdir/boot
fi
# if above both failed,force a brute way
[ -z "$GRUBDIR" -o -z "$GRUBFILE" ] && GRUBDIR='' && GRUBFILE='' && {
[[ -f '/boot/grub/grub.cfg' ]] && GRUBTYPE='0' && GRUBDIR='/boot/grub' && GRUBFILE='grub.cfg';
[[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub2/grub.cfg' ]] && GRUBTYPE='0' && GRUBDIR='/boot/grub2' && GRUBFILE='grub.cfg';
[[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub/grub.conf' ]] && GRUBTYPE='3' && GRUBDIR='/boot/grub' && GRUBFILE='grub.conf';
}
[[ "$tmpBUILD" != "1" ]] && {
# all failed,so we give up
[ -z "$GRUBDIR" -o -z "$GRUBFILE" ] && echo -ne "Error! \nNo working grub.\n" && exit 1;
[[ ! -f $GRUBDIR/$GRUBFILE ]] && echo "Error! No working grub file $GRUBFILE. " && exit 1;
[[ ! -f $GRUBDIR/$GRUBFILE.old ]] && [[ -f $GRUBDIR/$GRUBFILE.bak ]] && mv -f $GRUBDIR/$GRUBFILE.bak $GRUBDIR/$GRUBFILE.old;
mv -f $GRUBDIR/$GRUBFILE $GRUBDIR/$GRUBFILE.bak;
[[ -f $GRUBDIR/$GRUBFILE.old ]] && cat $GRUBDIR/$GRUBFILE.old >$GRUBDIR/$GRUBFILE || cat $GRUBDIR/$GRUBFILE.bak >$GRUBDIR/$GRUBFILE;
}
# the final boot dir will inst to
[[ "$tmpBUILD" != "1" && "$tmpBUILD" != "11" ]] && [[ "$tmpTARGETMODE" != "1" || "$tmpBUILDINSTTEST" == '1' ]] && insttotmp=`df -P "$GRUBDIR"/"$GRUBFILE" | grep /dev/`
[[ "$tmpBUILDGENE" != "2" ]] && [[ "$tmpBUILD" != "1" && "$tmpBUILD" != "11" ]] && [[ "$tmpTARGETMODE" != "1" || "$tmpBUILDINSTTEST" == '1' ]] && instto="/boot"
[[ "$tmpBUILDGENE" == "2" ]] && [[ "$GRUBTYPE" == "1" ]] && [[ "$tmpBUILD" != "1" && "$tmpBUILD" != "11" ]] && [[ "$tmpTARGETMODE" != "1" || "$tmpBUILDINSTTEST" == '1' ]] && [[ `find /boot/efi -name grub.cfg -o -name grub.conf|wc -l` == 1 ]] && instto=${insttotmp##*[[:space:]]}
[[ "$tmpBUILDGENE" == "2" ]] && [[ "$GRUBTYPE" == "1" ]] && [[ "$tmpBUILD" != "1" && "$tmpBUILD" != "11" ]] && [[ "$tmpTARGETMODE" != "1" || "$tmpBUILDINSTTEST" == '1' ]] && [[ `find /boot/efi -name grub.cfg -o -name grub.conf|wc -l` == 0 ]] && instto="/boot"
[[ "$tmpBUILDGENE" == "2" ]] && [[ "$GRUBTYPE" == "2" ]] && [[ "$tmpBUILD" != "1" && "$tmpBUILD" != "11" ]] && [[ "$tmpTARGETMODE" != "1" || "$tmpBUILDINSTTEST" == '1' ]] && instto="$GRUBDIR"
[[ "$tmpBUILD" == "11" || "$tmpBUILD" == "1" ]] && instto="$GRUBDIR"
# force anyway
[[ "$instto" == "" ]] && [[ "$tmpBUILD" != "1" && "$tmpBUILD" != "11" ]] && [[ "$tmpTARGETMODE" != "1" || "$tmpBUILDINSTTEST" == '1' ]] && instto="/boot"
[[ "$tmpBUILD" != "11" && "$tmpBUILD" != "1" ]] && {
[[ "$FORCE1STHDNAME" != '' ]] && {
defaulthd="$FORCE1STHDNAME";
defaulthdid=$(fdisk -l /dev/$defaulthd 2>/dev/null| grep 'Disk identifier' | awk '{print $NF}' | sed 's/0x//');
[[ "$tmpTARGETMODE" != "1" ]] && { [ -z "$defaulthdid" ] && echo -ne "Error! \nselected defaulthd has a invalid id.\n" && exit 1; }
echo -en "[ \033[32m force \033[0m ] [ \033[32m $defaulthd,$instto \033[0m ]";
} || {
mapper=$(df -P $instto | grep -Eo '/dev/[^ ]*')
# in case this is a raid ($instto accross much disk),we should add head -n1
defaulthd=$(lsblk -rn --inverse $mapper | grep -w disk | awk '{print $1}' | sort -u| head -n1)
defaulthdid=$(fdisk -l /dev/$defaulthd 2>/dev/null| grep 'Disk identifier' | awk '{print $NF}' | sed 's/0x//')
[[ "$tmpTARGETMODE" != "1" ]] && { [ -z "$instto" -o -z "$defaulthd" ] && echo -ne "Error! \nCant select defaulthd.\n" && exit 1; }
echo -en "[ \033[32m auto \033[0m ] [ \033[32m $defaulthd,$instto \033[0m ]";
}
} || echo -en "[ \033[32m non linux \033[0m ]"
}
preparepreseed(){
#never use
[[ -n "$custWORD" ]] && myPASSWORD="$(openssl passwd -1 "$custWORD")";
[[ -z "$myPASSWORD" ]] && myPASSWORD='$1$4BJZaD0A$y1QykUnJ6mXprENfwpseH0';
> $topdir/$remasteringdir/initramfs/preseed.cfg # $topdir/$remasteringdir/initramfs_arm64/preseed.cfg
tee -a $topdir/$remasteringdir/initramfs/preseed.cfg $topdir/$remasteringdir/initramfs_arm64/preseed.cfg > /dev/null <<EOF
# commonones:
# ----------
# Don't do the usual installation of everything we can find.
# $([[ "$tmpTARGET" != 'debian' ]] && echo d-i anna/standard_modules boolean false || echo \#d-i anna/standard_modules boolean false)
#pass the lowmem note,but still it may have problems
d-i debian-installer/language string en
d-i debian-installer/country string US
d-i debian-installer/locale string en_US.UTF-8
d-i lowmem/low note
# $([[ "$tmpINSTEMBEDVNC" != '1' ]] && echo d-i debian-installer/framebuffer boolean false) is not needed,we also mentioned and moved it to bootcode before
d-i debian-installer/framebuffer boolean false
d-i console-setup/layoutcode string us
d-i keyboard-configuration/xkb-keymap string us
d-i hw-detect/load_firmware boolean true
# d-i netcfg/choose_interface select $IFETH
d-i netcfg/disable_autoconfig boolean true
d-i netcfg/dhcp_failed note
d-i netcfg/dhcp_options select Configure network manually
# d-i netcfg/get_ipaddress string $custIPADDR
# d-i netcfg/get_ipaddress string $([[ "$setNet" == '1' && "$FORCENETCFGSTR" != '' ]] && echo "$FIP" || echo "$IP")
# d-i netcfg/get_netmask string $([[ "$setNet" == '1' && "$FORCENETCFGSTR" != '' ]] && echo "$FMASK" || echo "$MASK")
# d-i netcfg/get_gateway string $([[ "$setNet" == '1' && "$FORCENETCFGSTR" != '' ]] && echo "$FGATE" || echo "$GATE")
d-i netcfg/get_nameservers string 1.1.1.1 8.8.8.8 2001:67c:2b0::4 2001:67c:2b0::6
d-i netcfg/no_default_route boolean true
d-i netcfg/confirm_static boolean true
d-i mirror/country string manual
#d-i mirror/http/hostname string $IP
# d-i mirror/http/hostname string $DEBMIRROR
# d-i mirror/http/directory string /_build/debianbase
d-i mirror/http/proxy string
d-i debian-installer/allow_unauthenticated boolean true
d-i debian-installer/allow_unauthenticated_ssl boolean true
# debianones:
# ----------
d-i apt-setup/services-select multiselect
d-i passwd/root-login boolean ture
d-i passwd/make-user boolean false
d-i passwd/root-password-crypted password $([[ "$FORCEPASSWORD" != '' && "$FORCEPASSWORD" != '0' ]] && echo $(openssl passwd -1 "$FORCEPASSWORD") || echo $(openssl passwd -1 "inst.sh"))
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
d-i clock-setup/utc boolean true
d-i time/zone string US/Eastern
d-i clock-setup/ntp boolean true
d-i partman-auto/method string lvm
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/choose_label string gpt
d-i partman-partitioning/default_label string gpt
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-auto-lvm/new_vg_name string cl
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i base-installer/kernel/image string linux-image-5.10.0-22-$([[ "$tmpHOSTARCH" != '1' ]] && echo amd || echo arm)64
tasksel tasksel/first multiselect minimal
d-i pkgsel/update-policy select none
d-i pkgsel/include string openssh-server
d-i pkgsel/upgrade select none
popularity-contest popularity-contest/participate boolean false
d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string default
d-i grub-installer/force-efi-extra-removable boolean true
d-i finish-install/reboot_in_progress note
d-i debian-installer/exit/reboot boolean true
EOF
[[ "$tmpTARGETMODE" == '4' ]] && {
#dont use onthefly
#ONTHEFLYPIPECMDSTR='wget -qO- --no-check-certificate '$TARGETDDURL' | dd of=$(list-devices disk |head -n1) bs=10M status=progress';
# we must pre calc below before inplace dd
DEFAULTHD=`lsblk -e 7 -e 11 -d | tail -n+2 | cut -d" " -f1 |head -n 1`
}
[[ "$tmpBUILD" != "11" && "$tmpBUILD" != "1" ]] && { [[ "$(find /sys/class/net/ -type l ! -lname '*/devices/virtual/net/*' | wc -l)" -lt 2 ]] && echo -en "[ \033[32m single nic: use $DEFAULTNIC \033[0m ]" || echo -en "[ \033[32m multiple eth: use $DEFAULTNIC \033[0m ]"; } || echo -en "[ \033[32m non linux: use $DEFAULTNIC \033[0m ]"
[[ "$tmpBUILD" != "11" && "$tmpBUILD" != "1" ]] && { [[ "$(lsblk -e 7 -e 11 -d | tail -n+2 | wc -l)" -lt 2 ]] && echo -en "[ \033[32m single hd: use $defaulthd \033[0m ]" || echo -en "[ \033[32m multiple hd: use $defaulthd \033[0m ]"; } || echo -en "[ \033[32m non linux: use sysvol \033[0m ]"
#if multiple hd force 1sthdname where /boot is
#if multiple eth force 1stethname where ip is
}
patchpreseed(){
# in debian installer, some machine dhcp mode are not clever enough, so just leave it force, force, force
# [[ "$AutoNet" == '2' ]] && {
# [[ "$tmpBUILD" != "1" ]] && sed -e '/netcfg\/disable_autoconfig/d' -e '/netcfg\/dhcp_options/d' -e '/netcfg\/get_nameserver/ !{/netcfg\/get_.*/d}' -e '/netcfg\/confirm_static/d' -i $topdir/$remasteringdir/initramfs/preseed.cfg || sed -e '/netcfg\/disable_autoconfig/d' -e '/netcfg\/dhcp_options/d' -e '/netcfg\/get_nameserver/ !{/netcfg\/get_.*/d}' -e '/netcfg\/confirm_static/d' -i "" $topdir/$remasteringdir/initramfs/preseed.cfg
# [[ "$tmpBUILD" != "1" ]] && sed -e '/netcfg\/disable_autoconfig/d' -e '/netcfg\/dhcp_options/d' -e '/netcfg\/get_nameserver/ !{/netcfg\/get_.*/d}' -e '/netcfg\/confirm_static/d' -i $topdir/$remasteringdir/initramfs_arm64/preseed.cfg || sed -e '/netcfg\/disable_autoconfig/d' -e '/netcfg\/dhcp_options/d' -e '/netcfg\/get_nameserver/ !{/netcfg\/get_.*/d}' -e '/netcfg\/confirm_static/d' -i "" $topdir/$remasteringdir/initramfs_arm64/preseed.cfg
# }
#[[ "$GRUBPATCH" == '1' ]] && {
# sed -i 's/^d-i\ grub-installer\/bootdev\ string\ default//g' $topdir/$remasteringdir/initramfs/preseed.cfg
#}
#[[ "$GRUBPATCH" == '0' ]] && {
# sed -i 's/debconf-set\ grub-installer\/bootdev.*\"\;//g' $topdir/$remasteringdir/initramfs/preseed.cfg
#}
# vncserver need this?
#[[ "$GRUBPATCH" == '0' ]] && {
# sed -i 's/debconf-set\ grub-installer\/bootdev.*\"\;//g' /tmp/boot/preseed.cfg
#}
[[ "$tmpBUILD" != "1" ]] && sed -e '/user-setup\/allow-password-weak/d' -e '/user-setup\/encrypt-home/d' -i $topdir/$remasteringdir/initramfs/preseed.cfg || sed -e '/user-setup\/allow-password-weak/d' -e '/user-setup\/encrypt-home/d' -i "" $topdir/$remasteringdir/initramfs/preseed.cfg
[[ "$tmpBUILD" != "1" ]] && sed -e '/user-setup\/allow-password-weak/d' -e '/user-setup\/encrypt-home/d' -i $topdir/$remasteringdir/initramfs_arm64/preseed.cfg || sed -e '/user-setup\/allow-password-weak/d' -e '/user-setup\/encrypt-home/d' -i "" $topdir/$remasteringdir/initramfs_arm64/preseed.cfg
#sed -i '/pkgsel\/update-policy/d' $topdir/$remasteringdir/initramfs/preseed.cfg
#sed -i 's/umount\ \/media.*true\;\ //g' $topdir/$remasteringdir/initramfs/preseed.cfg
}
download_file() {
local url="$1"
local file="$2"
# 3,4 optional
local seg="$3"
local code="$4"
local retry=0
local quiet=0
verify_file() {
if [ -s "$file" ]; then
if [ -n "$code" ]; then ( echo "${code} ${file}" | md5sum -c --quiet );return $?;fi
if [ -z "$code" ]; then :;return 0;fi
fi
return 1
}
download_file_to_path() {
if verify_file; then
return 0
#else
# echo -en "[ \033[31m `basename $url`, verify failed!! \033[0m ]"
# exit 1
fi
if [ $retry -ge 3 ]; then
rm -f "$file"
echo -en "[ \033[31m `basename $url`,failed!! \033[0m ]"
exit 1
fi
[[ -n "$seg" ]] && {
if [ "$tmpBUILD" != "1" ]; then
( (for i in `seq -w 000 $seg`;do wget -qO- --no-check-certificate $url"_"$i; done) > $file )
else
( (for i in `seq -f '%03.0f' 000 $seg`;do wget -qO- --no-check-certificate $url"_"$i; done) > $file )
fi
}
if [ -z "$seg" ]; then ( wget -qO- --no-check-certificate $url ) > $file;quiet='1';fi
if [ "$?" != "0" ] && ! verify_file; then
retry=$(expr $retry + 1)
download_file_to_path
else
[[ "$quiet" != '1' ]] && echo -en "[ \033[32m `basename $url`,ok!! \033[0m ]"
fi
}
download_file_to_path
}
function getbasics(){
compositemode="$1"
instcheck=$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n binary-arm64 || echo -n binary-amd64)/instcheck.dat
installmodechoosevmlinuz=$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n binary-arm64 || echo -n binary-amd64)/tarball/vmlinuz$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n _arm64)
installmodechoosevmlinuz2=vmlinuz$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n _arm64)
installmodechoosevmlinuzcode=`wget --no-check-certificate -qO- "$DEBMIRROR"/_build/onekeydevdesk/"$instcheck"|grep "$installmodechoosevmlinuz2":|awk -F ':' '{ print $2}'`
installmodechoosetdlcore=$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n binary-arm64 || echo -n binary-amd64)/tarball/initrfs$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n _arm64).img
installmodechoosetdlcore2=initrfs$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n _arm64).img
installmodechoosetdlcorecode=`wget --no-check-certificate -qO- "$DEBMIRROR"/_build/onekeydevdesk/"$instcheck"|grep "$installmodechoosetdlcore2":|awk -F ':' '{ print $2}'`
# when down was used,only targetmode 0 occurs
[[ "$1" == 'down' && ( "$tmpTARGETMODE" != '4' || "$tmpTARGETMODE" != '1' ) ]] && {
[[ ! -f $topdir/$downdir/onekeydevdesk/$installmodechoosevmlinuz2 || ! -s $topdir/$downdir/onekeydevdesk/$installmodechoosevmlinuz2 ]] && download_file $DEBMIRROR/_build/onekeydevdesk/$installmodechoosevmlinuz $topdir/$downdir/onekeydevdesk/$installmodechoosevmlinuz2 030 $installmodechoosevmlinuzcode
[[ ! -f $topdir/$downdir/onekeydevdesk/$installmodechoosetdlcore2 || ! -s $topdir/$downdir/onekeydevdesk/$installmodechoosetdlcore2 ]] && download_file $DEBMIRROR/_build/onekeydevdesk/$installmodechoosetdlcore $topdir/$downdir/onekeydevdesk/$installmodechoosetdlcore2 060 $installmodechoosetdlcorecode
}
[[ "$1" == 'down' && "$tmpTARGETMODE" == '4' && "$tmpTARGET" == 'debianct' ]] && { [[ ! -f $topdir/$downdir/x.xz || ! -s $topdir/$downdir/x.xz ]] && download_file $TARGETDDURL $topdir/$downdir/x.xz 099; }
[[ "$1" == 'down' && "$tmpTARGETMODE" == '4' && "$tmpTARGET" == 'debianctmu' ]] && { [[ ! -f $topdir/$downdir/x.xz || ! -s $topdir/$downdir/x.xz ]] && download_file $TARGETDDURL"/onekeydevdeskd-01core$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo _arm64).xz" $topdir/$downdir/x.xz 999; }
[[ "$1" == 'down' && "$tmpTARGETMODE" == '4' && "$tmpTARGET" == 'debiandemu' ]] && {
[[ ! -f $topdir/$downdir/x.xz || ! -s $topdir/$downdir/x.xz ]] && download_file $TARGETDDURL"/onekeydevdeskd-01core$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo _arm64).xz" $topdir/$downdir/x.xz 999
[[ ! -f $topdir/$downdir/vmlinuz || ! -s $topdir/$downdir/vmlinuz ]] && download_file $TARGETDDURL"/vmlinuz$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo _arm64)" $topdir/$downdir/vmlinuz 029
[[ ! -f $topdir/$downdir/initrfs.img || ! -s $topdir/$downdir/initrfs.img ]] && download_file $TARGETDDURL"/initrfs$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo _arm64).img" $topdir/$downdir/initrfs.img 049
}
}
function processbasics(){
if [[ "$tmpTARGETMODE" != '0' && "$tmpTARGETMODE" != '1' && "$tmpTARGETMODE" != '2' && "$tmpTARGETMODE" != '4' ]]; then
#cd $topdir/$remasteringdir/initramfs/files;
#CWD="$(pwd)"
#echo -en "[ \033[32m cd to ${CWD##*/} \033[0m ]"
#echo -en " - busy unpacking initrfs.img ..."
[[ "$tmpBUILD" != "1" ]] && tar Jxf $topdir/$downdir/onekeydevdesk/initrfs$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n _arm64).img --warning=no-timestamp -C $topdir/$remasteringdir/initramfs/files || tar Jxf $topdir/$downdir/onekeydevdesk/initrfs$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n _arm64).img -C $topdir/$remasteringdir/initramfs/files
[[ "$?" != "0" ]] && exit 1
fi
if [[ "$tmpTARGETMODE" == '4' && "$tmpTARGET" == 'debianct' ]]; then
#echo -en " - busy unpacking x.xz ..."
(cd $topdir/$remasteringdir;tar Jxf $topdir/$downdir/x.xz --warning=no-timestamp;[[ "$?" != "0" ]] && exit 1);
fi
if [[ "$tmpTARGETMODE" == '4' && "$tmpTARGET" == 'debianctmu' ]]; then
(mkdir -p /x;cd /x;tar Jxf $topdir/$downdir/x.xz --warning=no-timestamp --strip-components=1 01-core --exclude=01-core/dev/*;[[ "$?" != "0" ]] && exit 1);
fi
#cp -aR $topdir/$downdir/onekeydevdesk/debian-live ./lib >>/dev/null 2>&1
#chmod +x ./lib/debian-live/*
#cp -aR $topdir/$downdir/onekeydevdesk/updates ./lib/modules/5.10.0-22-amd64 >>/dev/null 2>&1
}
processgrub(){
[[ "$tmpTARGETMODE" == '0' && "$tmpTARGET" == 'debian' ]] && { # tee -a $topdir/$remasteringdir/initramfs/preseed.cfg $topdir/$remasteringdir/initramfs_arm64/preseed.cfg > /dev/null <<EOF
# we mixed the efi and bios togeth in 30atomic
# must not place anna-install network-console here in preseed/early_command but instead in partman/early_command
dipreseedearlycommandstring="$([[ "$tmpINSTWITHMANUAL" == '1' ]] && echo "screen -dmS reboot /sbin/reboot -d 300" )"
dipartmanearlycommandstring="$([[ "$tmpINSTWITHMANUAL" == '1' ]] && echo "/usr/lib/rescue-patchs/forcelost.sh;/usr/lib/rescue-patchs/startssh.sh;" )anna net-retriever default;/usr/lib/debianinstall-patchs/preinstall.sh "$TARGETDDURL" $([[ "$tmpBUILD" != "11" && "$tmpBUILD" != "1" ]] && echo "$defaulthdid" || echo "nonlinux" )"
# sometimes https were auto-transed to http, we should adjust it backed
dipreseedlatecommandstring="/usr/lib/debianinstall-patchs/postinstall.sh $DEBMIRROR"
} #EOF
# both inst and buildmode share PIPECMSTR defines but without forcenetcfgstr and force github mirror for buildmode
# we use both ext2/fat16 duplicated parts cause some machine only regnoice ext2(the ones boot with its own grub instead of on disk grubs)but not fat16
[[ "$tmpTARGET" == devdeskos* ]] && {
choosevmlinuz=$TARGETDDURL/vmlinuz$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n _arm64)
chooseinitrfs=$TARGETDDURL/initrfs$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n _arm64).img
chooseonekeydevdeskd1=$TARGETDDURL/onekeydevdeskd-01core$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n _arm64).xz
chooseonekeydevdeskd2=$TARGETDDURL/onekeydevdeskd-02gui$([ "$tmpHOSTARCH" == '1' -a "$tmpHOSTARCH" != '' ] && echo -n _arm64).xz
}
# we meant to use live-installer but it is too complicated so we turn to parted
# there is only grub-efi on arm64,shall we separate preseed?
# we must put force1sthdname before forcenetcfgstr,because argpositiion 1,2,3,4 is always there(fixedly appear) but 5 not(if not forced,it dont occpy a pos),we pust fixed ones piorr in front
[[ "$tmpTARGETMODE" == '0' && "$tmpTARGET" == devdeskos* ]] && { # tee -a $topdir/$remasteringdir/initramfs/preseed.cfg $topdir/$remasteringdir/initramfs_arm64/preseed.cfg > /dev/null <<EOF
# must not place anna-install network-console here in preseed/early_command but instead in partman/early_command
# in debian installer, some machine dhcp mode are not clever enough, so just force autonet 1 and 2 both static
dipreseedearlycommandstring="$([[ "$tmpINSTWITHMANUAL" == '1' ]] && echo "screen -dmS reboot /sbin/reboot -d 300" )"
dipartmanearlycommandstring="$([[ "$tmpINSTWITHMANUAL" == '1' ]] && echo "/usr/lib/rescue-patchs/forcelost.sh;/usr/lib/rescue-patchs/startssh.sh;" )/usr/lib/liveinstall-patchs/longrunpipebgcmd_redirectermoniter.sh "$choosevmlinuz,$chooseinitrfs,$chooseonekeydevdeskd1,$chooseonekeydevdeskd2" $([[ "$tmpBUILD" != "11" && "$tmpBUILD" != "1" ]] && echo "$defaulthdid" || echo "nonlinux" ) $([[ "$FORCE1STNICNAME" != '' ]] && echo "$IFETHMAC" || echo "\"\$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.*' |head -n1 |sed 's/proto.*\|onlink.*//g' |awk '{print \$NF}')\"") $([[ "$FORCEPASSWORD" != '' ]] && echo "$FORCEPASSWORD") $([ "$setNet" == '1' -a "$FORCENETCFGSTR" != '' ] && echo "$FIP,$FMASK,$FGATE";[ "$AutoNet" == '1' -o "$AutoNet" == '2' ] && [ "$IP" != '' -a "$MASK" != '' -a "$GATE" != '' ] && echo "$IP","$MASK","$GATE")"
} #EOF
# azure hd need bs=10M or it will fail
[[ "$tmpTARGET" != 'debian10r' ]] && [[ "$UNZIP" == '0' ]] && PIPECMDSTR='wget -qO- --no-check-certificate '$TARGETDDURL' |stdbuf -oL dd of=$(list-devices disk |head -n1) bs=10M 2> /var/log/progress & pid=`expr $! + 0`;echo $pid';
[[ "$tmpTARGET" == 'debian10r' ]] && [[ "$UNZIP" == '2' ]] && [[ "$tmpBUILD" != "11" && "$tmpBUILD" != "1" ]] && PIPECMDSTR='(for i in `seq -w 000 699`;do wget -qO- --no-check-certificate '$TARGETDDURL'_$i; done) |tar JOx |stdbuf -oL dd of='$defaulthdid' bs=10M 2> /var/log/progress & pid=`expr $! + 0`;echo $pid' || PIPECMDSTR='(for i in `seq -w 000 699`;do wget -qO- --no-check-certificate '$TARGETDDURL'_$i; done) |tar JOx |stdbuf -oL dd of=nonlinux bs=10M 2> /var/log/progress & pid=`expr $! + 0`;echo $pid';
# we must put force1sthdname before forcenetcfgstr,because argpositiion 1,2,3,4,5 is always there(fixedly appear) but 6 not(if not forced,it dont occpy a pos),we pust fixed ones piorr in front
[[ "$tmpTARGETMODE" == '0' ]] && [[ "$tmpTARGET" != 'debian' && "$tmpTARGET" != devdeskos* && "$tmpTARGET" != dummy ]] && { # tee -a $topdir/$remasteringdir/initramfs/preseed.cfg $topdir/$remasteringdir/initramfs_arm64/preseed.cfg > /dev/null <<EOF
# anna-install wget-udeb here?
# must not place anna-install network-console here in preseed/early_command but instead in partman/early_command
# in debian installer, some machine dhcp mode are not clever enough, so just force autonet 1 and 2 both static
dipreseedearlycommandstring="$([[ "$tmpINSTWITHMANUAL" == '1' ]] && echo "screen -dmS reboot /sbin/reboot -d 300" )"
dipartmanearlycommandstring="$([[ "$tmpINSTWITHMANUAL" == '1' ]] && echo "/usr/lib/rescue-patchs/forcelost.sh;/usr/lib/rescue-patchs/startssh.sh;" )/usr/lib/ddinstall-patchs/longrunpipebgcmd_redirectermoniter.sh "$TARGETDDURL,$UNZIP" $([[ "$tmpBUILD" != "11" && "$tmpBUILD" != "1" ]] && echo "$defaulthdid" || echo "nonlinux" ) $([[ "$FORCE1STNICNAME" != '' ]] && echo "$IFETHMAC" || echo "\"\$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.*' |head -n1 |sed 's/proto.*\|onlink.*//g' |awk '{print \$NF}')\"") $([[ "$FORCEINSTCTL" != '' ]] && echo "$FORCEINSTCTL") $([[ "$FORCEPASSWORD" != '' ]] && echo "$FORCEPASSWORD") $([ "$setNet" == '1' -a "$FORCENETCFGSTR" != '' ] && echo "$FIP,$FMASK,$FGATE";[ "$AutoNet" == '1' -o "$AutoNet" == '2' ] && [ "$IP" != '' -a "$MASK" != '' -a "$GATE" != '' ] && echo "$IP","$MASK","$GATE")"
} #EOF
[[ "$tmpTARGETMODE" == '2' ]] && [[ "${tmpTARGET:0:11}" == '10000:/dev/' ]] && { # tee -a $topdir/$remasteringdir/initramfs/preseed.cfg $topdir/$remasteringdir/initramfs_arm64/preseed.cfg > /dev/null <<EOF
dipreseedearlycommandstring="$([[ "$tmpINSTWITHMANUAL" == '1' ]] && echo "screen -dmS reboot /sbin/reboot -d 300" )"
dipartmanearlycommandstring="$([[ "$tmpINSTWITHMANUAL" == '1' ]] && echo "/usr/lib/rescue-patchs/forcelost.sh;/usr/lib/rescue-patchs/startssh.sh;" )/usr/lib/ncrestore-patchs/longrunpipebgcmd_redirectermoniter.sh "$tmpTARGET""
} #EOF
# important for submenu in typing dummy
[[ "$tmpTARGETMODE" == '0' && "$tmpTARGET" == 'dummy' ]] && { # tee -a $topdir/$remasteringdir/initramfs/preseed.cfg $topdir/$remasteringdir/initramfs_arm64/preseed.cfg > /dev/null <<EOF
#debian d-i has a bug cuasing bgcmd not running,so we use screen
# must not place anna-install network-console here in preseed/early_command but instead in partman/early_command
dipreseedearlycommandstring="$([[ "$tmpINSTWITHMANUAL" == '1' ]] && echo "screen -dmS reboot /sbin/reboot -d 300" )"
dipartmanearlycommandstring="$([[ "$tmpINSTWITHMANUAL" == '1' ]] && echo "/usr/lib/rescue-patchs/forcelost.sh;" )/usr/lib/rescue-patchs/startssh.sh;UDPKG_QUIET=1 exec udpkg --configure --force-configure di-utils-shell"
} #EOF
[[ "$GRUBTYPE" != '3' && "$GRUBTYPE" != '10' ]] && {
READGRUB=''$remasteringdir'/boot/grub.read'
# -a is important to avoid grep error of binary file matching and initrdfail for ubuntu fix
# under win need escape cf, dont need grep \ and initrdfail
[[ "$GRUBTYPE" == '11' ]] && cat $GRUBDIR/$GRUBFILE |sed 's/\r//g' |sed -n '1h;1!H;$g;s/\n/%%%%%%%/g;$p' |grep -a -om 1 'menuentry [^{]*{[^}]*}%%%%%%%' |sed 's/%%%%%%%/\n/g' >$READGRUB || cat $GRUBDIR/$GRUBFILE |sed -e 's/"\${initrdfail}"/\$initrdfail/g' |sed -n '1h;1!H;$g;s/\n/%%%%%%%/g;$p' |grep -a -om 1 'menuentry\ [^{]*{[^}]*}%%%%%%%' |sed 's/%%%%%%%/\n/g' >$READGRUB
LoadNum="$(cat $READGRUB |grep -c 'menuentry ')"
if [[ "$LoadNum" -eq '1' ]]; then
cat $READGRUB |sed '/^$/d' >$remasteringdir/boot/grub.new;
elif [[ "$LoadNum" -gt '1' ]]; then
CFG0="$(awk '/menuentry /{print NR}' $READGRUB|head -n 1)";
CFG2="$(awk '/menuentry /{print NR}' $READGRUB|head -n 2 |tail -n 1)";
CFG1="";
for tmpCFG in `awk '/}/{print NR}' $READGRUB`
do
[ "$tmpCFG" -gt "$CFG0" -a "$tmpCFG" -lt "$CFG2" ] && CFG1="$tmpCFG";
done
[[ -z "$CFG1" ]] && {