upgrade-scripts: Get rid of error info during reboot 41/305441/2
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 1 Feb 2024 14:24:19 +0000 (15:24 +0100)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 2 Feb 2024 15:35:18 +0000 (16:35 +0100)
Change-Id: Ibb5cc7de302a319f0c29bb7f2c936e71f1068ae2

scripts/upgrade-support/upgrade-fota.sh
scripts/upgrade-support/upgrade-trigger.sh

index b0917e8..89f55ab 100755 (executable)
@@ -57,6 +57,11 @@ reboot_to_fota() {
        cleanup_files
        /bin/sync
        flog "[Info] Rebooting to fota"
+
+       # System will reboot, so the script will be aborted. We don't want this to be
+       # treated as an error.
+       set -u errexit
+       untrap
        if ! /sbin/reboot fota; then
                critical_flog "[Error] Failed to reboot fota"
                exit 1
@@ -79,10 +84,9 @@ if ! write_version_info "$VERSION_FILE"; then
        exit 1
 fi
 
+critical_log "RO update: $SCRIPT_NAME success" "$LOG_FILE"
+
 if ! reboot_to_fota; then
        cleanup
        exit 1
 fi
-cleanup
-
-critical_log "RO update: $SCRIPT_NAME success" "$LOG_FILE"
index 64077bf..638e8af 100644 (file)
@@ -91,11 +91,24 @@ do_update() {
 
                set_upgrade_status 40
 
+               # During the execution of ${SCRIPT_UPGRADE_FOTA} system will reboot, so the
+               # script will be aborted. We don't want this to be treated as an error.
+               untrap
+               set -u errexit
                if ! "${FOTA_DIR}/${SCRIPT_UPGRADE_FOTA}"; then
-                       exit_error
+                       # We want to check if we are here becasue the reboot interrupted the
+                       # execution of ${SCRIPT_UPGRADE_FOTA} or for some other reason.
+                       # If a reboot is currently in progress then /proc/1/exe will point to
+                       # something other than "systemd" (e.g. deviced-shudown).
+                       if [ "$(basename "$(readlink /proc/1/exe)")" = "systemd" ]; then
+                               # No, it's not a reboot. Rather it is a regular error.
+                               exit_error
+                       else
+                               set_upgrade_status 80
+                               echo "[Info] RO update: $SCRIPT_NAME success"
+                       fi
                fi
 
-               set_upgrade_status 80
        else
                echo "[Error] Non-A/B upgrade is unsupported"
                device_board_set_upgrade_status -1
@@ -163,6 +176,4 @@ log "[Info] Delta verification success"
 set_upgrade_status 1
 verify_img "${DOWNLOAD_DELTA}"
 do_update
-
-critical_log "RO update: $SCRIPT_NAME success" "$LOG_FILE"
 ) 9> "$FLOCK_PATH"