From 5f60391b63568329f34d17111d312fdccfe44a39 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 5 Jun 2023 13:31:51 +0200 Subject: [PATCH] firmware: handle script errors by aborting the upgrade #6594 The individual scripts should return an error and clean up their state in case they aborted (which isn't too easy but in most cases moving the relevant files to the final location is a good way of dealing with this problem). --- src/opnsense/scripts/firmware/upgrade.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/opnsense/scripts/firmware/upgrade.sh b/src/opnsense/scripts/firmware/upgrade.sh index bc57fc7a2..8ad3386b8 100755 --- a/src/opnsense/scripts/firmware/upgrade.sh +++ b/src/opnsense/scripts/firmware/upgrade.sh @@ -38,11 +38,15 @@ echo "Currently running $(opnsense-version) at $(date)" >> ${LOCKFILE} ${TEE} ${LOCKFILE} < ${PIPEFILE} & if opnsense-update -u > ${PIPEFILE} 2>&1; then - /usr/local/etc/rc.syshook upgrade - - echo '***REBOOT***' >> ${LOCKFILE} - sleep 5 - /usr/local/etc/rc.reboot + ${TEE} ${LOCKFILE} < ${PIPEFILE} & + if ! /usr/local/etc/rc.syshook upgrade > ${PIPEFILE} 2>&1; then + # aboort pending upgrades + opnsense-update -e >> ${LOCKFILE} 2>&1 + else + echo '***REBOOT***' >> ${LOCKFILE} + sleep 5 + /usr/local/etc/rc.reboot + fi fi echo '***DONE***' >> ${LOCKFILE}