-
Notifications
You must be signed in to change notification settings - Fork 0
/
diweb.sh
executable file
·1275 lines (987 loc) · 64.4 KB
/
diweb.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
## GPL,Written By MoeClub.org and linux-live.org,moded and enhanced by minlearn (https://gitee.com/minlearn/wes7x86cnlite/) for 1, wes7x86cnlite remastering and installing (both local install and cloud dd) as its recovery 2, and for self-contained git mirror/image hosting (both debian and system img) 3, and for hyperv/baremetal machine model supports.
## meant to work/tested under debian family linux with bash > 4, ubuntu less than 20.04
## usage: ci.sh [[-b 0 ] -h 0] -t wes7x86cnlite|debianbase
## usage: diweb.sh -t wes7x86cnlite|deepin20|win10ltsc|winsrv2019|wes7x86cnlite61715284|osx10146
# =================================================================
# globals
# =================================================================
# mirror settings(deb and targetddurl)
export custDEBMIRROR1='https://github.com/virocean/wes7x86cnlite/raw/master'
export custIMGMIRROR1='https://github.com/virocean/wes7x86cnlite/raw/master'
#export custDEBMIRROR1='https://gitee.com/virocean/wes7x86cnlite/raw/master'
#export custIMGMIRROR1='https://gitee.com/virocean/wes7x86cnlite/raw/master'
# apply a fixed mirror/targetddurl selection to force override autoselectdebmirror results based on -t -m args given
# for fix target ddurl,just -t url
export FORCEMIRROR=''
# BUILD/HOST/TARGET tripe,most usually are auto informed
export tmpBUILD='0' #0:linux,1:unix,osx,2,lxc
export tmpBUILDGENE='0' #0:legcay mbr;1:uefi
export tmpBUILDREUSEPBIFS='0' #use prebuilt initrfs.img in tmpbuild,0 dont use,1,use initrfs1.img,2,use initrfs2.img,auto informed
export tmpBUILDPUTPVEINIFS='0' # put pve building prodcure inside initramfs?
export tmpBUILDCI='0' #full ci/cd mode,with git and split post addon actions,auto informed
export tmpHOST='0' #0:cloud host;1:bearmetal
export tmpHOSTMODEL='' #0,kvm guest,1,pd guest,2,hv guest,3,mpb,auto informed,not customable
export tmpTARGET='' #debianbase(none),wes7x86cnlite,winsrvcore2019,deepin20,wes7x86cnlite61715284,osx10146
export tmpTARGETMODE='0' #0:CLOUDDDINSTALL ONLY MODE? 1:CLOUDDDINSTALL+BUILD FULL MODE? defaultly it sholudbe 0
export tmpTARGETINSTANTWITHOUTVNC='0' #simple ci/cd mode,no interactive
# customables,autoanswers for ci/cd
export custWORD=''
export custIPADDR=''
export custIPMASK=''
export custIPGATE=''
export custIMGSIZE='20'
export custUSRANDPASS='tdl'
export tmpTGTNICNAME='eth0'
# 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 tmpTGTNICIP='111.111.111.111'
#input target wifi connecting settings(in valid hotspotname,hotspotpasswd,wifinicname form,passwd 8-63 long,enter to leave blank)
export tmpWIFICONNECT='CMCC-Lsl,11111111,wlan0'
# input target ip or domain that will be embeded into client
export tmpEBDCLIENTURL='t.shalol.com'
export GENCLIENTS='y'
export GENCLIENTSWINOSX='n'
export PACKCLIENTS='n'
export GENCONTAINERS='2' # 0:owt+anbox+dpi,1:owt+winebox+dpi,2:all 0,1
export PACKAPPPS='n'
# dir settings
downdir='_build'
remasteringdir='_tmpremastering'
targetdir='_tmptarget'
export PATH=.:./tools:../tools:/usr/sbin:/usr/bin:/sbin:/bin:/
topdir=$(dirname $(readlink -f $0))
cd $topdir
CWD="$(pwd)"
echo "Changing current directory to $CWD"
[[ "$EUID" -ne '0' ]] && echo "Error:This script must be run as root!" && exit 1
[[ ! "$(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)" == "Darwin" ]] && tmpBUILD='1' && read -s -n1 -p "osx detected"
while [[ $# -ge 1 ]]; do
case $1 in
-m|--forcemirror)
shift
FORCEMIRROR="$1"
[[ -n "$FORCEMIRROR" ]] && echo "mirror forced to some value,will override autoselectdebmirror results"
shift
;;
-b|--build)
shift
tmpBUILD="$1"
[[ "$tmpBUILD" == '2' ]] && echo "lxc given,will auto inform tmpBUILDCI and tmpBUILDREUSEPBIFS as 1,this is not by customs" && tmpBUILDCI='1' && tmpBUILDREUSEPBIFS='1' && tmpTARGETMODE='1' && echo -en "\n" && [[ -z "$tmpBUILDCI" ]] && echo "buildci were empty" && exit 1
[[ "$tmpBUILD" != '2' ]] && tmpBUILDCI='0' && tmpBUILDREUSEPBIFS='0' && tmpTARGETMODE='1'
shift
;;
-uefi)
shift
tmpBUILDGENE="$1"
[[ "$tmpBUILDGENE" == '1' ]] && echo "uefi forced,will process efi booting"
shift
;;
-h|--host)
shift
tmpHOST="$1"
[[ "$tmpHOST" == '1' ]] && echo "baremetal host args given,will use mbp hostmodel and set TARGETMODE as 1,this is auto informed not by customs" && tmpHOSTMODEL='mbp' && tmpTARGETMODE='1' && echo -en "\n" && [[ -z "$tmpHOSTMODEL" ]] && echo "hostmodel were empty" && exit 1
[[ "$tmpHOST" == '0' ]] && tmpTARGETMODE='1'
[[ "$tmpHOST" == '2' ]] && tmpHOSTMODEL='hv'
shift
;;
-t|--target)
shift
tmpTARGET="$1"
case $tmpTARGET in
debianbase) tmpTARGETMODE='1' ;;
wes7x86cnlite)
[[ "$tmpTARGETMODE" != '1' ]] && echo "instonly mode detected"
[[ "$tmpTARGETMODE" == '1' ]] && echo "fullgen mode detected"
[[ "$tmpHOST" != '2' && "$tmpTARGET" == 'wes7x86cnlite' ]] && tmpTARGETMODEL=1 || tmpTARGETMODEL='0' ;;
deepin20|win10ltsc|winsrv2019|wes7x86cnlite61715284|osx10146) tmpTARGETMODE='0' ;;
*) echo "$tmpTARGET" |grep -q '^http://\|^ftp://\|^https://';[[ $? -ne '0' ]] && echo "targetname not known" && exit 1 || echo "raw urls detected,will override autotargetddurl results" ;;
esac
shift
;;
*)
if [[ "$1" != 'error' ]]; then echo -ne "\nInvaild option: '$1'\n\n"; fi
echo -ne " Usage(args are self explained):\n\tbash $(basename $0)\t-m/--forcemirror\n\t\t\t\t-b/--build\n\t\t\t\t--uefi\n\t\t\t\t-h/--host\n\t\t\t\t-t/--target\n\t\t\t\t\n"
exit 1;
;;
esac
done
#clear
# =================================================================
# Below are function libs
# =================================================================
function CheckDependence(){
FullDependence='0';
lostdeplist="";
for BIN_DEP in `[[ "$tmpBUILDFORM" -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 `[[ "$tmpBUILDFORM" -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
echo -en "[ \033[32m $BIN_DEP";
if [ "$Founded" == '0' ]; then
echo -en ",ok \033[0m] ";
else
FullDependence='1';
echo -en ",\033[31m not ok \033[0m] ";
lostdeplist+="$BIN_DEP"
fi
fi
done
[[ "$tmpBUILDGENE" != '1' && "$tmpTARGET" == 'wes7x86cnlite' && "$tmpTARGETMODE" == '1' ]] && [[ ! -f /usr/lib/grub/x86_64-efi/acpi.mod ]] && echo -en "[ \033[32m grub-efi,\033[31m not ok \033[0m] " && FullDependence='1' && lostdeplist+="grub-efi"
[[ "$tmpBUILDGENE" == '1' ]] && [[ ! -f /usr/lib/grub/x86_64-efi/acpi.mod ]] && echo -en "[ \033[32m grub-efi,\033[31m not ok \033[0m] " && FullDependence='1' && lostdeplist+="grub-efi"
if [ "$FullDependence" == '1' ]; then
echo -ne "\n \033[31m Error! \033[0m Please use '\033[33m apt-get \033[0m' to install it.\n"
[[ $lostdeplist =~ "ar" ]] && echo "please apt-get install binutils in debian"
[[ $lostdeplist =~ "xzcat" ]] && echo "please apt-get install xzcat in debian"
[[ $lostdeplist =~ "md5sum" || $lostdeplist =~ "sha1sum" || $lostdeplist =~ "sha256sum" ]] && echo "please apt-get install coreutils in debian"
[[ $lostdeplist =~ "losetup" ]] && echo "please apt-get install util-linux in debian"
[[ $lostdeplist =~ "parted" ]] && echo "please apt-get install parted in debian"
[[ $lostdeplist =~ "mkfs.vfat" ]] && echo "please apt-get install dosfstools in debian"
[[ $lostdeplist =~ "squashfs" ]] && echo "please apt-get install squashfs-tools in debian"
[[ $lostdeplist =~ "sqlite3" ]] && echo "please apt-get install sqlite3 in debian"
[[ $lostdeplist =~ "unzip" ]] && echo "please apt-get install unzip in debian"
[[ $lostdeplist =~ "zip" ]] && echo "please apt-get install zip in debian"
[[ $lostdeplist =~ "grub-mkimage" ]] && echo "please apt-get install grub2 in debian"
[[ $lostdeplist =~ "grub-efi" ]] && echo "please apt-get install grub-efi in debian"
[[ $lostdeplist =~ "7z" ]] && echo "please apt-get install p7zip in debian"
exit 1;
fi
}
function SelectDEBMirror(){
[ $# -ge 1 ] || exit 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');
SpeedLog0=''
SpeedLog1=''
SpeedLog2=''
for mirror in `[[ "$tmpBUILDFORM" -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
# CheckPass1='0';
# DistsList="$(wget --no-check-certificate -qO- "$CurMirror/dists/" |grep -o 'href=.*/"' |cut -d'"' -f2 |sed '/-\|old\|Debian\|experimental\|stable\|test\|sid\|devel/d' |grep '^[^/]' |sed -n '1h;1!H;$g;s/\n//g;s/\//\;/g;$p')";
# for DIST in `echo "$DistsList" |sed 's/;/\n/g'`
# do
# [[ "$DIST" == "buster" ]] && CheckPass1='1' && break;
# done
# [[ "$CheckPass1" == '0' ]] && {
# echo -ne '\nbuster not find in $CurMirror/dists/, Please check it! \n\n'
# bash $0 error;
# exit 1;
# }
# CheckPass2=0
# ImageFile="SUB_MIRROR/releases/linux"
# [ -n "$ImageFile" ] || exit 1
# URL=`echo "$ImageFile" |sed "s#SUB_MIRROR#${CurMirror}#g"`
# wget --no-check-certificate --spider --timeout=3 -o /dev/null "$URL"
# [ $? -eq 0 ] && CheckPass2=1 && echo "$CurMirror" && break
# done
CurrentMirrorSpeed=$(curl --connect-timeout 10 -m 10 -Lo /dev/null -skLw "%{speed_download}" $CurMirror/debianbase/1mtest) && CurrentMirrorSpeed=${CurrentMirrorSpeed/.*}
[ "$mirror" == "Debian0" ] && SpeedLog0="$CurrentMirrorSpeed"
[ "$mirror" == "Debian1" ] && SpeedLog1="$CurrentMirrorSpeed"
[ "$mirror" == "Debian2" ] && SpeedLog2="$CurrentMirrorSpeed"
done
[[ "$SpeedLog0" != "0.000" && "$SpeedLog0" -gt "$SpeedLog1" && "$SpeedLog0" -gt "$SpeedLog2" ]] && echo "${MirrorTocheck[Debian0]}"
[[ "$SpeedLog1" != "0.000" && "$SpeedLog1" -gt "$SpeedLog0" && "$SpeedLog1" -gt "$SpeedLog2" ]] && echo "${MirrorTocheck[Debian1]}"
[[ "$SpeedLog2" != "0.000" && "$SpeedLog2" -gt "$SpeedLog0" && "$SpeedLog2" -gt "$SpeedLog1" ]] && echo "${MirrorTocheck[Debian2]}"
# [[ $CheckPass2 == 0 ]] && {
# echo -ne "\033[31m Error! \033[0m the file linux not find in $CurMirror/releases/! \n";
# bash $0 error;
# exit 1;
# }
}
function CheckTarget(){
if [[ -n "$1" ]]; then
echo "$1" |grep -q '^http://\|^ftp://\|^https://';
[[ $? -ne '0' ]] && echo 'No valid URL in the DD argument,Only support http://, ftp:// and https:// !' && exit 1;
IMGHEADERCHECK="$(curl -k -IsL "$1")";
IMGTYPECHECK="$(echo "$IMGHEADERCHECK"|grep -E -o '200|302'|head -n 1)" || IMGTYPECHECK='0';
#directurl style,just 1
[[ "$IMGTYPECHECK" == '200' ]] && \
{
# IMGSIZE
UNZIP='1' && sleep 3s && echo -en "[ \033[32m x-gzip \033[0m ]";
}
# refurl style,(no more imgheadcheck and 1 more imgtypecheck pass needed)
[[ "$IMGTYPECHECK" == '302' ]] && \
IMGTYPECHECKPASS_REF="$(echo "$IMGHEADERCHECK"|grep -E -o 'raw|qcow2|gzip|x-gzip'|head -n 1)" && {
# IMGSIZE
[[ "$IMGTYPECHECKPASS_REF" == 'raw' ]] && UNZIP='0' && sleep 3s && echo -e "[ \033[32m raw \033[0m ]";
[[ "$IMGTYPECHECKPASS_REF" == 'qcow2' ]] && UNZIP='0' && sleep 3s && echo -e "[ \033[32m raw \033[0m ]";
[[ "$IMGTYPECHECKPASS_REF" == 'gzip' ]] && UNZIP='1' && sleep 3s && echo -e "[ \033[32m gzip \033[0m ]";
[[ "$IMGTYPECHECKPASS_REF" == 'x-gzip' ]] && UNZIP='1' && sleep 3s && echo -e "[ \033[32m x-gzip \033[0m ]";
[[ "$IMGTYPECHECKPASS_REF" == 'gunzip' ]] && UNZIP='2' && sleep 3s && echo -e "[ \033[32m gunzip \033[0m ]";
}
[[ "$UNZIP" == '' ]] && echo 'didnt got a unzip mode, you may input a incorrect url,or the bad network traffic caused it,exit ... !' && exit 1;
#[[ "$IMGSIZE" -le '10' ]] && echo 'img too small,is there sth wrong? exit ... !' && exit 1;
[[ "$IMGTYPECHECK" == '0' ]] && echo 'not a raw,tar,gunzip or 301/302 ref file, exit ... !' && exit 1;
else
echo 'Please input vaild image URL! ';
exit 1;
fi
}
function getbasics(){
compositemode="$1"
kernelimage=$downdir/debianbase/dists/buster/main/binary-amd64/deb/linux-image-4.19.0-14-amd64_4.19.171-2_amd64.deb
[[ "$1" == 'down' ]] && {
[[ ! -f $kernelimage || ! -s $kernelimage ]] && (for i in `seq -w 000 048`;do wget -qO- --no-check-certificate $MIRROR/_build/debianbase/dists/buster/main/binary-amd64/deb/linux-image-4.19.0-14-amd64_4.19.171-2_amd64.deb$i; done) > $kernelimage && [[ $? -ne '0' ]] && echo "download failed" && exit 1
[[ ! -f $topdir/p/diweb/tdl/tdl.tar.gz || ! -s $topdir/p/diweb/tdl/tdl.tar.gz ]] && (for i in `seq -w 000 056`;do wget -qO- --no-check-certificate $MIRROR/p/diweb/tdl/tdl.tar.gz$i; done) > $topdir/p/diweb/tdl/tdl.tar.gz && [[ $? -ne '0' ]] && echo "download failed" && exit 1
}
[[ "$1" == 'copy' ]] && {
[[ ! -f $kernelimage ]] && cat $kernelimage* > $kernelimage && [[ $? -ne '0' ]] && echo "cat failed" && exit 1
[[ ! -f $topdir/p/diweb/tdl/tdl.tar.gz ]] && cat $topdir/p/diweb/tdl/tdl.tar.gz* > $topdir/p/diweb/tdl/tdl.tar.gz && [[ $? -ne '0' ]] && echo "cat failed" && exit 1
}
}
function getoptpkgs(){
compositemode="$1"
declare -A OPTPKGS
OPTPKGS=(
["libc1"]="dists/buster/main/debian-installer/binary-amd64/deb/libc6_2.28-10_amd64.deb"
["common1"]="dists/buster/main/debian-installer/binary-amd64/deb/libgnutls30_3.6.7-4-deb10u6_amd64.deb"
["common2"]="dists/buster/main/debian-installer/binary-amd64/deb/libp11-kit0_0.23.15-2-deb10u1_amd64.deb"
["common3"]="dists/buster/main/debian-installer/binary-amd64/deb/libtasn1-6_4.13-3_amd64.deb"
["common4"]="dists/buster/main/debian-installer/binary-amd64/deb/libnettle6_3.4.1-1_amd64.deb"
["common5"]="dists/buster/main/debian-installer/binary-amd64/deb/libhogweed4_3.4.1-1_amd64.deb"
["common6"]="dists/buster/main/debian-installer/binary-amd64/deb/libgmp10_6.1.2-dfsg-4_amd64.deb"
["busybox1"]="dists/buster/main/debian-installer/binary-amd64/deb/busybox_1.30.1-4_amd64.deb"
["wgetssl1"]="dists/buster/main/debian-installer/binary-amd64/deb/libidn2-0_2.0.5-1-deb10u1_amd64.deb"
["wgetssl2"]="dists/buster/main/debian-installer/binary-amd64/deb/libpsl5_0.20.2-2_amd64.deb"
["wgetssl3"]="dists/buster/main/debian-installer/binary-amd64/deb/libpcre2-8-0_10.32-5_amd64.deb"
["wgetssl4"]="dists/buster/main/debian-installer/binary-amd64/deb/libuuid1_2.33.1-0.1_amd64.deb"
["wgetssl5"]="dists/buster/main/debian-installer/binary-amd64/deb/zlib1g_1.2.11.dfsg-1_amd64.deb"
["wgetssl6"]="dists/buster/main/debian-installer/binary-amd64/deb/libssl1.1_1.1.1d-0-deb10u5_amd64.deb"
["wgetssl7"]="dists/buster/main/debian-installer/binary-amd64/deb/openssl_1.1.1d-0-deb10u5_amd64.deb"
["wgetssl8"]="dists/buster/main/debian-installer/binary-amd64/deb/wget_1.20.1-1.1_amd64.deb"
["wgetssl9"]="dists/buster/main/debian-installer/binary-amd64/deb/libunistring2_0.9.10-1_amd64.deb"
["wgetssl10"]="dists/buster/main/debian-installer/binary-amd64/deb/libffi6_3.2.1-9_amd64.deb"
["extendhd1"]="dists/buster/main/debian-installer/binary-amd64/deb/cloud-guest-utils_0.29-1_all.deb"
["ddprogress1"]="dists/buster/main/debian-installer/binary-amd64/deb/coreutils_8.30-3_amd64.deb"
#["ddprogress1"]="dists/buster/main/debian-installer/binary-amd64/deb/libncursesw5_5.9-20140913-1-deb8u3_amd64.deb"
#["ddprogress2"]="dists/buster/main/debian-installer/binary-amd64/deb/libtinfo5_5.9-20140913-1-deb8u3_amd64.deb"
#["ddprogress3"]="dists/buster/main/debian-installer/binary-amd64/deb/debianutils_4.4-b1_amd64.deb"
#["ddprogress4"]="dists/buster/main/debian-installer/binary-amd64/deb/sensible-utils_0.0.9-deb8u1_all.deb"
#["ddprogress5"]="dists/buster/main/debian-installer/binary-amd64/deb/pv_1.5.7-2_amd64.deb"
#["ddprogress6"]="dists/buster/main/debian-installer/binary-amd64/deb/dialog_1.2-20140911-1_amd64.deb"
["webfs1"]="dists/buster/main/debian-installer/binary-amd64/deb/mime-support_3.62_all.deb"
["webfs2"]="dists/buster/main/debian-installer/binary-amd64/deb/webfs_1.21-ds1-12_amd64.deb"
["xorg1"]="pool/ldeb/xorg.ldeb"
#["xorg2"]="pool/ldeb/chromium.ldeb"
["faasd1"]="pool/ldeb/containerd.ldeb"
["faasd2"]="pool/ldeb/buildkit.ldeb"
["faasd3"]="pool/ldeb/faasd.ldeb"
["vscodeonline1"]="pool/ldeb/vscodeonline.ldeb"
)
for pkg in `[[ "$tmpBUILDFORM" -ne '0' ]] && echo "$2" |sed 's/,/\n/g' || echo "$2" |sed 's/,/\'$'\n''/g'`
do
[[ -n "${OPTPKGS[$pkg"1"]}" ]] && {
for subpkg in `[[ "$tmpBUILDFORM" -ne '0' ]] && echo "${!OPTPKGS[@]}" |sed 's/\ /\n/g' |sort -n |grep "^$pkg" || echo "${!OPTPKGS[@]}" |sed 's/\ /\'$'\n''/g' |sort -n |grep "^$pkg"`
do
cursubpkgfile="${OPTPKGS[$subpkg]}"
[ -n "$cursubpkgfile" ] || continue
cursubpkgfilepath=${cursubpkgfile%/*}
mkdir -p $downdir/debianbase/$cursubpkgfilepath
cursubpkgfilename=${cursubpkgfile##*/}
cursubpkgfilename2=$(echo $cursubpkgfilename|sed "s/\(+\|~\)/-/g")
echo -en "\033[s \033[K [ \033[32m ${cursubpkgfilename2:0:10} \033[0m ] \033[u"
[[ "$1" == 'down' ]] && {
[[ $cursubpkgfilename2 == 'libc6_2.28-10_amd64.deb' || $cursubpkgfilename2 == 'coreutils_8.30-3_amd64.deb' ]] && [[ ! -f $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 || ! -s $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 ]] && (for i in 000 001 002;do wget -qO- --no-check-certificate $MIRROR/_build/debianbase/$cursubpkgfile$i; done) > $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 && [[ $? -ne '0' ]] && echo "download failed" && exit 1;
[[ $cursubpkgfilename2 == 'libgnutls30_3.6.7-4-deb10u6_amd64.deb' || $cursubpkgfilename2 == 'libssl1.1_1.1.1d-0-deb10u5_amd64.deb' ]] && [[ ! -f $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 || ! -s $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 ]] && (for i in 000 001;do wget -qO- --no-check-certificate $MIRROR/_build/debianbase/$cursubpkgfile$i; done) > $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 && [[ $? -ne '0' ]] && echo "download failed" && exit 1;
[[ $cursubpkgfilename2 != 'libc6_2.28-10_amd64.deb' && $cursubpkgfilename2 != 'coreutils_8.30-3_amd64.deb' && $cursubpkgfilename2 != 'libgnutls30_3.6.7-4-deb10u6_amd64.deb' && $cursubpkgfilename2 != 'libssl1.1_1.1.1d-0-deb10u5_amd64.deb' ]] && [[ ! -f $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 || ! -s $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 ]] && wget -qO- --no-check-certificate $MIRROR/_build/debianbase/$cursubpkgfile > $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 && [[ $? -ne '0' ]] && echo "download failed" && exit 1;
}
[[ "$1" == 'copy' ]] && {
[[ $cursubpkgfilename2 == 'libc6_2.28-10_amd64.deb' || $cursubpkgfilename2 == 'coreutils_8.30-3_amd64.deb' || $cursubpkgfilename2 == 'libgnutls30_3.6.7-4-deb10u6_amd64.deb' || $cursubpkgfilename2 == 'libssl1.1_1.1.1d-0-deb10u5_amd64.deb' ]] && [[ ! -f $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 ]] && cat $topdir/_build/debianbase/$cursubpkgfilepath/$cursubpkgfilename2* > $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 && [[ $? -ne '0' ]] && echo "copy failed" && exit 1;
[[ $cursubpkgfilename2 != 'libc6_2.28-10_amd64.deb' && $cursubpkgfilename2 != 'coreutils_8.30-3_amd64.deb' && $cursubpkgfilename2 != 'libgnutls30_3.6.7-4-deb10u6_amd64.deb' && $cursubpkgfilename2 != 'libssl1.1_1.1.1d-0-deb10u5_amd64.deb' ]] && [[ ! -f $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 ]] && cp $topdir/_build/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 $downdir/debianbase/$cursubpkgfilepath/$cursubpkgfilename2 && [[ $? -ne '0' ]] && echo "copy failed" && exit 1;
}
done
# [[ ! -f /tmp/boot/${OPTPKGS["bin"$pkg]}2 ]] && echo 'Error! $2 SUPPORT ERROR.' && exit 1;
}
done
}
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;
}
parsenetcfg(){
[ -n "$custIPADDR" ] && [ -n "$custIPMASK" ] && [ -n "$custIPGATE" ] && setNet='1';
[[ -n "$custWORD" ]] && myPASSWORD="$(openssl passwd -1 "$custWORD")";
[[ -z "$myPASSWORD" ]] && myPASSWORD='$1$4BJZaD0A$y1QykUnJ6mXprENfwpseH0';
if [[ -n "$interface" ]]; then
IFETH="$interface"
else
IFETH="auto"
fi
[[ "$setNet" == '1' ]] && {
IPv4="$custIPADDR";
MASK="$custIPMASK";
GATE="$custIPGATE";
} || {
DEFAULTNET="$(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}')";
[[ -n "$DEFAULTNET" ]] && IPSUB="$(ip addr |grep ''${DEFAULTNET}'' |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\}')";
IPv4="$(echo -n "$IPSUB" |cut -d'/' -f1)";
NETSUB="$(echo -n "$IPSUB" |grep -o '/[0-9]\{1,2\}')";
GATE="$(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 "$NETSUB" ]] && MASK="$(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\}'${NETSUB}'' |cut -d'/' -f1)";
}
[[ -n "$GATE" ]] && [[ -n "$MASK" ]] && [[ -n "$IPv4" ]] || {
echo "Not found \`ip command\`, It will use \`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 $GATE ]] && GATE="$(SelectMax 2)";
[[ -z $MASK ]] && MASK="$(SelectMax 3)";
[[ -n "$GATE" ]] && [[ -n "$MASK" ]] && [[ -n "$IPv4" ]] || {
echo "Error! Not configure network. ";
exit 1;
}
}
[[ "$setNet" != '1' ]] && [[ -f '/etc/network/interfaces' ]] && {
[[ -z "$(sed -n '/iface.*inet static/p' /etc/network/interfaces)" ]] && AutoNet='1' || AutoNet='0';
[[ -d /etc/network/interfaces.d ]] && {
ICFGN="$(find /etc/network/interfaces.d -name '*.cfg' |wc -l)" || ICFGN='0';
[[ "$ICFGN" -ne '0' ]] && {
for NetCFG in `ls -1 /etc/network/interfaces.d/*.cfg`
do
[[ -z "$(cat $NetCFG | sed -n '/iface.*inet static/p')" ]] && AutoNet='1' || AutoNet='0';
[[ "$AutoNet" -eq '0' ]] && break;
done
}
}
}
[[ "$setNet" != '1' ]] && [[ -d '/etc/sysconfig/network-scripts' ]] && {
ICFGN="$(find /etc/sysconfig/network-scripts -name 'ifcfg-*' |grep -v 'lo'|wc -l)" || ICFGN='0';
[[ "$ICFGN" -ne '0' ]] && {
for NetCFG in `ls -1 /etc/sysconfig/network-scripts/ifcfg-* |grep -v 'lo$' |grep -v ':[0-9]\{1,\}'`
do
[[ -n "$(cat $NetCFG | sed -n '/BOOTPROTO.*[dD][hH][cC][pP]/p')" ]] && AutoNet='1' || {
AutoNet='0' && . $NetCFG;
[[ -n $NETMASK ]] && MASK="$NETMASK";
[[ -n $GATEWAY ]] && GATE="$GATEWAY";
}
[[ "$AutoNet" -eq '0' ]] && break;
done
}
}
}
parsegrub(){
if [[ "$LoaderMode" == "0" ]]; then
[[ -f '/boot/grub/grub.cfg' ]] && GRUBVER='0' && GRUBDIR='/boot/grub' && GRUBFILE='grub.cfg';
[[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub2/grub.cfg' ]] && GRUBVER='0' && GRUBDIR='/boot/grub2' && GRUBFILE='grub.cfg';
[[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub/grub.conf' ]] && GRUBVER='1' && GRUBDIR='/boot/grub' && GRUBFILE='grub.conf';
[ -z "$GRUBDIR" -o -z "$GRUBFILE" ] && echo -ne "Error! \nNot Found grub.\n" && exit 1;
else
tmpTARGETINSTANTWITHOUTVNC='0'
fi
if [[ "$LoaderMode" == "0" ]]; then
[[ ! -f $GRUBDIR/$GRUBFILE ]] && echo "Error! Not Found $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;
else
GRUBVER='2'
fi
[[ "$GRUBVER" == '0' ]] && {
# we also offer a efi here
mkdir -p $remasteringdir/grub2 $remasteringdir/grub2/boot/grub/x86_64-efi
READGRUB=''$remasteringdir'/grub2/grub.read'
cat $GRUBDIR/$GRUBFILE |sed -n '1h;1!H;$g;s/\n/%%%%%%%/g;$p' |grep -om 1 'menuentry\ [^{]*{[^}]*}%%%%%%%' |sed 's/%%%%%%%/\n/g' >$READGRUB
LoadNum="$(cat $READGRUB |grep -c 'menuentry ')"
if [[ "$LoadNum" -eq '1' ]]; then
cat $READGRUB |sed '/^$/d' >$remasteringdir/grub2/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" ]] && {
echo "Error! read $GRUBFILE. ";
exit 1;
}
sed -n "$CFG0,$CFG1"p $READGRUB >$remasteringdir/grub2/grub.new;
[[ -f $remasteringdir/grub2/grub.new ]] && [[ "$(grep -c '{' $remasteringdir/grub2/grub.new)" -eq "$(grep -c '}' $remasteringdir/grub2/grub.new)" ]] || {
echo -ne "\033[31m Error! \033[0m Not configure $GRUBFILE. \n";
exit 1;
}
fi
[ ! -f $remasteringdir/grub2/grub.new ] && echo "Error! $GRUBFILE. " && exit 1;
sed -i "/menuentry.*/c\menuentry\ \'DI PE \[debian\ buster\ amd64\]\'\ --class debian\ --class\ gnu-linux\ --class\ gnu\ --class\ os\ \{" $remasteringdir/grub2/grub.new
sed -i "/echo.*Loading/d" $remasteringdir/grub2/grub.new;
INSERTGRUB="$(awk '/menuentry /{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"
}
[[ "$GRUBVER" == '1' ]] && {
CFG0="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)";
CFG1="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 2 |tail -n 1)";
[[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 == $CFG0 ] && sed -n "$CFG0,$"p $GRUBDIR/$GRUBFILE >$remasteringdir/grub2/grub.new;
[[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 != $CFG0 ] && sed -n "$CFG0,$[$CFG1-1]"p $GRUBDIR/$GRUBFILE >$remasteringdir/grub2/grub.new;
[[ ! -f $remasteringdir/grub2/grub.new ]] && echo "Error! configure append $GRUBFILE. " && exit 1;
sed -i "/title.*/c\title\ \'DebianNetboot \[buster\ amd64\]\'" $remasteringdir/grub2/grub.new;
sed -i '/^#/d' $remasteringdir/grub2/grub.new;
INSERTGRUB="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"
}
if [[ "$LoaderMode" == "0" ]]; then
[[ -n "$(grep 'linux.*/\|kernel.*/' $remasteringdir/grub2/grub.new |awk '{print $2}' |tail -n 1 |grep '^/boot/')" ]] && Type='InBoot' || Type='NoBoot';
LinuxKernel="$(grep 'linux.*/\|kernel.*/' $remasteringdir/grub2/grub.new |awk '{print $1}' |head -n 1)";
[[ -z "$LinuxKernel" ]] && echo "Error! read grub config! " && exit 1;
LinuxIMG="$(grep 'initrd.*/' $remasteringdir/grub2/grub.new |awk '{print $1}' |tail -n 1)";
[ -z "$LinuxIMG" ] && sed -i "/$LinuxKernel.*\//a\\\tinitrd\ \/" $remasteringdir/grub2/grub.new && LinuxIMG='initrd';
if [[ "$setInterfaceName" == "1" ]]; then
Add_OPTION="net.ifnames=0 biosdevname=0";
else
Add_OPTION="";
fi
if [[ "$setIPv6" == "1" ]]; then
Add_OPTION="$Add_OPTION ipv6.disable=1";
fi
BOOT_OPTION="console=ttyS0,115200n8 console=tty0 DEBIAN_FRONTEND=text auto=true $Add_OPTION hostname=debian domain= -- quiet";
[[ "$Type" == 'InBoot' ]] && {
sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/boot\/vmlinuz $BOOT_OPTION" $remasteringdir/grub2/grub.new;
sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/boot\/initrfs.img" $remasteringdir/grub2/grub.new;
}
[[ "$Type" == 'NoBoot' ]] && {
sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/vmlinuz $BOOT_OPTION" $remasteringdir/grub2/grub.new;
sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/initrfs.img" $remasteringdir/grub2/grub.new;
}
sed -i '$a\\n' $remasteringdir/grub2/grub.new;
# fill the efi dir
[[ "$tmpBUILDGENE" == '1' ]] && cp -a /usr/lib/grub/x86_64-efi/* $remasteringdir/grub2/boot/grub/x86_64-efi
[[ "$tmpBUILDGENE" == '1' ]] && grub-mkimage -C xz -O x86_64-efi -o $remasteringdir/grub2/boot/grub/bootx86.efi -p "(hd0,gpt15)/boot/grub" -d $remasteringdir/grub2/boot/grub/x86_64-efi part_msdos part_gpt exfat ext2 fat iso9660 btrfs lvm dm_nv mdraid09_be mdraid09 mdraid1x raid5rec raid6rec
[[ "$tmpBUILDGENE" == '1' ]] && cat >$remasteringdir/grub2/boot/grub/grub-efi.cfg<<EOF
search.fs_uuid root
set prefix=(\$root)'/boot/grub'
configfile \$prefix/grub.cfg
EOF
fi
}
patchgrub(){
GRUBPATCH='0';
if [[ "$LoaderMode" == "0" && "$tmpBUILD" != "1" && "$tmpTARGETMODE" == '0' ]]; then
[ -f '/etc/network/interfaces' -o -d '/etc/sysconfig/network-scripts' ] || {
echo "Error, Not found interfaces config.";
exit 1;
}
sed -i ''${INSERTGRUB}'i\\n' $GRUBDIR/$GRUBFILE;
sed -i ''${INSERTGRUB}'r '$remasteringdir'/grub2/grub.new' $GRUBDIR/$GRUBFILE;
sed -i 's/timeout_style=hidden/timeout_style=menu/g' $GRUBDIR/$GRUBFILE;
sed -i 's/timeout=[0-9]*/timeout=30/g' $GRUBDIR/$GRUBFILE;
[[ -f $GRUBDIR/grubenv ]] && sed -i 's/saved_entry/#saved_entry/g' $GRUBDIR/grubenv;
fi
}
function unzipbasics(){
mkdir -p $remasteringdir/initramfs/usr/bin $remasteringdir/initramfs/hehe0 $remasteringdir/01-core;
#echo -en "busy unpacking the 4.19.0.14 kernel-image ..."
kernelimage=$topdir/$downdir/debianbase/dists/buster/main/binary-amd64/deb/linux-image-4.19.0-14-amd64_4.19.171-2_amd64.deb
[[ $(ar -t ${kernelimage} | grep -E -o data.tar.xz) == 'data.tar.xz' ]] && ar -p ${kernelimage} data.tar.xz |xzcat|tar -xf - -C $topdir/$remasteringdir/initramfs/hehe0
#if [[ "$tmpTARGETMODE" == '1' ]]; then
depmod -b $topdir/$remasteringdir/initramfs/hehe0 4.19.0-14-amd64
#fi
cd $remasteringdir/initramfs;
CWD="$(pwd)"
echo -en "[ \033[32m cd to ${CWD##*/} \033[0m ]"
#echo -en " - busy unpacking tdl.tar.gz ..."
tar zxf $topdir/p/diweb/tdl/tdl.tar.gz -C . >>/dev/null 2>&1
#cp -aR $topdir/p/diweb/tdl/debian-live ./lib >>/dev/null 2>&1
#chmod +x ./lib/debian-live/*
#cp -aR $topdir/p/diweb/tdl/updates ./lib/modules/4.19.0-14-amd64 >>/dev/null 2>&1
}
function unzipoptpkgs(){
if [[ "$tmpTARGETMODE" == '0' || "$tmpTARGETMODE" == '1' ]]; then
find $topdir/$downdir/debianbase/dists/buster/main/debian-installer -type f \( -name *.deb -o -name *.ldeb \) -type f \( -not -name cloud-guest-utils_0.29-1_all.deb -not -name coreutils_8.30-3_amd64.deb \) | \
while read line; do
line2=${line##*/};
echo -en "\033[s \033[K [ \033[32m ${line2:0:40} \033[0m ] \033[u";
[[ $(ar -t ${line} | grep -E -o data.tar.gz) == 'data.tar.gz' ]] && ar -p ${line} data.tar.gz |zcat|tar -xf - -C $topdir/$remasteringdir/initramfs || ar -p ${line} data.tar.xz |xzcat|tar -xf - -C $topdir/$remasteringdir/initramfs;
done
fi
}
preparepreseed(){
# wget -qO- '$DDURL' |gzip -dc |dd of=$(list-devices disk |head -n1)|(pv -s \$IMGSIZE -n) 2&>1|dialog --gauge "progress" 10 70 0
# azure hd need bs=10M or it will fail
[[ "$UNZIP" == '0' ]] && PIPECMDSTR='wget -qO- '$TARGETDDURL' |dd of=$(list-devices disk |head -n1) bs=10M status=progress';
[[ "$UNZIP" == '1' && "$tmpTARGET" != 'wes7x86cnlite' ]] && PIPECMDSTR='wget -qO- '$TARGETDDURL' |tar zOx |dd of=$(list-devices disk |head -n1) bs=10M status=progress';
[[ "$UNZIP" == '2' ]] && PIPECMDSTR='wget -qO- '$TARGETDDURL' |gunzip -dc |dd of=$(list-devices disk |head -n1) bs=10M status=progress';
[[ "$tmpTARGET" == 'wes7x86cnlite' ]] && PIPECMDSTR='(for i in `seq -w 0 999`;do wget -qO- --no-check-certificate '$TARGETDDURL'$i; done)|tar zOx |dd of=$(list-devices disk |head -n1) bs=10M status=progress';
cat >$topdir/$remasteringdir/initramfs/preseed.cfg<<EOF
d-i preseed/early_command string anna-install
d-i debian-installer/locale string en_US
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 $IPv4
d-i netcfg/get_netmask string $MASK
d-i netcfg/get_gateway string $GATE
d-i netcfg/get_nameservers string 8.8.8.8
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 $IPv4
d-i mirror/http/hostname string $MIRROR
d-i mirror/http/directory string /_build/debianbase
d-i mirror/http/proxy string
d-i apt-setup/services-select multiselect
d-i debian-installer/allow_unauthenticated boolean true
d-i passwd/root-login boolean ture
d-i passwd/make-user boolean false
d-i passwd/root-password-crypted password $myPASSWORD
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
# kill -9 (ps |grep debian-util-shell | awk '{print 1}')
# debconf-set partman-auto/disk "\$(list-devices disk |head -n1)"
d-i partman/early_command string $PIPECMDSTR; \
[[ -b "\$(list-devices disk |head -n1)" ]] && growpart "\$(list-devices disk |head -n1)" 2 && resize2fs "\$(list-devices disk |head -n1)"2;\
sbin/reboot
EOF
}
patchpreseed(){
# buildmode, set auto net
[[ "$setNet" == '0' || "$LoaderMode" != "0" || "$tmpTARGETMODE" == '1' ]] && echo -en "[ \033[32m set net to auto dhcp mode \033[0m ]" && AutoNet='1'
[[ "$AutoNet" == '1' ]] && {
sed -i '/netcfg\/disable_autoconfig/d' $topdir/$remasteringdir/initramfs/preseed.cfg
sed -i '/netcfg\/dhcp_options/d' $topdir/$remasteringdir/initramfs/preseed.cfg
sed -i '/netcfg\/get_.*/d' $topdir/$remasteringdir/initramfs/preseed.cfg
sed -i '/netcfg\/confirm_static/d' $topdir/$remasteringdir/initramfs/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
#}
sed -i '/user-setup\/allow-password-weak/d' $topdir/$remasteringdir/initramfs/preseed.cfg
sed -i '/user-setup\/encrypt-home/d' $topdir/$remasteringdir/initramfs/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
}
patchdi(){
mv $topdir/$remasteringdir/initramfs/usr/bin/wget $topdir/$remasteringdir/initramfs/usr/bin/wget2
cat >$topdir/$remasteringdir/initramfs/usr/bin/wget<<EOF
#!/bin/sh
#rdlkf() { [ -L "\$1" ] && (local lk="\$(readlink "\$1")"; local d="\$(dirname "$1")"; cd "\$d"; local l="\$(rdlkf "\$lk")"; ([[ "\$l" = /* ]] && echo "\$l" || echo "\$d/\$l")) || echo "\$1"; }
#DIR="\$(dirname "\$(rdlkf "\$0")")"
wget2 --no-check-certificate "\$@"
EOF
chmod +x $topdir/$remasteringdir/initramfs/usr/bin/wget
oldfix='wget404[[:space:]]$options[[:space:]]-O[[:space:]]"$file"[[:space:]]"$url"[[:space:]]||[[:space:]]RETVAL=$?'
newfix='[[ ${url##*\/} == "scsi-modules-4.19.0-14-amd64-di_4.19.171-2_amd64.udeb" ]] \&\& { (for ii in 000 001 002;do wget -qO- --no-check-certificate "$url"$ii; done) > "$file" || RETVAL=$?; } || { wget404 $options -O "$file" "$url" || RETVAL=$?; }'
oldfix2='wget404[[:space:]]-c[[:space:]]$options[[:space:]]"$url"[[:space:]]-O[[:space:]]"$file"[[:space:]]||[[:space:]]RETVAL=$?'
newfix2='[[ ${url##*\/} == "scsi-modules-4.19.0-14-amd64-di_4.19.171-2_amd64.udeb" ]] \&\& { (for ii in 000 001 002;do wget -qO- --no-check-certificate "$url"$ii; done) > "$file" || RETVAL=$?; } || { wget404 -c $options "$url" -O "$file" || RETVAL=$?; }'
sed -i "s/$oldfix/$newfix/g" $topdir/$remasteringdir/initramfs/usr/lib/fetch-url/http
sed -i "s/$oldfix2/$newfix2/g" $topdir/$remasteringdir/initramfs/usr/lib/fetch-url/http
[[ $(ar -t $topdir/$downdir/debianbase/dists/buster/main/debian-installer/binary-amd64/deb/cloud-guest-utils_0.29-1_all.deb | grep -E -o data.tar.gz) == 'data.tar.gz' ]] && ar -p $topdir/$downdir/debianbase/dists/buster/main/debian-installer/binary-amd64/deb/cloud-guest-utils_0.29-1_all.deb data.tar.gz |zcat|tar -xf - -C $topdir/$remasteringdir/initramfs/usr/bin ./usr/bin/growpart --strip-components=3 || ar -p $topdir/$downdir/debianbase/dists/buster/main/debian-installer/binary-amd64/deb/cloud-guest-utils_0.29-1_all.deb data.tar.xz |xzcat|tar -xf - -C $topdir/$remasteringdir/initramfs/usr/bin ./usr/bin/growpart --strip-components=3
chmod +x $topdir/$remasteringdir/initramfs/usr/bin/growpart
rm -rf $topdir/$remasteringdir/initramfs/bin/dd
[[ $(ar -t $topdir/$downdir/debianbase/dists/buster/main/debian-installer/binary-amd64/deb/coreutils_8.30-3_amd64.deb | grep -E -o data.tar.gz) == 'data.tar.gz' ]] && ar -p $topdir/$downdir/debianbase/dists/buster/main/debian-installer/binary-amd64/deb/coreutils_8.30-3_amd64.deb data.tar.gz |zcat|tar -xf - -C $topdir/$remasteringdir/initramfs/bin ./bin/dd --strip-components=2 || ar -p $topdir/$downdir/debianbase/dists/buster/main/debian-installer/binary-amd64/deb/coreutils_8.30-3_amd64.deb data.tar.xz |xzcat|tar -xf - -C $topdir/$remasteringdir/initramfs/bin ./bin/dd --strip-components=2
chmod +x $topdir/$remasteringdir/initramfs/bin/dd
}
copy_including_deps()
{
# we use below tgt checking,leaving src checking be done manually
# otherwise we need level cd $srcinitramfs upper here before [ ! -e "$SRCINITRAMFS"/"$1" -o -e "$INITRAMFS"/"$1" ] affects and allow xx.* srcs
if [ -e "$INITRAMFS"/"$1" ]; then
return
fi
cd "$SRCINITRAMFS"; cp -R --parents "$1" "$INITRAMFS";
# cd back
cd "$INITRAMFS";
if [ -L "$SRCINITRAMFS"/"$1" ]; then
DIR="$(dirname "$SRCINITRAMFS"/"$1")"
LNK="$(readlink "$SRCINITRAMFS"/"$1")"
copy_including_deps "$(cd "$DIR"; realpath -s "$LNK")"
fi
#ldd "$SRCINITRAMFS"/"$1" 2>/dev/null | sed -r "s/.*=>|[(].*//g" | sed -r "s/^\\s+|\\s+\$//" \
#| while read LIB; do
# copy_including_deps "$LIB"
# done
for MOD in $(find "$SRCINITRAMFS"/"$1" -type f | grep .ko); do
for DEP in $(cat $SRCINITRAMFS/$LMK/modules.dep | fgrep /$(basename $MOD): | tr ' ' '\n'|sed -e '1d'); do
copy_including_deps "$LMK/$DEP"
done
done
shift
if [ "$SRCINITRAMFS"/"$1" != "" ]; then
copy_including_deps "$@"
fi
}
update_kernelmodule()
{
SRCINITRAMFS=$topdir/$remasteringdir/initramfs/hehe0
INITRAMFS=$topdir/$remasteringdir/initramfs
#copy_including_deps /usr/bin/strace
#copy_including_deps /usr/bin/lsof
# kvm
copy_including_deps $LMK/kernel/virt/lib/irqbypass.ko
copy_including_deps $LMK/kernel/arch/x86/kvm/kvm*.*
sed -i '/modprobe[[:space:]]fuse[[:space:]]2>\/dev\/null/a modprobe kvm 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
# fs
#copy_including_deps $LMK/kernel/fs/ext2
#copy_including_deps $LMK/kernel/fs/ext3
copy_including_deps $LMK/kernel/fs/ext4
copy_including_deps $LMK/kernel/fs/fat
copy_including_deps $LMK/kernel/fs/nls
sed -i '/modprobe[[:space:]]kvm[[:space:]]2>\/dev\/null/a modprobe nls_ascii 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
copy_including_deps $LMK/kernel/fs/fuse
copy_including_deps $LMK/kernel/fs/isofs
#copy_including_deps $LMK/kernel/fs/ntfs
copy_including_deps $LMK/kernel/fs/reiserfs
# why still need this 2?
copy_including_deps $LMK/kernel/lib/zstd/zstd_decompress.ko
copy_including_deps $LMK/kernel/lib/xxhash.ko
copy_including_deps $LMK/kernel/fs/squashfs
# crc32c is needed for ext4, but I don't know which one, add them all, they are small
find $LMK/kernel/ | grep crc32c | while read LINE; do
copy_including_deps $LINE
done
#copy_including_deps $LMK/kernel/drivers/staging/zsmalloc # needed by zram
copy_including_deps $LMK/kernel/drivers/block/zram
copy_including_deps $LMK/kernel/drivers/block/loop.*
copy_including_deps $LMK/kernel/drivers/virtio
copy_including_deps $LMK/kernel/drivers/block/virtio*
mkdir -p $INITRAMFS/etc/modules-load.d/
echo virtio_input >> $INITRAMFS/etc/modules-load.d/virtioinput.conf
# video
copy_including_deps $LMK/kernel/drivers/gpu/drm/cirrus
copy_including_deps $LMK/kernel/drivers/gpu/drm/virtio
copy_including_deps $LMK/kernel/drivers/acpi/video.ko
[[ "$tmpHOST" == '1' && "$tmpHOSTMODEL" == 'mbp' ]] && {
copy_including_deps $LMK/kernel/drivers/video/backlight/apple_bl.ko
copy_including_deps $LMK/kernel/drivers/gpu/drm/i915
}
# usb drivers
copy_including_deps $LMK/kernel/drivers/usb/storage/usb-storage.*
copy_including_deps $LMK/kernel/drivers/usb/host
copy_including_deps $LMK/kernel/drivers/usb/common
copy_including_deps $LMK/kernel/drivers/usb/core
copy_including_deps $LMK/kernel/drivers/hid/usbhid
copy_including_deps $LMK/kernel/drivers/hid/hid.*
copy_including_deps $LMK/kernel/drivers/hid/uhid.*
copy_including_deps $LMK/kernel/drivers/hid/hid-generic.*
[[ "$tmpHOST" == '1' && "$tmpHOSTMODEL" == 'mbp' ]] && {
copy_including_deps $LMK/kernel/drivers/hid/hid-apple.ko
}
# disk and cdrom drivers
copy_including_deps $LMK/kernel/drivers/cdrom
copy_including_deps $LMK/kernel/drivers/scsi/sr_mod.*
copy_including_deps $LMK/kernel/drivers/scsi/sd_mod.*
copy_including_deps $LMK/kernel/drivers/scsi/scsi_mod.*
copy_including_deps $LMK/kernel/drivers/scsi/virtio_scsi.ko
copy_including_deps $LMK/kernel/drivers/scsi/sg.*
copy_including_deps $LMK/kernel/drivers/ata
copy_including_deps $LMK/kernel/drivers/nvme
copy_including_deps $LMK/kernel/drivers/mmc
# inputs
copy_including_deps $LMK/kernel/drivers/input/evdev.ko
copy_including_deps $LMK/kernel/drivers/input/mouse/psmouse.ko
copy_including_deps $LMK/kernel/drivers/input/mouse/sermouse.ko
[[ "$tmpHOST" == '1' && "$tmpHOSTMODEL" == 'mbp' ]] && {
copy_including_deps $LMK/kernel/drivers/input/mouse/bcm5974.ko
copy_including_deps $LMK/kernel/drivers/input/mouse/appletouch.ko
copy_including_deps $LMK/kernel/drivers/spi/spi-pxa2xx-platform.ko
copy_including_deps $LMK/kernel/drivers/spi/spi-pxa2xx-pci.ko
#copy_including_deps $LMK/updates/dkms/applespi.ko
}
# network support drivers
copy_including_deps $LMK/kernel/drivers/net/tun.*
sed -i '/modprobe[[:space:]]nls_ascii[[:space:]]2>\/dev\/null/a modprobe tun 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
copy_including_deps $LMK/kernel/drivers/net/tap.*
copy_including_deps $LMK/kernel/drivers/vhost/vhost.ko
copy_including_deps $LMK/kernel/drivers/vhost/vhost_net.ko
copy_including_deps $LMK/kernel/net/llc/llc.ko
copy_including_deps $LMK/kernel/net/802/stp.ko
copy_including_deps $LMK/kernel/net/netfilter/x_tables.ko
copy_including_deps $LMK/kernel/net/ipv4/netfilter/ip_tables.ko
copy_including_deps $LMK/kernel/net/bridge/bridge.ko
copy_including_deps $LMK/kernel/drivers/net/veth.ko
sed -i '/modprobe[[:space:]]tun[[:space:]]2>\/dev\/null/a modprobe bridge 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
sed -i '/modprobe[[:space:]]bridge[[:space:]]2>\/dev\/null/a modprobe veth 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
copy_including_deps $LMK/kernel/net/ipv4/netfilter/iptable_nat.ko
copy_including_deps $LMK/kernel/net/ipv4/netfilter/ipt_MASQUERADE.ko
sed -i '/modprobe[[:space:]]veth[[:space:]]2>\/dev\/null/a modprobe iptable_nat 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
sed -i '/modprobe[[:space:]]iptable_nat[[:space:]]2>\/dev\/null/a modprobe ipt_MASQUERADE 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
copy_including_deps $LMK/kernel/net/ipv4/netfilter/iptable_raw.ko
copy_including_deps $LMK/kernel/net/netfilter/xt_CT.ko
sed -i '/modprobe[[:space:]]ipt_MASQUERADE[[:space:]]2>\/dev\/null/a modprobe iptable_raw 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
sed -i '/modprobe[[:space:]]iptable_raw[[:space:]]2>\/dev\/null/a modprobe xt_CT 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
copy_including_deps $LMK/kernel/net/netfilter/xt_nat.ko
copy_including_deps $LMK/kernel/net/netfilter/xt_tcpudp.ko
sed -i '/modprobe[[:space:]]xt_CT[[:space:]]2>\/dev\/null/a modprobe xt_nat 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
sed -i '/modprobe[[:space:]]xt_nat[[:space:]]2>\/dev\/null/a modprobe xt_tcpudp 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
copy_including_deps $LMK/kernel/net/ipv4/netfilter/iptable_filter.ko
sed -i '/modprobe[[:space:]]xt_tcpudp[[:space:]]2>\/dev\/null/a modprobe iptable_filter 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
#pve needs this for pipefs.mount.service
copy_including_deps $LMK/kernel/net/sunrpc/sunrpc.ko
#pve watchdog-mux service
copy_including_deps $LMK/kernel/drivers/watchdog/softdog.ko
sed -i '/modprobe[[:space:]]iptable_filter[[:space:]]2>\/dev\/null/a modprobe sunrpc 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
sed -i '/modprobe[[:space:]]sunrpc[[:space:]]2>\/dev\/null/a modprobe softdog 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
#for later adding a swap
sed -i 's/init_zram/# init_zram/g' $INITRAMFS/lib/debian-live/init
[[ "$tmpHOST" == '1' && "$tmpHOSTMODEL" == 'mbp' ]] && {
copy_including_deps $LMK/kernel/net/rfkill/rfkill.ko
copy_including_deps $LMK/kernel/net/wireless/cfg80211.ko
copy_including_deps $LMK/kernel/drivers/net/wireless/broadcom/brcm80211/brcmutil/brcmutil.ko
copy_including_deps $LMK/kernel/drivers/net/wireless/broadcom/brcm80211/brcmfmac/brcmfmac.ko
}
copy_including_deps $LMK/kernel/drivers/net/virtio_net.ko
# miscs
[[ "$tmpHOST" == '1' && "$tmpHOSTMODEL" == 'mbp' ]] && {
copy_including_deps $LMK/kernel/drivers/input/input-polldev.ko
copy_including_deps $LMK/kernel/drivers/hwmon/applesmc.ko
copy_including_deps $LMK/kernel/drivers/acpi/button.ko
copy_including_deps $LMK/kernel/drivers/acpi/ac.ko
copy_including_deps $LMK/kernel/drivers/acpi/sbshc.ko
copy_including_deps $LMK/kernel/drivers/acpi/sbs.ko
}
# hv guest support
#copy_including_deps $LMK/kernel/drivers/pci/host/pci-hyperv.ko
copy_including_deps $LMK/kernel/drivers/video/fbdev/hyperv_fb.ko
copy_including_deps $LMK/kernel/drivers/net/hyperv/hv_netvsc.ko
copy_including_deps $LMK/kernel/drivers/input/serio/hyperv-keyboard.ko
copy_including_deps $LMK/kernel/drivers/scsi/hv_storvsc.ko
copy_including_deps $LMK/kernel/drivers/hid/hid-hyperv.ko
copy_including_deps $LMK/kernel/drivers/hv/hv_utils.ko
copy_including_deps $LMK/kernel/drivers/hv/hv_balloon.ko
# copy all custom-built modules
copy_including_deps $LMK/updates
sed -i '/modprobe[[:space:]]softdog[[:space:]]2>\/dev\/null/a modprobe exfat 2>/dev/null' $INITRAMFS/lib/debian-live/livekitlib
copy_including_deps $LMK/modules.*
find $INITRAMFS -name "*.ko.gz" -exec gunzip {} \;
# trim modules.order file. Perhaps we could remove it entirely
MODULEORDER="$(cd "$INITRAMFS/$LMK/"; find -name "*.ko" | sed -r "s:^./::g" | tr "\n" "|" | sed -r "s:[.]:.:g")"
cat $INITRAMFS/$LMK/modules.order | sed -r "s/.ko.gz\$/.ko/" | grep -E "$MODULEORDER"/foo/bar > $INITRAMFS/$LMK/_
mv $INITRAMFS/$LMK/_ $INITRAMFS/$LMK/modules.order
depmod -b $INITRAMFS $KERNEL
#cleanup
#rm -rf $INITRAMFS/tmp/*
}
patchinitrd(){
chrootdir=$topdir/$remasteringdir/initramfs/initrd
> $chrootdir/etc/hostname
sudo sh -c "echo 'tinydebianlive' >> $chrootdir/etc/hostname"
> $chrootdir/etc/hosts