forked from sakaki-/buildkernel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildkernel
executable file
·2287 lines (2259 loc) · 89.9 KB
/
buildkernel
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
#
# Build kernel, modules and initial ramdisk in correct sequence, ensuring kernel
# config is conformed, then sign if possible and copy to EFI boot partition.
#
# Copyright (c) 2014-2020 sakaki <[email protected]>
#
# License (GPL v3.0)
# ------------------
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
set -e
set -u
shopt -s nullglob
# Scroll to the bottom of this script to follow the main program flow.
# ********************** variables *********************
PROGNAME="$(basename "${0}")"
CONFFILE="/etc/${PROGNAME}.conf"
VERSION="1.2.1"
ETCPROFILE="/etc/profile"
DEFAULTEFIBOOTFILE="bootx64.efi"
EFIBOOTFILE="${DEFAULTEFIBOOTFILE}"
LINUXDIR="/usr/src/linux"
NEWVERSION=""
INITRAMFSNAME=""
VMLINUZNAME=""
CURRENTVERSION="linux-$(uname -r)"
CURRENTCONFIG="/proc/config.gz"
TARGETCONFIG=""
BOOTDIR="/boot"
EFIROOTDIR="${BOOTDIR}/efi"
DEFAULTEFIBOOTDIR="/EFI/Boot"
EFIBOOTDIR="${DEFAULTEFIBOOTDIR}"
FULLEFIBOOTDIR="${EFIROOTDIR}${EFIBOOTDIR}"
EFICONFIGFILE="config"
OLDSUFFIX=".old"
DEFAULTLUKSKEYFILE="luks-key.gpg"
LUKSKEYFILE="${DEFAULTLUKSKEYFILE}"
MODPROBEDIR="/etc/modprobe.d"
CMDLINE_ROOT="/dev/ram0"
SYSTEMD_INIT="/usr/lib/systemd/systemd"
SYSTEMD_NEW_INIT="/lib/systemd/systemd"
OPENRC_INIT="/sbin/init"
if [[ -e "${SYSTEMD_NEW_INIT}" ]]; then
# new path exists, so use it
CMDLINE_REAL_INIT="${SYSTEMD_NEW_INIT}"
else
# fallback for older systems
CMDLINE_REAL_INIT="${SYSTEMD_INIT}"
fi
SECUREBOOTKEY="/etc/efikeys/db.key"
SECUREBOOTCERT="/etc/efikeys/db.crt"
SIGNEDSUFFIX=".signed"
ADDITIONALKERNELCMDS=""
ADDITIONALGENKERNELOPTS="--all-ramdisk-modules --firmware"
CMDLINE_REAL_ROOT="/dev/mapper/vg1-root"
CMDLINE_REAL_RESUME="/dev/mapper/vg1-swap"
declare -i DEFAULTCREATEEFIBOOT=1
declare -i CREATEEFIBOOT="${DEFAULTCREATEEFIBOOT}"
declare -i DEFAULTCOMPRESSINITRAMFS=1
declare -i COMPRESSINITRAMFS="${DEFAULTCOMPRESSINITRAMFS}"
declare -i DISABLE_SUSPEND=0
declare -i DISABLE_HIBERNATION=0
declare -i DISABLE_LVM=0
# you can use xconfig etc if you like - override in /etc/buildkernel.conf
CONFIGTYPE="menuconfig"
# following should already be in the environment; but to be safe...
export NUMCPUS=$(grep -E 'processor\s+:' /proc/cpuinfo | wc -l)
export NUMCPUSPLUSONE=$(( NUMCPUS + 1 ))
export MAKEOPTS="${MAKEOPTS--j${NUMCPUSPLUSONE} -l${NUMCPUS}}"
export EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS---jobs=${NUMCPUSPLUSONE} --load-average=${NUMCPUS}}"
# below silently updates an old config, auto-choosing defaults for new values
CONFIGUPDATETYPE="olddefconfig"
SILENTUPDATETYPE="olddefconfig"
RED_TEXT="" GREEN_TEXT="" YELLOW_TEXT="" RESET_ATTS="" ALERT_TEXT=""
if [[ -v TERM && -n "${TERM}" && "${TERM}" != "dumb" ]]; then
RED_TEXT="$(tput setaf 1)$(tput bold)"
GREEN_TEXT="$(tput setaf 2)$(tput bold)"
YELLOW_TEXT="$(tput setaf 3)$(tput bold)"
RESET_ATTS="$(tput sgr0)"
ALERT_TEXT="$(tput bel)"
fi
# used in subshells
UNCOMPRESSEDINITRAMFS="${BOOTDIR}/initramfs.cpio"
INITRAMFSDIR="${BOOTDIR}/initramfs"
VERBOSITY=1
PREFIXSTRING="* "
SHOWPREFIX="${GREEN_TEXT}${PREFIXSTRING}${RESET_ATTS}"
SHOWSUFFIX=""
GPG1PATHFROM="/usr/bin/staticgpg"
GPG1PATHTO="${INITRAMFSDIR}/usr/bin/gpg"
GPGBUILDDIR="/root/tmpgpgbuild"
TMPGPGPATH="${GPGBUILDDIR}/usr/bin/gpg"
declare -i USINGUSBKEYFOREFI=0
declare -i BACKUPOLDKERNEL=1
declare -i BUILT_EXTERNAL_MODULES=1
EFIPARTNAME="EFI boot partition"
DEFAULTKEYMAP="us"
KEYMAP="${DEFAULTKEYMAP}"
# leave blank if you don't want to use the plymouth graphical boot
# manager, otherwise override to a theme of your choice, such as "text" or
# "solar"
DEFAULTPLYMOUTHTHEME=""
PLYMOUTHTHEME="${DEFAULTPLYMOUTHTHEME}"
# default init system supported by this script is systemd, but we now
# also support OpenRC
DEFAULTINITSYSTEM="systemd"
INITSYSTEM="${DEFAULTINITSYSTEM}"
# following variable is conformed on installation by ebuild
# (to reflect setting of "plymouth" USE flag)
USE_PLYMOUTH=false
VERBOSITYFLAG=""
ASKFLAG=""
ALERTFLAG=""
PORTAGEINFO=""
MAKE=""
# following array variables set by load_all_devices function
declare -A ALLUUIDS
declare -A FSUUIDS
declare -A PARTUUIDS
declare -a GPGUUIDS
declare -a LUKSUUIDS
declare -a EFIUUIDS
# following array variables set by find_all_efi_boot_entries
# (held in boot index order, NOT boot order)
declare -a EBOOTIDS EBOOTNAMES EBOOTPATHS EBOOTUUIDS
declare -a EBOOTISACTIVES EBOOTORDER
declare -i EFIBOOTENTRIESSEARCHED=0
# stores whether boot entry is for Windows or not, keyed by partition UUID
declare -A HASWINBOOTLOADER
# map between BOOT ID (a 4 digit hex string) and index in EBOOT... arrays
declare -A EBOOTIDTOINDEX
# used to unwind mountpoints on failure
declare -A ALLMOUNTS
# has a '1' entry for all USB partitions; set by load_all_devices
declare -A ISUSBPART
# used by menu-driven config setting
declare -i CONFIGDIRTY=0
# set if CRYPTPATHMAP declared in config file
declare -i CRYPTPATHMAPFORCED=0
# archived prior versions of key config variables
PROCVARS=("EFIPARTUUID" "CRYPTPARTUUID" "KEYFILEPARTUUID" "LUKSKEYFILE" \
"EFIBOOTDIR" "EFIBOOTFILE" "PLYMOUTHTHEME" "KEYMAP" "INITSYSTEM")
NEXTVAR=""
for NEXTVAR in "${PROCVARS[@]}"; do
declare "OLD_${NEXTVAR}"=""
done
# running under EFI?
declare -i USINGEFI=0
# efivarfs mounted ro on entry? (OpenRC does, systemd doesn't)
declare -i ONENTRYROEFIVARFS=0
# and subsequently remounted rw?
declare -i EFIVARFSREMOUNTEDRW=0
# has support for kernel modules
declare -i USINGMODULES=1
declare -i MOUNTEDONENTRY=0
declare -i DOUNMOUNT=1
# program arguments (booleans in this case)
declare -i ARG_ASK=0 ARG_CLEAN=0 ARG_COPYFROMSTAGING=0 ARG_HELP=0
declare -i ARG_STAGEONLY=0 ARG_UNMOUNTATEND=0 ARG_VERBOSE=0 ARG_VERSION=0
declare -i ARG_POSTCLEAR=0 ARG_MENUCONFIG=0 ARG_SNAPSHOTBACKUP=0
declare -i ARG_EASYSETUP=0 ARG_IS_NEW_KERNEL_AVAILABLE=0
declare -i ARG_REBUILD_EXTERNAL_MODULES=0 ARG_ALERT=0
# non-boolean arguments
declare -i ADJUSTMENT=19
# ***************** various functions ******************
cleanup_and_exit_with_code() {
# add any additional cleanup code here
set +e
trap - EXIT
umount_all_remembered_mountpoints
restore_efivarfs_mount_state
exit $1
}
fn_exists() {
declare -f -F "${1}" > /dev/null
return $?
}
show() {
local MESSAGE=${1:-""}
local VERBLEVEL=${2:-${VERBOSITY}}
if (( VERBLEVEL >=1 )); then
echo -e "${SHOWPREFIX}${MESSAGE}${SHOWSUFFIX}"
fi
}
alertshow() {
local MESSAGE=${1:-""}
local VERBLEVEL=${2:-${VERBOSITY}}
if ((ARG_ALERT==0)); then
show "${@}"
elif (( VERBLEVEL >=1 )); then
echo -e "${SHOWPREFIX}${MESSAGE}${SHOWSUFFIX}${ALERT_TEXT}"
fi
}
warning() {
echo -e "${YELLOW_TEXT}${PREFIXSTRING}${RESET_ATTS}${PROGNAME}: Warning: ${1}" >&2
}
die() {
echo
echo -e "${RED_TEXT}${PREFIXSTRING}${RESET_ATTS}${PROGNAME}: Error: ${1} - exiting" >&2
cleanup_and_exit_with_code 1
}
trap_cleanup() {
trap - SIGHUP SIGQUIT SIGINT SIGTERM SIGKILL EXIT
die "Caught signal"
}
trap trap_cleanup SIGHUP SIGQUIT SIGINT SIGTERM SIGKILL EXIT
test_yn() {
echo -n -e "${SHOWPREFIX}${1} (y/n)? ${SHOWSUFFIX}${ALERT_TEXT}"
read -r -n 1
echo
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
return 0
else
return 1
fi
}
test_yn_need_enter() {
echo -n -e "${SHOWPREFIX}${1} (y/n)? ${SHOWSUFFIX}${ALERT_TEXT}"
read -r
echo
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
return 0
else
return 1
fi
}
continue_yn() {
if ! test_yn "${1}"; then
echo -e "${RED_TEXT}${PREFIXSTRING}${RESET_ATTS}Quitting" >&2
cleanup_and_exit_with_code 1
fi
}
suppress_colours() {
RED_TEXT=""
GREEN_TEXT=""
YELLOW_TEXT=""
RESET_ATTS=""
SHOWPREFIX="${PREFIXSTRING}"
}
suppress_alert() {
ALERT_TEXT=""
}
suppress_colour_and_alert_if_output_not_to_a_terminal() {
if [ ! -t 1 -o ! -t 2 ]; then
# we are going to a non-terminal
suppress_colours
suppress_alert
fi
}
check_file_exists() {
if [ ! -f "${1}" ]; then
die "File '${1}' does not exist"
fi
}
read_portage_info_if_necessary() {
if [ -z "${PORTAGEINFO}" ]; then
show "Checking Portage configuration, please wait..."
PORTAGEINFO="$(emerge --info)"
fi
}
extract_kernel_release_name() {
# extract the kernel release string, and setup the derived strings
# NB we now check kernelrelease, not kernelversion; it is possible that
# the kernelrelease may change during the build (e.g., by a 'clean'
# tagged release directory becoming marked 'dirty', and so having a '+'
# sign appended)
# LINUXBUILDDIR must be defined and non-blank on entry
NEWVERSION="linux-$(cd "${LINUXBUILDDIR}" && make -s kernelrelease)"
INITRAMFSNAME="$(echo $NEWVERSION | sed "s/linux/initramfs-genkernel-x86_64/")"
VMLINUZNAME="$(echo $NEWVERSION | sed "s/linux/vmlinuz/")"
}
check_gcc_config_and_reset_if_necessary() {
# check if gcc-config exists with an error - if it does, then
# attempt to set one based on the current gcc version number
if ! gcc-config --get-current-profile >/dev/null 2>&1; then
# unset or invalid, attempt to force this to the current gcc
# version
read_portage_info_if_necessary
local CHOST="$(grep '^CHOST=.*' <<<"${PORTAGEINFO}")"
CHOST="$(cut -d\" -f2 <<< ${CHOST})"
local GCC_VERSION=""
# can't be sure we have eix installed
if eix --version >/dev/null 2>&1; then
# we do, so can cleanly check latest installed gcc version
GCC_VERSION="$(eix --installed --exact sys-devel/gcc --format '<installedversions:NAMEVERSION>' --versionsort | tail -n 1)"
GCC_VERSION="${GCC_VERSION##*gcc-}"
else
# we don't, have to hack the most recent gcc version
GCC_VERSION="$(ls -1v "/usr/${CHOST}/gcc-bin" | tail -n 1)"
fi
local FULL_GCC_ID="${CHOST}-${GCC_VERSION}"
if gcc-config "${FULL_GCC_ID}"; then
warning "gcc configuration was reset"
if [ -s "${ETCPROFILE}" ]; then
set +e
set +u
shopt -u nullglob
source "${ETCPROFILE}"
shopt -s nullglob
set -e
set -u
fi
else
die "failed to set gcc configuration"
fi
fi
}
mount_and_remember() {
local DEVPATH="${1}"
local MOUNTPOINT="${2}"
local TYPE=${3:-""}
if [[ "${ALLMOUNTS[${MOUNTPOINT}]+_}" ]]; then
warning "Attempt to mount '${MOUNTPOINT}' more than once"
else
if [ -n "${TYPE}" ]; then
mount -t "${TYPE}" "${DEVPATH}" "${MOUNTPOINT}"
else
mount "${DEVPATH}" "${MOUNTPOINT}"
fi
# and remember we mounted it
ALLMOUNTS["${MOUNTPOINT}"]="${DEVPATH}"
fi
}
umount_and_forget() {
local MOUNTPOINT="${1}"
if [[ "${ALLMOUNTS[${MOUNTPOINT}]+_}" ]]; then
umount --lazy "${MOUNTPOINT}"
# and forget
unset -v "ALLMOUNTS[${MOUNTPOINT}]"
else
warning "Attempt to unmount '${MOUNTPOINT}', but not mounted"
fi
}
umount_all_remembered_mountpoints() {
local M ALLREMEMBEREDMOUNTS="${!ALLMOUNTS[@]}"
for M in ${ALLREMEMBEREDMOUNTS}; do
if (( DOUNMOUNT == 1 )) || [[ "${M}" != "${EFIROOTDIR}" ]]; then
warning "Unmounting '${M}'"
umount_and_forget "${M}"
fi
done
}
ensure_efivarfs_rw_if_present() {
if ((USINGEFI==1 && ONENTRYROEFIVARFS==1)); then
warning "Temporarily remounting efivarfs read-write"
mount -o remount,rw "/sys/firmware/efi/efivars"
EFIVARFSREMOUNTEDRW=1
fi
}
restore_efivarfs_mount_state() {
if ((USINGEFI==1 && ONENTRYROEFIVARFS==1 && EFIVARFSREMOUNTEDRW==1)); then
warning "Remounting efivarfs read-only"
if mount -o remount,ro "/sys/firmware/efi/efivars"; then
EFIVARFSREMOUNTEDRW=0
fi
fi
}
check_is_luks_volume() {
local CANONPART=$(findfs "${1}")
cryptsetup isLuks "${CANONPART}" || die "Path '${1}' is not a LUKS volume"
}
partuuid_is_on_usb_device() {
local CANONPART="${ALLUUIDS[${1}]}"
if [[ "${ISUSBPART[${CANONPART}]-0}" == "1" ]]; then
return 0
fi
return 1
}
check_partuuid_exists() {
if [ -z "${ALLUUIDS[${1}]+test}" ]; then
die "Partition with UUID '${1}' does not exist"
fi
}
source_etc_conf_file() {
# get the variables the user must set, and any overrides
if [ ! -s "${CONFFILE}" ]; then
warning "${CONFFILE} does not exist"
if test_yn "Would you like to run --easy-setup now to fix this"; then
interactively_set_buildkernel_config
cleanup_and_exit_with_code 0
else
die "Cannot proceed; please create ${CONFFILE} manually"
fi
fi
source "${CONFFILE}"
# make sure the PARTUUIDs are lower case, if defined
if [[ -v EFIPARTUUID ]]; then
EFIPARTUUID="${EFIPARTUUID,,}"
fi
if [[ -v CRYPTPARTUUID ]]; then
CRYPTPARTUUID="${CRYPTPARTUUID,,}"
fi
if [[ -v KEYFILEPARTUUID ]]; then
KEYFILEPARTUUID="${KEYFILEPARTUUID,,}"
fi
# remember if CRYPTPATHMAP set
if [[ -v CRYPTPATHMAP ]]; then
CRYPTPATHMAPFORCED=1
fi
# map INITSYSTEM to lower case
if [[ -v INITSYSTEM ]]; then
INITSYSTEM="${INITSYSTEM,,}"
fi
# perform checks on KERNEL_SIGNING_CERT and KERNEL_SIGNING_KEY
if [[ -v KERNEL_SIGNING_CERT ]]; then
if [[ ! -v KERNEL_SIGNING_KEY ]]; then
die "Cannot proceed; KERNEL_SIGNING_CERT is configured, but KERNEL_SIGNING_KEY is not."
fi
if [[ "${KERNEL_SIGNING_CERT}" == "auto" || "${KERNEL_SIGNING_KEY}" == "auto" ]]; then
if [[ "${KERNEL_SIGNING_CERT}" != "${KERNEL_SIGNING_KEY}" ]]; then
die "Cannot proceed; in automatic external module signing mode, both KERNEL_SIGNING_CERT and KERNEL_SIGNING_KEY must be set to \"auto\""
fi
KERNEL_SIGNING_CERT="${LINUXDIR}/certs/signing_key.x509"
KERNEL_SIGNING_KEY="${LINUXDIR}/certs/signing_key.pem"
else
if [[ ! -f "${KERNEL_SIGNING_CERT}" ]]; then
die "Cannot proceed; KERNEL_SIGNING_CERT is not a valid path to a file."
fi
if [[ ! -f "${KERNEL_SIGNING_KEY}" ]]; then
die "Cannot proceed; KERNEL_SIGNING_KEY is not a valid path to a file."
fi
fi
fi
if [[ -v KERNEL_SIGNING_KEY && ! -v KERNEL_SIGNING_CERT ]]; then
die "Cannot proceed; KERNEL_SIGNING_KEY is configured, but KERNEL_SIGNING_CERT is not."
fi
}
setup_final_variables() {
# post-processing once buildkernel.conf loaded
# critical that EFIPARTUUID and CRYPTPARTUUID are defined...
# (NB - buildkernel now also supports a LUKS filesystem that does not live
# in a GPT partition - you can simply override CRYPTPATHMAP directly in
# buildkernel.conf. If you set this, then CRYPTPARTUUID will not be checked
# and its contents (if any) will be ignored.)
if [ -z ${EFIPARTUUID+xxx} ]; then
warning "EFIPARTUUID not set in ${CONFFILE}"
if test_yn "Would you like to run --easy-setup now to fix this"; then
interactively_set_buildkernel_config
cleanup_and_exit_with_code 0
else
die "Cannot proceed; please edit ${CONFFILE} manually"
fi
fi
if ((CRYPTPATHMAPFORCED==1)); then
if [ -z "${CRYPTPATHMAP}" ]; then
die "CRYPTPATHMAP set to empty string in ${CONFFILE}; cannot proceed"
fi
warning "CRYPTPATHMAP defined in ${CONFFILE}"
warning "CRYPTPARTUUID will be ignored"
# check it
if ! cryptsetup isLuks "${CRYPTPATHMAP}"; then
die "CRYPTPATHMAP ('${CRYPTPATHMAP}') does not specify a LUKS filesystem"
fi
elif [ -z ${CRYPTPARTUUID+xxx} ]; then
warning "CRYPTPARTUUID not set in ${CONFFILE}"
if test_yn "Would you like to run --easy-setup now to fix this"; then
interactively_set_buildkernel_config
cleanup_and_exit_with_code 0
else
die "Cannot proceed; please edit ${CONFFILE} manually"
fi
fi
if [ -n "${PLYMOUTHTHEME}" ] && ! "${USE_PLYMOUTH}"; then
warning "You have specified a PLYMOUTHTHEME, but ${PROGNAME} was emerged"
warning "without the plymouth use flag set - ignoring."
PLYMOUTHTHEME=""
fi
EFIPATHMAP="PARTUUID=${EFIPARTUUID}"
if ((CRYPTPATHMAPFORCED==0)); then
if [ -z ${PARTUUIDS[${CRYPTPARTUUID}]+xxx} ]; then
CRYPTPATHMAP="UUID=${CRYPTPARTUUID}"
else
CRYPTPATHMAP="PARTUUID=${CRYPTPARTUUID}"
fi
fi # otherwise, leave it as set
# check if the user has specified an OpenRC init; if not, assume systemd
if [[ "${INITSYSTEM}" == "openrc" ]]; then
# need a different path for the init executable
CMDLINE_REAL_INIT="${OPENRC_INIT}"
elif [[ "${INITSYSTEM}" != "systemd" ]]; then
warning "Unrecognized INITSYSTEM, assuming systemd"
INITSYSTEM="systemd"
fi
# assume keyfile is also on the EFI system partition, unless KEYFILEPARTUUID
# has been set explicitly in buildkernel.conf
KEYFILEPARTUUID="${KEYFILEPARTUUID:-${EFIPARTUUID}}"
if [ -z ${PARTUUIDS[${KEYFILEPARTUUID}]+xxx} ]; then
KEYFILEPATHMAP="UUID=${KEYFILEPARTUUID}"
else
KEYFILEPATHMAP="PARTUUID=${KEYFILEPARTUUID}"
fi
# get the real root filesystem type if not specified
# falling back to ext4 if the findmnt-based lookup fails
if [[ ! -v CMDLINE_ROOTFSTYPE ]]; then
CMDLINE_ROOTFSTYPE="$(/bin/findmnt -n -o FSTYPE -S ${CMDLINE_REAL_ROOT} 2>/dev/null || echo ext4)"
CMDLINE_ROOTFSTYPE="$(head -n 1 <<<"${CMDLINE_ROOTFSTYPE}")"
fi
# we use path syntax rather than "=PARTUUID=" syntax, as more reliable
KERNEL_CMD_LINE="root=${CMDLINE_ROOT} crypt_root=${CRYPTPATHMAP} "
if ((DISABLE_LVM==0)); then
KERNEL_CMD_LINE+="dolvm "
fi
KERNEL_CMD_LINE+="real_root=${CMDLINE_REAL_ROOT} rootfstype=${CMDLINE_ROOTFSTYPE} "
KERNEL_CMD_LINE+="real_init=${CMDLINE_REAL_INIT} "
if [ -n "${LUKSKEYFILE}" ]; then
KERNEL_CMD_LINE+="root_keydev=${KEYFILEPATHMAP} root_key=${LUKSKEYFILE} "
fi
if ((DISABLE_HIBERNATION==0)); then
KERNEL_CMD_LINE+="real_resume=${CMDLINE_REAL_RESUME} "
fi
KERNEL_CMD_LINE+="keymap=${KEYMAP}"
if [ -n "${PLYMOUTHTHEME}" ]; then
KERNEL_CMD_LINE+=" quiet splash"
if [[ "${INITSYSTEM}" == "systemd" ]]; then
# make sure systemd doesn't print a version number during early boot
KERNEL_CMD_LINE+=" udev.log-priority=3"
fi
fi
if [ -n "${ADDITIONALKERNELCMDS}" ]; then
KERNEL_CMD_LINE+=" ${ADDITIONALKERNELCMDS}"
fi
if grep -q "^# CONFIG_MODULES is not set$" "${TARGETCONFIG}" > /dev/null; then
warning "No module support, disabling kernel modules."
USINGMODULES=0
else
USINGMODULES=1
fi
}
check_if_booted_under_efi() {
if [ -d "/sys/firmware/efi" ]; then
USINGEFI=1
# efivarfs mounted ro?
if findmnt "/sys/firmware/efi/efivars" --options "ro" &>/dev/null; then
ONENTRYROEFIVARFS=1
else
ONENTRYROEFIVARFS=0
fi
else
USINGEFI=0
fi
}
load_all_devices() {
# overwrites the variables ALLUUIDS, FSUUIDS, PARTUUIDS
# EFIUUIDS, GPGUUIDS, LUKSUUIDS, ISUSBPART
# we only look for non-LUKS partitions on attached USB devices
# for GPG keys, and don't mount to check that the file is there
ALLUUIDS=(); FSUUIDS=(); PARTUUIDS=();
EFIUUIDS=(); GPGUUIDS=(); LUKSUUIDS=()
ISUSBPART=()
local NEXTDEV NEXTUUID NEXTPARTUUID NEXTFSTYPE
shopt -s lastpipe
blkid -D | while read A; do
echo $A | grep -oP '^[^:]+' | tr -d '\012' && echo -ne "\t" &&
echo $A | grep -oP '(?<= TYPE=")[^"]+' | tr -d '\012' && echo -ne "\t" &&
echo $A | grep -oP '(?<= UUID=")[^"]+' | tr -d '\012' && echo -ne "\t" &&
echo $A | grep -oP '(?<= PARTUUID=")[^"]+' | tr -d '\012' && echo ""
done |
while read NEXTDEV NEXTFSTYPE NEXTUUID NEXTPARTUUID; do
if [ -n "${NEXTFSTYPE}" -a -n "${NEXTUUID}" ]; then
ALLUUIDS[${NEXTUUID}]="${NEXTDEV}"
FSUUIDS[${NEXTUUID}]="1"
if [ -n "${NEXTPARTUUID}" ]; then
ALLUUIDS[${NEXTPARTUUID}]="${NEXTDEV}"
PARTUUIDS[${NEXTPARTUUID}]="1"
fi
if [[ $(readlink "/sys/class/block/${NEXTDEV:5}") =~ usb ]]; then
ISUSBPART["${NEXTDEV}"]="1"
if [ ${NEXTFSTYPE} != crypto_LUKS ]; then
if [ -n "${NEXTPARTUUID}" ]; then
GPGUUIDS=("${GPGUUIDS[@]:+${GPGUUIDS[@]}}" "${NEXTUUID}" "${NEXTPARTUUID}")
else
GPGUUIDS=("${GPGUUIDS[@]:+${GPGUUIDS[@]}}" "${NEXTUUID}")
fi
fi
fi
case ${NEXTFSTYPE} in
vfat) # check for GPT "EFI System" magic UUID
if blkid -p "${NEXTDEV}" | grep -q c12a7328-f81f-11d2-ba4b-00a0c93ec93b; then
if [ -n "${NEXTPARTUUID}" ]; then
EFIUUIDS=("${EFIUUIDS[@]:+${EFIUUIDS[@]}}" "${NEXTUUID}" "${NEXTPARTUUID}")
else
EFIUUIDS=("${EFIUUIDS[@]:+${EFIUUIDS[@]}}" "${NEXTUUID}")
fi
fi
;;
crypto_LUKS)
if [ -n "${NEXTPARTUUID}" ]; then
LUKSUUIDS=("${LUKSUUIDS[@]:+${LUKSUUIDS[@]}}" "${NEXTUUID}" "${NEXTPARTUUID}")
else
LUKSUUIDS=("${LUKSUUIDS[@]:+${LUKSUUIDS[@]}}" "${NEXTUUID}")
fi
;;
*)
;;
esac
fi
done
}
find_all_efi_boot_entries() {
# overwrites the variables EBOOTIDS EBOOTNAMES EBOOTPATHS EBOOTUUIDS
# and EBOOTISACTIVES, EBOOTORDER
# and also HASWINBOOTLOADER and EBOOTIDTOINDEX
EBOOTIDS=(); EBOOTNAMES=(); EBOOTPATHS=(); EBOOTUUIDS=()
EBOOTISACTIVES=(); EBOOTORDER=()
local K ALLK="${!HASWINBOOTLOADER[@]}"
for K in ${ALLK}; do
unset -v "HASWINBOOTLOADER[${K}]"
done
ALLK="${!EBOOTIDTOINDEX[@]}"
for K in ${ALLK}; do
unset -v "EBOOTIDTOINDEX[${K}]"
done
if ((USINGEFI==0)); then
warning "This system wasn't booted under UEFI, cannot check boot entries"
return 0
fi
local NEXTLINE
declare -i NEXTINDEX=0
# only look for hard drive entries here
while read -r NEXTLINE; do
local NEXTID="${NEXTLINE:4:4}"
local NEXTSIG="${NEXTLINE:0:8}"
local NEXTISACTIVE="${NEXTLINE:8:1}"
if [[ "${NEXTISACTIVE}" == "*" ]]; then
NEXTISACTIVE="1"
else
NEXTISACTIVE="0"
fi
local NEXTUUID=$(egrep -o 'HD\([^(]*\)' <<<"${NEXTLINE}" | egrep -o '[[:xdigit:]]{8}(\-[[:xdigit:]]{4}){3}\-[[:xdigit:]]{12}')
local NEXTPATH=$(egrep -o 'File\([^(]*\)' <<<"${NEXTLINE}")
NEXTPATH="${NEXTPATH:5:-1}"
local NEXTNAME="$(efibootmgr | grep "^${NEXTSIG}" | cut -c11-)"
NEXTUUID="${NEXTUUID,,}"
if [[ -z "${NEXTID}" || -z "${NEXTNAME}" || -z "${NEXTPATH}" || -z "${NEXTUUID}" || -z "${NEXTISACTIVE}" ]]; then
# one of the required strings is empty, we cannot use this line
continue
fi
# assign results (Bash treats arrays as unset if not assigned a value)
EBOOTIDS=("${EBOOTIDS[@]:+${EBOOTIDS[@]}}" "${NEXTID}")
EBOOTNAMES=("${EBOOTNAMES[@]:+${EBOOTNAMES[@]}}" "${NEXTNAME}")
EBOOTPATHS=("${EBOOTPATHS[@]:+${EBOOTPATHS[@]}}" "${NEXTPATH}")
EBOOTUUIDS=("${EBOOTUUIDS[@]:+${EBOOTUUIDS[@]}}" "${NEXTUUID}")
EBOOTISACTIVES=("${EBOOTISACTIVES[@]:+${EBOOTISACTIVES[@]}}" "${NEXTISACTIVE}")
# archive whether or not this is a windows bootloader entry
# there can be >1 entry for the same UUID, so this acts like a
# 'dirty' flag
if grep -i -q "Windows" <<<"${NEXTNAME}" || \
grep -i -q "Microsoft" <<<"${NEXTPATH}"; then
HASWINBOOTLOADER["${NEXTUUID}"]="1"
fi
# store a lookup from boot ID (4 digit hex string) to index in these
# arrays
EBOOTIDTOINDEX["${NEXTID}"]="${NEXTINDEX}"
NEXTINDEX=$((NEXTINDEX+1))
done < <(efibootmgr -v | grep '^Boot0[^ ]*.*HD([^\)]*)')
# now extract the boot order, and save it into EBOOTORDER in ascending order
EBOOTORDER=($(efibootmgr | grep '^BootOrder' | sed 's/BootOrder: //g;s/,/ /g'))
EFIBOOTENTRIESSEARCHED=1
}
archive_current_config_variables() {
local NEXTVAR
for NEXTVAR in "${PROCVARS[@]}"; do
if [[ -v "${NEXTVAR}" ]] ; then
eval "OLD_${NEXTVAR}"="${!NEXTVAR}"
else
unset -v "OLD_${NEXTVAR}"
fi
done
}
warn_if_buildkernel_config_incomplete() {
declare -i WILLRUN=1
if [[ ! -v EFIPARTUUID ]]; then
warning "EFIPARTUUID not set in ${CONFFILE}"
WILLRUN=0
fi
if ((CRYPTPATHMAPFORCED==1)); then
if [ -z "${CRYPTPATHMAP}" ]; then
warning "CRYPTPATHMAP set to empty string in ${CONFFILE}"
WILLRUN=0
fi
warning "CRYPTPATHMAP defined in ${CONFFILE}"
warning "CRYPTPARTUUID will be ignored"
elif [[ ! -v CRYPTPARTUUID ]]; then
warning "CRYPTPARTUUID not set in ${CONFFILE}"
WILLRUN=0
fi
if ((WILLRUN==0)); then
warning "${PROGNAME} cannot create a kernel until you fix this"
fi
}
interactively_set_buildkernel_config() {
find_all_efi_boot_entries
archive_current_config_variables
declare -i DOSAVE=0 DOEXIT=0
declare -a TOPMENU=("Set EFI system partition" "Set LUKS root partition" \
"Set LUKS key options" "Set EFI boot file path"\
"Set boot splash options" "Set boot-time keymap" \
"Set init system" \
"Exit without saving" "Save and exit")
local X
PS3="Your choice: "
until ((DOEXIT==1)); do
show_current_key_config_status
show "Please choose an option:"
select X in "${TOPMENU[@]}"; do
printf "\n"
case "${X}" in
"Set EFI system partition") set_efi_system_partition; break ;;
"Set LUKS root partition") set_luks_root_partition; break ;;
"Set LUKS key options") set_luks_key_options; break ;;
"Set EFI boot file path") set_efi_boot_file_path; break ;;
"Set boot splash options") set_boot_splash_options; break ;;
"Set boot-time keymap") set_boot_time_keymap; break ;;
"Set init system") set_init_system; break ;;
"Exit without saving") DOEXIT=1; break ;;
"Save and exit") DOSAVE=1; DOEXIT=1; break ;;
*) warning "Please choose one of the menu options!"; break ;;
esac
done
if ((DOEXIT==1 && DOSAVE==0 && CONFIGDIRTY==1)); then
if ! test_yn_need_enter "Are you sure? Your changes will be lost. Proceed"; then
DOEXIT=0
fi
fi
done
if ((DOSAVE==0)); then
if ((CONFIGDIRTY==1)); then
warning "As instructed, your changes were not saved!"
else
show "Configuration unchanged."
fi
else
# user wants to save
if ((CONFIGDIRTY==1)); then
save_buildkernel_config
show "Configuration saved to ${CONFFILE}."
show "Be sure to run ${PROGNAME}, to rebuild the kernel with the new"
show "settings, before rebooting."
else
show "Configuration is unchanged, nothing to save."
fi
warn_if_efi_boot_file_clashes_with_windows_bootloader
warn_if_buildkernel_config_incomplete
fi
}
save_buildkernel_config() {
local NEXTVAR NEXTDEFAULTVAR
# ensure any existing definitions are commented out
for NEXTVAR in "${PROCVARS[@]}"; do
sed -i "/^${NEXTVAR}=/s/^/# /" "${CONFFILE}"
done
# get rid of the existing 'auto' section, if there is one
sed -i '/^# Automatically added by '"${PROGNAME}"' - edits here may be overwritten/,/^# End of automatically added section/d' "${CONFFILE}"
# now append remaining vars to end
printf "# Automatically added by ${PROGNAME} - edits here may be overwritten\n" >> "${CONFFILE}"
for NEXTVAR in "${PROCVARS[@]}"; do
if [[ -v "${NEXTVAR}" ]] ; then
# don't write out anything if we have the default value set anyway
NEXTDEFAULTVAR="DEFAULT${NEXTVAR}"
if [[ -v "${NEXTDEFAULTVAR}" && "${!NEXTVAR}" == "${!NEXTDEFAULTVAR}" ]] ; then
continue
fi
printf "${NEXTVAR}=\"${!NEXTVAR}\"\n" >> "${CONFFILE}"
fi
done
printf "# End of automatically added section\n" >> "${CONFFILE}"
# copy the keyfile, if location or path has changed
if [[ -v OLD_LUKSKEYFILE && -v LUKSKEYFILE && \
( -v OLD_EFIPARTUUID || -v OLD_KEYFILEPARTUUID ) ]]; then
local OLD_ACTUAL_KEYFILEPARTUUID="${OLD_KEYFILEPARTUUID:-${OLD_EFIPARTUUID}}"
local ACTUAL_KEYFILEPARTUUID="${KEYFILEPARTUUID:-${EFIPARTUUID}}"
if [[ -n "${LUKSKEYFILE}" && -n "${OLD_LUKSKEYFILE}" && \
( "${ACTUAL_KEYFILEPARTUUID}" != "${OLD_ACTUAL_KEYFILEPARTUUID}" || \
"${LUKSKEYFILE}" != "${OLD_LUKSKEYFILE}" ) ]]; then
show "Your LUKS keyfile location has changed:"
show "Old PARTUUID: ${OLD_ACTUAL_KEYFILEPARTUUID}, filename: '${OLD_LUKSKEYFILE}'"
show "New PARTUUID: ${ACTUAL_KEYFILEPARTUUID}, filename: '${LUKSKEYFILE}'"
if test_yn_need_enter "Would you like to copy the keyfile across now"; then
copy_file_from_partition_to_partition \
"${OLD_ACTUAL_KEYFILEPARTUUID}" "/${OLD_LUKSKEYFILE}" \
"${ACTUAL_KEYFILEPARTUUID}" "/${LUKSKEYFILE}" \
"keyfile copied successfully (original retained)" \
"Error copying keyfile - please copy manually"
else
warning "File not copied"
warning "Please ensure '${LUKSKEYFILE}' available on"
warning "partition ${ACTUAL_KEYFILEPARTUUID}"
warning "before attempting to reboot"
fi
fi
fi
# it may be dangerous to leave /boot/efi mounted, if the user has
# changed its location, so unmount it now if necessary
if mount | grep -q " ${EFIROOTDIR} " > /dev/null; then
show "Unmounting ${EFIROOTDIR} for safety"
umount_and_forget "${EFIROOTDIR}"
fi
}
set_efi_system_partition() {
declare -i DOEXIT=0 NUMEFIPARTS="${#EFIUUIDS[@]}"
local NUMREG='^[0-9]+$'
until ((DOEXIT==1)); do
show "Please choose which EFI system partition to use (or GO BACK):"
show_efi_system_partitions "GO BACK"
printf "%s" "${PS3}"
local N
read -r N
if [[ "${N}" =~ ${NUMREG} ]]; then
if ((N>=1 && N<=NUMEFIPARTS)); then
# valid partition, set it
if [[ -v EFIPARTUUID ]]; then
if [[ "${EFIPARTUUID}" != "${EFIUUIDS[$((N-1))]}" ]]; then
CONFIGDIRTY=1;
fi
else
CONFIGDIRTY=1;
fi
EFIPARTUUID="${EFIUUIDS[$((N-1))]}"
DOEXIT=1;
show "EFI system partition selected as follows:"
show_efi_system_partitions
warn_if_efi_boot_file_clashes_with_windows_bootloader
make_key_file_location_expicit_if_necessary_and_wanted
elif ((N==1+NUMEFIPARTS)); then
DOEXIT=1;
fi
fi
if ((DOEXIT==0)); then
warning "Please choose one of the menu options!"
fi
done
}
set_luks_root_partition() {
declare -i DOEXIT=0 NUMLUKSPARTS="${#LUKSUUIDS[@]}"
local NUMREG='^[0-9]+$'
until ((DOEXIT==1)); do
show "Please choose which LUKS partition contains the root LVM logical volume:"
show_luks_partitions "GO BACK"
printf "%s" "${PS3}"
local N
read -r N
if [[ "${N}" =~ ${NUMREG} ]]; then
if ((N>=1 && N<=NUMLUKSPARTS)); then
# valid partition, set it
if [[ -v CRYPTPARTUUID ]]; then
if [[ "${CRYPTPARTUUID}" != "${LUKSUUIDS[$((N-1))]}" ]]; then
CONFIGDIRTY=1;
fi
else
CONFIGDIRTY=1;
fi
CRYPTPARTUUID="${LUKSUUIDS[$((N-1))]}"
DOEXIT=1;
show "LUKS partition selected as follows:"
show_luks_partitions
elif ((N==1+NUMLUKSPARTS)); then
DOEXIT=1;
fi
fi
if ((DOEXIT==0)); then
warning "Please choose one of the menu options!"
fi
done
}
show_current_key_config_status() {
# main things we need are: EFIPARTUUID, CRYPTPARTUUID, KEYFILEPARTUUID
# LUKSKEYFILE, EFIBOOTDIR, EFIBOOTFILE, PLYMOUTHTHEME, KEYMAP and INITSYSTEM
local MODFLAG=""
if ((CONFIGDIRTY==1)); then
MODFLAG=" - MODIFIED"
fi
printf "\n"
show "Current configuration (from ${CONFFILE}${MODFLAG}):"
printf "\n"
printf " EFI system partition UUID: %-36s\n" "${EFIPARTUUID:-NEEDS SETTING}"
if ((CRYPTPATHMAPFORCED==0)); then
printf " LUKS root partition UUID: %-36s\n" "${CRYPTPARTUUID:-NEEDS SETTING}"
else
printf " LUKS root partition UUID: %-36s\n" "IGNORED, OVERRIDDEN BY CRYPTPATHMAP"
printf " (to '%s')\n" "${CRYPTPATHMAP}"
fi
printf " GPG keyfile partition UUID: %-36s\n" "${KEYFILEPARTUUID:-DEFAULT (=EFI system partition UUID)}"
printf " GPG keyfile (for LUKS): %-36s\n" "${LUKSKEYFILE:-NONE (using fallback passphrase)}"
printf " EFI boot directory: %-36s\n" "${EFIBOOTDIR:-NEEDS SETTING}"
printf " EFI boot file: %-36s\n" "${EFIBOOTFILE:-NEEDS SETTING}"
printf " Plymouth theme: %-36s\n" "${PLYMOUTHTHEME:-NONE (textual boot)}"
printf " Boot-time keymap: %-36s\n" "${KEYMAP:-NEEDS SETTING}"
if [[ "${INITSYSTEM}" == "systemd" ]]; then
printf " Init system: %-36s\n" "systemd"
else
printf " Init system: %-36s\n" "OpenRC"
fi
printf "\n"
}
show_gpg_keyfile_partitions() {
local LASTITEM=${1:-""}
declare -i I=0 NUMGPGPARTS="${#GPGUUIDS[@]}"
if ((NUMGPGPARTS==0)); then
show "No potential keyfile partitions found on your machine"
else
echo "Num Use UUID Path"
echo "--- --- ------------------------------------ -------------------------------"
for I in "${!GPGUUIDS[@]}"; do
local INUSE="[ ]"
if [[ ${KEYFILEPARTUUID:-""} == "${GPGUUIDS[$I]}" ]]; then
INUSE="[*]"
fi
printf "%2d) %3s %-36s %-10s\n" $((I+1)) \
"${INUSE}" "${GPGUUIDS[$I]}" "${ALLUUIDS[${GPGUUIDS[$I]}]}"
done
fi
if [ -n "${LASTITEM}" ]; then
printf "%2d) %s\n" $((NUMGPGPARTS+1)) "${LASTITEM}"
fi
}
show_luks_partitions() {
local LASTITEM=${1:-""}
declare -i I=0 NUMLUKSPARTS="${#LUKSUUIDS[@]}"
if ((NUMLUKSPARTS==0)); then
die "No LUKS partitions found on your machine"
else
echo "Num USB Use UUID Path"
echo "--- --- --- ------------------------------------ -------------------------------"
for I in "${!LUKSUUIDS[@]}"; do
local ISUSB=" N "
local INUSE="[ ]"
local DEVNAME=${ALLUUIDS["${LUKSUUIDS[$I]}"]}
if [ ${ISUSBPART[${DEVNAME}]+xxx} ] ; then
ISUSB=" Y "
fi
if [[ ${CRYPTPARTUUID:-""} == "${LUKSUUIDS[$I]}" ]]; then
INUSE="[*]"
fi
printf "%2d) %3s %3s %-36s %-10s\n" $((I+1)) \
"${ISUSB}" "${INUSE}" "${LUKSUUIDS[$I]}" "${DEVNAME}"
done
fi
if [ -n "${LASTITEM}" ]; then
printf "%2d) %s\n" $((NUMLUKSPARTS+1)) "${LASTITEM}"
fi
}
show_efi_system_partitions() {
local LASTITEM=${1:-""}
local DEVNAME
declare -i I=0 NUMEFIPARTS="${#EFIUUIDS[@]}"
if ((NUMEFIPARTS==0)); then
die "No EFI system partitions found on your machine"
else
echo "Num USB Win Use UUID Path"
echo "--- --- --- --- ------------------------------------ -------------------------------"
for I in "${!EFIUUIDS[@]}"; do
local ISUSB=" N "
local INUSE="[ ]"
local ISWIN=" N "
local DEVNAME=${ALLUUIDS[${EFIUUIDS[$I]}]}
if [ ${ISUSBPART[${DEVNAME}]+xxx} ] ; then
ISUSB=" Y "
fi
if [[ ${EFIPARTUUID:-""} == "${EFIUUIDS[$I]}" ]]; then
INUSE="[*]"
fi
if ((USINGEFI==0)); then
ISWIN="???"
elif [[ "${HASWINBOOTLOADER[${EFIUUIDS[$I]}]-0}" == "1" ]]; then
ISWIN=" Y "
fi
printf "%2d) %3s %3s %3s %-36s %-30s\n" $((I+1)) \
"${ISUSB}" "${ISWIN}" "${INUSE}" "${EFIUUIDS[$I]}" "${DEVNAME}"
done
fi
if [ -n "${LASTITEM}" ]; then
printf "%2d) %s\n" $((NUMEFIPARTS+1)) "${LASTITEM}"
fi
}