-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgdl
2627 lines (2466 loc) · 99.9 KB
/
gdl
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
#
# Installer script for Golden Drake Linux (GDL): Arch for gaming and game dev!
#
# Copyright (C) 2020-2025 Golden Drake Studios: goldendrakestudios.com
# Forked originally from the Anarchy installer: anarchyinstaller.gitlab.io
#
# shellcheck disable=SC2076,SC2086
# shellcheck source=gdl.conf
source /etc/gdl.conf || exit 1
# shellcheck source=lang/english.conf
source "${LANG_FILE}" || exit 1
################################################################################
# Initialize installer. If this is the script's first (automatic) run, create
# the log file (by posting its first log message), start the network manager,
# configure pacman, and enlarge the console font if a HiDPI display is detected,
# then return the user to the command line so they can run other commands before
# (or instead of) launching the install process. Otherwise (i.e., if the log
# file already exists), prepare for installation by evaluating the hardware
# environment, setting a 'force_quit' trap, etc.
#
# Globals: GDL_VERSION, LOG_FILE, REDUCE_EXTRANEOUS_TEXT, RAM, BATTERY, VM_TYPE,
# GPU_CHIPSET, DEFAULT_GPU_DRIVER, BASE_PACKAGES, MISC_PACKAGES, IGPU_PACKAGES
# Arguments: None
################################################################################
initialize() {
if [[ ! -f "${LOG_FILE}" ]]; then
log "Initializing GDL installer v${GDL_VERSION}"
systemctl start NetworkManager.service
sed -i '/#Parallel/s/#// ; s/#Color/Color\nILoveCandy/' /etc/pacman.conf
sed -zi 's/#\[multilib]\n#Include/[multilib]\nInclude/' /etc/pacman.conf
(( $(awk -F , '{print $1}' /sys/class/graphics/fb0/virtual_size) > 1920 )) \
&& setfont ter-v32n # large font for high-resolution screens
[[ -d /tmp/gdl ]] || mkdir /tmp/gdl
return_to_shell_prompt
elif (( $(wc -l "${LOG_FILE}" | awk '{print $1}') > 1 )); then
echo >>"${LOG_FILE}" # add white space
log "Relaunching installer..."
fi
trap force_quit SIGINT # call 'force_quit' when Ctrl+C is pressed
set -o pipefail # ensure $? remembers failures from piped commands
if (( $(tput lines) < 25 )) || grep -q 'accessibility=' /proc/cmdline; then
REDUCE_EXTRANEOUS_TEXT='true'
fi
if [[ -n "${BATTERY}" ]]; then
BASE_PACKAGES+="${MISC_PACKAGES[battery]}"
log "Battery: ${BATTERY} ($(cat "${BATTERY}/capacity")%)"
fi
if [[ "${VM_TYPE}" == 'none' ]]; then
if lspci | grep 'VGA' | grep -q 'Intel'; then
GPU_CHIPSET='Intel'
DEFAULT_GPU_DRIVER='xf86-video-intel'
BASE_PACKAGES+="${IGPU_PACKAGES[intel]}" # iGPU
fi
if lspci | grep 'VGA' | grep -Eq 'ATI|AMD'; then
GPU_CHIPSET='AMD/ATI'
DEFAULT_GPU_DRIVER='xf86-video-amdgpu'
BASE_PACKAGES+="${IGPU_PACKAGES[amd]}" # possibly iGPU
fi
if lspci | grep 'VGA' | grep -iq 'nvidia'; then
GPU_CHIPSET='NVIDIA'
DEFAULT_GPU_DRIVER='nvidia-dkms'
fi
log "Graphics chipset: ${GPU_CHIPSET}"
else
log "VM environment: ${VM_TYPE}"
[[ "${VM_TYPE}" =~ qemu|oracle|vmware ]] || VM_TYPE='other'
fi
RAM=$(( $(grep MemTotal /proc/meminfo | awk '{print $2}') / 1024 ))
log "Memory: ${RAM} MiB RAM"
}
################################################################################
# Return the user to the command line with a welcome message plus help text
# telling them how to (a) relaunch the installer, (b) read ArchWiki articles
# offline in the terminal, (c) reboot, or (d) shut down.
#
# Globals: SHELL_PROMPT_WELCOME, SHELL_PROMPT_HELP, ERRORS_LOGGED
# Arguments: None
################################################################################
return_to_shell_prompt() {
dragonsay "${SHELL_PROMPT_WELCOME}" --check-errors
echo -e "${SHELL_PROMPT_HELP}"
exit "${ERRORS_LOGGED}"
}
################################################################################
# Handle a sudden exit caused by the user pressing Ctrl+C.
#
# Globals: TITLE, FORCE_QUIT_TITLE, FORCE_QUIT_MSG, ERRORS_LOGGED, EXIT_CONFIRM,
# YES, NO
# Arguments: None
################################################################################
force_quit() {
TITLE="${FORCE_QUIT_TITLE}"
if yesno "${EXIT_CONFIRM}" "${YES}" "${NO}" --defaultno; then
log "User pressed Ctrl+C and cancelled installation (errors logged: \
${ERRORS_LOGGED})"
message "${FORCE_QUIT_MSG}"
return_to_shell_prompt
else
log "User pressed Ctrl+C, but then continued installation"
fi
}
################################################################################
# Present the language menu (for the installer, not the soon-to-be-installed
# system: its language is determined by 'set_locale'). If the associated
# language file differs from the previously-sourced language file, source it to
# update all language-specific globals and edit gdl.conf to ensure the same
# language file is sourced again if the installer is closed and relaunched.
#
# Globals: TITLE, SET_LANG_TITLE, LANG_FILE, SET_LANG_MSG, ERRORS_LOGGED,
# BOLD_RED, COLOR_RESET
# Arguments: None
################################################################################
set_installer_language() {
TITLE="${SET_LANG_TITLE}"
local language prev_lang_file="${LANG_FILE}"
until language="$(dialog --no-cancel --menu "\n${SET_LANG_MSG}" 20 60 10 \
'English' 'English' \
'Bulgarian' 'Български' \
'Dutch' 'Nederlands' \
'French' 'Français' \
'German' 'Deutsch' \
'Greek' 'Ελληνικά' \
'Hungarian' 'Magyar' \
'Indonesian' 'bahasa Indonesia' \
'Italian' 'Italiano' \
'Latvian' 'Latviešu' \
'Lithuanian' 'Lietuvių' \
'Polish' 'Polski' \
'Portuguese' 'Português' \
'Portuguese-Brazil' 'Português do Brasil' \
'Romanian' 'Română' \
'Russian' 'Русский' \
'Spanish' 'Español' \
'Swedish' 'Svenska')"; do
continue
done
LANG_FILE="/usr/share/gdl/lang/${language@L}.conf"
if [[ "${LANG_FILE}" != "${prev_lang_file}" ]]; then
if source "${LANG_FILE}"; then
sed -i "s:^LANG_FILE=.*:LANG_FILE='${LANG_FILE}':" /etc/gdl.conf
else
log_error "Language file '${LANG_FILE}' not found"
log "Exiting installer (errors logged: ${ERRORS_LOGGED})"
echo -e "${BOLD_RED}ERROR:${COLOR_RESET} No file found for '${language}'"
exit "${ERRORS_LOGGED}"
fi
fi
log "Installer language: ${language}"
}
################################################################################
# Present the keymap menu.
#
# Globals: TITLE, SET_KEYMAP_TITLE, KEYMAP, SET_KEYMAP_MSG, OTHER, OK, BACK
# Arguments: None
################################################################################
set_keymap() {
TITLE="${SET_KEYMAP_TITLE}"
local keymap_list
keymap_list="$(find /usr/share/kbd/keymaps -type f \
| sed -n -e 's!^.*/!!p' \
| grep '.map.gz' \
| sed 's/.map.gz//g' \
| sed 's/$/ ->/g' \
| sort)"
while true; do
if KEYMAP="$(dialog --no-cancel --ok-button "${OK}" --menu \
"\n${SET_KEYMAP_MSG}" 18 60 10 \
'us' 'United States' \
'uk' 'United Kingdom' \
'sv' 'Swedish' \
'slovene' 'Slovenian' \
'ru' 'Russian' \
'ro' 'Romanian' \
'pt-latin9' 'Portugal' \
'it' 'Italian' \
'hu' 'Hungarian' \
'fr' 'French' \
'es' 'Spanish' \
'el' 'Greek' \
'de' 'German' \
"${OTHER}" '->')"; then
if [[ "${KEYMAP}" != "${OTHER}" ]] \
|| KEYMAP="$(dialog --ok-button "${OK}" --cancel-button "${BACK}" \
--menu "\n${SET_KEYMAP_MSG}" 19 60 10 ${keymap_list})"; then
break
fi
fi
done
localectl set-keymap "${KEYMAP}"
loadkeys "${KEYMAP}"
log "Keymap: ${KEYMAP}"
}
################################################################################
# Check for an internet connection. If not found, attempt to auto-connect to
# Wi-Fi (if an SSID is provided) or present options via 'nmtui'.
#
# Globals: WIFI_SSID, WIFI_PASSWORD
# Arguments: None
################################################################################
check_internet_connection() {
until nc -zw 1 1.1.1.1 443 &>/dev/null; do
log "Internet connection not yet established..."
if ip address | grep -Eq 'wlp|wlo|wlan' \
&& [[ -n "${WIFI_SSID}" ]] \
&& nmcli dev wifi connect "${WIFI_SSID}" password \
"${WIFI_PASSWORD}"; then
log "* Using nmcli..."
else
log "* Using nmtui..."
nmtui
fi
done
log "Internet connection established"
}
################################################################################
# Present the locale menu.
#
# Globals: TITLE, SET_LOCALE_TITLE, LOCALE, SET_LOCALE_MSG, OTHER, OK, BACK
# Arguments: None
################################################################################
set_locale() {
TITLE="${SET_LOCALE_TITLE}"
local locale_list
locale_list="$(grep -E "^#?[a-z].*UTF-8" /etc/locale.gen \
| sed 's/#//' \
| awk '{print $1" ->"}')"
while true; do
if LOCALE="$(dialog --no-cancel --ok-button "${OK}" --menu \
"\n${SET_LOCALE_MSG}" 18 60 10 \
'bg_BG.UTF-8' 'Bulgarian (Bulgaria)' \
'de_DE.UTF-8' 'German (Germany)' \
'el_GR.UTF-8' 'Greek (Greece)' \
'en_AU.UTF-8' 'English (Australia)' \
'en_CA.UTF-8' 'English (Canada)' \
'en_GB.UTF-8' 'English (UK)' \
'en_US.UTF-8' 'English (US)' \
'es_ES.UTF-8' 'Spanish (Spain)' \
'es_MX.UTF-8' 'Spanish (Mexico)' \
'fr_FR.UTF-8' 'French (France)' \
'hu_HU.UTF-8' 'Hungarian (Hungary)' \
'id_ID.UTF-8' 'Indonesian (Indonesia)' \
'it_IT.UTF-8' 'Italian (Italy)' \
'ja_JP.UTF-8' 'Japanese (Japan)' \
'ko_KR.UTF-8' 'Korean (Korea)' \
'lt_LT.UTF-8' 'Lithuanian (Lithuania)' \
'lv_LV.UTF-8' 'Latvian (Latvia)' \
'nl_NL.UTF-8' 'Dutch (Netherlands)' \
'pl_PL.UTF-8' 'Polish (Poland)' \
'pt_BR.UTF-8' 'Portuguese (Brazil)' \
'pt_PT.UTF-8' 'Portuguese (Portugal)' \
'ro_RO.UTF-8' 'Romanian (Romania)' \
'ru_RU.UTF-8' 'Russian (Russia)' \
'sv_SE.UTF-8' 'Swedish (Sweden)' \
'zh_CN.UTF-8' 'Chinese (China)' \
'zh_HK.UTF-8' 'Chinese (Hong Kong)' \
'zh_SG.UTF-8' 'Chinese (Singapore)' \
'zh_TW.UTF-8' 'Chinese (Taiwan)' \
"${OTHER}" '->')"; then
if [[ "${LOCALE}" != "${OTHER}" ]] \
|| LOCALE="$(dialog --ok-button "${OK}" --cancel-button "${BACK}" \
--menu "\n${SET_LOCALE_MSG}" 19 60 10 ${locale_list})"; then
break
fi
fi
done
log "Locale: ${LOCALE}"
}
################################################################################
# Present the time zone menu.
#
# Globals: TITLE, SET_TIME_ZONE_TITLE, TIME_ZONE, SET_TIME_ZONE_MSG, OK, BACK
# Arguments: None
################################################################################
set_time_zone() {
TITLE="${SET_TIME_ZONE_TITLE}"
local zonelist sublist subzone subsubzone
zonelist="$(find /usr/share/zoneinfo -maxdepth 1 \
| sed -n -e 's!^.*/!!p' \
| grep -Ev 'posix|posixrules|right|zoneinfo|.*tab|W-SU|WET|MST7MDT|CST6CDT'\
| sort \
| sed 's/$/ ->/g')"
while true; do
TIME_ZONE="$(dialog --no-cancel --ok-button "${OK}" --menu \
"\n${SET_TIME_ZONE_MSG}" 18 60 10 ${zonelist})" || continue
if find /usr/share/zoneinfo -maxdepth 1 -type d \
| sed -n -e 's!^.*/!!p' \
| grep -q "${TIME_ZONE}"; then
sublist="$(find "/usr/share/zoneinfo/${TIME_ZONE}" -maxdepth 1 \
| sed -n -e 's!^.*/!!p' \
| sort \
| sed 's/$/ ->/g' \
| grep -v "${TIME_ZONE}")"
if subzone="$(dialog --ok-button "${OK}" --cancel-button "${BACK}" \
--menu "\n${SET_TIME_SUBZONE_MSG}" 18 60 10 ${sublist})"; then
if find "/usr/share/zoneinfo/${TIME_ZONE}" -maxdepth 1 -type d \
| sed -n -e 's!^.*/!!p' \
| grep -q "${subzone}"; then
sublist="$(find "/usr/share/zoneinfo/${TIME_ZONE}/${subzone}" \
-maxdepth 1 \
| sed -n -e 's!^.*/!!p' \
| sort \
| sed 's/$/ ->/g' \
| grep -v "${subzone}")"
if subsubzone="$(dialog --ok-button "${OK}" --cancel-button "${BACK}"\
--menu "\n${SET_TIME_SUBZONE_MSG}" 15 60 7 ${sublist})"; then
TIME_ZONE="${TIME_ZONE}/${subzone}/${subsubzone}"
break
fi
else
TIME_ZONE="${TIME_ZONE}/${subzone}"
break
fi
fi
else
break
fi
done
log "Time zone: ${TIME_ZONE}"
}
################################################################################
# Present partitioning options and facilitate preparing a drive (or drives) for
# Linux installation.
#
# Globals: TITLE, PREPARE_DRIVES_TITLE, PART_METHOD_MSG, RAM, PART_METHOD_AUTO,
# PART_METHOD_AUTO_ENCRYPT, PART_METHOD_MANUAL, SYSTEM_MOUNTED, DEVICE_LIST,
# ROOT_DRIVE, ROOT_FS, HOME_DRIVE_MSG, HOME_DRIVE, HOME_FS, UEFI_MSG, UEFI,
# GPT_MSG, GPT, BOOT_OR_ESP_MNT, BOOT_OR_ESP_SIZE, DEFAULT_ESP_SIZE_SMALL,
# DEFAULT_ESP_SIZE_LARGE, DEFAULT_BOOT_SIZE, SWAP_SIZE, ENABLE_HIBERNATION,
# SET_SWAP_SIZE_MSG, SWAP_INPUT_ERROR_MSG, PART_ERROR_MSG, OK, CANCEL, YES,
# NO, BASE_PACKAGES, MISC_PACKAGES, FS_PACKAGES
# Arguments: None
################################################################################
prepare_drives() {
TITLE="${PREPARE_DRIVES_TITLE}"
local partition_method partition_prefix root_gib home_gib
log "Initial partition layout:"
log_partitions
until "${SYSTEM_MOUNTED}"; do
unmount_and_close_everything --swapoff
# Present partitioning options
if ! partition_method="$(dialog --no-cancel --ok-button "${OK}" --menu \
"\n${PART_METHOD_MSG}" 16 70 3 \
"${PART_METHOD_AUTO}" '->' \
"${PART_METHOD_AUTO_ENCRYPT}" '->' \
"${PART_METHOD_MANUAL}" '->')"; then
continue
# If an auto-partitioning option is selected, present drive menu(s)
elif [[ "${partition_method}" != "${PART_METHOD_MANUAL}" ]]; then
if [[ "${partition_method}" == "${PART_METHOD_AUTO}" ]]; then
log "Auto-partitioning..."
elif [[ "${partition_method}" == "${PART_METHOD_AUTO_ENCRYPT}" ]]; then
log "Auto-partitioning with encryption..."
fi
# Root drive selection
prepare_device_menu --auto-root
ROOT_DRIVE="$(bash /tmp/gdl/part.sh)" || continue
root_gib="$(get_device_size "${ROOT_DRIVE}" --gib)"
log "* Root drive: ${ROOT_DRIVE} (${root_gib} GiB)"
ROOT_FS="$(get_filesystem)" || continue
log "* Root filesystem: ${ROOT_FS}"
# Home drive selection (optional)
if (( $(wc -l <<<"${DEVICE_LIST}") > 1 )); then
while yesno "${HOME_DRIVE_MSG}" "${YES}" "${NO}" --defaultno; do
prepare_device_menu --auto-home
HOME_DRIVE="$(bash /tmp/gdl/part.sh)" || continue
home_gib="$(get_device_size "${HOME_DRIVE}" --gib)"
log "* Home drive: ${HOME_DRIVE} (${home_gib} GiB)"
HOME_FS="$(get_filesystem)" || continue
log "* Home filesystem: ${HOME_FS}"
break
done
fi
# Check drive properties and set up boot
if [[ "${ROOT_DRIVE}" =~ nvme|mmc|md ]]; then
partition_prefix='p'
else
partition_prefix=''
fi
if efivar -l &>/dev/null && yesno "${UEFI_MSG}" "${YES}" "${NO}"; then
GPT='true'
UEFI='true'
BOOT_OR_ESP_MNT='/efi'
if (( $(cat "/sys/class/block/${ROOT_DRIVE}/queue/logical_block_size")
<= 512 )); then
BOOT_OR_ESP_SIZE="${DEFAULT_ESP_SIZE_SMALL}"
else
BOOT_OR_ESP_SIZE="${DEFAULT_ESP_SIZE_LARGE}"
fi
log "* UEFI/GPT setup activated (${BOOT_OR_ESP_SIZE} MiB ESP)"
else
BOOT_OR_ESP_MNT='/boot'
BOOT_OR_ESP_SIZE="${DEFAULT_BOOT_SIZE}"
if yesno "${GPT_MSG}" "${YES}" "${NO}" --defaultno; then
GPT='true'
log "* BIOS/GPT setup activated (${BOOT_OR_ESP_SIZE} MiB boot)"
else
log "* BIOS/MBR setup activated (${BOOT_OR_ESP_SIZE} MiB boot)"
fi
fi
# Set swap size
SWAP_SIZE=''
if yesno "${CREATE_SWAP_MSG}" "${YES}" "${NO}" --defaultno; then
while true; do
SWAP_SIZE="$(dialog --ok-button "${OK}" --cancel-button "${CANCEL}" \
--inputbox "\n${SET_SWAP_SIZE_MSG}" 12 55 \
"$(( RAM / 1024 / 2 + 1 ))G" \
| tr 'mg' 'MG' \
| tr -s 'MG' \
| tr -d 'a-zA-FH-LN-Z[:space:]')" || break
if [[ "${SWAP_SIZE}" =~ ^[0-9]+M$ ]]; then
SWAP_SIZE="${SWAP_SIZE/M}"
elif [[ "${SWAP_SIZE}" =~ ^[0-9]+G$ ]]; then
SWAP_SIZE=$(( ${SWAP_SIZE/G} * 1024 ))
else
log_error "Invalid swap size input: ${SWAP_SIZE}"
message "${SWAP_INPUT_ERROR_MSG}"
continue
fi
break
done
fi
[[ -z "${SWAP_SIZE}" ]] && SWAP_SIZE='0'
log "* Swap size: ${SWAP_SIZE} MiB"
# Format selected drive(s) or go back to main partitioning menu
wipe_drive "${ROOT_DRIVE}" "${root_gib}" "${ROOT_FS}" || continue
if [[ -n "${HOME_DRIVE}" ]]; then
wipe_drive "${HOME_DRIVE}" "${home_gib}" "${HOME_FS}" || continue
fi
fi
# Go to appropriate sub-function
case "${partition_method}" in
"${PART_METHOD_AUTO}")
if ! auto_partition; then
log_error "Auto-partitioning failed"
message "${PART_ERROR_MSG}"
fi
;;
"${PART_METHOD_AUTO_ENCRYPT}")
if ! auto_partition_with_encryption; then
log_error "Auto-partitioning with encryption failed"
message "${PART_ERROR_MSG}"
fi
;;
"${PART_METHOD_MANUAL}")
log "Manually partitioning..."
manually_partition
;;
esac
done
# Add packages, adjust settings, and log partition layout
"${UEFI}" && BASE_PACKAGES+="${MISC_PACKAGES[efi]}"
lsblk -no TYPE | grep -q 'lvm' && BASE_PACKAGES+="${MISC_PACKAGES[lvm]}"
[[ "${ROOT_FS}" == 'btrfs' ]] && BASE_PACKAGES+="${MISC_PACKAGES[root-btrfs]}"
for fs in "${!FS_PACKAGES[@]}"; do
mount | grep -q "type ${fs}" && BASE_PACKAGES+="${FS_PACKAGES[$fs]}"
done
(( SWAP_SIZE >= RAM / 2 )) && ENABLE_HIBERNATION='true'
log_partitions
}
################################################################################
# Automatically partition the drive(s) selected in 'prepare_drives' and mount
# the newly-created partitions.
#
# Globals: TITLE, AUTO_PART_TITLE, ROOT_PART, ROOT_FS, HOME_DRIVE, HOME_FS,
# BOOT_OR_ESP, BOOT_OR_ESP_MNT, UEFI, EFI_LOAD_MSG, BOOT_LOAD_MSG,
# MKFS_LOAD_MSG, SYSTEM_MOUNTED
# Arguments: None
# Returns: Number of errors detected.
################################################################################
auto_partition() {
TITLE="${AUTO_PART_TITLE}"
# Create and format partitions
partition_root_drive || return 1
zap_and_wipe "${BOOT_OR_ESP}" || return 1
if "${UEFI}"; then
(
mkfs.vfat -F32 "/dev/${BOOT_OR_ESP}" \
&& log " - ESP filesystem created: vfat (FAT32)"
) &>/dev/null &
load_bar "${EFI_LOAD_MSG}\n\n \Z1> \Z2mkfs.vfat -F32 /dev/${BOOT_OR_ESP}\Zn"
else # BIOS
(
mkfs.ext4 "/dev/${BOOT_OR_ESP}" \
&& log " - Boot filesystem created: ext4"
) &>/dev/null &
load_bar "${BOOT_LOAD_MSG}\n\n \Z1> \Z2mkfs.ext4 /dev/${BOOT_OR_ESP}\Zn"
fi
zap_and_wipe "${ROOT_PART}" || return 1
(
mkfs."${ROOT_FS}" "/dev/${ROOT_PART}" \
&& log " - Root filesystem created: ${ROOT_FS}"
) &>/dev/null &
load_bar "$(eval echo \"${MKFS_LOAD_MSG}\")\n\n \Z1> \Z2mkfs.${ROOT_FS} \
/dev/${ROOT_PART}\Zn"
if [[ -n "${HOME_DRIVE}" ]]; then
(
mkfs."${HOME_FS}" "/dev/${HOME_DRIVE}" \
&& log " - Home filesystem created: ${HOME_FS}"
) &>/dev/null &
load_bar "$(eval echo \"${MKFS_LOAD_MSG}\")\n\n \Z1> \Z2mkfs.${HOME_FS} \
/dev/${HOME_DRIVE}\Zn"
fi
# Mount partitions
if [[ "${ROOT_FS}" == 'btrfs' ]]; then
create_and_mount_btrfs_subvolume @ "/dev/${ROOT_PART}" || return 1
if [[ -z "${HOME_DRIVE}" ]]; then
create_and_mount_btrfs_subvolume @home "/dev/${ROOT_PART}" || return 1
fi
create_and_mount_btrfs_subvolume @var@log "/dev/${ROOT_PART}" || return 1
create_and_mount_btrfs_subvolume @var@cache "/dev/${ROOT_PART}" || return 1
elif mount "/dev/${ROOT_PART}" /mnt &>/dev/null; then
log " - Mounted /dev/${ROOT_PART} at /mnt"
else
log_error "Mounting /dev/${ROOT_PART} at /mnt failed"
return 1
fi
if [[ -n "${HOME_DRIVE}" ]]; then
if [[ "${HOME_FS}" == 'btrfs' ]]; then
create_and_mount_btrfs_subvolume @home "/dev/${HOME_DRIVE}" || return 1
elif mount -m "/dev/${HOME_DRIVE}" /mnt/home &>/dev/null; then
log " - Mounted /dev/${HOME_DRIVE} at /mnt/home"
else
log_error "Mounting /dev/${HOME_DRIVE} at /mnt/home failed"
return 1
fi
fi
if mount -m "/dev/${BOOT_OR_ESP}" "/mnt${BOOT_OR_ESP_MNT}" &>/dev/null; then
log " - Mounted /dev/${BOOT_OR_ESP} at /mnt${BOOT_OR_ESP_MNT}"
SYSTEM_MOUNTED='true'
else
log_error "Mounting /dev/${BOOT_OR_ESP} at /mnt${BOOT_OR_ESP_MNT} failed"
return 1
fi
log "Auto-partitioning complete:"
}
################################################################################
# Automatically partition and encrypt the drive(s) selected in 'prepare_drives',
# applying "LVM on LUKS" to the root drive (including a logical swap space if a
# non-zero swap size is set), and mount the newly-created partitions.
#
# Globals: TITLE, AUTO_PART_TITLE, ROOT_PART, ROOT_FS, HOME_DRIVE, HOME_FS, NO,
# YES, SWAP, SWAP_SIZE, BOOT_OR_ESP, BOOT_OR_ESP_MNT, UEFI, SYSTEM_MOUNTED,
# SYSTEM_AUTO_ENCRYPTED, ENCRYPTION_PASSWORD_CONFIRM, ENCRYPTION_CONFIRM,
# ENCRYPTION_PASSWORD_MSG, PASSWORD_EMPTY_MSG, PASSWORD_MISMATCH_MSG, ROOT_LV,
# ENCRYPTION_LOAD_MSG, SWAP_LOAD_MSG, EFI_LOAD_MSG, PVCREATE_LOAD_MSG,
# LVCREATE_LOAD_MSG, BOOT_LOAD_MSG, MKFS_LOAD_MSG, ROOT_PART_UUID, LVM_UUID,
# HOME_DRIVE_UUID
# Arguments: None
# Returns: Number of errors detected.
################################################################################
auto_partition_with_encryption() {
TITLE="${AUTO_PART_TITLE}"
local input input_check
# Set encryption password
if yesno "$(eval echo \"${ENCRYPTION_CONFIRM}\")" "${YES}" "${NO}" \
--defaultno; then
while true; do
if ! input="$(dialog --no-cancel --clear --insecure --passwordbox \
"\n$(eval echo \"${ENCRYPTION_PASSWORD_MSG}\")" 12 55)" \
|| ! input_check="$(dialog --no-cancel --clear --insecure \
--passwordbox "\n$(eval echo \"${ENCRYPTION_PASSWORD_CONFIRM}\")" \
12 55)" \
|| [[ -z "${input}" ]]; then
message "${PASSWORD_EMPTY_MSG}"
elif [[ "${input}" != "${input_check}" ]]; then
message "${PASSWORD_MISMATCH_MSG}"
else
break
fi
done
log "* Encryption password set"
else
return 0 # back to 'prepare_drives'
fi
# Create and encrypt partitions
partition_root_drive --no-swap || return 1
zap_and_wipe "${ROOT_PART}" || return 1
(
# shellcheck disable=SC2046
echo -n "${input}" | cryptsetup luksFormat \
$("${UEFI}" && echo '--pbkdf pbkdf2') "/dev/${ROOT_PART}"
"${UEFI}" && add_key_file_slot "${ROOT_PART}" "${input}"
log " - Root partition encrypted"
) &>/dev/null &
load_bar "${ENCRYPTION_LOAD_MSG}\n\n \Z1> \Z2cryptsetup luksFormat \
/dev/${ROOT_PART}\Zn"
ROOT_PART_UUID="$(lsblk -no UUID "/dev/${ROOT_PART}")"
echo -n "${input}" | cryptsetup open "/dev/${ROOT_PART}" cryptlvm
if [[ -n "${HOME_DRIVE}" ]]; then
(
echo -n "${input}" | cryptsetup luksFormat "/dev/${HOME_DRIVE}"
add_key_file_slot "${HOME_DRIVE}" "${input}"
log " - Home partition encrypted"
) &>/dev/null &
load_bar "${ENCRYPTION_LOAD_MSG}\n\n \Z1> \Z2cryptsetup luksFormat \
/dev/${HOME_DRIVE}\Zn"
HOME_DRIVE_UUID="$(lsblk -no UUID "/dev/${HOME_DRIVE}")"
echo -n "${input}" | cryptsetup open "/dev/${HOME_DRIVE}" crypthome
fi
unset input input_check
(
pvcreate /dev/mapper/cryptlvm \
&& log " - Physical volume created on /dev/mapper/cryptlvm"
vgcreate vg /dev/mapper/cryptlvm \
&& log " - Logical volume group created: vg"
) &>/dev/null &
load_bar "${PVCREATE_LOAD_MSG}\n\n \Z1> \Z2pvcreate /dev/mapper/cryptlvm\Zn"
LVM_UUID="$(lsblk -no UUID /dev/mapper/cryptlvm)"
if (( SWAP_SIZE > 0 )); then
SWAP='vg/lvswap'
(
lvcreate -L "${SWAP_SIZE}" vg -n lvswap \
&& mkswap "/dev/${SWAP}" \
&& swapon "/dev/${SWAP}" \
&& log " - Logical swap space created and activated: /dev/${SWAP}"
) &>/dev/null &
load_bar \
"${SWAP_LOAD_MSG}\n\n \Z1> \Z2lvcreate -L ${SWAP_SIZE} vg -n lvswap\Zn"
fi
ROOT_LV='vg/lvroot'
(
lvcreate -l 100%FREE vg -n lvroot \
&& log " - Logical root volume created: /dev/${ROOT_LV}"
[[ "${ROOT_FS}" == 'ext4' ]] \
&& lvreduce -L -256M "${ROOT_LV}" \
&& log " - 256 MiB removed from lvroot to allow use of e2scrub"
) &>/dev/null &
load_bar \
"${LVCREATE_LOAD_MSG}\n\n \Z1> \Z2lvcreate -l 100%FREE vg -n lvroot\Zn"
# Apply filesystems
if "${UEFI}"; then
(
mkfs.vfat -F32 "/dev/${BOOT_OR_ESP}" \
&& log " - ESP filesystem created: vfat (FAT32)"
) &>/dev/null &
load_bar "${EFI_LOAD_MSG}\n\n \Z1> \Z2mkfs.vfat -F32 /dev/${BOOT_OR_ESP}\Zn"
else # BIOS
(
mkfs.ext4 "/dev/${BOOT_OR_ESP}" \
&& log " - Boot filesystem created: ext4"
) &>/dev/null &
load_bar "${BOOT_LOAD_MSG}\n\n \Z1> \Z2mkfs.ext4 /dev/${BOOT_OR_ESP}\Zn"
fi
(
mkfs."${ROOT_FS}" "/dev/${ROOT_LV}" \
&& log " - Root filesystem created: ${ROOT_FS}"
) &>/dev/null &
load_bar "$(eval echo \"${MKFS_LOAD_MSG}\")\n\n \Z1> \Z2mkfs.${ROOT_FS} \
/dev/${ROOT_LV}\Zn"
if [[ -n "${HOME_DRIVE}" ]]; then
(
mkfs."${HOME_FS}" /dev/mapper/crypthome \
&& log " - Home filesystem created: ${HOME_FS}"
) &>/dev/null &
load_bar "$(eval echo \"${MKFS_LOAD_MSG}\")\n\n \Z1> \Z2mkfs.${HOME_FS} \
/dev/mapper/crypthome\Zn"
fi
# Mount partitions/volumes
if [[ "${ROOT_FS}" == 'btrfs' ]]; then
create_and_mount_btrfs_subvolume @ "/dev/${ROOT_LV}" || return 1
if [[ -z "${HOME_DRIVE}" ]]; then
create_and_mount_btrfs_subvolume @home "/dev/${ROOT_LV}" || return 1
fi
create_and_mount_btrfs_subvolume @var@log "/dev/${ROOT_LV}" || return 1
create_and_mount_btrfs_subvolume @var@cache "/dev/${ROOT_LV}" || return 1
elif mount "/dev/${ROOT_LV}" /mnt &>/dev/null; then
log " - Mounted /dev/${ROOT_LV} at /mnt"
else
log_error "Mounting /dev/${ROOT_LV} at /mnt failed"
return 1
fi
if [[ -n "${HOME_DRIVE}" ]]; then
if [[ "${HOME_FS}" == 'btrfs' ]]; then
create_and_mount_btrfs_subvolume @home /dev/mapper/crypthome || return 1
elif mount -m /dev/mapper/crypthome /mnt/home &>/dev/null; then
log " - Mounted /dev/mapper/crypthome at /mnt/home"
else
log_error "Mounting /dev/mapper/crypthome at /mnt/home failed"
return 1
fi
fi
if mount -m "/dev/${BOOT_OR_ESP}" "/mnt${BOOT_OR_ESP_MNT}" &>/dev/null; then
log " - Mounted /dev/${BOOT_OR_ESP} at /mnt${BOOT_OR_ESP_MNT}"
SYSTEM_MOUNTED='true'
SYSTEM_AUTO_ENCRYPTED='true'
else
log_error "Mounting /dev/${BOOT_OR_ESP} at /mnt${BOOT_OR_ESP_MNT} failed"
return 1
fi
log "Auto-partitioning with encryption complete:"
}
################################################################################
# Present options for manual partitioning of available drives and handle
# formatting and mounting of newly-created partitions.
#
# Globals: TITLE, MANUAL_PART_TITLE, EDIT_PART_TITLE, DEVICE_LIST, ROOT_DRIVE,
# ROOT_PART, ROOT_FS, GPT, UEFI, BOOT_OR_ESP_MNT, SYSTEM_MOUNTED, SWAP_SIZE,
# SWAP, ALREADY_MOUNTED_MSG, SELECT_MNT_MSG, CUSTOM_MNT_MSG, PART_FORMAT_MSG,
# EFI_VFAT_MSG, FS_VFAT_MSG, WRITE_CONFIRM, UNMOUNT_DRIVE_CONFIRM,
# EDIT_DRIVE_CONFIRM, ROOT_MNT_CONFIRM, ROOT_FORMAT_CONFIRM,
# UNMOUNT_ROOT_CONFIRM, UNMOUNT_PART_CONFIRM, SWAPOFF_CONFIRM, MNT_CONFIRM,
# PART_FORMAT_CONFIRM, WAIT_LOAD_MSG, MKFS_LOAD_MSG, ROOT_UNMOUNTED_ERROR_MSG,
# GPT_BIOS_ERROR_MSG, ROOT_MOUNT_ERROR_MSG, CUSTOM_MNT_CHAR_ERROR_MSG,
# CUSTOM_MNT_ROOT_ERROR_MSG, MOUNT_ERROR_MSG, PARTITION, SIZE, MOUNT_POINT,
# CUSTOM, EDIT, BACK, WRITE_CHANGES, OK, CANCEL, YES, NO, DONE
# Arguments: None
# Returns: Number of errors detected.
################################################################################
manually_partition() {
local part part_size part_type part_fs part_mount part_final \
empty_value='----' lvm_pv selected_fs
while true; do
# Prepare and present manual partitioning menu
TITLE="${MANUAL_PART_TITLE}"
prepare_device_menu --manual
if ! part="$(bash /tmp/gdl/part.sh | sed 's/^\s\+//g;s/\s\+$//g')" \
|| [[ -z "${part}" ]]; then
SYSTEM_MOUNTED='false'
return 0 # back to 'prepare_drives'
fi
log "* Menu selection: '${part}'"
# If user selected 'done', attempt to finish the partitioning process
if [[ "${part}" == "${DONE}" ]]; then
if ! "${SYSTEM_MOUNTED}"; then
log_error "Root partition not found"
message "${ROOT_UNMOUNTED_ERROR_MSG}"
continue
elif "${GPT}" && ! "${UEFI}" && ! fdisk -l | grep -q 'BIOS boot'; then
log_error "BIOS boot partition not found"
message "${GPT_BIOS_ERROR_MSG}"
continue
fi
part_final="$( (df -h \
| grep '/mnt' \
| awk '{print $1,$2,$6 "\\n"}' \
| sed 's/mnt\/\?//'; swapon \
| awk 'NR==2 {print $1,$3,"SWAP"}') \
| column -t)"
yesno "${WRITE_CONFIRM}\n\n${PARTITION} ${SIZE} ${MOUNT_POINT}\n\n\
${part_final}" "${OK}" "${CANCEL}" --defaultno || continue
# Add home and var subvolumes for Btrfs root (if mount points are free)
if mount | grep -q ' /mnt type btrfs'; then
mount | grep -q ' /mnt/home ' \
|| create_and_mount_btrfs_subvolume @home "/dev/${ROOT_PART}"
if ! mount | grep -q ' /mnt/var '; then
mount | grep -q ' /mnt/var/log ' \
|| create_and_mount_btrfs_subvolume @var@log "/dev/${ROOT_PART}"
mount | grep -q ' /mnt/var/cache ' \
|| create_and_mount_btrfs_subvolume @var@cache "/dev/${ROOT_PART}"
fi
fi
log "Manual partitioning complete:"
return 0 # all done: return to 'prepare_drives'
fi
# If not 'done', prepare and present a disk/partition editing menu
part_size="$(grep -w "${part}" <<<"${DEVICE_LIST}" | awk '{print $2}')"
part_type="$(grep -w "${part}" <<<"${DEVICE_LIST}" | awk '{print $3}')"
part_fs="$(grep -w "${part}" <<<"${DEVICE_LIST}" | awk '{print $4}')"
part_mount="$(df \
| grep -w "${part}" \
| awk '{print $6}' \
| sed 's/mnt\/\?//')"
[[ "${part_type}" == 'lvm' ]] && part="${part/-//}"
log " - Device info: ${part_type} ${part_fs} ${part_size} ${part_mount}"
[[ "${part_fs}" == 'linux_raid_member' ]] && continue # do nothing
# If user selected an entire drive, facilitate partitioning
if [[ "${part_type}" == 'disk' ]] \
|| [[ "${part_type}" =~ raid[0-9] && -z "${part_fs}" ]]; then
if mount | grep -q "${part}.*on /mnt"; then
if yesno "$(eval echo \"${UNMOUNT_DRIVE_CONFIRM}\")" "${EDIT}" \
"${CANCEL}" --defaultno; then
unmount_and_close_everything --swapoff
modify_partition_table "${part}"
fi
elif yesno "$(eval echo \"${EDIT_DRIVE_CONFIRM}\")" "${EDIT}" \
"${CANCEL}"; then
modify_partition_table "${part}"
fi
# If user selected a partition or md device, facilitate mounting/formatting
else
TITLE="${EDIT_PART_TITLE}"
# The root '/' mount point must be established before others
if [[ -z "${ROOT_PART}" ]]; then
# shellcheck disable=SC2015
yesno "$(eval echo \"${ROOT_MNT_CONFIRM}\")" "${YES}" "${NO}" \
--defaultno \
&& ROOT_FS="$(get_filesystem)" \
&& yesno "$(eval echo \"${ROOT_FORMAT_CONFIRM}\")" \
"${WRITE_CHANGES}" "${CANCEL}" --defaultno \
|| continue
zap_and_wipe "${part}" || return 1
(
mkfs."${ROOT_FS}" "/dev/${part}" \
&& log " - Root filesystem created for /dev/${part}: ${ROOT_FS}"
) &>/dev/null &
load_bar "$(eval echo \"${MKFS_LOAD_MSG}\")\n\n \Z1> \
\Z2mkfs.${ROOT_FS} /dev/${part}\Zn"
if [[ "${ROOT_FS}" == 'btrfs' ]]; then
if ! create_and_mount_btrfs_subvolume @ "/dev/${part}"; then
message "${ROOT_MOUNT_ERROR_MSG}"
return 1 # back to 'prepare_drives'
fi
elif mount "/dev/${part}" /mnt &>/dev/null; then
log " - Mounted /dev/${part} at /mnt"
else
log_error "Mounting /dev/${part} at /mnt failed"
message "${ROOT_MOUNT_ERROR_MSG}"
return 1 # back to 'prepare_drives'
fi
SYSTEM_MOUNTED='true'
ROOT_PART="${part}"
if [[ "${part_type}" == "lvm" ]]; then
lvm_pv="$(lvdisplay -m \
| grep -A 20 "/dev/${part}" \
| grep 'Physical volume' \
| sed 's/^\s\+//g;s/\s\+/ /g' \
| cut -d ' ' -f 3)"
ROOT_DRIVE="$(lsblk -dnro PKNAME "${lvm_pv}")"
else
ROOT_DRIVE="$(lsblk -dnro PKNAME "/dev/${part}")"
fi
log " - Root drive: ${ROOT_DRIVE}"
if parted "/dev/${ROOT_DRIVE}" print | grep -q 'Table: gpt'; then
GPT='true'
else
GPT='false'
fi
log " - GPT: ${GPT}"
# If the partition's already mounted, provide option to unmount
elif [[ -n "${part_mount}" ]]; then
if yesno "$(eval echo \"${ALREADY_MOUNTED_MSG}\")" "${EDIT}" "${BACK}" \
--defaultno; then
if [[ "${part}" == "${ROOT_PART}" ]]; then
if yesno "$(eval echo \"${UNMOUNT_ROOT_CONFIRM}\")" "${YES}" \
"${NO}" --defaultno; then
unmount_and_close_everything
fi
elif yesno "$(eval echo \"${UNMOUNT_PART_CONFIRM}\")" "${YES}" \
"${NO}" --defaultno; then
if "${UEFI}" && [[ "${part_mount}" == "${BOOT_OR_ESP_MNT}" ]]; then
UEFI='false'
BOOT_OR_ESP_MNT=''
log " - Unmounting ESP..."
fi
(
umount "/mnt${part_mount}" \
&& log " - Unmounted /dev/${part} from /mnt${part_mount}"
rm -r "/mnt${part_mount:?}"
) &>/dev/null &
load_bar "${WAIT_LOAD_MSG}\n\n \Z1> \Z2umount /mnt${part_mount}\Zn"
fi
fi
# If it's already in use as swap, provide option to 'swapoff' and wipe
elif lsblk | grep -q "${part} .*\[SWAP\]$"; then
if yesno "$(eval echo \"${SWAPOFF_CONFIRM}\")" "${YES}" "${NO}" \
--defaultno; then
SWAP=''
SWAP_SIZE=''
(
swapoff "/dev/${part}"
wipefs -a "/dev/${part}" \
&& log " - Swap partition /dev/${part} deactivated and wiped"
sleep 0.6
) &>/dev/null &
load_bar "${WAIT_LOAD_MSG}\n\n \Z1> \Z2swapoff /dev/${part}\Zn"
fi
# If it's a swap partition not in use, reformat and 'swapon'
elif (( $(fdisk -l \
| grep -w "${part}" \
| sed 's/\*//' \
| awk '{print $6}') == 82 )) &>/dev/null \
|| (fdisk -l /dev/"$(lsblk -dnro PKNAME "/dev/${part}")" \
| grep -q 'gpt' \
&& [[ "$(fdisk -l -o Device,Size,Type-UUID \
| grep -w "${part}" \
| awk '{print $3}')" == "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F" ]]\
) &>/dev/null; then
format_swap_partition "${part}"
# Otherwise, present mount point menu (inc. option to create swap)
elif yesno "$(eval echo \"${MNT_CONFIRM}\")" "${EDIT}" "${BACK}"; then
mnt="$(dialog --ok-button "${OK}" --cancel-button "${CANCEL}" \
--menu "\n$(eval echo \"${SELECT_MNT_MSG}\")" 15 60 6 \
'/home' '->' \
'/boot' '->' \
'/efi' '->' \
'/opt' '->' \
'/usr' '->' \
'/var' '->' \
'/tmp' '->' \
'[SWAP]' '->' \
"${CUSTOM}" '->')" || continue
if [[ "${mnt}" == '[SWAP]' ]]; then
format_swap_partition "${part}"
continue
elif [[ "${mnt}" == "${CUSTOM}" ]]; then
while true; do
mnt="$(dialog --ok-button "${OK}" --cancel-button "${CANCEL}" \
--inputbox "\n${CUSTOM_MNT_MSG}" 10 50 '/' \
| tr -d '[:space:]' \
| tr -s '/')" || continue 2
if grep -q "[\[\$\!\'\"\`\\|%&#@()+=<>~;:?.,^{}]\|]" \
<<<"${mnt}"; then
message "${CUSTOM_MNT_CHAR_ERROR_MSG}"
elif [[ "${mnt}" == '/' ]]; then
message "${CUSTOM_MNT_ROOT_ERROR_MSG}"
elif [[ -n "${mnt}" ]]; then
[[ "${mnt}" =~ ^/ ]] || mnt="/${mnt}"
break
fi
done
fi
log " - Mount point: ${mnt}"
# Provide formatting options
if yesno "${PART_FORMAT_MSG}" "${YES}" "${NO}" --defaultno; then
if is_esp_candidate "${part}" "${mnt}"; then
selected_fs="$(dialog --menu "\n${EFI_VFAT_MSG}" 12 65 1 'vfat' \
"${FS_VFAT_MSG}")" || continue
else
selected_fs="$(get_filesystem)" || continue
fi
yesno "$(eval echo \"${PART_FORMAT_CONFIRM}\")" "${WRITE_CHANGES}" \
"${CANCEL}" --defaultno || continue
zap_and_wipe "${part}" || return 1
(
case "${selected_fs}" in
vfat) mkfs.vfat -F32 "/dev/${part}" ;;
*) mkfs."${selected_fs}" "/dev/${part}" ;;
esac
log " - Filesystem created for ${mnt}: ${selected_fs}"
) &>/dev/null &
load_bar "$(eval echo \"${MKFS_LOAD_MSG}\")\n\n \Z1> \
\Z2mkfs.${selected_fs} /dev/${part}\Zn"
fi
# Attempt to mount the partition at the given mount point
if blkid | grep "${part}" | grep -q 'TYPE="btrfs"'; then
create_and_mount_btrfs_subvolume "${mnt////@}" "/dev/${part}" \
|| message "${MOUNT_ERROR_MSG}"
elif mount -m "/dev/${part}" "/mnt${mnt}" &>/dev/null; then
if is_esp_candidate "${part}" "${mnt}" \
&& mount | grep -q " /mnt${mnt} type vfat "; then
UEFI='true'
BOOT_OR_ESP_MNT="${mnt}"
log " - Mounting ESP..."
fi
log " - Mounted /dev/${part} at /mnt${mnt}"
else
log_error "Mounting /dev/${part} at /mnt${mnt} failed"
message "${MOUNT_ERROR_MSG}"
fi
fi
fi
done
}
################################################################################