nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0130-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch

5593c8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
5593c8
From: Christian Glombek <lorbus@fedoraproject.org>
5593c8
Date: Tue, 2 Apr 2019 16:22:21 +0200
5593c8
Subject: [PATCH] grub.d: Split out boot success reset from menu auto hide
5593c8
 script
5593c8
5593c8
Also rename fallback and menu auto hide script to be executed
5593c8
before and after boot success reset script.
5593c8
In menu auto hide script, rename last_boot_ok var to menu_hide_ok
5593c8
---
5593c8
 Makefile.util.def                                  | 14 ++++++++----
5593c8
 ...allback_counting.in => 08_fallback_counting.in} | 14 ++++++------
5593c8
 util/grub.d/10_reset_boot_success.in               | 25 ++++++++++++++++++++++
5593c8
 .../{01_menu_auto_hide.in => 12_menu_auto_hide.in} | 23 +++++---------------
5593c8
 4 files changed, 48 insertions(+), 28 deletions(-)
5593c8
 rename util/grub.d/{01_fallback_counting.in => 08_fallback_counting.in} (65%)
5593c8
 create mode 100644 util/grub.d/10_reset_boot_success.in
5593c8
 rename util/grub.d/{01_menu_auto_hide.in => 12_menu_auto_hide.in} (58%)
5593c8
5593c8
diff --git a/Makefile.util.def b/Makefile.util.def
d3c3ab
index 2e5e05b25f1..11ab2d6fad1 100644
5593c8
--- a/Makefile.util.def
5593c8
+++ b/Makefile.util.def
5593c8
@@ -459,14 +459,14 @@ script = {
5593c8
 };
5593c8
 
5593c8
 script = {
5593c8
-  name = '01_fallback_counting';
5593c8
-  common = util/grub.d/01_fallback_counting.in;
5593c8
+  name = '08_fallback_counting';
5593c8
+  common = util/grub.d/08_fallback_counting.in;
5593c8
   installdir = grubconf;
5593c8
 };
5593c8
 
5593c8
 script = {
5593c8
-  name = '01_menu_auto_hide';
5593c8
-  common = util/grub.d/01_menu_auto_hide.in;
5593c8
+  name = '12_menu_auto_hide';
5593c8
+  common = util/grub.d/12_menu_auto_hide.in;
5593c8
   installdir = grubconf;
5593c8
 };
5593c8
 
5593c8
@@ -518,6 +518,12 @@ script = {
5593c8
   condition = COND_HOST_LINUX;
5593c8
 };
5593c8
 
