1f092ca
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
1f092ca
From: Christian Glombek <lorbus@fedoraproject.org>
1f092ca
Date: Mon, 8 Oct 2018 11:57:04 +0200
1f092ca
Subject: [PATCH] Add comments and revert logic changes in 01_fallback_counting
1f092ca
1f092ca
---
1f092ca
 util/grub.d/01_fallback_counting.in | 27 +++++++++++++++------------
1f092ca
 1 file changed, 15 insertions(+), 12 deletions(-)
1f092ca
1f092ca
diff --git a/util/grub.d/01_fallback_counting.in b/util/grub.d/01_fallback_counting.in
1f092ca
index 1a0b5fbecfc..be0e770ea82 100644
1f092ca
--- a/util/grub.d/01_fallback_counting.in
1f092ca
+++ b/util/grub.d/01_fallback_counting.in
1f092ca
@@ -1,19 +1,22 @@
1f092ca
 #! /bin/sh -e
1f092ca
 
1f092ca
-if ! systemctl -q is-enabled greenboot.service >/dev/null 2>&1 ; then
1f092ca
-  exit 0
1f092ca
-fi
1f092ca
-
1f092ca
 # Boot Counting
1f092ca
+# The boot_counter env var can be used to count down boot attempts after an
1f092ca
+# OSTree upgrade and choose the rollback deployment when 0 is reached.  Both
1f092ca
+# boot_counter and boot_success need to be (re-)set from userspace.
1f092ca
 cat << EOF
1f092ca
 insmod increment
1f092ca
-if [ -z "\${boot_counter}" ]; then
1f092ca
-  set boot_counter=0
1f092ca
-elif [ "\${boot_counter}" = "0" -o "\${boot_counter}" = "-1" ]; then
1f092ca
-  increment default
1f092ca
-  set boot_counter=-1
1f092ca
-else
1f092ca
-  decrement boot_counter
1f092ca
+# Check if boot_counter exists and boot_success=0 to activate this behaviour.
1f092ca
+if [ -n "\${boot_counter}" -a "\${boot_success}" = "0" ]; then
1f092ca
+  # if countdown has ended, choose to boot rollback deployment (default=1 on
1f092ca
+  # OSTree-based systems)
1f092ca
+  if  [ "\${boot_counter}" = "0" -o "\${boot_counter}" = "-1" ]; then
1f092ca
+    set default=1
1f092ca
+    set boot_counter=-1
1f092ca
+  # otherwise decrement boot_counter
1f092ca
+  else
1f092ca
+    decrement boot_counter
1f092ca
+  fi
1f092ca
+  save_env boot_counter
1f092ca
 fi
1f092ca
-save_env boot_counter
1f092ca
 EOF