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

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