-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathaif
executable file
·2901 lines (2346 loc) · 106 KB
/
aif
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
#
# Architect Installation Framework (version 2.1.1 - 16-Mar-2016)
#
# Written by Carl Duff for Architect Linux
#
# This program is free software, provided under the GNU General Public License
# as published by the Free Software Foundation. So feel free to copy, distribute,
# or modify it as you wish.
#
######################################################################
## ##
## Installer Variables ##
## ##
######################################################################
# Temporary files to store menu selections
ANSWER="/tmp/.aif" # Basic menu selections
PACKAGES="/tmp/.pkgs" # Packages to install
BTRFS_OPTS="/tmp/.btrfs_opts" # BTRFS mount options
# Save retyping
VERSION="Architect Installation Framework 2.1.1"
# Installation
DM_INST="" # Which DMs have been installed?
DM_ENABLED=0 # Has a display manager been enabled?
NM_INST="" # Which NMs have been installed?
NM_ENABLED=0 # Has a network connection manager been enabled?
KEYMAP="us" # Virtual console keymap. Default is "us"
XKBMAP="us" # X11 keyboard layout. Default is "us"
ZONE="" # For time
SUBZONE="" # For time
LOCALE="en_US.UTF-8" # System locale. Default is "en_US.UTF-8"
KERNEL="n" # Kernel(s) installed (base install); kernels for mkinitcpio
GRAPHIC_CARD="" # graphics card
INTEGRATED_GC="" # Integrated graphics card for NVIDIA
NVIDIA_INST=0 # Indicates if NVIDIA proprietary driver has been installed
NVIDIA="" # NVIDIA driver(s) to install depending on kernel(s)
VB_MOD="" # Virtualbox guest modules to install depending on kernel(s)
SHOW_ONCE=0 # Show de_wm information only once
MOUNTPOINT="/mnt" # Installation: Root mount
MOUNT="" # Installation: All other mounts branching from Root
BTRFS=0 # BTRFS used? "1" = btrfs alone, "2" = btrfs + subvolume(s)
BTRFS_MNT="" # used for syslinux where /mnt is a btrfs subvolume
F2FS=0 # F2FS used? "1" = yes.
INCLUDE_PART='part\|lvm\|crypt' # Partition types to include for display and selection.
COPY_PACCONF=0 # Copy over installer /etc/pacman.conf to installed system?
# Architecture
ARCHI=`uname -m` # Display whether 32 or 64 bit system
SYSTEM="Unknown" # Display whether system is BIOS or UEFI. Default is "unknown"
ROOT_PART="" # ROOT partition
UEFI_PART="" # UEFI partition
UEFI_MOUNT="" # UEFI mountpoint
# Menu highlighting (automated step progression)
HIGHLIGHT=0 # Highlight items for Main Menu
HIGHLIGHT_SUB=0 # Highlight items for submenus
SUB_MENU="" # Submenu to be highlighted
# Logical Volume Management
LVM=0 # Logical Volume Management Detected?
LVM_SEP_BOOT=0 # 1 = Seperate /boot, 2 = seperate /boot & LVM
LVM_VG="" # Name of volume group to create or use
LVM_VG_MB=0 # MB remaining of VG
LVM_LV_NAME="" # Name of LV to create or use
LV_SIZE_INVALID=0 # Is LVM LV size entered valid?
VG_SIZE_TYPE="" # Is VG in Gigabytes or Megabytes?
# LUKS
LUKS=0 # Luks Detected?
LUKS_DEV="" # If encrypted, partition
LUKS_NAME="" # Name given to encrypted partition
LUKS_UUID="" # UUID used for comparison purposes
LUKS_OPT="" # Default or user-defined?
MOUNTPOINT="/mnt" # Installation: Root mount
MOUNT="" # Installation: All other mounts branching from Root
BTRFS=0 # BTRFS used? "1" = btrfs alone, "2" = btrfs + subvolume(s)
BTRFS_MNT="" # used for syslinux where /mnt is a btrfs subvolume
F2FS=0 # F2FS used? "1" = yes.
# Language Support
CURR_LOCALE="en_US.UTF-8" # Default Locale
FONT="" # Set new font if necessary
# Edit Files
FILE="" # File(s) to be reviewed
######################################################################
## ##
## Core Functions ##
## ##
######################################################################
# Add locale on-the-fly and sets source translation file for installer
select_language() {
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " Select Language " --menu "\nLanguage / sprache / taal / språk / lingua / idioma / nyelv / língua" 0 0 9 \
"1" $"English (en_**)" \
"2" $"Español (es_ES)" \
"3" $"Português [Brasil] (pt_BR)" \
"4" $"Português (pt_PT)" \
"5" $"Français (fr_FR)" \
"6" $"Russkiy (ru_RU)" \
"7" $"Italiano (it_IT)" \
"8" $"Nederlands (nl_NL)" \
"9" $"Magyar (hu_HU)" 2>${ANSWER}
case $(cat ${ANSWER}) in
"1") source /aif-dev-master/english.trans
CURR_LOCALE="en_US.UTF-8"
;;
"2") source /aif-dev-master/spanish.trans
CURR_LOCALE="es_ES.UTF-8"
;;
"3") source /aif-dev-master/portuguese_brasil.trans
CURR_LOCALE="pt_BR.UTF-8"
;;
"4") source /aif-dev-master/portuguese.trans
CURR_LOCALE="pt_PT.UTF-8"
;;
"5") source /aif-dev-master/french.trans
CURR_LOCALE="fr_FR.UTF-8"
;;
"6") source /aif-dev-master/russian.trans
CURR_LOCALE="ru_RU.UTF-8"
FONT="LatKaCyrHeb-14.psfu"
;;
"7") source /aif-dev-master/italian.trans
CURR_LOCALE="it_IT.UTF-8"
;;
"8") source /aif-dev-master/dutch.trans
CURR_LOCALE="nl_NL.UTF-8"
;;
"9") source /aif-dev-master/hungarian.trans
CURR_LOCALE="hu_HU.UTF-8"
FONT="lat2-16.psfu"
;;
# "4") source /aif-dev-master/turkish.trans
# CURR_LOCALE="tr_TR.UTF-8"
# FONT="LatKaCyrHeb-14.psfu"
# ;;
# "6") source /aif-dev-master/greek.trans
# CURR_LOCALE="el_GR.UTF-8"
# FONT="iso07u-16.psfu"
# ;;
# "12") source /aif-dev-master/polish.trans
# CURR_LOCALE="pl_PL.UTF-8"
# FONT="latarcyrheb-sun16"
# ;;
*) exit 0
;;
esac
# Generate the chosen locale and set the language
sed -i "s/#${CURR_LOCALE}/${CURR_LOCALE}/" /etc/locale.gen
locale-gen >/dev/null 2>&1
export LANG=${CURR_LOCALE}
[[ $FONT != "" ]] && setfont $FONT
}
# Check user is root, and that there is an active internet connection
# Seperated the checks into seperate "if" statements for readability.
check_requirements() {
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ChkTitle " --infobox "$_ChkBody" 0 0
sleep 2
if [[ `whoami` != "root" ]]; then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_Erritle " --infobox "$_RtFailBody" 0 0
sleep 2
exit 1
fi
if [[ ! $(ping -c 1 google.com) ]]; then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --infobox "$_ConFailBody" 0 0
sleep 2
exit 1
fi
# This will only be executed where neither of the above checks are true.
# The error log is also cleared, just in case something is there from a previous use of the installer.
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ReqMetTitle " --infobox "$_ReqMetBody" 0 0
sleep 2
clear
echo "" > /tmp/.errlog
pacman -Syy
}
# Adapted from AIS. Checks if system is made by Apple, whether the system is BIOS or UEFI,
# and for LVM and/or LUKS.
id_system() {
# Apple System Detection
if [[ "$(cat /sys/class/dmi/id/sys_vendor)" == 'Apple Inc.' ]] || [[ "$(cat /sys/class/dmi/id/sys_vendor)" == 'Apple Computer, Inc.' ]]; then
modprobe -r -q efivars || true # if MAC
else
modprobe -q efivarfs # all others
fi
# BIOS or UEFI Detection
if [[ -d "/sys/firmware/efi/" ]]; then
# Mount efivarfs if it is not already mounted
if [[ -z $(mount | grep /sys/firmware/efi/efivars) ]]; then
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
fi
SYSTEM="UEFI"
else
SYSTEM="BIOS"
fi
}
# Adapted from AIS. An excellent bit of code!
arch_chroot() {
arch-chroot $MOUNTPOINT /bin/bash -c "${1}"
}
# If there is an error, display it, clear the log and then go back to the main menu (no point in continuing).
check_for_error() {
if [[ $? -eq 1 ]] && [[ $(cat /tmp/.errlog | grep -i "error") != "" ]]; then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$(cat /tmp/.errlog)" 0 0
echo "" > /tmp/.errlog
main_menu_online
fi
}
# Ensure that a partition is mounted
check_mount() {
if [[ $(lsblk -o MOUNTPOINT | grep ${MOUNTPOINT}) == "" ]]; then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_ErrNoMount" 0 0
main_menu_online
fi
}
# Ensure that Arch has been installed
check_base() {
if [[ ! -e ${MOUNTPOINT}/etc ]]; then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_ErrNoBase" 0 0
main_menu_online
fi
}
# Simple code to show devices / partitions.
show_devices() {
lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT | grep "disk\|part\|lvm\|crypt\|NAME\|MODEL\|TYPE\|FSTYPE\|SIZE\|MOUNTPOINT" > /tmp/.devlist
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_DevShowOpt " --textbox /tmp/.devlist 0 0
}
######################################################################
## ##
## Configuration Functions ##
## ##
######################################################################
# Originally adapted from AIS. Added option to allow users to edit the mirrorlist.
configure_mirrorlist() {
# Generate a mirrorlist based on the country chosen.
mirror_by_country() {
COUNTRY_LIST=""
countries_list="AU Australia AT Austria BA Bosnia_Herzegovina BY Belarus BE Belgium BR Brazil BG Bulgaria CA Canada CL Chile CN China CO Colombia CZ Czech_Republic DK Denmark EE Estonia FI Finland FR France DE Germany GB United_Kingdom GR Greece HU Hungary IN India IE Ireland IL Israel IT Italy JP Japan KZ Kazakhstan KR Korea LT Lithuania LV Latvia LU Luxembourg MK Macedonia NL Netherlands NC New_Caledonia NZ New_Zealand NO Norway PL Poland PT Portugal RO Romania RU Russia RS Serbia SG Singapore SK Slovakia ZA South_Africa ES Spain LK Sri_Lanka SE Sweden CH Switzerland TW Taiwan TR Turkey UA Ukraine US United_States UZ Uzbekistan VN Vietnam"
for i in ${countries_list}; do
COUNTRY_LIST="${COUNTRY_LIST} ${i}"
done
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MirrorlistTitle " --menu "$_MirrorCntryBody" 0 0 0 $COUNTRY_LIST 2>${ANSWER} || install_base_menu
URL="https://www.archlinux.org/mirrorlist/?country=$(cat ${ANSWER})&use_mirror_status=on"
MIRROR_TEMP=$(mktemp --suffix=-mirrorlist)
# Get latest mirror list and save to tmpfile
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MirrorlistTitle " --infobox "$_PlsWaitBody" 0 0
curl -so ${MIRROR_TEMP} ${URL} 2>/tmp/.errlog
check_for_error
sed -i 's/^#Server/Server/g' ${MIRROR_TEMP}
nano ${MIRROR_TEMP}
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MirrorlistTitle " --yesno "$_MirrorGenQ" 0 0
if [[ $? -eq 0 ]];then
mv -f /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.orig
mv -f ${MIRROR_TEMP} /etc/pacman.d/mirrorlist
chmod +r /etc/pacman.d/mirrorlist
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MirrorlistTitle " --infobox "\n$_Done!\n\n" 0 0
sleep 2
else
configure_mirrorlist
fi
}
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MirrorlistTitle " \
--menu "$_MirrorlistBody" 0 0 6 \
"1" "$_MirrorbyCountry" \
"2" "$_MirrorRankTitle" \
"3" "$_MirrorEdit" \
"4" "$_MirrorRestTitle" \
"5" "$_MirrorPacman" \
"6" "$_Back" 2>${ANSWER}
case $(cat ${ANSWER}) in
"1") mirror_by_country
;;
"2") dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MirrorlistTitle " --infobox "$_MirrorRankBody $_PlsWaitBody" 0 0
cp -f /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
rankmirrors -n 10 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist 2>/tmp/.errlog
check_for_error
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MirrorlistTitle " --infobox "\n$_Done!\n\n" 0 0
sleep 2
;;
"3") nano /etc/pacman.d/mirrorlist
;;
"4") if [[ -e /etc/pacman.d/mirrorlist.orig ]]; then
mv -f /etc/pacman.d/mirrorlist.orig /etc/pacman.d/mirrorlist
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MirrorlistTitle " --msgbox "\n$_Done!\n\n" 0 0
else
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_MirrorNoneBody" 0 0
fi
;;
"5") nano /etc/pacman.conf
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MirrorPacman " --yesno "$_MIrrorPacQ" 0 0 && COPY_PACCONF=1 || COPY_PACCONF=0
pacman -Syy
;;
*) install_base_menu
;;
esac
configure_mirrorlist
}
# virtual console keymap
set_keymap() {
KEYMAPS=""
for i in $(ls -R /usr/share/kbd/keymaps | grep "map.gz" | sed 's/\.map\.gz//g' | sort); do
KEYMAPS="${KEYMAPS} ${i} -"
done
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_VCKeymapTitle " \
--menu "$_VCKeymapBody" 20 40 16 ${KEYMAPS} 2>${ANSWER} || prep_menu
KEYMAP=$(cat ${ANSWER})
loadkeys $KEYMAP 2>/tmp/.errlog
check_for_error
echo -e "KEYMAP=${KEYMAP}\nFONT=${FONT}" > /tmp/vconsole.conf
}
# Set keymap for X11
set_xkbmap() {
XKBMAP_LIST=""
keymaps_xkb=("af Afghani al Albanian am Armenian ara Arabic at German-Austria az Azerbaijani ba Bosnian bd Bangla be Belgian bg Bulgarian br Portuguese-Brazil bt Dzongkha bw Tswana by Belarusian ca French-Canada cd French-DR-Congo ch German-Switzerland cm English-Cameroon cn Chinese cz Czech de German dk Danish ee Estonian epo Esperanto es Spanish et Amharic fo Faroese fi Finnish fr French gb English-UK ge Georgian gh English-Ghana gn French-Guinea gr Greek hr Croatian hu Hungarian ie Irish il Hebrew iq Iraqi ir Persian is Icelandic it Italian jp Japanese ke Swahili-Kenya kg Kyrgyz kh Khmer-Cambodia kr Korean kz Kazakh la Lao latam Spanish-Lat-American lk Sinhala-phonetic lt Lithuanian lv Latvian ma Arabic-Morocco mao Maori md Moldavian me Montenegrin mk Macedonian ml Bambara mm Burmese mn Mongolian mt Maltese mv Dhivehi ng English-Nigeria nl Dutch no Norwegian np Nepali ph Filipino pk Urdu-Pakistan pl Polish pt Portuguese ro Romanian rs Serbian ru Russian se Swedish si Slovenian sk Slovak sn Wolof sy Arabic-Syria th Thai tj Tajik tm Turkmen tr Turkish tw Taiwanese tz Swahili-Tanzania ua Ukrainian us English-US uz Uzbek vn Vietnamese za English-S-Africa")
for i in ${keymaps_xkb}; do
XKBMAP_LIST="${XKBMAP_LIST} ${i}"
done
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepKBLayout " --menu "$_XkbmapBody" 0 0 16 ${XKBMAP_LIST} 2>${ANSWER} || install_graphics_menu
XKBMAP=$(cat ${ANSWER} |sed 's/_.*//')
echo -e "Section "\"InputClass"\"\nIdentifier "\"system-keyboard"\"\nMatchIsKeyboard "\"on"\"\nOption "\"XkbLayout"\" "\"${XKBMAP}"\"\nEndSection" > ${MOUNTPOINT}/etc/X11/xorg.conf.d/00-keyboard.conf
}
# locale array generation code adapted from the Manjaro 0.8 installer
set_locale() {
LOCALES=""
for i in $(cat /etc/locale.gen | grep -v "# " | sed 's/#//g' | sed 's/ UTF-8//g' | grep .UTF-8); do
LOCALES="${LOCALES} ${i} -"
done
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseSysLoc " --menu "$_localeBody" 0 0 12 ${LOCALES} 2>${ANSWER} || config_base_menu
LOCALE=$(cat ${ANSWER})
echo "LANG=\"${LOCALE}\"" > ${MOUNTPOINT}/etc/locale.conf
sed -i "s/#${LOCALE}/${LOCALE}/" ${MOUNTPOINT}/etc/locale.gen 2>/tmp/.errlog
arch_chroot "locale-gen" >/dev/null 2>>/tmp/.errlog
check_for_error
}
# Set Zone and Sub-Zone
set_timezone() {
ZONE=""
for i in $(cat /usr/share/zoneinfo/zone.tab | awk '{print $3}' | grep "/" | sed "s/\/.*//g" | sort -ud); do
ZONE="$ZONE ${i} -"
done
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseTimeHC " --menu "$_TimeZBody" 0 0 10 ${ZONE} 2>${ANSWER} || config_base_menu
ZONE=$(cat ${ANSWER})
SUBZONE=""
for i in $(cat /usr/share/zoneinfo/zone.tab | awk '{print $3}' | grep "${ZONE}/" | sed "s/${ZONE}\///g" | sort -ud); do
SUBZONE="$SUBZONE ${i} -"
done
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseTimeHC " --menu "$_TimeSubZBody" 0 0 11 ${SUBZONE} 2>${ANSWER} || config_base_menu
SUBZONE=$(cat ${ANSWER})
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseTimeHC " --yesno "$_TimeZQ ${ZONE}/${SUBZONE}?" 0 0
if [[ $? -eq 0 ]]; then
arch_chroot "ln -s /usr/share/zoneinfo/${ZONE}/${SUBZONE} /etc/localtime" 2>/tmp/.errlog
check_for_error
else
config_base_menu
fi
}
set_hw_clock() {
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseTimeHC " --menu "$_HwCBody" 0 0 2 \
"utc" "-" "localtime" "-" 2>${ANSWER}
[[ $(cat ${ANSWER}) != "" ]] && arch_chroot "hwclock --systohc --$(cat ${ANSWER})" 2>/tmp/.errlog && check_for_error
}
# Function will not allow incorrect UUID type for installed system.
generate_fstab() {
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseFstab " --menu "$_FstabBody" 0 0 4 \
"genfstab -p" "$_FstabDevName" \
"genfstab -L -p" "$_FstabDevLabel" \
"genfstab -U -p" "$_FstabDevUUID" \
"genfstab -t PARTUUID -p" "$_FstabDevPtUUID" 2>${ANSWER}
if [[ $(cat ${ANSWER}) != "" ]]; then
if [[ $SYSTEM == "BIOS" ]] && [[ $(cat ${ANSWER}) == "genfstab -t PARTUUID -p" ]]; then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_FstabErr" 0 0
generate_fstab
else
$(cat ${ANSWER}) ${MOUNTPOINT} > ${MOUNTPOINT}/etc/fstab 2>/tmp/.errlog
check_for_error
[[ -f ${MOUNTPOINT}/swapfile ]] && sed -i "s/\\${MOUNTPOINT}//" ${MOUNTPOINT}/etc/fstab
fi
fi
config_base_menu
}
set_hostname() {
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseHost " --inputbox "$_HostNameBody" 0 0 "arch" 2>${ANSWER} || config_base_menu
echo "$(cat ${ANSWER})" > ${MOUNTPOINT}/etc/hostname 2>/tmp/.errlog
echo -e "#<ip-address>\t<hostname.domain.org>\t<hostname>\n127.0.0.1\tlocalhost.localdomain\tlocalhost\t$(cat ${ANSWER})\n::1\tlocalhost.localdomain\tlocalhost\t$(cat ${ANSWER})" > ${MOUNTPOINT}/etc/hosts 2>>/tmp/.errlog
check_for_error
}
# Adapted and simplified from the Manjaro 0.8 and Antergos 2.0 installers
set_root_password() {
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrRoot " --clear --insecure --passwordbox "$_PassRtBody" 0 0 2> ${ANSWER} || config_base_menu
PASSWD=$(cat ${ANSWER})
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrRoot " --clear --insecure --passwordbox "$_PassReEntBody" 0 0 2> ${ANSWER} || config_base_menu
PASSWD2=$(cat ${ANSWER})
if [[ $PASSWD == $PASSWD2 ]]; then
echo -e "${PASSWD}\n${PASSWD}" > /tmp/.passwd
arch_chroot "passwd root" < /tmp/.passwd >/dev/null 2>/tmp/.errlog
rm /tmp/.passwd
check_for_error
else
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_PassErrBody" 0 0
set_root_password
fi
}
# Originally adapted from the Antergos 2.0 installer
create_new_user() {
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_NUsrTitle " --inputbox "$_NUsrBody" 0 0 "" 2>${ANSWER} || config_base_menu
USER=$(cat ${ANSWER})
# Loop while user name is blank, has spaces, or has capital letters in it.
while [[ ${#USER} -eq 0 ]] || [[ $USER =~ \ |\' ]] || [[ $USER =~ [^a-z0-9\ ] ]]; do
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_NUsrTitle " --inputbox "$_NUsrErrBody" 0 0 "" 2>${ANSWER} || config_base_menu
USER=$(cat ${ANSWER})
done
# Enter password. This step will only be reached where the loop has been skipped or broken.
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrNew " --clear --insecure --passwordbox "$_PassNUsrBody $USER\n\n" 0 0 2> ${ANSWER} || config_base_menu
PASSWD=$(cat ${ANSWER})
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrNew " --clear --insecure --passwordbox "$_PassReEntBody" 0 0 2> ${ANSWER} || config_base_menu
PASSWD2=$(cat ${ANSWER})
# loop while passwords entered do not match.
while [[ $PASSWD != $PASSWD2 ]]; do
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_PassErrBody" 0 0
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrNew " --clear --insecure --passwordbox "$_PassNUsrBody $USER\n\n" 0 0 2> ${ANSWER} || config_base_menu
PASSWD=$(cat ${ANSWER})
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrNew " --clear --insecure --passwordbox "$_PassReEntBody" 0 0 2> ${ANSWER} || config_base_menu
PASSWD2=$(cat ${ANSWER})
done
# create new user. This step will only be reached where the password loop has been skipped or broken.
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrNew " --infobox "$_NUsrSetBody" 0 0
sleep 2
# Create the user, set password, then remove temporary password file
arch_chroot "useradd ${USER} -m -g users -G wheel,storage,power,network,video,audio,lp -s /bin/bash" 2>/tmp/.errlog
check_for_error
echo -e "${PASSWD}\n${PASSWD}" > /tmp/.passwd
arch_chroot "passwd ${USER}" < /tmp/.passwd >/dev/null 2>/tmp/.errlog
rm /tmp/.passwd
check_for_error
# Set up basic configuration files and permissions for user
arch_chroot "cp /etc/skel/.bashrc /home/${USER}"
arch_chroot "chown -R ${USER}:users /home/${USER}"
[[ -e ${MOUNTPOINT}/etc/sudoers ]] && sed -i '/%wheel ALL=(ALL) ALL/s/^#//' ${MOUNTPOINT}/etc/sudoers
}
run_mkinitcpio() {
clear
KERNEL=""
# If LVM and/or LUKS used, add the relevant hook(s)
([[ $LVM -eq 1 ]] && [[ $LUKS -eq 0 ]]) && sed -i 's/block filesystems/block lvm2 filesystems/g' ${MOUNTPOINT}/etc/mkinitcpio.conf 2>/tmp/.errlog
([[ $LVM -eq 1 ]] && [[ $LUKS -eq 1 ]]) && sed -i 's/block filesystems/block encrypt lvm2 filesystems/g' ${MOUNTPOINT}/etc/mkinitcpio.conf 2>/tmp/.errlog
([[ $LVM -eq 0 ]] && [[ $LUKS -eq 1 ]]) && sed -i 's/block filesystems/block encrypt filesystems/g' ${MOUNTPOINT}/etc/mkinitcpio.conf 2>/tmp/.errlog
check_for_error
# Run Mkinitcpio command depending on kernel(s) installed
KERNEL=$(ls ${MOUNTPOINT}/boot/*.img | grep -v "fallback" | sed "s~${MOUNTPOINT}/boot/initramfs-~~g" | sed s/\.img//g | uniq)
for i in ${KERNEL}; do
arch_chroot "mkinitcpio -p ${i}" 2>>/tmp/.errlog
done
check_for_error
}
######################################################################
## ##
## System and Partitioning Functions ##
## ##
######################################################################
# Unmount partitions.
umount_partitions(){
MOUNTED=""
MOUNTED=$(mount | grep "${MOUNTPOINT}" | awk '{print $3}' | sort -r)
swapoff -a
for i in ${MOUNTED[@]}; do
umount $i >/dev/null 2>>/tmp/.errlog
done
check_for_error
}
# Revised to deal with partion sizes now being displayed to the user
confirm_mount() {
if [[ $(mount | grep $1) ]]; then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MntStatusTitle " --infobox "$_MntStatusSucc" 0 0
sleep 2
PARTITIONS=$(echo $PARTITIONS | sed "s~${PARTITION} [0-9]*[G-M]~~" | sed "s~${PARTITION} [0-9]*\.[0-9]*[G-M]~~" | sed s~${PARTITION}$' -'~~)
NUMBER_PARTITIONS=$(( NUMBER_PARTITIONS - 1 ))
else
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MntStatusTitle " --infobox "$_MntStatusFail" 0 0
sleep 2
prep_menu
fi
}
# btrfs specific for subvolumes
confirm_mount_btrfs() {
if [[ $(mount | grep $1) ]]; then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MntStatusTitle " --infobox "$_MntStatusSucc\n$(cat ${BTRFS_OPTS})",subvol="${BTRFS_MSUB_VOL}\n\n" 0 0
sleep 2
else
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MntStatusTitle " --infobox "$_MntStatusFail" 0 0
sleep 2
prep_menu
fi
}
# This function does not assume that the formatted device is the Root installation device as
# more than one device may be formatted. Root is set in the mount_partitions function.
select_device() {
DEVICE=""
devices_list=$(lsblk -lno NAME,SIZE,TYPE | grep 'disk' | awk '{print "/dev/" $1 " " $2}' | sort -u);
for i in ${devices_list[@]}; do
DEVICE="${DEVICE} ${i}"
done
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_DevSelTitle " --menu "$_DevSelBody" 0 0 4 ${DEVICE} 2>${ANSWER} || prep_menu
DEVICE=$(cat ${ANSWER})
}
# Finds all available partitions according to type(s) specified and generates a list
# of them. This also includes partitions on different devices.
find_partitions() {
PARTITIONS=""
NUMBER_PARTITIONS=0
partition_list=$(lsblk -lno NAME,SIZE,TYPE | grep $INCLUDE_PART | sed 's/part$/\/dev\//g' | sed 's/lvm$\|crypt$/\/dev\/mapper\//g' | awk '{print $3$1 " " $2}' | sort -u)
for i in ${partition_list}; do
PARTITIONS="${PARTITIONS} ${i}"
NUMBER_PARTITIONS=$(( NUMBER_PARTITIONS + 1 ))
done
# Double-partitions will be counted due to counting sizes, so fix
NUMBER_PARTITIONS=$(( NUMBER_PARTITIONS / 2 ))
# Deal with partitioning schemes appropriate to mounting, lvm, and/or luks.
case $INCLUDE_PART in
'part\|lvm\|crypt') # Deal with incorrect partitioning for main mounting function
if ([[ $SYSTEM == "UEFI" ]] && [[ $NUMBER_PARTITIONS -lt 2 ]]) || ([[ $SYSTEM == "BIOS" ]] && [[ $NUMBER_PARTITIONS -eq 0 ]]); then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_PartErrBody" 0 0
create_partitions
fi
;;
'part\|crypt') # Ensure there is at least one partition for LVM
if [[ $NUMBER_PARTITIONS -eq 0 ]]; then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_LvmPartErrBody" 0 0
create_partitions
fi
;;
'part\|lvm') # Ensure there are at least two partitions for LUKS
if [[ $NUMBER_PARTITIONS -lt 2 ]]; then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_LuksPartErrBody" 0 0
create_partitions
fi
;;
esac
}
create_partitions(){
# Securely destroy all data on a given device.
secure_wipe(){
# Warn the user. If they proceed, wipe the selected device.
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PartOptWipe " --yesno "$_AutoPartWipeBody1 ${DEVICE} $_AutoPartWipeBody2" 0 0
if [[ $? -eq 0 ]]; then
clear
# Install wipe where not already installed. Much faster than dd
if [[ ! -e /usr/bin/wipe ]]; then
pacman -Sy --noconfirm wipe 2>/tmp/.errlog
check_for_error
fi
clear
wipe -Ifre ${DEVICE}
# Alternate dd command - requires pv to be installed
#dd if=/dev/zero | pv | dd of=${DEVICE} iflag=nocache oflag=direct bs=4096 2>/tmp/.errlog
check_for_error
else
create_partitions
fi
}
# BIOS and UEFI
auto_partition(){
# Provide warning to user
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepPartDisk " --yesno "$_AutoPartBody1 $DEVICE $_AutoPartBody2 $_AutoPartBody3" 0 0
if [[ $? -eq 0 ]]; then
# Find existing partitions (if any) to remove
parted -s ${DEVICE} print | awk '/^ / {print $1}' > /tmp/.del_parts
for del_part in $(tac /tmp/.del_parts); do
parted -s ${DEVICE} rm ${del_part} 2>/tmp/.errlog
check_for_error
done
# Identify the partition table
part_table=$(parted -s ${DEVICE} print | grep -i 'partition table' | awk '{print $3}')
# Create partition table if one does not already exist
([[ $SYSTEM == "BIOS" ]] && [[ $part_table != "msdos" ]]) && parted -s ${DEVICE} mklabel msdos 2>/tmp/.errlog
([[ $SYSTEM == "UEFI" ]] && [[ $part_table != "gpt" ]]) && parted -s ${DEVICE} mklabel gpt 2>/tmp/.errlog
check_for_error
# Create paritions (same basic partitioning scheme for BIOS and UEFI)
if [[ $SYSTEM == "BIOS" ]]; then
parted -s ${DEVICE} mkpart primary ext3 1MiB 513MiB 2>/tmp/.errlog
else
parted -s ${DEVICE} mkpart ESP fat32 1MiB 513MiB 2>/tmp/.errlog
fi
parted -s ${DEVICE} set 1 boot on 2>>/tmp/.errlog
parted -s ${DEVICE} mkpart primary ext3 513MiB 100% 2>>/tmp/.errlog
check_for_error
# Show created partitions
lsblk ${DEVICE} -o NAME,TYPE,FSTYPE,SIZE > /tmp/.devlist
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "" --textbox /tmp/.devlist 0 0
else
create_partitions
fi
}
# Partitioning Menu
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepPartDisk " --menu "$_PartToolBody" 0 0 7 \
"$_PartOptWipe" "BIOS & UEFI" \
"$_PartOptAuto" "BIOS & UEFI" \
"cfdisk" "BIOS" \
"cgdisk" "UEFI" \
"fdisk" "BIOS & UEFI" \
"gdisk" "UEFI" \
"parted" "BIOS & UEFI" 2>${ANSWER}
clear
# If something selected
if [[ $(cat ${ANSWER}) != "" ]]; then
if ([[ $(cat ${ANSWER}) != "$_PartOptWipe" ]] && [[ $(cat ${ANSWER}) != "$_PartOptAuto" ]]); then
$(cat ${ANSWER}) ${DEVICE}
else
[[ $(cat ${ANSWER}) == "$_PartOptWipe" ]] && secure_wipe && create_partitions
[[ $(cat ${ANSWER}) == "$_PartOptAuto" ]] && auto_partition
fi
fi
prep_menu
}
# Set static list of filesystems rather than on-the-fly.
select_filesystem(){
# Clear special FS type flags
BTRFS=0
F2FS=0
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_FSTitle " --menu "$_FSBody" 0 0 12 \
"$_FSSkip" "-" \
"btrfs" "mkfs.btrfs -f" \
"ext2" "mkfs.ext2 -q" \
"ext3" "mkfs.ext3 -q" \
"ext4" "mkfs.ext4 -q" \
"f2fs" "mkfs.f2fs" \
"jfs" "mkfs.jfs -q" \
"nilfs2" "mkfs.nilfs2 -q" \
"ntfs" "mkfs.ntfs -q" \
"reiserfs" "mkfs.reiserfs -q" \
"vfat" "mkfs.vfat -F32" \
"xfs" "mkfs.xfs -f" 2>${ANSWER}
case $(cat ${ANSWER}) in
"$_FSSkip") FILESYSTEM="$_FSSkip" ;;
"btrfs") FILESYSTEM="mkfs.btrfs -f"
modprobe btrfs
BTRFS=1 ;;
"ext2") FILESYSTEM="mkfs.ext2 -q" ;;
"ext3") FILESYSTEM="mkfs.ext3 -q" ;;
"ext4") FILESYSTEM="mkfs.ext4 -q" ;;
"f2fs") FILESYSTEM="mkfs.f2fs"
modprobe f2fs
F2FS=1 ;;
"jfs") FILESYSTEM="mkfs.jfs -q" ;;
"nilfs2") FILESYSTEM="mkfs.nilfs2 -q" ;;
"ntfs") FILESYSTEM="mkfs.ntfs -q" ;;
"reiserfs") FILESYSTEM="mkfs.reiserfs -q" ;;
"vfat") FILESYSTEM="mkfs.vfat -F32" ;;
"xfs") FILESYSTEM="mkfs.xfs -f" ;;
*) prep_menu ;;
esac
# Warn about formatting!
if [[ $FILESYSTEM != $_FSSkip ]]; then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_FSTitle " --yesno "\n$FILESYSTEM $PARTITION\n\n" 0 0
if [[ $? -eq 0 ]]; then
${FILESYSTEM} ${PARTITION} >/dev/null 2>/tmp/.errlog
check_for_error
else
select_filesystem
fi
fi
}
mount_partitions() {
# subfunction for btrfs
btrfs_subvols() {
BTRFS_MSUB_VOL=""
BTRFS_OSUB_VOL=""
BTRFS_MNT=""
BTRFS_VOL_LIST="/tmp/.vols"
echo "" > ${BTRFS_VOL_LIST}
BTRFS_OSUB_NUM=1
# Name initial subvolume from which other (optional) subvolumes may branch from
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_btrfsSVTitle " --inputbox "$_btrfsMSubBody1 ${MOUNTPOINT}${MOUNT} $_btrfsMSubBody2" 0 0 "" 2>${ANSWER} || select_filesystem
BTRFS_MSUB_VOL=$(cat ${ANSWER})
# Loop while subvolume is blank or has spaces.
while [[ ${#BTRFS_MSUB_VOL} -eq 0 ]] || [[ $BTRFS_MSUB_VOL =~ \ |\' ]]; do
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --inputbox "$_btrfsSVErrBody" 0 0 "" 2>${ANSWER} || select_filesystem
BTRFS_MSUB_VOL=$(cat ${ANSWER})
done
# if root, then create flag for syslinux, systemd-boot and rEFInd bootloaders
[[ ${MOUNT} == "" ]] && BTRFS_MNT="rootflags=subvol="$BTRFS_MSUB_VOL
# change dir
cd ${MOUNTPOINT}${MOUNT} 2>/tmp/.errlog
btrfs subvolume create ${BTRFS_MSUB_VOL} 2>>/tmp/.errlog
cd
umount ${PARTITION} 2>>/tmp/.errlog
check_for_error
# Get any mount options and mount
btrfs_mount_opts
if [[ $(cat ${BTRFS_OPTS}) != "" ]]; then
mount -o $(cat ${BTRFS_OPTS})",subvol="${BTRFS_MSUB_VOL} ${PARTITION} ${MOUNTPOINT}${MOUNT} 2>/tmp/.errlog
else
mount -o "subvol="${BTRFS_MSUB_VOL} ${PARTITION} ${MOUNTPOINT}${MOUNT} 2>/tmp/.errlog
fi
# Check for error and confirm successful mount
check_for_error
confirm_mount_btrfs ${MOUNTPOINT}${MOUNT}
# Now change dir and create the subvolumes
cd ${MOUNTPOINT}${MOUNT} 2>/tmp/.errlog
check_for_error
# Loop while the termination character has not been entered
while [[ $BTRFS_OSUB_VOL != "*" ]]; do
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_btrfsSVTitle ($BTRFS_MSUB_VOL) " --inputbox "$_btrfsSVBody1 $BTRFS_OSUB_NUM $_btrfsSVBody2 $BTRFS_MSUB_VOL.$_btrfsSVBody3 $(cat ${BTRFS_VOL_LIST})" 0 0 "" 2>${ANSWER} || select_filesystem
BTRFS_OSUB_VOL=$(cat ${ANSWER})
# Loop while subvolume is blank or has spaces.
while [[ ${#BTRFS_OSUB_VOL} -eq 0 ]] || [[ $BTRFS_SUB_VOL =~ \ |\' ]]; do
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle ($BTRFS_MSUB_VOL) " --inputbox "$_btrfsSVErrBody ($BTRFS_OSUB_NUM)." 0 0 "" 2>${ANSWER} || select_filesystem
BTRFS_OSUB_VOL=$(cat ${ANSWER})
done
btrfs subvolume create ${BTRFS_OSUB_VOL} 2>/tmp/.errlog
check_for_error
BTRFS_OSUB_NUM=$(( BTRFS_OSUB_NUM + 1 ))
echo $BTRFS_OSUB_VOL" " >> ${BTRFS_VOL_LIST}
done
# Show the subvolumes created
echo -e "btrfs subvols:\n" > /tmp/.subvols
ls >> /tmp/.subvols
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --textbox /tmp/.subvols 0 0
cd
}
# This subfunction allows for btrfs-specific mounting options to be applied.
btrfs_mount_opts() {
echo "" > ${BTRFS_OPTS}
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_btrfsSVTitle " --checklist "$_btrfsMntBody" 0 0 16 \
"autodefrag" "-" off \
"compress=zlib" "-" off \
"compress=lzo" "-" off \
"compress=no" "-" off \
"compress-force=zlib" "-" off \
"compress-force=lzo" "-" off \
"discard" "-" off \
"noacl" "-" off \
"noatime" "-" off \
"nodatasum" "-" off \
"nospace_cache" "-" off \
"recovery" "-" off \
"skip_balance" "-" off \
"space_cache" "-" off \
"ssd" "-" off \
"ssd_spread" "-" off 2>${BTRFS_OPTS}
# Now clean up the file
sed -i 's/ /,/g' ${BTRFS_OPTS}
sed -i '$s/,$//' ${BTRFS_OPTS}
if [[ $(cat ${BTRFS_OPTS}) != "" ]]; then
dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_btrfsSVTitle " --yesno "$_btrfsMntConfBody $(cat $BTRFS_OPTS)\n" 0 0
[[ $? -eq 1 ]] && btrfs_mount_opts
fi
}
# Subfunction to save repetition of code
mount_current_partition(){
# Make the mount directory
mkdir -p ${MOUNTPOINT}${MOUNT} 2>/tmp/.errlog
# If btrfs without subvolumes has been selected, get subvolume opts
[[ $BTRFS -eq 1 ]] && btrfs_mount_opts
# If BTRFS with options (not subvols), else standard mount
if [[ $BTRFS -eq 1 ]] && [[ $(cat ${BTRFS_OPTS}) != "" ]]; then
mount -o $(cat ${BTRFS_OPTS}) ${PARTITION} ${MOUNTPOINT}${MOUNT} 2>>/tmp/.errlog
BTRFS=0 # reset
else
mount ${PARTITION} ${MOUNTPOINT}${MOUNT} 2>>/tmp/.errlog
fi
check_for_error
confirm_mount ${MOUNTPOINT}${MOUNT}
# If BTRFS subvolume option, act on mounted partition
[[ $BTRFS -eq 2 ]] && btrfs_subvols
# Identify if mounted partition is type "crypt" (LUKS on LVM, or LUKS alone)
if [[ $(lsblk -lno TYPE ${PARTITION} | grep "crypt") != "" ]]; then
# cryptname for bootloader configuration either way
LUKS=1
LUKS_NAME=$(echo ${PARTITION} | sed "s~^/dev/mapper/~~g")
# Check if LUKS on LVM (parent = lvm /dev/mapper/...)
cryptparts=$(lsblk -lno NAME,FSTYPE,TYPE | grep "lvm" | grep -i "crypto_luks" | uniq | awk '{print "/dev/mapper/"$1}')
for i in ${cryptparts}; do
if [[ $(lsblk -lno NAME ${i} | grep $LUKS_NAME) != "" ]]; then
LUKS_DEV="$LUKS_DEV cryptdevice=${i}:$LUKS_NAME"
LVM=1
break;
fi
done
# Check if LUKS alone (parent = part /dev/...)
cryptparts=$(lsblk -lno NAME,FSTYPE,TYPE | grep "part" | grep -i "crypto_luks" | uniq | awk '{print "/dev/"$1}')
for i in ${cryptparts}; do
if [[ $(lsblk -lno NAME ${i} | grep $LUKS_NAME) != "" ]]; then
LUKS_UUID=$(lsblk -lno UUID,TYPE,FSTYPE ${i} | grep "part" | grep -i "crypto_luks" | awk '{print $1}')
LUKS_DEV="$LUKS_DEV cryptdevice=UUID=$LUKS_UUID:$LUKS_NAME"
break;
fi
done
# If LVM logical volume....
elif [[ $(lsblk -lno TYPE ${PARTITION} | grep "lvm") != "" ]]; then
LVM=1
# First get crypt name (code above would get lv name)
cryptparts=$(lsblk -lno NAME,TYPE,FSTYPE | grep "crypt" | grep -i "lvm2_member" | uniq | awk '{print "/dev/mapper/"$1}')
for i in ${cryptparts}; do
if [[ $(lsblk -lno NAME ${i} | grep $(echo $PARTITION | sed "s~^/dev/mapper/~~g")) != "" ]]; then
LUKS_NAME=$(echo ${i} | sed s~/dev/mapper/~~g)
break;
fi
done
# Now get the device (/dev/...) for the crypt name
cryptparts=$(lsblk -lno NAME,FSTYPE,TYPE | grep "part" | grep -i "crypto_luks" | uniq | awk '{print "/dev/"$1}')
for i in ${cryptparts}; do
if [[ $(lsblk -lno NAME ${i} | grep $LUKS_NAME) != "" ]]; then
# Create UUID for comparison
LUKS_UUID=$(lsblk -lno UUID,TYPE,FSTYPE ${i} | grep "part" | grep -i "crypto_luks" | awk '{print $1}')
# Check if not already added as a LUKS DEVICE (i.e. multiple LVs on one crypt). If not, add.
if [[ $(echo $LUKS_DEV | grep $LUKS_UUID) == "" ]]; then
LUKS_DEV="$LUKS_DEV cryptdevice=UUID=$LUKS_UUID:$LUKS_NAME"
LUKS=1
fi