From 11f09fb523d68fcec5e43edd4e5fb730971efb44 Mon Sep 17 00:00:00 2001 From: Joonas Trussmann Date: Sat, 29 Oct 2022 16:21:13 +0300 Subject: [PATCH] added protections against empty unrd, made cmdline dismount more robust --- tests/02-enforce_slot_1.sh | 10 ++++++++++ units/01-corrupt_slot_1.sh | 7 ++++--- units/02-enforce_slot_1.sh | 3 +-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/02-enforce_slot_1.sh b/tests/02-enforce_slot_1.sh index ff04824..9de84fa 100644 --- a/tests/02-enforce_slot_1.sh +++ b/tests/02-enforce_slot_1.sh @@ -19,6 +19,16 @@ if [ $? -ne 2 ]; then exit 1 fi +#check for deleted unrd empty regression +unrd -d slot_1.status_active + +sh $UNITS/$UNIT + +if [ $? -ne 2 ]; then + echo "$UNIT did could not detect wrong slot" + exit 1 +fi + sh $UNITS/$UNIT fix #we expect a reboot diff --git a/units/01-corrupt_slot_1.sh b/units/01-corrupt_slot_1.sh index ab8255f..4424b96 100644 --- a/units/01-corrupt_slot_1.sh +++ b/units/01-corrupt_slot_1.sh @@ -3,7 +3,7 @@ #this script enforces wtfos usage to slot 1 and will re-flash slot 1 before switching if it appears corrupt check () { #check whatever our conditions is - this may be more complicated for other issues - if [ $(unrd slot_1.status_successful) != "1" ] || [ $(unrd slot_1.status_bootable) != "1" ]; then + if [ "$(unrd slot_1.status_successful)" != "1" ] || [ "$(unrd slot_1.status_bootable)" != "1" ]; then echo "Slot 1 is corrupt, can reflash from Slot 2" return 2 @@ -14,10 +14,11 @@ fix () { echo "reflashing slot_1" echo "please wait, this will take a few minutes" if [ -f /cache/ota.zip ] ; then - if mount | grep -q '/proc/cmdline' -q; then + while mount | grep -q '/proc/cmdline' -q; do echo "removing cmdline bindmount" umount /proc/cmdline - fi + sleep 1 + done echo "reflashing from ota.zip" echo "please wait, this will take a few minutes" update_engine --update_package=/cache/ota.zip diff --git a/units/02-enforce_slot_1.sh b/units/02-enforce_slot_1.sh index 88ecbfc..41ef77a 100644 --- a/units/02-enforce_slot_1.sh +++ b/units/02-enforce_slot_1.sh @@ -1,9 +1,8 @@ #/bin/sh - #this script enforces wtfos usage to slot 1 and will re-flash slot 1 before switching if it appears corrupt check () { #check whatever our conditions is - this may be more complicated for other issues - if [ $(unrd slot_1.status_active) == "1" ] && [ $(unrd slot_1.status_successful) == "1" ]; then + if [ "$(unrd slot_1.status_active)" == "1" ] && [ "$(unrd slot_1.status_successful)" == "1" ]; then ##and return 0 if all is well return 0 else