nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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