-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-debian.sh
executable file
·1563 lines (1278 loc) · 53.7 KB
/
build-debian.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
ltspBase=./
cd ${ltspBase} ; ltspBase=`pwd`/ ; cd - > /dev/null
ltspEtc=${ltspBase}etc/
boardModel=nas540
FWGETURL="ftp://ftp.zyxel.com/NAS540/firmware/NAS540_V5.20(AATB.0)C0.zip"
FWUSEVER=newer
fanSpeed=keep
boardName=nas
cpuArch=armhf
distBrand=Debian
#distName=wheezy
#distName=jessie
#distName=stretch
#distName=buster
#distName=bullseye
distName=bookworm
distURL=http://ftp.us.debian.org/debian
secuURL=http://security.debian.org
imageName=debian-nas
mainRepo="main"
moreRepo="main contrib non-free"
notUbuntu=true
imageMdMount=false
imageOmv=false
imageOmvInit=true
imageHostname=${imageName}
imageEth0Ip=192.168.1.233
imageEth0Mask=255.255.255.0
imageEth1Ip=192.168.2.233
imageEth1Mask=255.255.255.0
imageRouter=192.168.1.1
imageDNS=192.168.1.1
installRecommends=1
installISCSITarget=0
installMailServer=1
installNFSServer=1
installNTPServer=1
installSMBServer=1
installMiscServer=1
installWifi=0
installIpmitool=0
installSmartctl=1
distBrandLower=`echo $distBrand | tr A-Z a-z`
if [ $cpuArch = amd64 -o $cpuArch = i386 ]; then
boardName=pc
fi
distDeb=stretch
distKeyringFile=release-9.asc
distOmv=arrakis
versOmv=4
if [ ${distName} = bookworm ] ; then
distDeb=bookworm
distKeyringFile=release-12.asc
distOmv=sandworm
versOmv=7
elif [ ${distName} = bullseye ] ; then
distDeb=bullseye
distKeyringFile=release-11.asc
distOmv=shaitan
versOmv=6
elif [ ${distName} = buster ] ; then
distDeb=buster
distKeyringFile=release-10.asc
distOmv=usul
versOmv=5
elif [ ${distName} = stretch ] ; then
distDeb=stretch
distKeyringFile=release-9.asc
distOmv=arrakis
versOmv=4
elif [ ${distName} = jessie ] ; then
distDeb=jessie
distKeyringFile=release-8.asc
distOmv=erasmus
versOmv=3
elif [ ${distName} = wheezy ] ; then
distDeb=wheezy
distKeyringFile=release-7.asc
distOmv=stoneburner
versOmv=2
fi
# ---- functions ----
function admin_password() {
echo " *** user admin ..."
echo "password"
chroot ${ltspBase}${cpuArch} passwd admin
#chroot ${ltspBase}${cpuArch} smbpasswd -a admin
}
function user_password() {
firstUser=`cat ${ltspBase}${cpuArch}/etc/passwd |grep '504:500' | cut -d ':' -f 1`
if [ "x$firstUser" != "x" ]; then
echo " *** user $firstUser ..."
echo "password"
chroot ${ltspBase}${cpuArch} passwd $firstUser
echo "samba share password"
chroot ${ltspBase}${cpuArch} smbpasswd -a $firstUser
fi
}
# based on make_raspi2_image from https://bitbucket.org/ubuntu-mate/ubuntu-mate-rpi2/src and
# https://github.com/sneak/kvm-ubuntu-imagebuilder/blob/master/buildimage.sh#L211
function make_disk_image() {
BASEDIR=${ltspBase}images
BUILDDIR=${ltspBase}
#LDRDIR=${R}/root/source
LDRDIR=${ltspBase}archives
RELEASE=${distName}
R=${ltspBase}${cpuArch}
# Build the image file
DATE="$(date +%y.%j)"
IMAGE="${3}-${RELEASE}-${DATE}-${cpuArch}.img"
echo "Preparing images/${IMAGE} ......"
local FS="${1}"
local GB=${2}
if [ "${FS}" != "ext4" ] && [ "${FS}" != 'f2fs' ]; then
echo "ERROR! Unsupport filesystem requested. Exitting."
exit 1
fi
if [ ${GB} -ne 1 ] && [ ${GB} -ne 2 ] && [ ${GB} -ne 3 ] && [ ${GB} -ne 4 ] && [ ${GB} -ne 8 ]; then
echo "ERROR! Unsupport card image size requested. Exitting."
exit 1
fi
if [ ${GB} -eq 1 ]; then
SEEK=940
elif [ ${GB} -eq 2 ]; then
SEEK=1882
elif [ ${GB} -eq 3 ]; then
SEEK=2816
elif [ ${GB} -eq 4 ]; then
SEEK=3750
elif [ ${GB} -eq 8 ]; then
SEEK=7594
fi
BOOT_START_M=1
BOOT_SIZE_LIMIT=96
START_M=`expr ${BOOT_START_M} + ${BOOT_SIZE_LIMIT}`
SIZE_LIMIT=`expr ${SEEK} - 1 - ${START_M}`
BOOT_START=`expr ${BOOT_START_M} \* 2048`
BOOT_SIZE=`expr ${BOOT_SIZE_LIMIT} \* 2048`
START=`expr ${START_M} \* 2048`
SIZE=`expr ${SIZE_LIMIT} \* 2048`
START_B=`expr ${START_M} \* 1048576`
mkdir -p ${BASEDIR}
[ -e ${BASEDIR}/${IMAGE}.gz ] && rm ${BASEDIR}/${IMAGE}.gz
if [ -e ${LDRDIR}/${boardName}-loader.bin ]; then
START_B=`stat -c%s ${LDRDIR}/${boardName}-loader.bin`
#dd if=${LDRDIR}/${boardName}-loader.bin of="${BASEDIR}/${IMAGE}" bs=1M count=1
dd if=${LDRDIR}/${boardName}-loader.bin of="${BASEDIR}/${IMAGE}" bs=512
dd if=/dev/zero of="${BASEDIR}/${IMAGE}" bs=1M count=0 seek=1
else
dd if=/dev/zero of="${BASEDIR}/${IMAGE}" bs=1M count=1
fi
dd if=/dev/zero of="${BASEDIR}/${IMAGE}" bs=1M count=0 seek=${SEEK}
if [ ${cpuArch} != powerpc ] ; then
cat <<EOM | sfdisk -f "${BASEDIR}/${IMAGE}" > /dev/null
unit: sectors
1 : start= ${BOOT_START}, size= ${BOOT_SIZE}, Id= c, bootable
2 : start= ${START}, size= ${SIZE}, Id=83
3 : start= 0, size= 0, Id= 0
4 : start= 0, size= 0, Id= 0
EOM
else
# loader.bin contains:
#Partition Table: mac
#Number Start End Size File system Name Flags
# 1 512B 32767B 32256B Apple
# 2 32768B 1033215B 1000448B hfs untitled boot
# ... create third partition:
parted -s "${BASEDIR}/${IMAGE}" "mkpart ext4 ${START_B}B -0"
fi
BOOT_LOOP=/dev/null
ROOT_LOOP=/dev/null
if [ ${cpuArch} != powerpc ] ; then
BOOT_LOOP="$(losetup -o ${BOOT_START_M}M --sizelimit ${BOOT_SIZE_LIMIT}M -f --show ${BASEDIR}/${IMAGE})"
mkfs.vfat -n TC_BOOT -S 512 -s 16 -v "${BOOT_LOOP}" > /dev/null
ROOT_LOOP="$(losetup -o ${START_M}M --sizelimit ${SIZE_LIMIT}M -f --show ${BASEDIR}/${IMAGE})"
else
ROOT_LOOP="$(losetup -o ${START_B} --sizelimit ${SIZE_LIMIT}M -f --show ${BASEDIR}/${IMAGE})"
fi
if [ "${FS}" == "ext4" ]; then
if ! mkfs.ext4 -O ^metadata_csum -L TC_ROOT -m 0 "${ROOT_LOOP}" > /dev/null ; then
mkfs.ext4 -L TC_ROOT -m 0 "${ROOT_LOOP}" > /dev/null
fi
else
mkfs.f2fs -l TC_ROOT -o 1 "${ROOT_LOOP}" > /dev/null
fi
MOUNTDIR="${BUILDDIR}/mount"
mkdir -p "${MOUNTDIR}"
mount "${ROOT_LOOP}" "${MOUNTDIR}"
mkdir -p "${MOUNTDIR}/boot"
if [ ${cpuArch} != powerpc ] ; then
mount "${BOOT_LOOP}" "${MOUNTDIR}/boot"
fi
echo "Creating images/${IMAGE} ......"
rsync -a "$R/" "${MOUNTDIR}/" || true
rsync -a --progress "$R/" "${MOUNTDIR}/"
rm -rf ${MOUNTDIR}/tmp/* ${MOUNTDIR}/var/tmp/*
if [ ${GB} -eq 2 ]; then
sed -i s/'^deb-src'/'#deb-src'/g ${MOUNTDIR}/etc/apt/sources.list
sed -i s/'^deb-src'/'#deb-src'/g ${MOUNTDIR}/etc/apt/sources.list.d/*.list || true
fi
if [ "${boardName}" = "generic" -o "${boardName}" = "mac" -o "${boardName}" = "pc" ]; then
MR=${MOUNTDIR}
BOOTID=1234-5678
[ ${cpuArch} != powerpc ] && BOOTID=`sudo blkid ${BOOT_LOOP} | sed s/' '/'\n'/g | grep 'UUID=' | cut -d "=" -f 2 | sed s/'"'/''/g`
ROOTID=`sudo blkid ${ROOT_LOOP} | sed s/' '/'\n'/g | grep 'UUID=' | cut -d "=" -f 2 | sed s/'"'/''/g`
KERN="$(cd $MR/boot && ls vmlinu*-*)"
VER="${KERN}"
VER="${VER#vmlinux-}"
VER="${VER#vmlinuz-}"
if [ $cpuArch = amd64 -o $cpuArch = i386 ]; then
OLDBOOTID=0796-056F
OLDROOTID=19a9d539-2e70-4361-a4c2-227c68375759
OLDKRNVER=3.19.0-15-generic
sed -i s/${OLDBOOTID}/${BOOTID}/g $MR/boot/grub/grub.cfg
sed -i s/${OLDROOTID}/${ROOTID}/g $MR/boot/grub/grub.cfg
if [ -e $MR/${EFIDIR}/EFI/ubuntu/grub.cfg ]; then
sed -i s/${OLDBOOTID}/${BOOTID}/g $MR/${EFIDIR}/EFI/ubuntu/grub.cfg
sed -i s/${OLDROOTID}/${ROOTID}/g $MR/${EFIDIR}/EFI/ubuntu/grub.cfg
fi
#sed -i 's|/dev/sda1|UUID="${BOOTID}"|g' ${MOUNTDIR}/etc/fstab
#sed -i 's|/dev/sda2|UUID="${ROOTID}"|g' ${MOUNTDIR}/etc/fstab
sed -i s/${OLDKRNVER}/${VER}/g $MR/boot/grub/grub.cfg
[ -e $MR/sbin/init-tc ] || sed -i 's| init=/sbin/init-tc||g' $MR/boot/grub/grub.cfg
[ -e $MR/sbin/upstart ] || sed -i 's| init=/sbin/upstart||g' $MR/boot/grub/grub.cfg
fi
fi
sed -i 's|/dev/sda1|LABEL="TC_BOOT"|g' ${MOUNTDIR}/etc/fstab
sed -i 's|/dev/sda2|LABEL="TC_ROOT"|g' ${MOUNTDIR}/etc/fstab
if [ ${cpuArch} != powerpc ] ; then
umount "${MOUNTDIR}/boot"
losetup -d "${BOOT_LOOP}"
if cp -p $R/boot/vmlinuz-* "${MOUNTDIR}/boot/" ; then
cp -p $R/boot/config-* "${MOUNTDIR}/boot/"
cp -p $R/boot/initrd.img-* "${MOUNTDIR}/boot/"
cp -p $R/boot/System.map-* "${MOUNTDIR}/boot/"
fi
fi
umount "${MOUNTDIR}"
losetup -d "${ROOT_LOOP}"
DISK_LOOP=/dev/null
DISK_LOOP="$(losetup -f --show ${BASEDIR}/${IMAGE})"
gdisk ${DISK_LOOP} <<EOF
c
1
TC_BOOT
c
2
TC_ROOT
x
c
1
54cdf5da-deb1-b007-a694-32880502ef34
c
2
54cdf5da-deb1-f007-a694-32880502ef34
p
w
y
EOF
losetup -d "${DISK_LOOP}"
if [ $cpuArch != amd64 -a $cpuArch != i386 ]; then
echo "Creating images/${IMAGE}.gz ......"
gzip ${BASEDIR}/${IMAGE}
fi
}
UpdateConfig() {
true
}
askClientOpt() {
EXTRAOPT=$(whiptail --title "Image Creator $version Extra Options" --cancel-button "Quit" --ok-button "Select" --checklist "What components would you like to use?" 22 80 10 \
"aptrecommends" "Install Recommends" $installRecommends \
"iscsitarget" "iSCSI Target" $installISCSITarget \
"mailserver" "Mail Server" $installMailServer \
"nfsserver" "NFS Server" $installNFSServer \
"ntpserver" "NTP Server" $installNTPServer \
"smbserver" "SMB Server" $installSMBServer \
"miscserver" "Avahi/SNMP/FTP/TFTP Server" $installMiscServer \
"wifi" "WiFi/WLAN" $installWifi \
"ipmitool" "IPMI Tool" $installIpmitool \
"smartctl" "S.M.A.R.T. Monitoring Tools" $installSmartctl \
3>&1 1>&2 2>&3)
r=$?
if [ $r = 0 ]; then
installRecommends=0
UpdateConfig installRecommends $installRecommends
installISCSITarget=0
UpdateConfig installISCSITarget $installISCSITarget
installMailServer=0
UpdateConfig installMailServer $installMailServer
installNFSServer=0
UpdateConfig installNFSServer $installNFSServer
installNTPServer=0
UpdateConfig installNTPServer $installNTPServer
installSMBServer=0
UpdateConfig installSMBServer $installSMBServer
installMiscServer=0
UpdateConfig installMiscServer $installMiscServer
installWifi=0
UpdateConfig installWifi $installWifi
installIpmitool=0
UpdateConfig installIpmitool $installIpmitool
installSmartctl=0
UpdateConfig installSmartctl $installSmartctl
for o in $EXTRAOPT ; do
case ${o} in
\"aptrecommends\")
installRecommends=1
UpdateConfig installRecommends $installRecommends
echo enable $o
;;
\"iscsitarget\")
installISCSITarget=1
UpdateConfig installISCSITarget $installISCSITarget
echo enable $o
;;
\"mailserver\")
installMailServer=1
UpdateConfig installMailServer $installMailServer
echo enable $o
;;
\"nfsserver\")
installNFSServer=1
UpdateConfig installNFSServer $installNFSServer
echo enable $o
;;
\"ntpserver\")
installNTPServer=1
UpdateConfig installNTPServer $installNTPServer
echo enable $o
;;
\"smbserver\")
installSMBServer=1
UpdateConfig installSMBServer $installSMBServer
echo enable $o
;;
\"miscserver\")
installMiscServer=1
UpdateConfig installMiscServer $installMiscServer
echo enable $o
;;
\"wifi\")
installWifi=1
UpdateConfig installWifi $installWifi
echo enable $o
;;
\"ipmitool\")
installIpmitool=1
UpdateConfig installIpmitool $installIpmitool
echo enable $o
;;
\"smartctl\")
installSmartctl=1
UpdateConfig installSmartctl $installSmartctl
echo enable $o
;;
*)
echo what?
esac
done
fi
}
WriteConfigFile() {
cat <<EOFDRUBCF | tee ${ltspBase}${cpuArch}/etc/${distBrandLower}-build.conf
boardModel=${boardModel}
FWGETURL="${FWGETURL}"
FWUSEVER="${FWUSEVER}"
fanSpeed=${fanSpeed}
firstUser=${firstUser}
imageMdMount=${imageMdMount}
imageOmv=${imageOmv}
imageOmvInit=${imageOmvInit}
imageHostname=${imageHostname}
imageEth0Ip=${imageEth0Ip}
imageEth0Mask=${imageEth0Mask}
imageEth1Ip=${imageEth1Ip}
imageEth1Mask=${imageEth1Mask}
imageRouter=${imageRouter}
imageDNS=${imageDNS}
installRecommends=${installRecommends}
installISCSITarget=${installISCSITarget}
installMailServer=${installMailServer}
installNFSServer=${installNFSServer}
installNTPServer=${installNTPServer}
installSMBServer=${installSMBServer}
installMiscServer=${installMiscServer}
installWifi=${installWifi}
installIpmitool=${installIpmitool}
installSmartctl=${installSmartctl}
EOFDRUBCF
mkdir -p ${ltspBase}etc
cp -p ${ltspBase}${cpuArch}/etc/${distBrandLower}-build.conf ${ltspBase}etc/
}
# ---- main ----
if [ x$1 = xadminpassword ]; then
admin_password
exit 0
elif [ x$1 = xuserpassword ]; then
user_password
exit 0
elif [ x$1 = xdiskimage ]; then
make_disk_image ext4 3 $imageName
exit 0
fi
echo " *** install packages on build host ..."
apt-get install -y debootstrap gdisk qemu-user-static binfmt-support whiptail dosfstools rsync patch
apt-get install -y python-minimal || apt-get install -y python2-minimal || apt-get install -y python3-minimal
[ -e ${ltspBase}etc/${distBrandLower}-build.conf ] && . ${ltspBase}etc/${distBrandLower}-build.conf
[ -e ${ltspBase}${cpuArch}/etc/${distBrandLower}-build.conf ] && . ${ltspBase}${cpuArch}/etc/${distBrandLower}-build.conf
BMODEL=$(whiptail --default-item ${boardModel} --title "Image Creator Firmware Extraction" --cancel-button "Quit" --ok-button "Select" --menu "Which firmware would you like to download to get hardware tools?" 18 72 10 \
"nsa310s" "Zyxel NSA310S" \
"nsa320s" "Zyxel NSA320S" \
"nsa325" "Zyxel NSA325" \
"nas326" "Zyxel NAS326" \
"nas520" "Zyxel NAS520" \
"nas540" "Zyxel NAS540" \
"nas542" "Zyxel NAS542" \
"nas5xx" "Enter Download Link ->" \
"onboot" "Get tools on first boot" \
3>&1 1>&2 2>&3)
boardModelEOL=nsa310a
if [ "x$BMODEL" = "xold" ]; then
BMODEL=$(whiptail --default-item ${boardModelEOL} --title "Image Creator Firmware Extraction" --cancel-button "Quit" --ok-button "Select" --menu "Which firmware would you like to use to get tools?" 18 72 10 \
"nsa210" "Zyxel NSA210" \
"nsa220p" "Zyxel NSA220Plus" \
"nsa221" "Zyxel NSA221" \
"nsa2401" "Zyxel NSA2401" \
"nsa310a" "Zyxel NSA310" \
3>&1 1>&2 2>&3)
fi
if [ "x$BMODEL" = "nas5xx" ]; then
INIT=$FWGETURL
FWGETURL=$(whiptail --inputbox "Enter the URL for FW download" 8 78 $INIT --title "FW URL" 3>&1 1>&2 2>&3)
fi
if [ ! -z $BMODEL ]; then
boardModel=${BMODEL}
fi
FWOLDVER="5.11"
case ${boardModel} in
nsa210) FWOLDVER="4.23" ;;
nsa220p) FWOLDVER="3.23" ;;
nsa221) FWOLDVER="4.41" ;;
nsa2401) FWOLDVER="1.11" ;;
nsa310a) FWOLDVER="4.22" ;;
nsa310s) FWOLDVER="4.75(AALH.0)" ;;
nsa320s) FWOLDVER="4.75(AANV.0)" ;;
nsa325) FWOLDVER="4.80" ;;
esac
FWNEWVER="5.21"
case ${boardModel} in
nsa210) FWNEWVER="4.41" ;;
nsa220p) FWNEWVER="3.25" ;;
nsa221) FWNEWVER="4.41" ;;
nsa2401) FWNEWVER="1.20" ;;
nsa310a) FWNEWVER="4.40" ;;
nsa310s) FWNEWVER="4.75(AALH.1)" ;;
nsa320s) FWNEWVER="4.75(AANV.1)" ;;
nsa325) FWNEWVER="4.81" ;;
nas326) FWNEWVER="5.21" ;;
esac
if [ "${boardModel}" != "onboot" -a "${boardModel}" != "nas5xx" ]; then
BFWUSEVER=$(whiptail --default-item ${FWUSEVER} --title "Image Creator Firmware Extraction" --cancel-button "Quit" --ok-button "Select" --menu "Which firmware version would you like to download?" 18 72 10 \
"older" "V${FWOLDVER}" \
"newer" "V${FWNEWVER}" \
3>&1 1>&2 2>&3)
if [ ! -z $BFWUSEVER ]; then
FWUSEVER=${BFWUSEVER}
fi
fi
FSPEED=$(whiptail --default-item ${fanSpeed} --title "Image Creator Fan Speed" --cancel-button "Quit" --ok-button "Select" --menu "Which fan speed should be set on boot (NAS5xx only)?" 18 72 10 \
"0x00000fa0" "600 rpm" \
"0x00000dac" "750 rpm" \
"0x00000bb8" "900 rpm" \
"0x000009c4" "1000 rpm" \
"0x000007d0" "1100 rpm" \
"0x000005dc" "1200 rpm" \
"0x000003e8" "1300 rpm" \
"keep" "No change" \
3>&1 1>&2 2>&3)
if [ ! -z $FSPEED ]; then
fanSpeed=${FSPEED}
fi
mdMountDefault="--defaultno"
if $imageMdMount = true ]; then
mdMountDefault=""
fi
erexitstatus=0
whiptail $mdMountDefault --title "MD mount on boot" --yesno "Autostart MD RAID and mount volumes on boot?" 8 72 || erexitstatus=$?
if [ $erexitstatus = 0 ]; then
imageMdMount=true
else
imageMdMount=false
fi
omvDefault="--defaultno"
if ${imageOmv} = true ]; then
omvDefault=""
fi
erexitstatus=0
whiptail $omvDefault --title "Install openmediavault" --yesno "Would you like to include openmediavault?" 8 72 || erexitstatus=$?
if [ $erexitstatus = 0 ]; then
imageOmv=true
else
imageOmv=false
fi
if ${imageOmv} = true ]; then
installRecommends=1
installISCSITarget=1
installMailServer=1
installNFSServer=1
installNTPServer=1
installSMBServer=1
installMiscServer=1
installSmartctl=1
if [ ${versOmv} -gt 3 ]; then
installISCSITarget=0
fi
if [ ${versOmv} -gt 4 ]; then
installNTPServer=0
fi
omviDefault="--defaultno"
if ${imageOmvInit} = true ]; then
omviDefault=""
fi
erexitstatus=0
whiptail $omviDefault --title "Init openmediavault on boot" --yesno "Autostart omv-initsystem on first boot?" 8 72 || erexitstatus=$?
if [ $erexitstatus = 0 ]; then
imageOmvInit=true
else
imageOmvInit=false
fi
else
askClientOpt
fi
if [ ! -e ${ltspBase}${cpuArch}/tmp/debootstrap.done ]; then
echo " *** debootstrap ..."
mkdir -p ${ltspBase}etc
distKeyringUrl=https://ftp-master.debian.org/keys/${distKeyringFile}
#wget -O ${ltspEtc}${distKeyringFile} ${distKeyringUrl}
wget ${distKeyringUrl} -qO- | gpg --import --no-default-keyring --keyring ${ltspEtc}${distKeyringFile}.gpg
#--keyring=${ltspEtc}${distKeyringFile}
debootstrap --arch ${cpuArch} --foreign --variant=minbase --include=locales --keyring=${ltspEtc}${distKeyringFile}.gpg ${distName} ${ltspBase}${cpuArch} ${distURL}
cp -p /usr/bin/qemu-arm-static ${ltspBase}${cpuArch}/usr/bin/
echo " *** debootstrap second stage ..."
chroot ${ltspBase}${cpuArch} /debootstrap/debootstrap --second-stage || true
touch ${ltspBase}${cpuArch}/tmp/debootstrap.done
else
bash ${ltspBase}drushut-${cpuArch}.sh || true
bash ${ltspBase}drushut-${cpuArch}.sh || true
fi
if [ -e ${ltspBase}${cpuArch}/etc/resolv.conf ]; then
if ! readlink ${ltspBase}${cpuArch}/etc/resolv.conf | grep -q systemd ; then
[ ! -e ${ltspBase}${cpuArch}/etc/resolv.conf-resolvconf ] && chroot ${ltspBase}${cpuArch} cp -pP /etc/resolv.conf /etc/resolv.conf-resolvconf
fi
fi
if [ -e ${ltspBase}${cpuArch}/etc/resolv.conf-resolvconf ]; then
if ! readlink ${ltspBase}${cpuArch}/etc/resolv.conf | grep -q systemd ; then
chroot ${ltspBase}${cpuArch} cp -pP /etc/resolv.conf-resolvconf /etc/resolv.conf
fi
fi
echo " *** add repositories ..."
cat <<EOFASLR | tee ${ltspBase}${cpuArch}/etc/apt/sources.list
deb ${distURL}/ ${distName} ${moreRepo}
#deb-src ${distURL}/ ${distName} ${moreRepo}
EOFASLR
cat <<EOFASLU | tee -a ${ltspBase}${cpuArch}/etc/apt/sources.list
deb ${distURL}/ ${distName}-updates ${moreRepo}
#deb-src ${distURL}/ ${distName}-updates ${moreRepo}
EOFASLU
if [ $distName = bullseye -o $distName = bookworm ]; then
cat <<EOFASLS | tee -a ${ltspBase}${cpuArch}/etc/apt/sources.list
deb ${secuURL}/ ${distName}-security main contrib non-free
#deb-src ${secuURL}/ ${distName}-security main contrib non-free
EOFASLS
else
cat <<EOFASLS | tee -a ${ltspBase}${cpuArch}/etc/apt/sources.list
deb ${secuURL}/ ${distName}/updates main contrib non-free
#deb-src ${secuURL}/ ${distName}/updates main contrib non-free
EOFASLS
fi
touch ${ltspBase}${cpuArch}/tmp/repositories.done
echo " *** language settings ..."
defaultLocale=`echo ${LANG} | sed s/'utf8'/'UTF-8'/g`
defaultLocaleRegion=`echo ${defaultLocale} | cut -d "." -f 1`
defaultLocaleShort=`echo ${defaultLocale} | cut -d "_" -f 1`
defaultLocaleCharMap=`echo ${defaultLocale} | cut -d "." -f 2`
kbLayoutcode=`cat /etc/default/keyboard | grep XKBLAYOUT | cut -d "=" -f 2 | cut -d '"' -f 2`
tzArea=`cat /etc/timezone | cut -d "/" -f 1`
tzZone=`cat /etc/timezone | cut -d "/" -f 2`
kbLayoutcode=`cat /etc/default/keyboard | grep XKBLAYOUT | cut -d "=" -f 2 | cut -d '"' -f 2`
kbModelcode=`cat /etc/default/keyboard | grep XKBMODEL | cut -d "=" -f 2 | cut -d '"' -f 2`
kbVariantcode=`cat /etc/default/keyboard | grep XKBVARIANT | cut -d "=" -f 2 | cut -d '"' -f 2`
kbOptionscode=`cat /etc/default/keyboard | grep XKBOPTIONS | cut -d "=" -f 2 | cut -d '"' -f 2`
kbXkbkeymap="${kbLayoutcode}"
if [ -n $kbVariantcode ]; then
kbXkbkeymap="${kbLayoutcode}(${kbVariantcode})"
fi
if [ ! -e ${ltspBase}${cpuArch}/tmp/language.done ]; then
if $notUbuntu ; then
echo 'LANG='${defaultLocale} | tee ${ltspBase}${cpuArch}/etc/default/locale
[ ! -e ${ltspBase}${cpuArch}/etc/locale.gen-backup ] && cp -p ${ltspBase}${cpuArch}/etc/locale.gen ${ltspBase}${cpuArch}/etc/locale.gen-backup
echo ${defaultLocale}' '${defaultLocaleCharMap} | tee ${ltspBase}${cpuArch}/etc/locale.gen
else
chroot ${ltspBase}${cpuArch} apt-get install -y language-pack-en-base
chroot ${ltspBase}${cpuArch} apt-get install -y language-pack-${defaultLocaleShort}-base
#sed -i s/'LANG=C'/'LANG=de_DE'/g /etc/default/locale
echo 'LANG="'${defaultLocale}'"' | tee ${ltspBase}${cpuArch}/etc/default/locale
fi
chroot ${ltspBase}${cpuArch} apt-get update
chroot ${ltspBase}${cpuArch} locale-gen ${defaultLocaleRegion}
chroot ${ltspBase}${cpuArch} dpkg-reconfigure -f noninteractive locales
if $notUbuntu ; then
#cat ${ltspBase}${cpuArch}/etc/locale.gen | grep '# '${defaultLocaleShort} | sed s/'# '${defaultLocaleShort}/${defaultLocaleShort}/g | tee ${ltspBase}${cpuArch}/etc/locale.gen
cat ${ltspBase}${cpuArch}/etc/locale.gen-backup | sed s/'# '${defaultLocaleShort}/${defaultLocaleShort}/g | grep ^${defaultLocaleShort} | tee ${ltspBase}${cpuArch}/etc/locale.gen
chroot ${ltspBase}${cpuArch} debconf-set-selections <<EOFDRUDCSLO
locales locales/default_environment_locale select ${defaultLocale}
EOFDRUDCSLO
chroot ${ltspBase}${cpuArch} dpkg-reconfigure -f noninteractive locales
fi
grep -q 'LANGUAGE=' ${ltspBase}${cpuArch}/etc/default/locale || echo 'LANGUAGE="'${defaultLocaleShort}'"' | tee -a ${ltspBase}${cpuArch}/etc/default/locale
grep -q 'LC_MESSAGES=' ${ltspBase}${cpuArch}/etc/default/locale || echo 'LC_MESSAGES="'${defaultLocale}'"' | tee -a ${ltspBase}${cpuArch}/etc/default/locale
chroot ${ltspBase}${cpuArch} apt-get update
echo "${tzArea}/${tzZone}" | tee ${ltspBase}${cpuArch}/etc/timezone
[ -e ${ltspBase}${cpuArch}/usr/share/zoneinfo/${tzArea}/${tzZone} ] && ln -sf /usr/share/zoneinfo/${tzArea}/${tzZone} ${ltspBase}${cpuArch}/etc/localtime
mkdir -p ${ltspBase}${cpuArch}/root/board-debs
cat <<EOFDRUDCSI | tee ${ltspBase}${cpuArch}/root/board-debs/debconf-selections.txt
console-setup console-setup/codesetcode string Lat15
console-setup console-setup/fontsize-fb47 select 16
console-setup console-setup/codeset47 select # Latin1 and Latin5 - western Europe and Turkic languages
console-setup console-setup/fontsize string 16
console-setup console-setup/store_defaults_in_debconf_db boolean true
console-setup console-setup/charmap47 select ${defaultLocaleCharMap}
console-setup console-setup/fontface47 select VGA
console-setup console-setup/fontsize-text47 select 16
console-setup console-setup/ask_detect boolean false
console-setup console-setup/charmap select ${defaultLocaleCharMap}
console-setup console-setup/codeset select # Latin1 and Latin5 - western Europe and Turkic languages
console-setup console-setup/compose select No compose key
console-setup console-setup/detected note
console-setup console-setup/fontface select VGA
console-setup console-setup/fontsize-fb select 16
console-setup console-setup/fontsize-text select 16
console-setup console-setup/layoutcode string ${kbLayoutcode}
console-setup console-setup/modelcode string ${kbModelcode}
console-setup console-setup/optionscode string ${kbOptionscode}
console-setup console-setup/switch select No temporary switch
console-setup console-setup/toggle select No toggling
console-setup console-setup/ttys string /dev/tty[1-6]
console-setup console-setup/unsupported_config_layout boolean true
console-setup console-setup/unsupported_config_options boolean true
console-setup console-setup/unsupported_layout boolean true
console-setup console-setup/unsupported_options boolean true
console-setup console-setup/variantcode string ${kbVariantcode}
keyboard-configuration keyboard-configuration/modelcode string ${kbModelcode}
keyboard-configuration keyboard-configuration/ctrl_alt_bksp boolean false
keyboard-configuration keyboard-configuration/optionscode string ${kbOptionscode}
keyboard-configuration keyboard-configuration/compose select No compose key
keyboard-configuration keyboard-configuration/layoutcode string ${kbLayoutcode}
keyboard-configuration keyboard-configuration/toggle select No toggling
keyboard-configuration keyboard-configuration/store_defaults_in_debconf_db boolean true
keyboard-configuration console-setup/ask_detect boolean false
keyboard-configuration keyboard-configuration/unsupported_config_layout boolean true
keyboard-configuration keyboard-configuration/xkb-keymap select ${kbXkbkeymap}
keyboard-configuration keyboard-configuration/variantcode string ${kbVariantcode}
keyboard-configuration keyboard-configuration/unsupported_layout boolean true
keyboard-configuration keyboard-configuration/switch select No temporary switch
keyboard-configuration keyboard-configuration/unsupported_options boolean true
keyboard-configuration keyboard-configuration/unsupported_config_options boolean true
tzdata tzdata/Areas select ${tzArea}
tzdata tzdata/Zones/${tzArea} select ${tzZone}
EOFDRUDCSI
touch ${ltspBase}${cpuArch}/tmp/language.done
fi
cat <<EOFDRUDCSJN | tee ${ltspBase}${cpuArch}/root/board-debs/debconf-selections-nbd.txt
jackd2 jackd/tweak_rt_limits boolean false
nbd-client nbd-client/killall boolean false
nbd-client nbd-client/host string
nbd-client nbd-client/port string
nbd-client nbd-client/device string
nbd-client nbd-client/type select raw
nbd-client nbd-client/number string 0
nbd-client nbd-client/extra string
EOFDRUDCSJN
cat <<EOFDRUDCSD | tee ${ltspBase}${cpuArch}/root/board-debs/debconf-selections-dash.txt
dash dash/sh boolean false
EOFDRUDCSD
echo " *** install packages ..."
WriteConfigFile
chroot ${ltspBase}${cpuArch} mount -t proc /proc /proc
mkdir -p ${ltspBase}${cpuArch}/root/bin
cp ${ltspBase}dru-nas.txt ${ltspBase}${cpuArch}/root/bin/dru-nas.sh
chmod ugo+rx ${ltspBase}${cpuArch}/root/bin/dru-nas.sh
cp ${ltspBase}dru-omv.txt ${ltspBase}${cpuArch}/root/bin/dru-omv.sh
chmod ugo+rx ${ltspBase}${cpuArch}/root/bin/dru-omv.sh
cp ${ltspBase}dru-usr.txt ${ltspBase}${cpuArch}/root/bin/dru-usr.sh
chmod ugo+rx ${ltspBase}${cpuArch}/root/bin/dru-usr.sh
#cp ${ltspBase}dru-post.txt ${ltspBase}${cpuArch}/root/bin/dru-post.sh
#chmod ugo+rx ${ltspBase}${cpuArch}/root/bin/dru-post.sh
mkdir -p ${ltspBase}${cpuArch}/root/source
cp -p ${ltspBase}archives/openmediavault-init-scripts.tar.gz ${ltspBase}${cpuArch}/root/source/
chroot ${ltspBase}${cpuArch} bash -e /root/bin/dru-nas.sh
if [ ${imageOmv} = true ]; then
chroot ${ltspBase}${cpuArch} bash -e /root/bin/dru-omv.sh
fi
linuxImageSuffix="-generic"
if [ $cpuArch = "i386" ]; then
linuxImageSuffix="-686-pae"
elif [ $cpuArch = "amd64" ]; then
linuxImageSuffix="-amd64"
elif [ $cpuArch = "armhf" ]; then
linuxImageSuffix="-armmp"
fi
mkdir -p ${ltspBase}${cpuArch}/root/board-debs
cat <<EOFDRULININST | tee ${ltspBase}${cpuArch}/root/board-debs/drulininst.sh > /dev/null
#!/bin/bash
apt-get install -y linux-image${linuxImageSuffix}
if [ $cpuArch = amd64 -o $cpuArch = i386 ]; then
DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -y grub-pc
update-grub-gfxpayload || ${notUbuntu}
mkdir -p /boot/grub/fonts
mkdir -p /boot/grub/i386-pc
mkdir -p /boot/grub/locale
cp -p /usr/lib/grub/i386-pc/*.lst /boot/grub/i386-pc/
cp -p /usr/lib/grub/i386-pc/*.mod /boot/grub/i386-pc/
cp -p /usr/lib/grub/i386-pc/*.o /boot/grub/i386-pc/
cp -p /usr/lib/grub/i386-pc/boot.img /boot/grub/i386-pc/
#core.img?
cp -p /usr/share/grub/unicode.pf2 /boot/grub/fonts/
cp -p /usr/share/grub/unicode.pf2 /boot/grub/
cp -p /usr/share/locale-langpack/${defaultLocaleShort}/LC_MESSAGES/grub.mo /boot/grub/locale/${defaultLocaleShort}.mo || ${notUbuntu}
apt-get install -y memtest86+
[ -e /usr/share/grub/default/grub ] && cp -p /usr/share/grub/default/grub /etc/default/grub
# sed -i s/'GRUB_HIDDEN_TIMEOUT=0'/'#GRUB_HIDDEN_TIMEOUT=0'/g /etc/default/grub
if grep GRUB_RECORDFAIL_TIMEOUT /etc/default/grub > /dev/null ; then
sed -i 's|GRUB_RECORDFAIL_TIMEOUT=.*|GRUB_RECORDFAIL_TIMEOUT=10|g' /etc/default/grub
else
echo "GRUB_RECORDFAIL_TIMEOUT=10" | tee -a /etc/default/grub > /dev/null
fi
fi
touch /tmp/\`basename \$0\`.done
echo "OK"
EOFDRULININST
chmod ugo+rx ${ltspBase}${cpuArch}/root/board-debs/drulininst.sh
if [ "${cpuArch:0:3}" != "arm" ]; then
true
elif [ -e ${ltspBase}${cpuArch}/bin/systemctl.druic -a -e ${ltspBase}${cpuArch}/bin/systemctl.distrib ]; then
chroot ${ltspBase}${cpuArch} rm /bin/systemctl
chroot ${ltspBase}${cpuArch} dpkg-divert --local --rename --remove /bin/systemctl
if [ -e ${ltspBase}${cpuArch}/bin/logger.distrib ]; then
chroot ${ltspBase}${cpuArch} rm /bin/logger
chroot ${ltspBase}${cpuArch} dpkg-divert --local --rename --remove /bin/logger
fi
fi
chroot ${ltspBase}${cpuArch} systemctl enable ssh
chroot ${ltspBase}${cpuArch} systemctl disable quota || true
chroot ${ltspBase}${cpuArch} systemctl disable quotaon
chroot ${ltspBase}${cpuArch} systemctl disable systemd-quotacheck
if [ "${cpuArch:0:3}" != "arm" ]; then
true
elif [ -e ${ltspBase}${cpuArch}/sbin/quotacheck -a ! -e ${ltspBase}${cpuArch}/sbin/quotacheck.distrib ]; then
chroot ${ltspBase}${cpuArch} dpkg-divert --local --rename --add /sbin/quotacheck
chroot ${ltspBase}${cpuArch} ln -s /bin/true /sbin/quotacheck
fi
if [ ${imageOmv} = true ]; then
chroot ${ltspBase}${cpuArch} systemctl disable openmediavault-beep-down
chroot ${ltspBase}${cpuArch} systemctl disable openmediavault-beep-up
fi
if [ "${cpuArch:0:3}" != "arm" ]; then
chroot ${ltspBase}${cpuArch} bash -e /root/board-debs/drulininst.sh
cd ${ltspBase}${cpuArch}
tar xzvf ${ltspBase}archives/${boardName}-bootloader-${cpuArch}.tar.gz
cd -
fi
for z in `ls ${ltspBase}archives/linux-bsp-*-${cpuArch}.zip` ; do
zd=`basename ${z}`
zd=${zd/linux-bsp-/}
zd=${zd/-${cpuArch}.zip/}
zs=install-bsp-boot.sh
mkdir -p ${ltspBase}${cpuArch}/root/board-debs/${zd}
cd ${ltspBase}${cpuArch}/root/board-debs/${zd}
unzip -o ${z}
if [ -e install-bsp.sh ]; then
zs=install-bsp.sh
fi
cd - > /dev/null
sed -i s/'sudo '/''/g ${ltspBase}${cpuArch}/root/board-debs/${zd}/${zs}
chroot ${ltspBase}${cpuArch} /root/board-debs/${zd}/${zs}
cd ${ltspBase}${cpuArch}/root/board-debs
if [ ! -e ${zs} ]; then
ln -s ${zd}/${zs} ${zs}
fi
cd - > /dev/null
done
chroot ${ltspBase}${cpuArch} bash -e /root/bin/dru-usr.sh
bash ${ltspBase}drushut-${cpuArch}.sh || true
bash ${ltspBase}drushut-${cpuArch}.sh || true
chroot ${ltspBase}${cpuArch} umount /proc || true
echo " *** configuration ..."
INIT=$imageHostname
imageHostname=$(whiptail --inputbox "Enter the hostname" 8 78 $INIT --title "Hostname" 3>&1 1>&2 2>&3)
INIT=$imageEth0Ip
imageEth0Ip=$(whiptail --inputbox "Enter the IP for eth0/egiga0 (leave empty for dhcp)" 8 78 $INIT --title "First NIC Interface IP" 3>&1 1>&2 2>&3)
if [ "x${imageEth0Ip}" != "x" -a "x${imageEth0Ip}" != "xdhcp" ]; then
INIT=$imageEth0Mask
imageEth0Mask=$(whiptail --inputbox "Enter the network mask for eth0/egiga0" 8 78 $INIT --title "First NIC Interface Mask" 3>&1 1>&2 2>&3)
else
imageRouter=
imageDNS=
fi
INIT=$imageEth1Ip
imageEth1Ip=$(whiptail --inputbox "Enter the IP for eth1/egiga1 (leave empty to skip)" 8 78 $INIT --title "Second NIC Interface IP" 3>&1 1>&2 2>&3)
if [ "x${imageEth1Ip}" != "x" -a "x${imageEth1Ip}" != "xdhcp" ]; then
INIT=$imageEth1Mask
imageEth1Mask=$(whiptail --inputbox "Enter the network mask for eth1/egiga1" 8 78 $INIT --title "Second NIC Interface Mask" 3>&1 1>&2 2>&3)
fi
INIT=$imageRouter
imageRouter=$(whiptail --inputbox "Enter the IP for gateway/router (leave empty to skip)" 8 78 $INIT --title "Gateway IP" 3>&1 1>&2 2>&3)
INIT=$imageDNS
imageDNS=$(whiptail --inputbox "Enter the IP for DNS/nameserver (leave empty to skip)" 8 78 $INIT --title "DNS IP" 3>&1 1>&2 2>&3)
#date "+%Y-%m-%d %H:%M:%S"
date "+%Y-%m-01 00:%M:%S" | tee ${ltspBase}${cpuArch}/etc/fake-hwclock.data
cat <<EOFDRUNI | tee ${ltspBase}${cpuArch}/etc/network/interfaces-dhcp > /dev/null
# The loopback network interface
auto lo
iface lo inet loopback
EOFDRUNI
#iface default inet dhcp
#allow-hotplug wlan0
#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf