15a207
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
15a207
From: Christian Glombek <lorbus@fedoraproject.org>
15a207
Date: Tue, 31 Jul 2018 11:12:06 +0200
dbfd2e
Subject: [PATCH] Boot Counting
15a207
dbfd2e
Adds 01_fallback_counting.in script to support boot counting before
dbfd2e
falling back to the previous menu entry automatically
15a207
---
15a207
 Makefile.util.def                   |  6 ++++++
15a207
 util/grub.d/01_fallback_counting.in | 12 ++++++++++++
15a207
 2 files changed, 18 insertions(+)
15a207
 create mode 100644 util/grub.d/01_fallback_counting.in
15a207
15a207
diff --git a/Makefile.util.def b/Makefile.util.def
15a207
index cba4d500198..c8cb91308d9 100644
15a207
--- a/Makefile.util.def
15a207
+++ b/Makefile.util.def
15a207
@@ -448,6 +448,12 @@ script = {
15a207
   installdir = grubconf;
15a207
 };
15a207
 
15a207
+script = {
15a207
+  name = '01_fallback_counting';
15a207
+  common = util/grub.d/01_fallback_counting.in;
15a207
+  installdir = grubconf;
15a207
+};
15a207
+
15a207
 script = {
15a207
   name = '01_menu_auto_hide';
15a207
   common = util/grub.d/01_menu_auto_hide.in;
15a207
diff --git a/util/grub.d/01_fallback_counting.in b/util/grub.d/01_fallback_counting.in
15a207
new file mode 100644
f0ceaa
index 00000000000..ecfc7401474
15a207
--- /dev/null
15a207
+++ b/util/grub.d/01_fallback_counting.in
15a207
@@ -0,0 +1,12 @@
15a207
+#! /bin/sh -e
15a207
+
15a207
+# Boot Counting
f0ceaa
+if [ "\${boot_counter}" -a "\${boot_success}" = "0" ]; then
15a207
+  if  [ "\${boot_counter}" = "0" -o "\${boot_counter}" = "-1" ]; then
15a207
+    set default=1
15a207
+    set boot_counter=-1
15a207
+  else
15a207
+    set boot_counter=$((\${boot_counter}-1))
15a207
+  fi
15a207
+  save_env boot_counter
15a207
+fi