[bootloader] Refactor method for safe efi label

This commit is contained in:
Adriaan de Groot 2018-02-20 10:47:14 -05:00
parent 7f53e970fc
commit 06536b6a66

View File

@ -167,6 +167,18 @@ def create_loader(loader_path):
loader_file.write(line) loader_file.write(line)
def efi_label():
if "efiBootloaderId" in libcalamares.job.configuration:
efi_bootloader_id = libcalamares.job.configuration[
"efiBootloaderId"]
else:
branding = libcalamares.globalstorage.value("branding")
efi_bootloader_id = branding["bootloaderEntryName"]
file_name_sanitizer = str.maketrans(" /", "_-")
return efi_bootloader_id.translate(file_name_sanitizer)
def install_systemd_boot(efi_directory): def install_systemd_boot(efi_directory):
""" """
Installs systemd-boot as bootloader for EFI setups. Installs systemd-boot as bootloader for EFI setups.
@ -218,14 +230,8 @@ def install_grub(efi_directory, fw_type):
if not os.path.isdir(install_efi_directory): if not os.path.isdir(install_efi_directory):
os.makedirs(install_efi_directory) os.makedirs(install_efi_directory)
if "efiBootloaderId" in libcalamares.job.configuration: efi_bootloader_id = efi_label()
efi_bootloader_id = libcalamares.job.configuration[
"efiBootloaderId"]
else:
branding = libcalamares.globalstorage.value("branding")
distribution = branding["bootloaderEntryName"]
file_name_sanitizer = str.maketrans(" /", "_-")
efi_bootloader_id = distribution.translate(file_name_sanitizer)
# get bitness of the underlying UEFI # get bitness of the underlying UEFI
try: try:
sysfile = open("/sys/firmware/efi/fw_platform_size", "r") sysfile = open("/sys/firmware/efi/fw_platform_size", "r")
@ -303,7 +309,17 @@ def install_secureboot(efi_directory):
""" """
Installs the secureboot shim in the system by calling efibootmgr. Installs the secureboot shim in the system by calling efibootmgr.
""" """
raise NotImplementedError efi_bootloader_id = efi_label()
subprocess.call([
"/usr/sbin/efibootmgr",
"-c",
"-w",
"-L", efi_bootloader_id,
"-d", path, # TODO
"-p", num, # TODO
"-l", efidir)# TODO
def vfat_correct_case(parent, name): def vfat_correct_case(parent, name):
for candidate in os.listdir(parent): for candidate in os.listdir(parent):