-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsparky-installer-dev
executable file
·2960 lines (2700 loc) · 95.9 KB
/
sparky-installer-dev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# remastersys-installer has been created by Tony "Fragadelic" Brijeski
# Copyright 2008-2012 Under the GNU GPL2 License
# Originally Created September 12th,2008
# Updated to replace zenity with yad July 2012
#
# sparky-installer has been forked
# for SparkyLinux by pavroo <pavroo@onet.eu> 2013/08/04
# Copyright 2013-2020 Under the GNU GPL2 License
#
# Auto-partitioning added by darekem73
# Last update 2020/05/31
# TODO: optionally add swap to encrypted variants (automatic key generation to encrypt swap); alternative - add swap file for encrypted installations (option in initial setup)
# [ ] swap partition or swap file (only with no lvm)
# [ ] lvm ?
# [ ] separate home or home on root
# [ ] encrypted or not (if lvm)
# [ ] encrypted home (no lvm or lvm separate home)
# [ ] encrypted root (no lvm)
# [ ] no separate boot (only swap file if swap cheosen)
# TODO: in manual partitioning add option to create LVM on top of encrypting volumes
# TODO: introduce language independent variables for text
# TODO: wipefs for deleting fs signature prior to lvm / fdisk (?)
# TODO: checklist to select options prior to partitioning scheme (instead of option combinations being individual otpions)
#
# This script requires dialog to run, as of 2020/05/18 the yad support is removed
# Last update 2020/05/18 by pavroo
#
# remove deps: yad, gparted, zenity
# new deps: lvm2, cryptsetup
# checking to make sure script is running with root privileges
testroot="`whoami`"
if [ "$testroot" != "root" ]; then
echo "Must be run as root... Exiting now..."
exit 1
fi
# remove stored language setting if any
if [ -f /tmp/sparky-advanced-installer ]; then
rm -f /tmp/sparky-advanced-installer
fi
#set some constants for autopartitioner
(( K=1024 ))
(( M=$K*$K ))
(( G=$K*$K*$K ))
DEFAULT_EFIPARTSIZE=300
DEFAULT_BOOTPARTSIZE=500
DEFAULT_SWAP_SIZE_G=1
(( DEFAULT_SWAP_SIZE=$DEFAULT_SWAP_SIZE_G*$G ))
MIN_PART_SIZE=5 # G
MAX_PART_SIZE=30 # G
ROOT_PART_RATIO=3 # 1/3 of target partition
ENCRYPTED_DRIVES_OPEN=0
CRYPTTAB=""
# fstab by partname (enables easy restore after formatting root partition)
FSTAB_BY_UUID=0
LUKS_TYPE="luks2" #luks1 if no /boot+generate new keyslot to avoid asking for password (for each encrypted drive) and add keys to initramfs
NO_BOOT_PART=0 #/boot partition manadatory for encryption unless "10" EXPERIMENTAL is chosen
EXCLUDED_PARTS="@" # quick and dirty, may not be empty as it filters out everything later
# set options - text only
DIALOG="`which dialog`"
HEIGHT="0"
WIDTH="0"
MENUHEIGHT="0"
TITLE="--title "
TEXT=""
ENTRY="--inputbox "
MENU="--menu"
YESNO="--yesno "
MSGBOX="--msgbox "
PASSWORD="--passwordbox "
PARTITIONPROG="cfdisk"
AUTOPARTITIONPROGRAM="fdisk"
CHOICE_FILE=/tmp/choice.$$
TITLETEXT="Sparky (Advanced) Installer"
if [ -f /lib/live/mount/rootfs/filesystem.squashfs/etc/sparkybackup/sparkybackup.conf ]; then
CHECKMINI=`cat /lib/live/mount/rootfs/filesystem.squashfs/etc/sparkybackup/sparkybackup.conf | grep minimal`
CHECKMINICLI=`cat /lib/live/mount/rootfs/filesystem.squashfs/etc/sparkybackup/sparkybackup.conf | grep cli`
CHECKISOVER=`cat /lib/live/mount/rootfs/filesystem.squashfs/etc/sparkybackup/sparkybackup.conf | grep CUSTOMISO`
CHECKSERVER=`cat /lib/live/mount/rootfs/filesystem.squashfs/etc/sparkybackup/sparkybackup.conf | grep server`
CHECKRESCUE=`cat /lib/live/mount/rootfs/filesystem.squashfs/etc/sparkybackup/sparkybackup.conf | grep rescue`
fi
#if [ -f /usr/bin/sparky-xterm ]; then
# SPARKYXTERM="/usr/bin/sparky-xterm"
#elif [ -f /usr/bin/sparky-terminal ]; then
# SPARKYXTERM="/usr/bin/sparky-terminal -e"
#else
# echo "sparky-xterm is missing... Exiting..."
# exit 1
#fi
TESTEFI0=`lsmod | grep efi`
if [ -d /sys/firmware/efi/efivars ] || [ "$TESTEFI0" != "" ]; then
TESTEFI="EFI detected"
else
TESTEFI=""
fi
#if [ "$1" = "gui" -o "$2" = "gui" ]; then
# GUI="$DISPLAY"
#fi
#if [ "$GUI" != "" ]; then
#
# testyad=`which yad`
#
# if [ "$testyad" != "" ]; then
# DIALOGMENU="`which yad` --window-icon=/usr/share/icons/sparky/sparkybackupsys/sparky48.png --width=600 --height=400 --fixed --center"
# DIALOG="`which yad` --window-icon=/usr/share/icons/sparky/sparkybackupsys/sparky48.png --width=450 --fixed --center"
# TITLE="--always-print-result --dialog-sep --image=/usr/share/icons/sparky/sparkybackupsys/sparky48.png --title="
# TEXT="--text="
# ENTRY="--entry "
# ENTRYTEXT="--entry-text "
# MENU="--list --column=Pick --column=Info"
# YESNO=" --button=Yes:0 --button=No:1 "
# MSGBOX=" --button=Ok:0 "
# PASSWORD="--entry --hide-text "
#
# testgparted=`which gparted`
# if [ "$testgparted" = "" ]; then
# PARTITIONPROG="$SPARKYXTERM cfdisk"
# else
# PARTITIONPROG="gparted"
# fi
# TITLETEXT="Sparky (Advanced) Installer"
# fi
#
#fi
# if NOT Live system just quit, do nothing
testmode=`grep "1000" /etc/passwd | grep -v "Live"`
if [ "$testmode" != "" ]; then
# if [ "$GUI" != "" ]; then
# xmessage "It is NOT Live system! The Live Installer has to be launched in Live environment only. Exiting now..."
# exit 1
# else
echo "It is NOT Live system! The Live Installer has to be launched in Live environment only. Exiting now..."
exit 1
# fi
fi
# if no dialog or yad installed just quit
if [ "$DIALOG" = "" ]; then
# if [ "$GUI" != "" ]; then
# xmessage "Cannot find dialog or yad. Exiting now..."
# exit 1
# else
echo "Cannot find dialog... Exiting now..."
exit 1
# fi
fi
# choose installer language
if [ -f /tmp/sparky-advanced-installer ]; then
rm -f /tmp/sparky-advanced-installer
fi
#if [ "$GUI" != "" ]; then
#DEFLANGS=`$DIALOGMENU $TITLE"$TITLETEXT" $YESNO $MENU $TEXT"Please choose the Advanced Installer language:" \
#Brazilian "Brasileiro" \
#English "English" \
#French "Français" \
#German "Deutsch" \
#Greek "ελληνικά" \
#Hungarian "Magyar" \
#Indonesian "Indonesia" \
#Italian "Italiano" \
#Polish "Polski" \
#Portuguese "Português" \
#Russian "Pусский" \
#Exit "Exiting now..."`
#
# if [ "$?" = "0" ]; then
# DEFLANGS=`echo $DEFLANGS | cut -d "|" -f 1`
# echo "$DEFLANGS" > /tmp/sparky-advanced-installer
# fi
#
# if [ "$DEFLANGS" = "Brazilian" ]; then
# DEFLANG="Brazilian"
# elif [ "$DEFLANGS" = "English" ]; then
# DEFLANG="English"
# elif [ "$DEFLANGS" = "French" ]; then
# DEFLANG="French"
# elif [ "$DEFLANGS" = "German" ]; then
# DEFLANG="German"
# elif [ "$DEFLANGS" = "Greek" ]; then
# DEFLANG="Greek"
# elif [ "$DEFLANGS" = "Hungarian" ]; then
# DEFLANG="Hungarian"
# elif [ "$DEFLANGS" = "Indonesian" ]; then
# DEFLANG="Indonesian"
# elif [ "$DEFLANGS" = "Italian" ]; then
# DEFLANG="Italian"
# elif [ "$DEFLANGS" = "Polish" ]; then
# DEFLANG="Polish"
# elif [ "$DEFLANGS" = "Portuguese" ]; then
# DEFLANG="Portuguese"
# elif [ "$DEFLANGS" = "Russian" ]; then
# DEFLANG="Russian"
# elif [ "$DEFLANGS" = "Exit" ]; then
# exit 1
# else
# exit 1
# fi
#elif [ "$GUI" = "" ]; then
$DIALOG $TITLE"$TITLETEXT" $MENU $TEXT"Please choose the Advanced Installer language:" $HEIGHT $WIDTH $MENUHEIGHT Brazilian "Brasileiro" English "English" French "Français" German "Deutsch" Greek "ελληνικά" Hungarian "Magyar" Indonesian "Indonesia" Italian "Italiano" Polish "Polski" Portuguese "Português" Russian "Pусский" Exit "Exiting now..." 2>/tmp/sparky-advanced-installer
if [ "$?" = "0" ]; then
DEFLANG=`cat /tmp/sparky-advanced-installer`
else
DEFLANG="Exit"
fi
if [ "$DEFLANG" = "Exit" ]; then
$DIALOG $TITLE"$TITLETEXT" $MSGBOX $TEXT"Exiting the Installer now..." $HEIGHT $WIDTH
exit 1
fi
#fi
# get default's locale file
DEFLOCDIR="/usr/share/sparky/sparky-advanced-installer"
if [ "$DEFLANG" = "Brazilian" ]; then
. $DEFLOCDIR/pt_BR
elif [ "$DEFLANG" = "French" ]; then
. $DEFLOCDIR/fr
elif [ "$DEFLANG" = "German" ]; then
. $DEFLOCDIR/de
elif [ "$DEFLANG" = "Greek" ]; then
. $DEFLOCDIR/el
elif [ "$DEFLANG" = "Hungarian" ]; then
. $DEFLOCDIR/hu
elif [ "$DEFLANG" = "Indonesian" ]; then
. $DEFLOCDIR/id_ID
elif [ "$DEFLANG" = "Italian" ]; then
. $DEFLOCDIR/it
elif [ "$DEFLANG" = "Polish" ]; then
. $DEFLOCDIR/pl
elif [ "$DEFLANG" = "Portuguese" ]; then
. $DEFLOCDIR/pt_PT
elif [ "$DEFLANG" = "Russian" ]; then
. $DEFLOCDIR/ru
else
. $DEFLOCDIR/en
fi
# the first dialog text
if [ -f /lib/live/mount/medium/live/minimal ] || [ "$CHECKMINI" != "" ]; then
INSTALLTEXT1="$LOCAL1 $LOCAL3 $LOCAL4 $LOCAL5\n\n$LOCAL6\nsudo apt update\nsudo apt install sparky-backup-core\n\n$LOCAL7\n$LOCAL8"
elif [ "$CHECKSERVER" != "" ]; then
INSTALLTEXT1="$LOCAL1 $LOCAL118 $LOCAL5\n\n$LOCAL6\nsudo apt update\nsudo apt install sparky-backup-core\n\n$LOCAL7\n$LOCAL8"
else
INSTALLTEXT1="$LOCAL2\n\n$LOCAL6\nsudo apt update\nsudo apt install sparky-backup-core\n\n$LOCAL7\n$LOCAL8"
fi
if [ "$TESTEFI" != "" ]; then
PARTITIONTEXT="$LOCAL9\n\n$PARTITIONPROG $LOCAL10\n\n$LOCAL11 If you want to encrypt root partition prepare a 500M boot partition that will remain unencrypted.\n\n$LOCAL12\n\n$LOCAL13 $PARTITIONPROG $LOCAL14\n\n$LOCAL15"
else
PARTITIONTEXT="$LOCAL9\n\n$PARTITIONPROG $LOCAL10\n\n$LOCAL11 If you want to encrypt root partition prepare a 500M boot partition that will remain unencrypted.\n\n$LOCAL13 $PARTITIONPROG $LOCAL14\n\n$LOCAL15"
fi
#progressbar () {
# # check yad version, replace it with zenity of the progressbar if yad is a sparky build
# TESTZENITY="`which zenity`"
# if [ "$TESTZENITY" != "" ]; then
# YADVERSION="`dpkg-query -l | grep yad | grep sparky`"
# if [ "$YADVERSION" != "" ]; then
# tail -f /usr/bin/sparky-installer | `which zenity` --window-icon=/usr/share/icons/sparky/sparkybackupsys/sparky48.png --width=450 --progress --pulsate --auto-close --no-cancel --auto-kill --title="$TITLETEXT" --text="$@"
# else
# tail -f /usr/bin/sparky-installer | $DIALOG $TITLE"$TITLETEXT" $TEXT"$@" --no-buttons --progress --pulsate --auto-close --progress-text="$LOCAL122"
# fi
# else
# tail -f /usr/bin/sparky-installer | $DIALOG $TITLE"$TITLETEXT" $TEXT"$@" --no-buttons --progress --pulsate --auto-close --progress-text="$LOCAL122"
# fi
#}
. /etc/live/config.conf
. /etc/sparkybackup/sparkybackup.conf
. /etc/sparkybackup/sparkylinux-installer.conf
get_password() {
PASS_TYPE=$1
tmpPASS1="1"
tmpPASS2="2"
# empty password reserved for dynamic key generation for swap
while [ "$tmpPASS1" != "$tmpPASS2" ] && [ "$tmpPASS1" != "" ] && [ "$tmpPASS2" != "" ]; do
$DIALOG $TITLE"$TITLETEXT" $PASSWORD $TEXT"Enter $PASS_TYPE password" $HEIGHT $WIDTH 2>$CHOICE_FILE
if [ "$?" = "0" ]; then
tmpPASS1=`cat $CHOICE_FILE`
else
exit 1
fi
rm $CHOICE_FILE
$DIALOG $TITLE"$TITLETEXT" $PASSWORD $TEXT"Re-enter $PASS_TYPE password" $HEIGHT $WIDTH 2>$CHOICE_FILE
if [ "$?" = "0" ]; then
tmpPASS2=`cat $CHOICE_FILE`
else
exit 1
fi
rm $CHOICE_FILE
if [ "$tmpPASS1" != "$tmpPASS2" ]; then
$DIALOG $TITLE"$TITLETEXT" $MSGBOX $TEXT"$LOCAL41" $HEIGHT $WIDTH
fi
done
THE_PASSWORD=$tmpPASS1
rm $CHOICE_FILE
}
clear_lvm() {
LIST_OF_VGS=$(vgs | sed 1D | awk '{printf "%s ", $1}')
LIST_OF_PVS=$(pvs | sed 1D | awk '{printf "%s ", $1}')
LIST_OF_LVS=$(lvs | sed 1D | awk '{printf "%s ", $1}')
if [ "$LIST_OF_VGS" != "" ]; then
$DIALOG $TITLE"$TITLETEXT" $YESNO $TEXT"Delete all LVM objects\nVGs: $LIST_OF_VGS\nLVs: $LIST_OF_LVS\nPVs: $LIST_OF_PVS?" $HEIGHT $WIDTH
if [ $? != 0 ]; then
exit 1
fi
for vg in LIST_OF_VGS; do
vgchange -an $vg
done
for f in $LIST_OF_VGS; do
yes | lvremove $f
yes | vgremove $f
done
for f in $LIST_OF_PVS; do
yes | pvremove $f
done
fi
}
check_lvm() {
LIST_OF_VGS=$(vgs | sed 1D | awk '{printf "%s ", $1}')
LIST_OF_PVS=$(pvs | sed 1D | awk '{printf "%s ", $1}')
LIST_OF_LVS=$(lvs | sed 1D | awk '{printf "%s ", $1}')
if [ "$LIST_OF_VGS" != "" ]; then
return 1
else
return 0
fi
}
collect_encrypted_drives() {
DRIVES=`lsblk -l -p -o NAME,TYPE,FSTYPE | grep 'crypto_LUKS' | awk '{print $1}'`
if [ "$DRIVES" = "" ]; then
return 1
fi
ENCRYPTED_DRIVES=""
for i in $DRIVES; do
encrdrive="$i"
encrdrivesize=`lsblk -o NAME,SIZE,TYPE -l -p -b | grep -m 1 "$i" | awk '{print $2}'`
ENCRYPTED_DRIVES="$ENCRYPTED_DRIVES $encrdrive $encrdrivesize"
done
return 0
}
collect_encryption_parameters() {
# ENCRYPTED_DRIVES must be set
if [ "$ENCRYPTED_DRIVES" == "" ]; then
echo "ENCRYPTED_DRIVES must be set"
exit 1
fi
ALL_OPEN=0
ALREADY_OPEN="@"
while [ $ALL_OPEN -eq 0 ]; do
ENCRYPTED_DRIVES=$(echo $ENCRYPTED_DRIVES | awk -v EXCL=$ALREADY_OPEN 'BEGIN { RS=" " }; $1 ~ EXCL { getline; next }; { printf "%s ", $0 }')
$DIALOG $TITLE"$TITLETEXT" $MENU $TEXT"Select drive to open" $HEIGHT $WIDTH $MENUHEIGHT Exit "Exit" $ENCRYPTED_DRIVES 2>$CHOICE_FILE
if [ $? -eq 0 ]; then
OPENDRIVE=`cat $CHOICE_FILE`
else
OPENDRIVE="Exit"
fi
rm $CHOICE_FILE
if [ "$OPENDRIVE" = "Exit" ]; then
ALL_OPEN=1
else
DRIVE_TO_ENCRYPT="$OPENDRIVE"
get_password "$DRIVE_TO_ENCRYPT"
DRIVE_TO_ENCRYPT_PASS=$THE_PASSWORD
if [ "$DRIVES_TO_ENCRYPT_TEXT_ONLY" = "" ]; then
DRIVES_TO_ENCRYPT_TEXT_ONLY="$DRIVE_TO_ENCRYPT"
else
DRIVES_TO_ENCRYPT_TEXT_ONLY="$DRIVES_TO_ENCRYPT_TEXT_ONLY|$DRIVE_TO_ENCRYPT"
fi
CRYPT_DRIVE_MAPPED=$(echo $DRIVE_TO_ENCRYPT | awk -F"/" '{print $NF"_crypt"}')
if [ "$DRIVES_TO_ENCRYPT" = "" ]; then
DRIVES_TO_ENCRYPT="$DRIVE_TO_ENCRYPT:$DRIVE_TO_ENCRYPT_PASS:$CRYPT_DRIVE_MAPPED"
else
DRIVES_TO_ENCRYPT="$DRIVES_TO_ENCRYPT|$DRIVE_TO_ENCRYPT:$DRIVE_TO_ENCRYPT_PASS:$CRYPT_DRIVE_MAPPED"
fi
# exclude encryption host drives from selecting as target partitions to mount
if [ "$EXCLUDED_PARTS" = "" ]; then
EXCLUDED_PARTS="$DRIVE_TO_ENCRYPT"
else
EXCLUDED_PARTS="$EXCLUDED_PARTS|$DRIVE_TO_ENCRYPT"
fi
# exclude already open drives from the list of candidates for opening
ALREADY_OPEN="$ALREADY_OPEN|$DRIVE_TO_ENCRYPT"
fi
done
}
drive_to_part() {
if [ $ENCRYPTED_DRIVES_OPEN -eq 1 ]; then
# if drive has open encrypted partitions - remove drive from list
if [ "$DRIVES_TO_ENCRYPT" = "" ]; then
echo "This should not happen. DRIVES_TO_ENCRYPT should be set if ENCRYPTED_DRIVES_OPEN set to 1."
exit 1
else
EXCLUSION_LIST=""
NF=$(echo $DRIVES_TO_ENCRYPT | awk -F"|" '{print NF}')
for i in `seq $NF`; do
CMD=$(echo $DRIVES_TO_ENCRYPT | cut -d "|" -f $i)
PART=$(echo $CMD | cut -d: -f1)
PASS=$(echo $CMD | cut -d: -f2)
MAPPED=$(echo $CMD | cut -d: -f3)
if [ "$EXCLUSION_LIST" = "" ]; then
EXCLUSION_LIST="${PART%?}" #remove partition number, dirty way of not showing the same disk for partitioning
else
EXCLUSION_LIST="$EXCLUSION_LIST|${PART%?}"
fi
done
DRIVES=`lsblk -l -p | grep 'disk' | egrep -v $EXCLUSION_LIST | awk '{print $1}'`
fi
else
DRIVES=`lsblk -l -p | grep 'disk' | awk '{print $1}'`
fi
partdrivemenu=""
for i in $DRIVES; do
partdrive="$i"
partdrivesize=`lsblk -o NAME,SIZE,TYPE -l -p -b | grep -m 1 "$i" | awk '{print $2}'`
partdrivemenu="$partdrivemenu $partdrive $partdrivesize"
done
$DIALOG $TITLE"$TITLETEXT" $MENU $TEXT"Select drive to partition" $HEIGHT $WIDTH $MENUHEIGHT Exit "Exit" $partdrivemenu 2>$CHOICE_FILE
if [ "$?" = "0" ]; then
PARTDRIVE=`cat $CHOICE_FILE`
PARTDRIVESIZE=`lsblk -o NAME,SIZE,TYPE -l -p -b | grep -m 1 "$PARTDRIVE" | awk '{print $2}'`
else
PARTDRIVE="Exit"
fi
rm $CHOICE_FILE
}
ask_for_part() {
TYPE="$1"
PARTITIONS=`lsblk -o NAME,SIZE,TYPE -l -p -b | sed 1D | egrep -v $EXCLUDED_PARTS | awk '{print $1}'`
PARTLIST=`echo $PARTITIONS`
partmenu=""
for i in $PARTLIST; do
part="$i"
partsize=`lsblk -o NAME,SIZE,TYPE -l -p -b | grep -m 1 "$i" | awk '{print $2}'`
partmenu="$partmenu $part $partsize"
done
$DIALOG $TITLE"$TITLETEXT" $MENU $TEXT"Select partition for $TYPE" $HEIGHT $WIDTH $MENUHEIGHT Exit "Exit" $partmenu 2>$CHOICE_FILE
if [ "$?" = "0" ]; then
PARTTOMOUNT=`cat $CHOICE_FILE`
PARTTOMOUNT="$PARTTOMOUNT"
else
PARTTOMOUNT="Exit"
fi
rm $CHOICE_FILE
}
ask_for_mountpoint() {
LOCATION="$1"
$DIALOG $TITLE"$TITLETEXT" --inputbox "Mountpoint for $LOCATION" $HEIGHT $WIDTH 2>$CHOICE_FILE
if [ "$?" = "0" ]; then
MOUNTPOINT=`cat $CHOICE_FILE`
else
echo "Error in mountpoint"
exit 1
fi
rm $CHOICE_FILE
}
ask_for_filesystem() {
LOCATION="$1"
if [ "$2" = "noformat" ]; then
NOFORMAT="$2 noformat"
else
NOFORMAT=""
fi
$DIALOG $TITLE"$TITLETEXT" $MENU $TEXT"Select filesystem for $LOCATION" $HEIGHT $WIDTH $MENUHEIGHT $NOFORMAT ext4 "ext4" ext3 "ext3" ext2 "ext2" btrfs "Btrfs" xfs "Xfs" 2>$CHOICE_FILE
if [ "$?" = "0" ]; then
FSTYPE=`cat $CHOICE_FILE`
else
FSTYPE="ext4"
fi
rm $CHOICE_FILE
}
gather_part_data() {
PART_TYPE="$1"
status=0
PARTTOMOUNT=""
ask_for_part $PART_TYPE
if [ "$?" != "0" ]; then
exit 1
fi
case $PART_TYPE in
"efi")
FSTYPE="vfat"
MOUNTPOINT="/boot/efi"
if [ "$PARTTOMOUNT" = "Exit" ]; then
status=1
else
$DIALOG $TITLE"$TITLETEXT" $YESNO $TEXT"Format $PART_TYPE?" $HEIGHT $WIDTH
if [ $? != 0 ]; then
FSTYPE="noformat"
fi
status=0
fi
FSTABOPT="defaults"
DUMP_PASS="0 0"
TARGETEFI=$PARTTOMOUNT #needed for final message
FORMATEFIPART=$FSTYPE #needed for final message
;;
"root")
MOUNTPOINT="/"
FSTYPE=""
if [ "$PARTTOMOUNT" = "Exit" ]; then
status=1
else
ask_for_filesystem $PART_TYPE "format"
status=0
fi
case $FSTYPE in
"ext2"|"ext3"|"ext4")
FSTABOPT="errors=remount-ro,defaults"
;;
"xfs")
FSTABOPT="noatime,defaults"
;;
"btrfs")
FSTABOPT="subvol=@,noatime,space_cache,autodefrag,defaults" #for direct storing in store_part
HFSTABOPT="subvol=@home,defaults,noatime,space_cache,autodefrag" # needed for subvolume fstab entry
;;
esac
ENCRYPT_ROOT=0
# if encrypted drives opnen for installation - do not offer reencryption
if [ $ENCRYPTED_DRIVES_OPEN -eq 0 ]; then
$DIALOG $TITLE"$TITLETEXT" $YESNO $TEXT"Encrypt root partition?\n$PARTTOMOUNT" $HEIGHT $WIDTH
if [ $? -eq 0 ]; then
ENCRYPT_ROOT=1
fi
fi
if [ $ENCRYPT_ROOT -eq 1 ]; then
DRIVE_TO_ENCRYPT="$PARTTOMOUNT"
get_password "$DRIVE_TO_ENCRYPT encryption"
DRIVE_TO_ENCRYPT_PASS=$THE_PASSWORD
if [ "$DRIVES_TO_ENCRYPT_TEXT_ONLY" = "" ]; then
DRIVES_TO_ENCRYPT_TEXT_ONLY="$DRIVE_TO_ENCRYPT"
else
DRIVES_TO_ENCRYPT_TEXT_ONLY="$DRIVES_TO_ENCRYPT_TEXT_ONLY|$DRIVE_TO_ENCRYPT"
fi
CRYPT_DRIVE_MAPPED=$(echo $DRIVE_TO_ENCRYPT | awk -F"/" '{print $NF"_crypt"}')
if [ "$DRIVES_TO_ENCRYPT" = "" ]; then
DRIVES_TO_ENCRYPT="$DRIVE_TO_ENCRYPT:$DRIVE_TO_ENCRYPT_PASS:$CRYPT_DRIVE_MAPPED"
else
DRIVES_TO_ENCRYPT="$DRIVES_TO_ENCRYPT|$DRIVE_TO_ENCRYPT:$DRIVE_TO_ENCRYPT_PASS:$CRYPT_DRIVE_MAPPED"
fi
CRYPT=1
EXCLUDED_PARTS="$EXCLUDED_PARTS|$DRIVE_TO_ENCRYPT"
PARTTOMOUNT="/dev/mapper/$CRYPT_DRIVE_MAPPED"
DUMP_PASS="0 1"
ROOTFSTYPE=$FSTYPE #needed for final message
TARGETPART=$PARTTOMOUNT #needed below for GRUB installation
# change the next swap partition to boot
index=0
while [ "${MANDATORY_PARTS[$index]}" != "swap" ] && [ $index -lt "${#MANDATORY_PARTS[@]}" ]; do ((index++)); done
if [ $index -lt "${#MANDATORY_PARTS[@]}" ]; then
MANDATORY_PARTS[$index]="boot"
fi
else
DUMP_PASS="0 1"
ROOTFSTYPE=$FSTYPE #needed for final message
TARGETPART=$PARTTOMOUNT #needed below for GRUB installation
fi
;;
"swap")
if [ "$PARTTOMOUNT" = "Exit" ]; then
FSTYPE="noswap"
MOUNTPOINT="noswap"
status=0
else
FSTYPE="swap"
MOUNTPOINT="none"
FSTABOPT="sw"
DUMP_PASS="0 0"
status=0
fi
SWAP=$PARTTOMOUNT #for logging
;;
"home")
MOUNTPOINT="/home"
if [ "$PARTTOMOUNT" = "Exit" ]; then
FSTYPE=""
status=0
else
FSTYPE=""
ask_for_filesystem $PART_TYPE "noformat"
status=0
fi
case $FSTYPE in
"noformat"|"ext2"|"ext3"|"ext4")
FSTABOPT="defaults"
;;
"xfs")
FSTABOPT="noatime,defaults"
;;
"btrfs")
FSTABOPT="defaults,noatime,space_cache,autodefrag" #for storing in store_part
HFSTABOPT="defaults,noatime,space_cache,autodefrag" #will overwrite HFSTAB from root FS entry; to be used only if btrfs and HOMEPART=Exit
;;
esac
ENCRYPT_HOME=0
# if encrypted drives opnen for installation - do not offer reencryption
if [ $ENCRYPTED_DRIVES_OPEN -eq 0]; then
if [[ "$FSTYPE" != "noformat" && "$PARTTOMOUNT" != "Exit" ]]; then
$DIALOG $TITLE"$TITLETEXT" $YESNO $TEXT"Encrypt home partition?\n$PARTTOMOUNT" $HEIGHT $WIDTH
if [ $? -eq 0 ]; then
ENCRYPT_HOME=1
fi
fi
fi
if [ $ENCRYPT_HOME -eq 1 ]; then
DRIVE_TO_ENCRYPT="$PARTTOMOUNT"
get_password "$DRIVE_TO_ENCRYPT encryption"
DRIVE_TO_ENCRYPT_PASS=$THE_PASSWORD
if [ "$DRIVES_TO_ENCRYPT_TEXT_ONLY" = "" ]; then
DRIVES_TO_ENCRYPT_TEXT_ONLY="$DRIVE_TO_ENCRYPT"
else
DRIVES_TO_ENCRYPT_TEXT_ONLY="$DRIVES_TO_ENCRYPT_TEXT_ONLY|$DRIVE_TO_ENCRYPT"
fi
CRYPT_DRIVE_MAPPED=$(echo $DRIVE_TO_ENCRYPT | awk -F"/" '{print $NF"_crypt"}')
if [ "$DRIVES_TO_ENCRYPT" = "" ]; then
DRIVES_TO_ENCRYPT="$DRIVE_TO_ENCRYPT:$DRIVE_TO_ENCRYPT_PASS:$CRYPT_DRIVE_MAPPED"
else
DRIVES_TO_ENCRYPT="$DRIVES_TO_ENCRYPT|$DRIVE_TO_ENCRYPT:$DRIVE_TO_ENCRYPT_PASS:$CRYPT_DRIVE_MAPPED"
fi
CRYPT=1
EXCLUDED_PARTS="$EXCLUDED_PARTS|$DRIVE_TO_ENCRYPT"
PARTTOMOUNT="/dev/mapper/$CRYPT_DRIVE_MAPPED"
DUMP_PASS="0 2"
HFSTYPE="ext4" #needed below final message
HOMEPART="$PARTTOMOUNT" # needed below for final message
else
DUMP_PASS="0 2"
HFSTYPE=$FSTYPE #needed below for choosing folders for rsync if noformat and for final message
HOMEPART=$PARTTOMOUNT # Exit=home_on_root or @home subvolume needs to be created, other options n/a; needed below for final message
fi
;;
"boot")
# only due to encryption this becomes mandatory, which means no swap
FSTYPE="ext4"
MOUNTPOINT="/boot"
if [ "$PARTTOMOUNT" = "Exit" ]; then
status=1
else
FSTABOPT="defaults"
DUMP_PASS="0 2"
status=0
fi
;;
"other")
MOUNTPOINT=""
FSTYPE=""
if [ "$PARTTOMOUNT" = "Exit" ]; then
status=0
else
ask_for_mountpoint $PARTTOMOUNT
if [ "$MOUNTPOINT" != "" ]; then
ask_for_filesystem $PART_TYPE "noformat"
status=0
else
status=1
fi
fi
FSTABOPT="defaults"
DUMP_PASS="0 2"
;;
esac
return $status
}
store_parts() {
if [ "$PARTS_TO_MOUNT" = "" ]; then
PARTS_TO_MOUNT="$PARTTOMOUNT:$MOUNTPOINT:$FSTYPE:$FSTABOPT:$DUMP_PASS"
else
PARTS_TO_MOUNT="$PARTS_TO_MOUNT|$PARTTOMOUNT:$MOUNTPOINT:$FSTYPE:$FSTABOPT:$DUMP_PASS"
fi
EXCLUDED_PARTS="$EXCLUDED_PARTS|$PARTTOMOUNT"
}
parts_to_mount_to_text() {
NF=$(echo $PARTS_TO_MOUNT | awk -F"|" '{print NF}')
PARTS_TO_MOUNT_TEXT=""
for i in `seq $NF`; do
CMD=$(echo $PARTS_TO_MOUNT | cut -d "|" -f $i)
PART=$(echo $CMD | cut -d: -f1)
MOUNT=$(echo $CMD | cut -d: -f2)
FS=$(echo $CMD | cut -d: -f3)
FSTABOPT=$(echo $CMD | cut -d: -f4)
DUMP_PASS=$(echo $CMD | cut -d: -f5)
if [ "$PARTS_TO_MOUNT_TEXT" = "" ]; then
PARTS_TO_MOUNT_TEXT="$PART $MOUNT $FS"
else
PARTS_TO_MOUNT_TEXT="$PARTS_TO_MOUNT_TEXT\n$PART $MOUNT $FS"
fi
done
}
select_mount_points() {
# mount mandatory partitions
CRYPT=0
PARTTOMOUNT=""
for p in `seq 1 ${#MANDATORY_PARTS[@]}`; do
(( i=p-1 ))
part=${MANDATORY_PARTS[$i]}
gather_part_data $part
if [ $? -eq 0 ]; then
# home on root = Exit, don't mount separate partition
if [ "$PARTTOMOUNT" != "Exit" ]; then
store_parts
fi
else
echo "Error in selecting partitions"
exit 1
fi
done
# mount any other partitions
$DIALOG $TITLE"$TITLETEXT" $YESNO $TEXT"Do you want to mount other partitions?" $HEIGHT $WIDTH
if [ $? = 0 ]; then
PARTTOMOUNT=""
while [ "$PARTTOMOUNT" != "Exit" ]; do
gather_part_data "other"
if [ "$PARTTOMOUNT" != "Exit" ]; then
store_parts
else
break
fi
done
fi
}
calc_root_size() {
if [ $1 -gt $(( $MAX_PART_SIZE*$G )) ]; then
(( ROOT_PART_SIZE=$MAX_PART_SIZE*$G ))
elif [ $1 -gt $(( $MIN_PART_SIZE*$G )) ]; then
(( ROOT_PART_SIZE=$1/$ROOT_PART_RATIO ))
fi
}
create_partitions() {
# $PARTS_TO_CREATE must be set
if [ "$PARTS_TO_CREATE" == "" ]; then
echo "PARTS_TO_CREATE must be set"
exit 1
fi
if [ "$TESTEFI" != "" ]; then
echo "g" > $CHOICE_FILE
else
echo "o" > $CHOICE_FILE
fi
NF=$(echo $PARTS_TO_CREATE | awk -F"|" '{print NF}')
for i in `seq $NF`; do
CMD=$(echo $PARTS_TO_CREATE | cut -d "|" -f $i)
PART=$(echo $CMD | cut -d: -f1)
TYPE=$(echo $CMD | cut -d: -f2)
SIZE=$(echo $CMD | cut -d: -f3)
echo "n" >> $CHOICE_FILE
if [ "$TESTEFI" == "" ]; then
echo "p" >> $CHOICE_FILE
fi
echo $PART >> $CHOICE_FILE
echo "" >> $CHOICE_FILE
if [ "$SIZE" == "" ]; then
echo "" >> $CHOICE_FILE
else
(( SIZE=$SIZE/$M ))
echo "+$SIZE""M" >> $CHOICE_FILE
fi
echo "t" >> $CHOICE_FILE
if [ "$PART" != "1" ]; then
echo $PART >> $CHOICE_FILE
fi
echo $TYPE >> $CHOICE_FILE
done
if [ "$TESTEFI" == "" ]; then
#make boot partition bootable if not EFI
echo "a" >> $CHOICE_FILE
echo "1" >> $CHOICE_FILE
fi
echo "w" >> $CHOICE_FILE
# unmount all /TARGET & swapoff prior to autopartition
PARTSTOUNMOUNT=$(lsblk -o NAME,MOUNTPOINT -l -p -b | sed 1D | grep $PARTDRIVE | grep -v "SWAP" | awk 'NF>1 {print $1}')
for p in $PARTSTOUNMOUNT; do
# warning - possible deadlock(?)
while [ "`mount | grep $p`" ]; do
umount -R $(lsblk -o NAME,MOUNTPOINT -l -p -b | sed 1D | grep -v "SWAP" | grep -m 1 $p | awk 'NF>1 {print $2}')
done
done
CHECKSWAP=$(lsblk -o NAME,MOUNTPOINT -l -p -b | sed 1D | awk 'NF>1 && $2 ~ /SWAP/ {print $1}')
if [ "$CHECKSWAP" != "" ]; then
swapoff $CHECKSWAP
fi
#autopartition device
cat $CHOICE_FILE | $AUTOPARTITIONPROGRAM $PARTDRIVE
sleep 2
rm $CHOICE_FILE
}
parts_to_create_to_text() {
PARTS_TO_CREATE_TEXT=""
NF=$(echo $PARTS_TO_CREATE | awk -F"|" '{print NF}')
for i in `seq $NF`; do
CMD=$(echo $PARTS_TO_CREATE | cut -d "|" -f $i)
PART=$(echo $CMD | cut -d: -f1)
TYPE=$(echo $CMD | cut -d: -f2)
SIZE=$(echo $CMD | cut -d: -f3)
if [ "$SIZE" = "" ]; then
SIZE_TEXT="rest of drive"
else
SIZE_TEXT=$SIZE"b"
fi
if [ "$PARTS_TO_CREATE_TEXT" = "" ]; then
PARTS_TO_CREATE_TEXT="$PARTDRIVE$PART Size: $SIZE_TEXT Type: $TYPE"
else
PARTS_TO_CREATE_TEXT="$PARTS_TO_CREATE_TEXT\n$PARTDRIVE$PART Size: $SIZE_TEXT Type: $TYPE"
fi
done
}
generate_encryption_key() {
KEYFILE="$1"
echo $KEYFILE
mkdir -p -m0700 /etc/keys
umask 0077 && dd if=/dev/urandom bs=1 count=64 of=/etc/keys/$KEYFILE conv=excl,fsync
}
add_encryption_key_slot() {
PART=$1
PASS=$2
KEYFILE=$3
echo $PASS | cryptsetup luksAddKey $PART /etc/keys/$KEYFILE -l ${#PASS} -q -d -
}
encrypt_drives() {
# DRIVES_TO_ENCRYPT and DRIVES_TO_ENCRYPT_TEXT_ONLY must be set
if [ "$DRIVES_TO_ENCRYPT" == "" ]; then
echo "DRIVES_TO_ENCRYPT must be set"
exit 1
fi
FORMAT=0
if [ "$1" = "format" ]; then
FORMAT=1
$DIALOG $TITLE"$TITLETEXT" $YESNO $TEXT"Encrypt $DRIVES_TO_ENCRYPT_TEXT_ONLY?\nIt can take several seconds so don't panick!" $HEIGHT $WIDTH
else
$DIALOG $TITLE"$TITLETEXT" $YESNO $TEXT"Open $DRIVES_TO_ENCRYPT_TEXT_ONLY?\nIt can take several seconds so don't panick!" $HEIGHT $WIDTH
fi
if [ $? != 0 ]; then
exit 1
fi
# closing open crypt volumes
for f in $(lsblk -l -p | grep crypt | awk '{ print $1 }'); do
cryptsetup close $f
done
#CRYPTTAB=""
NF=$(echo $DRIVES_TO_ENCRYPT | awk -F"|" '{print NF}')
for i in `seq $NF`; do
CMD=$(echo $DRIVES_TO_ENCRYPT | cut -d "|" -f $i)
PART=$(echo $CMD | cut -d: -f1)
PASS=$(echo $CMD | cut -d: -f2)
MAPPED=$(echo $CMD | cut -d: -f3)
KEY_ADDED=0
if [ $FORMAT -eq 1 ]; then
if [ "$PASS" != "" ]; then
KEY_FILE=""
echo $PASS | cryptsetup luksFormat --type $LUKS_TYPE -l ${#PASS} -q -d - $PART
sleep 2
if [ $NO_BOOT_PART -eq 1 ]; then
# if no /boot then KEY_FILE=$PART.key; KEY_ADDED=1
KEY_FILE=$(echo $PART | tr "/" "_" | sed 's/^.//')".key"
generate_encryption_key $KEY_FILE
add_encryption_key_slot $PART $PASS $KEY_FILE
KEY_ADDED=1
fi
else
SWAPPASS=$(dd if=/dev/urandom count=8 bs=1)
echo $SWAPPASS | cryptsetup luksFormat --type $LUKS_TYPE -l ${#SWAPPASS} -q -d - $PART
sleep 2
fi
fi
if [ "$PASS" != "" ]; then
echo $PASS | cryptsetup luksOpen $PART $MAPPED -l ${#PASS} -d -
sleep 2
else
echo $SWAPPASS | cryptsetup luksOpen $PART $MAPPED -l ${#SWAPPASS} -d -
sleep 2
fi
UUID=$(blkid -o value -s UUID $PART)
OPTIONS="luks,discard"
if [ $KEY_ADDED -eq 1 ]; then
KEY=/etc/keys/$KEY_FILE
OPTIONS="$OPTIONS,key-slot=1"
else
KEY="none"
fi
if [ "$CRYPTTAB" = "" ]; then
if [ "$PASS" = "" ]; then
CRYPTTAB="$MAPPED:$UUID:/dev/urandom cipher=aes-xts-plain64,size=256,swap,discard"
else
CRYPTTAB="$MAPPED:$UUID:$KEY $OPTIONS"
fi
else
if [ "$PASS" = "" ]; then
CRYPTTAB="$CRYPTTAB|$MAPPED:$UUID:/dev/urandom cipher=aes-xts-plain64,size=256,swap,discard"
else
CRYPTTAB="$CRYPTTAB|$MAPPED:$UUID:$KEY $OPTIONS,initramfs"
fi
fi
done
}
configure_lvm() {
# TODO: wip - currently not used; much more sophisticated editor needed)
# fill in EXCLUDED_PARTS for pvs
# 1. select pvs (+remove them from the list)
PVS_SELECTED=0
PVS="@" #quick and dirty
while [ $PVS_SELECTED -eq 0 ]; do
DRIVES=`lsblk -l -p | grep part | egrep -v $EXCLUDED_PARTS | egrep -v $PVS | awk '{print $1}'`
partdrivemenu=""
for i in $DRIVES; do
partdrive="$i"
partdrivesize=`lsblk -o NAME,SIZE,TYPE -l -p -b | grep -m 1 "$i" | awk '{print $2}'`
partdrivemenu="$partdrivemenu $partdrive $partdrivesize"
done
$DIALOG $TITLE"$TITLETEXT" $MENU $TEXT"Select drive for lvm pv." $HEIGHT $WIDTH $MENUHEIGHT Exit "Exit" $partdrivemenu 2>$CHOICE_FILE
if [ "$?" = "0" ]; then
PV=`cat $CHOICE_FILE`
else
PV="Exit"
fi
rm $CHOICE_FILE
if [ "$PV" != "Exit" ]; then
if [ "$PVS" = "" ]; then
PVS="$PV"
else
PVS="$PVS|$PV"
fi
$DIALOG $TITLE"$TITLETEXT" $YESNO $TEXT"Do you want to add another pv?" $HEIGHT $WIDTH
if [ $? != 0 ]; then
PVS_SELECTED=1
fi
else
PVS_SELECTED=1
fi
done
if [ "$EXCLUDED_PARTS" = "" ]; then
EXCLUDED_PARTS="$PVS"
else
EXCLUDED_PARTS="$EXCLUDED_PARTS|$PVS"