5593c8
+script = {
5593c8
+  name = '10_reset_boot_success';
5593c8
+  common = util/grub.d/10_reset_boot_success.in;
5593c8
+  installdir = grubconf;
5593c8
+};
5593c8
+
5593c8
 script = {
5593c8
   name = '10_xnu';
5593c8
   common = util/grub.d/10_xnu.in;
5593c8
diff --git a/util/grub.d/01_fallback_counting.in b/util/grub.d/08_fallback_counting.in
5593c8
similarity index 65%
5593c8
rename from util/grub.d/01_fallback_counting.in
5593c8
rename to util/grub.d/08_fallback_counting.in
d3c3ab
index be0e770ea82..2e2c3ff7d31 100644
5593c8
--- a/util/grub.d/01_fallback_counting.in
5593c8
+++ b/util/grub.d/08_fallback_counting.in
5593c8
@@ -1,15 +1,17 @@
5593c8
 #! /bin/sh -e
5593c8
-
5593c8
-# Boot Counting
5593c8
+# Fallback Countdown
5593c8
+#
5593c8
+# This snippet depends on 10_reset_boot_success and needs to be kept in sync.
5593c8
+#
5593c8
 # The boot_counter env var can be used to count down boot attempts after an
5593c8
-# OSTree upgrade and choose the rollback deployment when 0 is reached.  Both
5593c8
-# boot_counter and boot_success need to be (re-)set from userspace.
5593c8
+# OSTree upgrade and choose the rollback deployment when 0 is reached.
5593c8
+# Both boot_counter=X and boot_success=1 need to be set from userspace.
5593c8
 cat << EOF
5593c8
 insmod increment
5593c8
 # Check if boot_counter exists and boot_success=0 to activate this behaviour.
5593c8
 if [ -n "\${boot_counter}" -a "\${boot_success}" = "0" ]; then
5593c8
-  # if countdown has ended, choose to boot rollback deployment (default=1 on
5593c8
-  # OSTree-based systems)
5593c8
+  # if countdown has ended, choose to boot rollback deployment,
5593c8
+  # i.e. default=1 on OSTree-based systems.
5593c8
   if  [ "\${boot_counter}" = "0" -o "\${boot_counter}" = "-1" ]; then
5593c8
     set default=1
5593c8
     set boot_counter=-1
5593c8
diff --git a/util/grub.d/10_reset_boot_success.in b/util/grub.d/10_reset_boot_success.in
5593c8
new file mode 100644
d3c3ab
index 00000000000..6c88d933dde
5593c8
--- /dev/null
5593c8
+++ b/util/grub.d/10_reset_boot_success.in
5593c8
@@ -0,0 +1,25 @@
5593c8
+#! /bin/sh -e
5593c8
+# Reset Boot Success
5593c8
+#
5593c8
+# The 08_fallback_counting and 12_menu_auto_hide snippets rely on this one
5593c8
+# and need to be kept in sync.
5593c8
+#
5593c8
+# The boot_success var needs to be set to 1 from userspace to mark a boot successful.
5593c8
+cat << EOF
5593c8
+insmod increment
5593c8
+# Hiding the menu is ok if last boot was ok or if this is a first boot attempt to boot the entry
5593c8
+if [ "\${boot_success}" = "1" -o "\${boot_indeterminate}" = "1" ]; then
5593c8
+  set menu_hide_ok=1
5593c8
+else
5593c8
+  set menu_hide_ok=0 
5593c8
+fi
5593c8
+# Reset boot_indeterminate after a successful boot, increment otherwise
5593c8
+if [ "\${boot_success}" = "1" ] ; then
5593c8
+  set boot_indeterminate=0
5593c8
+else
5593c8
+  increment boot_indeterminate
5593c8
+fi
5593c8
+# Reset boot_success for current boot 
5593c8
+set boot_success=0
5593c8
+save_env boot_success boot_indeterminate
5593c8
+EOF
5593c8
diff --git a/util/grub.d/01_menu_auto_hide.in b/util/grub.d/12_menu_auto_hide.in
5593c8
similarity index 58%
5593c8
rename from util/grub.d/01_menu_auto_hide.in
5593c8
rename to util/grub.d/12_menu_auto_hide.in
d3c3ab
index ad175870a54..6a7c0fa0d43 100644
5593c8
--- a/util/grub.d/01_menu_auto_hide.in
5593c8
+++ b/util/grub.d/12_menu_auto_hide.in
5593c8
@@ -1,5 +1,8 @@
5593c8
 #! /bin/sh
5593c8
-
5593c8
+# Menu Auto Hide
5593c8
+#
5593c8
+# This snippet depends on 10_reset_boot_success and needs to be kept in sync.
5593c8
+#
5593c8
 # Disable / skip generating menu-auto-hide config parts on serial terminals
5593c8
 for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
5593c8
   case "$x" in
5593c8
@@ -10,29 +13,13 @@ for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
5593c8
 done
5593c8
 
5593c8
 cat << EOF
5593c8
-if [ "\${boot_success}" = "1" -o "\${boot_indeterminate}" = "1" ]; then
5593c8
-  set last_boot_ok=1
5593c8
-else
5593c8
-  set last_boot_ok=0
5593c8
-fi
5593c8
-
5593c8
-# Reset boot_indeterminate after a successful boot
5593c8
-if [ "\${boot_success}" = "1" ] ; then
5593c8
-  set boot_indeterminate=0
5593c8
-# Avoid boot_indeterminate causing the menu to be hidden more then once
5593c8
-elif [ "\${boot_indeterminate}" = "1" ]; then
5593c8
-  set boot_indeterminate=2
5593c8
-fi
5593c8
-set boot_success=0
5593c8
-save_env boot_success boot_indeterminate
5593c8
-
5593c8
 if [ x\$feature_timeout_style = xy ] ; then
5593c8
   if [ "\${menu_show_once}" ]; then
5593c8
     unset menu_show_once
5593c8
     save_env menu_show_once
5593c8
     set timeout_style=menu
5593c8
     set timeout=60
5593c8
-  elif [ "\${menu_auto_hide}" -a "\${last_boot_ok}" = "1" ]; then
5593c8
+  elif [ "\${menu_auto_hide}" -a "\${menu_hide_ok}" = "1" ]; then
5593c8
     set orig_timeout_style=\${timeout_style}
5593c8
     set orig_timeout=\${timeout}
5593c8
     if [ "\${fastboot}" = "1" ]; then