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