From 8f01688b34e1f2366e5ed516de45e0aaec5a4443 Mon Sep 17 00:00:00 2001 From: Anton Midyukov Date: Thu, 20 May 2021 23:55:28 +0700 Subject: [PATCH] grub: Fix selection of default item 1. Didn't work before because the variable was not exported. 2. Fixed the logic broken by the introduction of support for saving the selected item on the FAT partition. --- features.in/grub/cfg.in/00defaults.cfg | 2 +- features.in/grub/config.mk | 1 + features.in/grub/stage1/scripts.d/01-grub | 17 ++++++----------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/features.in/grub/cfg.in/00defaults.cfg b/features.in/grub/cfg.in/00defaults.cfg index 6b1d4ffb..b0e39401 100644 --- a/features.in/grub/cfg.in/00defaults.cfg +++ b/features.in/grub/cfg.in/00defaults.cfg @@ -14,7 +14,7 @@ if [ -s $pfxfat/grubenv ]; then load_env --file $pfxfat/grubenv set default="${saved_entry}" else - default=@default_id@ + set default=@default_id@ fi function savedefault { if [ -z "${boot_once}" -a -s $pfxfat/grubenv ]; then diff --git a/features.in/grub/config.mk b/features.in/grub/config.mk index 117af348..71d69446 100644 --- a/features.in/grub/config.mk +++ b/features.in/grub/config.mk @@ -9,6 +9,7 @@ ifeq (,$(filter-out i586 x86_64,$(ARCH))) @$(call try,BOOTVGA,normal) endif @$(call set,RELNAME,ALT ($(IMAGE_NAME))) + @$(call xport,GRUB_DEFAULT) # UI is overwritten use/grub/ui/%: use/grub diff --git a/features.in/grub/stage1/scripts.d/01-grub b/features.in/grub/stage1/scripts.d/01-grub index c8558d29..bf92a29d 100755 --- a/features.in/grub/stage1/scripts.d/01-grub +++ b/features.in/grub/stage1/scripts.d/01-grub @@ -29,25 +29,20 @@ local CFG=$1 if [ -n "$GLOBAL_GRUB_DEFAULT" ]; then if [ -n "$(grep -i "$GLOBAL_GRUB_DEFAULT" "$CFG")" ]; then DEFAULT="$GLOBAL_GRUB_DEFAULT" - sed -i '/^default/d' - echo "default=$DEFAULT" >> "$CFG" else echo "error: $GLOBAL_GRUB_DEFAULT missing in $CFG" >&2 exit 1 fi -fi -DEFAULT="$(grep -i '\-\-id ' "$CFG" | head -1 | rev| cut -f2 -d' ' |rev)" -if grep -i '@default_id@' "$CFG"; then - sed -i "s/@default_id@/$DEFAULT/" "$CFG" -fi -if ! grep -i '^\s*\(set\s\+\)\?default=' "$CFG"; then - if [ -n "$DEFAULT" ]; then - echo "default=$DEFAULT" >> "$CFG" - else +elif [ -n "$(grep -i "--id 'linux'" "$CFG")" ]; then + DEFAULT=linux +else + DEFAULT="$(grep -i '\-\-id ' "$CFG" | head -1 | rev| cut -f2 -d' ' |rev)" + if [ -z "$DEFAULT" ]; then echo "error: no DEFAULT or UI directive and cannot guess for $CFG" >&2 exit 1 fi fi +sed -i "s/@default_id@/$DEFAULT/" "$CFG" } default_change "$CFG"