From 0dba98b6e86a671129e5922fadeb19f57cd1af74 Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Wed, 23 Nov 2022 00:52:51 +0100 Subject: [PATCH] armbian-next: `aggregation.py` and `package-lists.sh` usage in core grub-* extensions - fix grub-riscv64.sh; this needs merging into grub itself later --- extensions/grub-riscv64.sh | 28 +++++++++++++++++++++++++++- extensions/grub.sh | 4 +++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/extensions/grub-riscv64.sh b/extensions/grub-riscv64.sh index 87f51f4e49..b2a87466eb 100644 --- a/extensions/grub-riscv64.sh +++ b/extensions/grub-riscv64.sh @@ -35,7 +35,9 @@ function extension_prepare_config__prepare_grub-riscv64() { DISTRO_KERNEL_PACKAGES="" DISTRO_FIRMWARE_PACKAGES="" - export PACKAGE_LIST_BOARD="${PACKAGE_LIST_BOARD} ${DISTRO_FIRMWARE_PACKAGES} ${DISTRO_KERNEL_PACKAGES} ${uefi_packages}" + # @TODO: use actual arrays. Yeah... + # shellcheck disable=SC2086 + add_packages_to_image ${DISTRO_FIRMWARE_PACKAGES} ${DISTRO_KERNEL_PACKAGES} ${uefi_packages} display_alert "Activating" "GRUB with SERIALCON=${SERIALCON}; timeout ${UEFI_GRUB_TIMEOUT}; BIOS=${UEFI_GRUB_TARGET_BIOS}" "" } @@ -73,6 +75,30 @@ pre_umount_final_image__install_grub() { exit_with_error "${install_grub_cmdline} failed!" } + ### Sanity check. The produced "/boot/grub/grub.cfg" should: + declare -i has_failed_sanity_check=0 + + # - NOT have any mention of `/dev` inside; otherwise something is going to fail + if grep -q '/dev' "${chroot_target}/boot/grub/grub.cfg"; then + display_alert "GRUB sanity check failed" "grub.cfg contains /dev" "err" + SHOW_LOG=yes run_host_command_logged grep '/dev' "${chroot_target}/boot/grub/grub.cfg" "||" true + has_failed_sanity_check=1 + else + display_alert "GRUB config sanity check passed" "no '/dev' found in grub.cfg" "info" + fi + + # - HAVE references to initrd, otherwise going to fail. + if ! grep -q 'initrd.img' "${chroot_target}/boot/grub/grub.cfg"; then + display_alert "GRUB config sanity check failed" "no initrd.img references found in /boot/grub/grub.cfg" "err" + has_failed_sanity_check=1 + else + display_alert "GRUB config sanity check passed" "initrd.img references found OK in /boot/grub/grub.cfg" "debug" + fi + + if [[ ${has_failed_sanity_check} -gt 0 ]]; then + exit_with_error "GRUB config sanity check failed, image will be unbootable; see above errors" + fi + # Remove host-side config. rm -f "${MOUNT}"/etc/default/grub.d/99-armbian-host-side.cfg diff --git a/extensions/grub.sh b/extensions/grub.sh index 77b39249a4..468a9c22f0 100644 --- a/extensions/grub.sh +++ b/extensions/grub.sh @@ -61,7 +61,9 @@ function extension_prepare_config__prepare_flash_kernel() { DISTRO_FIRMWARE_PACKAGES="" fi - export PACKAGE_LIST_BOARD="${PACKAGE_LIST_BOARD} ${DISTRO_FIRMWARE_PACKAGES} ${DISTRO_KERNEL_PACKAGES} ${uefi_packages}" + # @TODO: use actual arrays. Yeah... + # shellcheck disable=SC2086 + add_packages_to_image ${DISTRO_FIRMWARE_PACKAGES} ${DISTRO_KERNEL_PACKAGES} ${uefi_packages} display_alert "Activating" "GRUB with SERIALCON=${SERIALCON}; timeout ${UEFI_GRUB_TIMEOUT}; BIOS=${UEFI_GRUB_TARGET_BIOS}" "" }