-
Notifications
You must be signed in to change notification settings - Fork 2
/
install
executable file
·983 lines (748 loc) · 27.5 KB
/
install
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
#!/bin/bash
# Common routines
function bindFolder {
local SOURCE=$1
local TARGET=$2
mount --bind ${SOURCE} ${TARGET} || exitInstall
printInfo " - Bound \"${SOURCE}\" to \"${TARGET}\"."
}
function canRun {
if [ ${PARAM_RESUME_LINENO} -eq 0 ] || [ ${BASH_LINENO[0]} -ge ${PARAM_RESUME_LINENO} ]; then
true
else
printInfo " - Skipped block execution at line ${BASH_LINENO[0]}."
false
fi
}
function createFolder {
local FOLDER=$1
mkdir -p ${FOLDER} > /dev/null || exitInstall
printInfo " - Created folder \"${FOLDER}\"."
}
function exitInstall {
EXIT_CODE=$?
ERROR_LINE=${BASH_LINENO[0]}
printInfo ""
{
printInfo "Installation aborted at line ${ERROR_LINE}."
if [ ${RESUME_LINENO} -gt 0 ]; then
printInfo "You may fix the problem and resume the installation by adding \"--resume ${RESUME_LINENO}\"."
fi
} | boxes -d shell -i none
exit ${EXIT_CODE}
}
function mountDevice {
local DEVICE=$1
local FOLDER=$2
mount ${DEVICE} ${FOLDER} > /dev/null || exitInstall
printInfo " - Mounted device \"${DEVICE}\" to \"${FOLDER}\"."
}
function printError {
echo -e "$@" >&2
}
function printInfo {
echo -e "$@" >&1
}
function printPerforming {
printInfo "\nPerforming \"${FUNCNAME[1]}\"...\n"
}
function saveResumeCheckPoint {
RESUME_LINENO=${BASH_LINENO[0]}
}
function unbindFolder {
local FOLDER=$1
if mountpoint -q ${FOLDER}; then
umount ${FOLDER} > /dev/null || exitInstall
printInfo " - Unbound folder \"${FOLDER}\"."
fi
}
function umountFolder {
local FOLDER=$1
if mountpoint -q ${FOLDER}; then
umount -l ${FOLDER} > /dev/null || exitInstall
printInfo " - Unmounted folder \"${FOLDER}\"."
fi
}
function removeFolder {
local FOLDER=$1
rm -rf ${FOLDER} > /dev/null || exitInstall
printInfo " - Removed folder \"${FOLDER}\"."
}
# Parse arguments
PARAM_CLEAN=0
PARAM_RESUME_LINENO=0
PARAM_INITRD_TOOL=2
PARAM_BOOT_DEV=
PARAM_BOOT_DEV_GRUB_INDEX=0
PARAM_BOOT_PART=1
PARAM_HOST_UUID=
PARAM_HOST_FSTYPE=ntfs-3g
PARAM_HOST_FSOPTIONS=noatime
PARAM_LOOP_DIR=.linux-loops
PARAM_LOOP_SIZE=0
PARAM_LVM_VG=vg_system
PARAM_LVM_LV_ROOT=lv_root
PARAM_SWAP_FILE=swap.raw
PARAM_SWAP_SIZE=0
function showHelp {
printInfo "Synopsis:\n"
printInfo " $(basename $0) [OPTIONS]\n"
printInfo " Executive arguments:\n"
printInfo " -h | --help : this screen."
printInfo " -c | --clean : clean already performed steps."
printInfo " -r | --resume : resume execution from a given line number."
printInfo ""
printInfo " Mandatory arguments:\n"
printInfo " -b | --boot-device : boot (USB) device (eg: /dev/sdc)."
printInfo " -u | --host-uuid : loop files host device UUID (got by blkid)."
printInfo " -f | --host-fs-type : host device filesystem type (default: \"${PARAM_HOST_FSTYPE}\")."
printInfo " -s | --loopback-file-size : loopback main file size (in Gigabytes)."
printInfo " -w | --swap-file-size : swap file size (in Gigabytes)."
printInfo ""
printInfo " Optional arguments:\n"
printInfo " -g | --boot-device-grub-index : boot device grub index (eg: 0 for '(hd0,msdos1)'; default: ${PARAM_BOOT_DEV_GRUB_INDEX})."
printInfo " -p | --boot-partition-index : boot partition index (default: ${PARAM_BOOT_PART})."
printInfo " -i | --initrd-tool : InitRD tools => 1 = initramfs-tools, 2 = dracut (default: ${PARAM_INITRD_TOOL})."
printInfo " -o | --host-fs-options : host device filesystem options (default: \"${PARAM_HOST_FSOPTIONS}\")."
printInfo " -d | --loops-dir : host device loopback files root relative folder (default: \"${PARAM_LOOP_DIR}\")."
printInfo " -v | --volume-group-name : volume group name (default: \"${PARAM_LVM_VG}\")."
printInfo " -l | --logical-volume-name : root logical volume name (default: \"${PARAM_LVM_LV_ROOT}\")."
printInfo ""
}
function parseOptions {
if [ $# -eq 0 ]; then
showHelp
exit 1
fi
GET_OPT=$(getopt -o -hi::b::p::u::f::g::o::d::s::w::r::v::l::c --long help,initrd-tool::,boot-device::,boot-device-grub-index::,boot-partition-index::,host-uuid::,host-fs-type::,host-fs-options::,loops-dir::,loopback-file-size::,swap-file-size::,resume::,volume-group-name,logical-volume-name,clean -- "$@" 2>&1 1>/dev/null)
EXIT_CODE=$?
if [ ${EXIT_CODE} != 0 ]; then
printError "Arguments parsing error(s):"
printError "$(echo "${GET_OPT}" | sed -e 's/getopt: / - /')"
exit $?
fi
while true; do
case "$1" in
-b | --boot-device )
PARAM_BOOT_DEV=$2
shift 2
;;
-c | --clean )
PARAM_CLEAN=1
shift
;;
-d | --loops-dir )
if [ ! -z "$2" ]; then
PARAM_LOOP_DIR=$2
shift 2
else
printError "Missing host loopback files folder."
exit 1
fi
;;
-f | --host-fs-type )
if [ ! -z "$2" ]; then
PARAM_HOST_FSTYPE=$2
shift 2
else
printError "Missing host UUID."
exit 1
fi
;;
-g | --boot-device-grub-index )
PARAM_BOOT_DEV_GRUB_INDEX=$2
shift 2
;;
-h | --help )
showHelp
exit 1
;;
-i | --initrd-tool )
case $2 in
[1-2] )
PARAM_INITRD_TOOL=$2
shift 2
;;
* )
printError "Invalid InitRD tool ($2)."
exit 1
;;
esac
;;
-l | --logical-volume-name )
if [ ! -z "$2" ]; then
PARAM_LVM_LV_ROOT=$2
shift 2
else
printError "Missing root logical volume name."
exit 1
fi
;;
-o | --host-fs-options )
PARAM_HOST_FSOPTIONS=$2
shift 2
;;
-p | --boot-partition-index )
case $2 in
[0-9]* )
PARAM_BOOT_PART=$2
shift 2
;;
* )
printError "Invalid boot partition index ($2)."
exit 1
;;
esac
;;
-r | --resume )
case $2 in
[0-9]* )
PARAM_RESUME_LINENO=$2
shift 2
;;
* )
printError "Invalid resume line number ($2)."
exit 1
;;
esac
;;
-s | --loopback-file-size )
case $2 in
[0-9]* )
PARAM_LOOP_SIZE=$2
shift 2
;;
* )
printError "Invalid main loopback file size ($2)."
exit 1
;;
esac
;;
-u | --host-uuid )
if [ ! -z "$2" ]; then
PARAM_HOST_UUID=$2
shift 2
else
printError "Missing host UUID."
exit 1
fi
;;
-v | --volume-group-name )
if [ ! -z "$2" ]; then
PARAM_LVM_VG=$2
shift 2
else
printError "Missing volume group name."
exit 1
fi
;;
-w | --swap-file-size )
case $2 in
[0-9]* )
PARAM_SWAP_SIZE=$2
shift 2
;;
* )
printError "Invalid swap file size ($2)."
exit 1
;;
esac
;;
* )
break
;;
esac
done
if [ ${PARAM_CLEAN} -eq 1 ]; then
PARAM_RESUME_LINENO=0 # Force restart
fi
}
parseOptions $@
# Environment setup
CURRENT_DIR=$(readlink -f $(dirname $0))
RESUME_LINENO=0
BOOT_MNT=/mnt/boot
BOOT_PART=${PARAM_BOOT_DEV}${PARAM_BOOT_PART}
HOST_UUID=UUID=${PARAM_HOST_UUID}
HOST_MNT=/mnt/host
LOOP_DEV=$(losetup -f)
LOOP_DIR=${HOST_MNT}/${PARAM_LOOP_DIR}
LOOP_FILE=${LOOP_DIR}/${PARAM_LVM_VG}0.lvm
LOOP_SIZE=$((PARAM_LOOP_SIZE * 1000))
LOOP_MAX=$(ls -1l /dev/loop* | grep -E '^b.*' | awk '{ print $6 }' | sort -r | head -1)
SWAP_FILE=${LOOP_DIR}/${PARAM_SWAP_FILE}
SWAP_SIZE=$((PARAM_SWAP_SIZE * 1000))
LVM_TARGET_MNT=/mnt/target
LVM_DEFAULT_CONF=${LVM_TARGET_MNT}/etc/default
LVM_GRUB_CONF=${LVM_TARGET_MNT}/etc/grub.d
LVM_DRACUT_CONF=${LVM_TARGET_MNT}/etc/dracut.conf.d
LVM_DRACUT_MODULES=${LVM_TARGET_MNT}/usr/lib/dracut/modules.d
LVM_INITRAMFS_CONF=${LVM_TARGET_MNT}/etc/initramfs-tools/conf.din
LVM_INITRAMFS_SCRIPTS=${LVM_TARGET_MNT}/etc/initramfs-tools/scripts
LVM_LOGROTATE_CONF=${LVM_TARGET_MNT}/etc/logrotate.d
LVM_RSYSLOG_CONF=${LVM_TARGET_MNT}/etc/rsyslog.d
LVM_LV_ROOT_DEV=/dev/${PARAM_LVM_VG}/${PARAM_LVM_LV_ROOT}
# Pre-requisites check
function checkPreRequisites {
if [[ $EUID > 0 ]]; then
printError "Please run as root/sudo!"
exit 1
fi
if [ ! -b "${PARAM_BOOT_DEV}" ]; then
printError "Invalid boot device (\"${PARAM_BOOT_DEV}\""")."
exit 1
fi
if [ ! -b "${PARAM_BOOT_DEV}${PARAM_BOOT_PART}" ]; then
printError "Invalid boot partition \"${PARAM_BOOT_DEV}${PARAM_BOOT_PART}\"."
exit 1
fi
blkid -s UUID -o value | grep "${PARAM_HOST_UUID}" &> /dev/null
EXIT_CODE=$?
if [ -z "${PARAM_HOST_UUID}" ] || [ ${EXIT_CODE} -ne 0 ]; then
printError "Invalid host UUID (\"${PARAM_HOST_UUID}\")."
exit 1
fi
if [ -z "${PARAM_HOST_FSTYPE}" ]; then
printError "Invalid or missing host filesystem type."
exit 1
fi
if [ -z "${PARAM_LOOP_DIR}" ]; then
printError "Invalid or missing host loopback files folder."
exit 1
fi
if [ "${LOOP_SIZE}" -le 0 ]; then
printError "Invalid main loopback file size (${LOOP_SIZE})."
exit 1
fi
if [ -z "${PARAM_LVM_VG}" ]; then
printError "Invalid or missing volume group name."
exit 1
fi
if [ -z "${PARAM_LVM_LV_ROOT}" ]; then
printError "Invalid or missing root logical volume name."
exit 1
fi
if [ -z "${PARAM_SWAP_SIZE}" ] || [ "${PARAM_SWAP_SIZE}" -le 0 ]; then
printError "Invalid swap file size (${PARAM_SWAP_SIZE})."
exit 1
fi
[ -x /usr/bin/boxes ] || apt-get install -y boxes || exit 1
}
checkPreRequisites
# Ask for confirmation
function askForConfirmation {
{
printInfo "You have chosen the following settings:\n"
set | grep -e "^PARAM_"
} | boxes -d shell -i none
printInfo "\nDo you want to proceed (y/n)? "
read -r
[[ $REPLY =~ ^[Yy]$ ]] || exit 2
if [ ${PARAM_CLEAN} -eq 1 ]; then
printInfo ""
printInfo "Attention! You have chosen to clean all. Are you sure (y/n)?" | boxes -d shell -i none
read -r
[[ $REPLY =~ ^[Yy]$ ]] || exit 2
printInfo ""
fi
}
askForConfirmation
# Clean
function doCleanUp {
local WANT_REMOVE_ALL=$1
if [ "${WANT_REMOVE_ALL}" -eq 1 ]; then
printInfo " - 'Remove all' flag has been set!"
else
printPerforming
fi
umountFolder ${LVM_TARGET_MNT}
removeFolder ${LVM_TARGET_MNT}
umountFolder ${BOOT_MNT}
removeFolder ${BOOT_MNT}
if [ -f SWAP_FILE ] && [ "${WANT_REMOVE_ALL}" -eq 1 ]; then
rm ${SWAP_FILE} > /dev/null || exitInstall
printInfo " - Removed swap file \"${SWAP_FILE}\"."
fi
if [ "${WANT_REMOVE_ALL}" -eq 1 ]; then
if lvdisplay ${LVM_LV_ROOT_DEV} &> /dev/null; then
{
lvchange -an ${LVM_LV_ROOT_DEV} > /dev/null \
&& lvremove -y ${LVM_LV_ROOT_DEV} > /dev/null
} || exitInstall
printInfo " - Removed LV \"${LVM_LV_ROOT_DEV}\"."
fi
if vgdisplay ${PARAM_LVM_VG} &> /dev/null; then
{
vgchange -an ${PARAM_LVM_VG} > /dev/null \
&& vgremove -y ${PARAM_LVM_VG} > /dev/null
} || exitInstall
printInfo " - Removed VG \"${PARAM_LVM_VG}\"."
fi
else
if lvdisplay ${LVM_LV_ROOT_DEV} &> /dev/null; then
lvchange -an ${LVM_LV_ROOT_DEV} > /dev/null || exitInstall
printInfo " - Deactivated LV \"${LVM_LV_ROOT_DEV}\"."
fi
if vgdisplay ${PARAM_LVM_VG} &> /dev/null; then
vgchange -an ${PARAM_LVM_VG} > /dev/null|| exitInstall
printInfo " - Deactivated VG \"${PARAM_LVM_VG}\"."
fi
fi
if losetup -nl | grep ${LOOP_DEV} &> /dev/null; then
if pvdisplay ${LOOP_DEV} &> /dev/null && [ "${WANT_REMOVE_ALL}" -eq 1 ]; then
pvremove -y ${LOOP_DEV} > /dev/null || exitInstall
printInfo " - Removed PV \"${LOOP_DEV}\"."
fi
losetup -d ${LOOP_DEV} > /dev/Jnull || exitInstall
printInfo " - Detached main loopback device \"${LOOP_DEV}\"."
fi
if [ -f ${LOOP_FILE} ] && [ "${WANT_REMOVE_ALL}" -eq 1 ]; then
rm ${LOOP_FILE} > /dev/null || exitInstall
printInfo " - Removed main loopback file \"${LOOP_FILE}\"."
fi
if mountpoint -q ${HOST_MNT}; then
printInfo " - Sleeping for a while (to avoid busy error)..."
losetup -D &> /dev/null
sleep 5
umountFolder ${HOST_MNT}
fi
removeFolder ${HOST_MNT}
}
[ ${PARAM_CLEAN} -eq 1 ] && doCleanUp 1
# System loop files setup
function doSystemLoopFilesSetup {
printPerforming
canRun && createFolder ${HOST_MNT}
saveResumeCheckPoint
canRun && mountDevice ${HOST_UUID} ${HOST_MNT}
saveResumeCheckPoint
canRun && createFolder ${LOOP_DIR}
saveResumeCheckPoint
if canRun; then
printInfo " - Creating main loopback file \"${LOOP_FILE}\"..."
dd status=progress if=/dev/zero of=${LOOP_FILE} bs=1M count=${LOOP_SIZE} || exitInstall
printInfo " - Created main loopback file \"${LOOP_FILE}\"."
fi
saveResumeCheckPoint
if canRun; then
losetup ${LOOP_DEV} ${LOOP_FILE} || exitInstall
printInfo " - Attached loopback device \"${LOOP_DEV}\" to file \"${LOOP_FILE}\"."
fi
saveResumeCheckPoint
if canRun; then
pvcreate -v ${LOOP_DEV} > /dev/null || exitInstall
printInfo " - Created PV \"${LOOP_DEV}\"."
fi
saveResumeCheckPoint
if canRun; then
vgcreate -v ${PARAM_LVM_VG} ${LOOP_DEV} > /dev/null || exitInstall
printInfo " - Created VG \"${PARAM_LVM_VG}\"."
fi
saveResumeCheckPoint
if canRun; then
lvcreate -v -l 100%FREE -n ${PARAM_LVM_LV_ROOT} ${PARAM_LVM_VG} > /dev/null || exitInstall
printInfo " - Created LV \"${LVM_LV_ROOT_DEV}\"."
fi
saveResumeCheckPoint
}
doSystemLoopFilesSetup
# Linux distribution installation
function doLinuxDistributionInstallation {
printPerforming
saveResumeCheckPoint
if canRun; then
{
printInfo " Ubiquity will start shortly, so you have to enter on your own the following settings:\n"
printInfo " - Partitioning : \"something else\"."
printInfo " - Device for boot loader installation : \"${PARAM_BOOT_DEV}\"."
printInfo " - Boot partition (/boot) : \"${BOOT_PART}\", ext4, at least 512Mb size."
printInfo " - Root partition (/) : \"/dev/mapper/${PARAM_LVM_VG}-${PARAM_LVM_LV_ROOT}\", ext4, 100% size."
printInfo " - Swap partition : none for the moment (answer to continue without swap space)."
printInfo "\n Please answer to continue testing at installation end!"
} | boxes -d shell -i none
printInfo "\n Do you want to proceed with Ubiquity (y/n)?"
read -r
[[ $REPLY =~ ^[Yy]$ ]] || exitInstall
printInfo " Starting Ubiquity..."
ubiquity || exitInstall
printInfo "\n Ubiquity does not always reports a correct exit code, so: do you want to continue with installation (y/n)?"
read -r
[[ $REPLY =~ ^[Yy]$ ]] || exitInstall
saveResumeCheckPoint
fi
canRun && umountFolder /target # Sometimes left by Ubiquity!
saveResumeCheckPoint
}
doLinuxDistributionInstallation
# Swap file setup
function doSwapFileSetup {
printPerforming
if canRun; then
printInfo " - Creating swap file \"${SWAP_FILE}\"..."
dd status=progress if=/dev/zero of=${SWAP_FILE} bs=1M count=${SWAP_SIZE} || exitInstall
printInfo " - Created swap file \"${SWAP_FILE}\"."
fi
saveResumeCheckPoint
if canRun; then
mkswap ${SWAP_FILE} > /dev/null || exitInstall
printInfo " - Initialized swap file \"${SWAP_FILE}\"."
fi
saveResumeCheckPoint
if canRun; then
chmod 0600 ${SWAP_FILE} || exitInstall
printInfo " - Set swap file \"${SWAP_FILE}\" mode (if supported by the target filesystem)."
fi
saveResumeCheckPoint
canRun && createFolder ${LVM_TARGET_MNT}
saveResumeCheckPoint
canRun && mountDevice ${LVM_LV_ROOT_DEV} ${LVM_TARGET_MNT}
saveResumeCheckPoint
if canRun; then
local TMP_SWAP_FILE=/host/${PARAM_LOOP_DIR}/${PARAM_SWAP_FILE}
echo -e "\n${TMP_SWAP_FILE}\tnone\tswap\tsw,mode=600\t0\t0\n" >> ${LVM_TARGET_MNT}/etc/fstab || exitInstall
printInfo " - Added swap file \"${TMP_SWAP_FILE}\" to target FSTAB file."
fi
saveResumeCheckPoint
}
doSwapFileSetup
# InitRd image setup
function doInitRdImageSetup_Pre {
printPerforming
canRun && createFolder ${BOOT_MNT}
saveResumeCheckPoint
canRun && mountDevice ${BOOT_PART} ${BOOT_MNT}
saveResumeCheckPoint
if canRun; then
echo "nameserver 8.8.8.8" > ${LVM_TARGET_MNT}/etc/resolv.conf || exitInstall
printInfo " - Configured Google DNS (maybe needed by APT)."
fi
saveResumeCheckPoint
canRun && bindFolder /dev ${LVM_TARGET_MNT}/dev
saveResumeCheckPoint
canRun && bindFolder /dev/pts ${LVM_TARGET_MNT}/dev/pts
saveResumeCheckPoint
canRun && bindFolder /sys ${LVM_TARGET_MNT}/sys
saveResumeCheckPoint
canRun && bindFolder /proc ${LVM_TARGET_MNT}/proc
saveResumeCheckPoint
canRun && bindFolder /run ${LVM_TARGET_MNT}/run
saveResumeCheckPoint
canRun && bindFolder ${BOOT_MNT} ${LVM_TARGET_MNT}/boot
saveResumeCheckPoint
}
doInitRdImageSetup_Pre
function doInitRdImageSetup_Dracut {
printPerforming
if canRun; then
chroot \
${LVM_TARGET_MNT} \
dpkg -l | awk '{ print $2 }' | grep -e '^dracut$' &> /dev/null
if [ $? -ne 0 ]; then
printInfo " - Installing Dracut..."
chroot \
${LVM_TARGET_MNT} \
apt-get install -y --no-install-recommends dracut \
|| exitInstall
printInfo " - Dracut installed."
else
printInfo " - Dracut already installed."
fi
fi
saveResumeCheckPoint
if canRun; then
cp ${CURRENT_DIR}/assets/dracut/*.conf ${LVM_DRACUT_CONF}/ || exitInstall
printInfo " - Installed configuration files."
fi
saveResumeCheckPoint
if canRun; then
cp -r ${CURRENT_DIR}/assets/dracut/90buddy-linux/ ${LVM_DRACUT_MODULES}/ || exitInstall
printInfo " - Installed module."
fi
saveResumeCheckPoint
if canRun; then
local TMP_SCRIPT_BASENAME=update-dracut
local TMP_SCRIPT_NAME=${CURRENT_DIR}/assets/dracut/${TMP_SCRIPT_BASENAME}
local TMP_FOLDER=${LVM_TARGET_MNT}/sbin/
cp ${TMP_SCRIPT_NAME} ${TMP_FOLDER}/ \
&& chmod +x ${TMP_FOLDER}/${TMP_SCRIPT_BASENAME} \
|| exitInstall
printInfo " - Installed script \"${TMP_SCRIPT_NAME}\" into \"${TMP_FOLDER}\"."
fi
saveResumeCheckPoint
if canRun; then
printInfo " - Updating InitRd image..."
chroot ${LVM_TARGET_MNT} /sbin/update-dracut --all || exitInstall
printInfo " - Updated InitRd image."
fi
saveResumeCheckPoint
}
function doInitRdImageSetup_InitRamFsTools {
printPerforming
if canRun; then
chroot \
${LVM_TARGET_MNT} \
dpkg -l | awk '{ print $2 }' | grep -e '^initramfs-tools$' &> /dev/null
if [ $? -ne 0 ]; then
printInfo " - Installing InitRamFs Tools..."
chroot \
${LVM_TARGET_MNT} \
apt-get install -y initramfs-tools \
|| exitInstall
printInfo " - InitRamFs Tools installed."
else
printInfo " - InitRamFs Tools already installed."
fi
fi
if canRun; then
local TMP_SCRIPT_NAME=${CURRENT_DIR}/assets/initramfs/lvm-loops-setup
cp ${TMP_SCRIPT_NAME} ${LVM_INITRAMFS_SCRIPTS}/local-top/ || exitInstall
printInfo " - Installed script \"${TMP_SCRIPT_NAME}\" into \"local-top\"."
fi
saveResumeCheckPoint
if canRun; then
local TMP_SCRIPTS_NAME=${LVM_INITRAMFS_SCRIPTS}/local-top/*
chmod +x ${TMP_SCRIPTS_NAME} || exitInstall
printInfo " - Set \"${TMP_SCRIPTS_NAME}\" scripts mode."
fi
saveResumeCheckPoint
if canRun; then
local TMP_SCRIPT_NAME=${CURRENT_DIR}/assets/initramfs/lvm-loops-finalize
local TMP_TARGET=${LVM_INITRAMFS_SCRIPTS}/local-bottom/
cp ${TMP_SCRIPT_NAME} ${TMP_TARGET} || exitInstall
printInfo " - Installed script \"${TMP_SCRIPT_NAME}\" into \"${TMP_TARGET}\"."
fi
saveResumeCheckPoint
if canRun; then
local TMP_SCRIPTS_NAME=${LVM_INITRAMFS_SCRIPTS}/local-bottom/*
chmod +x ${TMP_SCRIPTS_NAME} || exitInstall
printInfo " - Set \"${TMP_SCRIPTS_NAME}\" scripts mode."
fi
saveResumeCheckPoint
if canRun; then
cp ${CURRENT_DIR}/assets/initramfs/compress ${LVM_INITRAMFS_CONF} || exitInstall
printInfo " - Configured compression."
fi
saveResumeCheckPoint
if canRun; then
printInfo " - Updating InitRd image..."
chroot ${LVM_TARGET_MNT} /usr/sbin/update-initramfs -u -k all || exitInstall
printInfo " - Updated InitRd image."
fi
saveResumeCheckPoint
}
[ ${PARAM_INITRD_TOOL} -eq 2 ] \
&& doInitRdImageSetup_Dracut \
|| doInitRdImageSetup_InitRamFsTools
function doInitRdImageSetup_Post {
printPerforming
canRun && unbindFolder ${LVM_TARGET_MNT}/dev/pts
saveResumeCheckPoint
canRun && unbindFolder ${LVM_TARGET_MNT}/dev
saveResumeCheckPoint
canRun && unbindFolder ${LVM_TARGET_MNT}/sys
saveResumeCheckPoint
canRun && unbindFolder ${LVM_TARGET_MNT}/proc
saveResumeCheckPoint
canRun && unbindFolder ${LVM_TARGET_MNT}/run
saveResumeCheckPoint
canRun && unbindFolder ${LVM_TARGET_MNT}/boot
saveResumeCheckPoint
}
doInitRdImageSetup_Post
# Grub configuration
function doGrubConfiguration {
printPerforming
if canRun; then
local TMP_CONFIG=${LVM_DEFAULT_CONF}/grub
sed -ri 's/GRUB_TIMEOUT=[0-9]+/GRUB_TIMEOUT=30/' ${TMP_CONFIG} || exitInstall
sed -ri 's/^ *(GRUB_DEFAULT *=.+)/#\1/' ${TMP_CONFIG} || exitInstall
if grep 'GRUB_TIMEOUT_STYLE' ${TMP_CONFIG} &> /dev/null; then
sed -ri 's/GRUB_TIMEOUT_STYLE=.+/GRUB_TIMEOUT_STYLE="menu"/' ${TMP_CONFIG} || exitInstall
else
echo -e "\nGRUB_TIMEOUT_STYLE=\"menu\"" >> ${TMP_CONFIG} || exitInstall
fi
printInfo " - Configured timeout (file \"${TMP_CONFIG}\")."
fi
saveResumeCheckPoint
if canRun; then
local TMP_SOURCE=${CURRENT_DIR}/assets/grub/buddy-linux.cfg
local TMP_GRUB_D=${LVM_DEFAULT_CONF}/grub.d
local TMP_TARGET=${TMP_GRUB_D}/buddy-linux.cfg
{
createFolder ${TMP_GRUB_D} \
&& cp ${TMP_SOURCE} ${TMP_TARGET} \
&& sed -i -r "s:\{\{PARAM_BOOT_DEV_GRUB_INDEX\}\}:${PARAM_BOOT_DEV_GRUB_INDEX}:" ${TMP_TARGET} \
&& sed -i -r "s:\{\{PARAM_BOOT_PART\}\}:${PARAM_BOOT_PART}:" ${TMP_TARGET} \
&& sed -i -r "s:\{\{PARAM_HOST_UUID\}\}:${PARAM_HOST_UUID}:" ${TMP_TARGET} \
&& sed -i -r "s:\{\{PARAM_HOST_FSOPTIONS\}\}:${PARAM_HOST_FSOPTIONS}:" ${TMP_TARGET} \
&& sed -i -r "s:\{\{PARAM_HOST_FSTYPE\}\}:${PARAM_HOST_FSTYPE}:" ${TMP_TARGET} \
&& sed -i -r "s:\{\{LVM_LV_ROOT_DEV\}\}:${LVM_LV_ROOT_DEV}:" ${TMP_TARGET} \
&& sed -i -r "s:\{\{PARAM_LOOP_DIR\}\}:${PARAM_LOOP_DIR}:" ${TMP_TARGET} \
&& sed -i -r "s:\{\{PARAM_LVM_VG\}\}:${PARAM_LVM_VG}:" ${TMP_TARGET}
} || exitInstall
printInfo " - Installed configuration file \"${TMP_SOURCE}\" into \"${TMP_TARGET}\"."
fi
saveResumeCheckPoint
if canRun; then
local TMP_SCRIPT_NAME=${CURRENT_DIR}/assets/grub/10_buddy-linux
local TMP_FOLDER=${LVM_GRUB_CONF}/
cp ${TMP_SCRIPT_NAME} ${TMP_FOLDER} || exitInstall
printInfo " - Installed script \"${TMP_SCRIPT_NAME}\" into \"${TMP_FOLDER}\"."
fi
saveResumeCheckPoint
if canRun; then
chmod -x ${LVM_GRUB_CONF}/10_linux || exitInstall
printInfo " - Disabled default grub menu entries."
fi
canRun && bindFolder /dev ${LVM_TARGET_MNT}/dev
saveResumeCheckPoint
canRun && bindFolder /sys ${LVM_TARGET_MNT}/sys
saveResumeCheckPoint
canRun && bindFolder /proc ${LVM_TARGET_MNT}/proc
saveResumeCheckPoint
canRun && bindFolder ${BOOT_MNT} ${LVM_TARGET_MNT}/boot
saveResumeCheckPoint
if canRun; then
printInfo " - Updating Grub..."
chroot ${LVM_TARGET_MNT} /usr/sbin/update-grub || exitInstall
printInfo " - Updated Grub."
fi
saveResumeCheckPoint
canRun && unbindFolder ${LVM_TARGET_MNT}/dev
saveResumeCheckPoint
canRun && unbindFolder ${LVM_TARGET_MNT}/sys
saveResumeCheckPoint
canRun && unbindFolder ${LVM_TARGET_MNT}/proc
saveResumeCheckPoint
canRun && unbindFolder ${LVM_TARGET_MNT}/boot
saveResumeCheckPoint
}
doGrubConfiguration
# RSYSLOG - Filter out loops error messages
function doRsyslogSetup {
printPerforming
if canRun; then
local TMP_SCRIPT_NAME=${CURRENT_DIR}/assets/rsyslog/30-loop-errors.conf
local TMP_FOLDER=${LVM_RSYSLOG_CONF}/
cp ${TMP_SCRIPT_NAME} ${TMP_FOLDER} || exitInstall
printInfo " - Installed script \"${TMP_SCRIPT_NAME}\" into \"${TMP_FOLDER}\"."
fi
saveResumeCheckPoint
if canRun; then
local TMP_SCRIPT_NAME=${CURRENT_DIR}/assets/rsyslog/buddy-linux
local TMP_FOLDER=${LVM_LOGROTATE_CONF}/
cp ${TMP_SCRIPT_NAME} ${TMP_FOLDER} || exitInstall
printInfo " - Installed configuration \"${TMP_SCRIPT_NAME}\" into \"${TMP_FOLDER}\"."
fi
saveResumeCheckPoint
}
doRsyslogSetup
# Finalization
function doFinalization {
printPerforming
canRun && doCleanUp 0
saveResumeCheckPoint
printInfo " - Installation completed successufully."
printInfo " - Please, reboot to start new system."
}
doFinalization