From d7883ec32b2bb907fce17fb759c08c5cd9851fc3 Mon Sep 17 00:00:00 2001 From: Lyndon Brown Date: Mon, 4 May 2020 16:12:45 +0100 Subject: config: improve BIOS/EFI bootloader selection handling the design choice from when EFI support was introduced was to change `--bootloader` to `--bootloaders`, with users specifying their selection of BIOS and EFI bootloaders together. at this time there were not even any decent validation checks being performed, and invalid combinations could cause some chaos. since then proper validation was put in place, including checking that only a single instance of each of BIOS and EFI bootloaders exists in the selection. here we tweak things such that we stick with the same option, but we split the selection up such that we store the BIOS and EFI selections separately within the saved config file, and offer it up to scripts to help simplify those scripts. we must however retain support for splitting from the combined option, both because we still use it in the combined option, and for backwards compatibility with older saved configs. Gbp-Dch: Short --- functions/configuration.sh | 56 ++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'functions') diff --git a/functions/configuration.sh b/functions/configuration.sh index 85873bdcd..b74ea0e50 100755 --- a/functions/configuration.sh +++ b/functions/configuration.sh @@ -287,24 +287,33 @@ Prepare_config () ;; esac - if [ -z "${LB_BOOTLOADERS}" ] - then - case "${LB_ARCHITECTURE}" in - amd64|i386) - case "${LB_IMAGE_TYPE}" in - hdd|netboot) - LB_BOOTLOADERS="syslinux" - ;; - *) - LB_BOOTLOADERS="syslinux,grub-efi" - ;; - esac - ;; - esac + case "${LB_ARCHITECTURE}" in + amd64|i386) + LB_BOOTLOADER_BIOS="${LB_BOOTLOADER_BIOS:-syslinux}" + if ! In_list "${LB_IMAGE_TYPE}" hdd netboot; then + LB_BOOTLOADER_EFI="${LB_BOOTLOADER_EFI:-grub-efi}" + fi + ;; + esac + # Command line option combines BIOS and EFI selection in one. + # Also, need to support old config files that held `LB_BOOTLOADERS`. + # Note that this function does not perform validation, so none is done here. + if [ -n "${LB_BOOTLOADERS}" ]; then + LB_BOOTLOADERS="$(echo "${LB_BOOTLOADERS}" | tr "," " ")" + unset LB_BOOTLOADER_BIOS + unset LB_BOOTLOADER_EFI + local BOOTLOADER + for BOOTLOADER in $LB_BOOTLOADERS; do + case "${BOOTLOADER}" in + grub-legacy|grub-pc|syslinux) + LB_BOOTLOADER_BIOS="${BOOTLOADER}" + ;; + grub-efi) + LB_BOOTLOADER_EFI="${BOOTLOADER}" + ;; + esac + done fi - LB_BOOTLOADERS="$(echo "${LB_BOOTLOADERS}" | tr "," " ")" - - LB_FIRST_BOOTLOADER=$(echo "${LB_BOOTLOADERS}" | awk '{ print $1 }') LB_CHECKSUMS="${LB_CHECKSUMS:-sha256}" @@ -572,9 +581,18 @@ Validate_config_permitted_values () exit 1 fi - if [ -z "${LB_BOOTLOADERS}" ]; then + if [ -z "${LB_BOOTLOADER_BIOS}" ] && [ -z "${LB_BOOTLOADER_EFI}" ]; then Echo_warning "You have specified no bootloaders; I predict that you will experience some problems!" - else + fi + if [ -n "${LB_BOOTLOADER_BIOS}" ] && ! In_list "${LB_BOOTLOADER_BIOS}" grub-legacy grub-pc syslinux; then + Echo_error "You have specified an invalid BIOS bootloader." + exit 1 + fi + if [ -n "${LB_BOOTLOADER_EFI}" ] && ! In_list "${LB_BOOTLOADER_EFI}" grub-efi; then + Echo_error "You have specified an invalid EFI bootloader." + exit 1 + fi + if [ -n "${LB_BOOTLOADERS}" ]; then local BOOTLOADER local BOOTLOADERS_BIOS=0 local BOOTLOADERS_EFI=0 -- cgit v1.2.3