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