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