From: Jacek Kryszyn Date: Fri, 4 Oct 2024 10:43:07 +0000 (+0200) Subject: scripts: move reboot to the main upgrade script X-Git-Tag: accepted/tizen/unified/20241130.125031~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e08a01f2ed89b138afad93df706f6f6a1cd35f52;p=platform%2Fcore%2Fsystem%2Fupgrade.git scripts: move reboot to the main upgrade script This solves few issues with upgrade scripts. Before this change reboot was executed in upgrade-fota.sh which was executed by upgrade-trigger.sh. There had to be some checks to decide if upgrade-fota.sh was interrupted by reboot or for other reasons. In case of interruption by reboot there were some unwanted error messages anyway. Moving reboot to upgrade-trigger.sh simplifies scripts. Now it is certain that if the exit status of upgrade-fota.sh is different than 0 then it has to be treated as an error. This change unifies the way how set flags are used and error_exit function is used more often instead of combination of setting upgrade progess status and exit. Change-Id: I7850e498fb26cd52565fd320709b4e38cf4f221a --- diff --git a/scripts/clone_partitions/clone_partitions.sh b/scripts/clone_partitions/clone_partitions.sh index 33d6678..d6204dd 100644 --- a/scripts/clone_partitions/clone_partitions.sh +++ b/scripts/clone_partitions/clone_partitions.sh @@ -100,12 +100,11 @@ clone_background() { start_clone } -set -o errexit +set -o errexit -o errtrace -o pipefail trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR -set -o errtrace -e -o pipefail if [ -n "${UPGRADE_DEBUG}" ]; then - set -x + set -o xtrace fi . /usr/libexec/upgrade-support/upgrade-common.inc diff --git a/scripts/upgrade-support/upgrade-fota.sh b/scripts/upgrade-support/upgrade-fota.sh index 98b550c..f3eb1b1 100755 --- a/scripts/upgrade-support/upgrade-fota.sh +++ b/scripts/upgrade-support/upgrade-fota.sh @@ -1,13 +1,13 @@ #!/bin/bash -set -o errexit +set -o errexit -o errtrace -o pipefail trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR -set -o errtrace -e -o pipefail - if [ -n "${UPGRADE_DEBUG}" ]; then - set -x + set -o xtrace fi +progress_to=$1 + PATH=/bin:/usr/bin:/sbin:/usr/sbin FOTA_DIR="/opt/usr/data/fota" @@ -50,7 +50,7 @@ mount() { return 0 } -reboot_to_fota() { +prepare_reboot_to_fota() { log "[Info] Write paths..." touch "$DO_RW_UPDATE_FILE" log "[Info] calling sync" @@ -58,20 +58,10 @@ reboot_to_fota() { log "[Info] Switching board partition from $CURRENT_AB, to $NEXT_AB" if ! device_board_switch_partition "$NEXT_AB"; then critical_log "[Error] Failed to switch board slot to $NEXT_AB" - exit 1 + return 1 fi cleanup_files /bin/sync - log "[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_log "[Error] Failed to reboot fota" - exit 1 - fi } prepare_fota_update_dir() { @@ -81,18 +71,20 @@ prepare_fota_update_dir() { prepare_fota_update_dir check_ab_partition_scheme check_used_block_device + if ! mount; then cleanup - exit 1 + exit_error fi + if ! write_version_info "$VERSION_FILE"; then cleanup - exit 1 + exit_error fi critical_log "[Info] RO update: $SCRIPT_NAME success" -if ! reboot_to_fota; then +if ! prepare_reboot_to_fota; then cleanup - exit 1 + exit_error fi diff --git a/scripts/upgrade-support/upgrade-partial.sh b/scripts/upgrade-support/upgrade-partial.sh index 0001bae..226e9b8 100755 --- a/scripts/upgrade-support/upgrade-partial.sh +++ b/scripts/upgrade-support/upgrade-partial.sh @@ -1,10 +1,9 @@ #!/bin/bash -set -o errexit +set -o errexit -o errtrace -o pipefail trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR -set -o errtrace -e -o pipefail if [ -n "${UPGRADE_DEBUG}" ]; then - set -x + set -o xtrace fi PATH=/bin:/usr/bin:/sbin:/usr/sbin @@ -29,7 +28,7 @@ check_args() { if [[ (( $SINGLE_DELTA = true ) && ( ! -f "$DELTA_TAR_A" )) || \ (( $SINGLE_DELTA = false ) && (( ! -f "$DELTA_TAR_A" ) || ( ! -f "$DELTA_TAR_B"))) ]]; then log "[Error] Usage: $0 path_to_delta.tar[.gz] [path_to_second_delta.tar[.gz]]" - exit 1 + exit_error fi if [ $SINGLE_DELTA = true ]; then diff --git a/scripts/upgrade-support/upgrade-prepare-partitions.sh b/scripts/upgrade-support/upgrade-prepare-partitions.sh index 75576ff..908af46 100755 --- a/scripts/upgrade-support/upgrade-prepare-partitions.sh +++ b/scripts/upgrade-support/upgrade-prepare-partitions.sh @@ -1,10 +1,9 @@ #!/bin/bash -set -o errexit +set -o errexit -o errtrace -o pipefail trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR -set -o errtrace -e -o pipefail if [ -n "${UPGRADE_DEBUG}" ]; then - set -x + set -o xtrace fi progress_to=$1 diff --git a/scripts/upgrade-support/upgrade-trigger.sh b/scripts/upgrade-support/upgrade-trigger.sh index 7c24580..5bc9649 100644 --- a/scripts/upgrade-support/upgrade-trigger.sh +++ b/scripts/upgrade-support/upgrade-trigger.sh @@ -1,15 +1,15 @@ #!/bin/bash # Master script for upgrade. Called by update-manager/manually to start upgrade procedure. -set -o errexit +set -o errexit -o errtrace -o pipefail trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR -set -o errtrace -e -o pipefail if [ -n "${UPGRADE_DEBUG}" ]; then - set -x + set -o xtrace fi -PROGRESS_AFTER_RO=80 PROGRESS_AFTER_CLONING=20 +PROGRESS_AFTER_UPDATE=79 +PROGRESS_AFTER_FINISH=80 ERR_RO_UPDATE_IN_PROGRESS=2 ERR_FINISH_BEFORE_RO_UPDATE_COMPLETE=3 @@ -121,6 +121,7 @@ do_update() { unpack_file "${DELTA_A}" "${SCRIPT_UPGRADE_PREPARE_PARTITIONS}" "${DELTA_A_CHECKSUM_FILE}" "" run_script "${FOTA_DIR}/${SCRIPT_UPGRADE_PREPARE_PARTITIONS} $PROGRESS_AFTER_CLONING" + if [ $RET -ne 0 ]; then exit_error fi @@ -133,7 +134,6 @@ do_update() { # be modified, so they will not be a clone of the current partitions device_board_clear_partition_ab_cloned - run_script "${FOTA_DIR}/${SCRIPT_UPGRADE_PARTIAL} ${DELTA_A} ${DELTA_B}" if [ $RET -ne 0 ] ; then @@ -141,40 +141,38 @@ do_update() { exit_error fi - set_upgrade_progress_status $PROGRESS_AFTER_RO - - # 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 + set_upgrade_progress_status $PROGRESS_AFTER_UPDATE else log "[Error] Non-A/B upgrade is unsupported" - device_board_set_upgrade_progress_status -1 - exit 1 + exit_error fi } do_finish() { - current_upgrade_progress_status=$(device_board_get_upgrade_progress_status) - if [ "$current_upgrade_progress_status" != "$PROGRESS_AFTER_RO" ]; then + current_upgrade_progress_status=$($GET_UPGRADE_PROGRESS_STATUS) + + if [ "$current_upgrade_progress_status" != "$PROGRESS_AFTER_UPDATE" ]; then critical_log "[Error] Cannot finish upgrade - RO Upgrade has not been completed" exit $ERR_FINISH_BEFORE_RO_UPDATE_COMPLETE fi run_script "${FOTA_DIR}/${SCRIPT_UPGRADE_FOTA}" - if ! [ $RET -ne 0 ]; then - # 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_progress_status $PROGRESS_AFTER_RO - log "[Info] RO update: $SCRIPT_NAME success" - fi + + if [ $RET -ne 0 ]; then + critical_log "Error: failed tu run ${FOTA_DIR}/${SCRIPT_UPGRADE_FOTA}" "$LOG_FILE" + exit_error + fi + + set_upgrade_progress_status $PROGRESS_AFTER_FINISH + + log "[Info] Rebooting to fota" + + if ! /sbin/reboot fota; then + critical_log "[Error] Failed to reboot fota" + exit_error fi + + log "[Info] RO update: $SCRIPT_NAME success" } verify_file() { @@ -185,14 +183,12 @@ verify_file() { VALID_CHECKSUM=$(awk "\$2 ~ /^$FILE_NAME\$/ {print \$1}" "$CHECKSUM_FILE") if [ "$VALID_CHECKSUM" == "" ]; then log "[Error] No $FILE_NAME in $CHECKSUM_FILE" - device_board_set_upgrade_progress_status -1 - exit 1 + exit_error fi if ! echo "$VALID_CHECKSUM $FILE_PATH" | sha1sum --check --status; then log "[Error] Checksum for file $FILE_NAME is invalid [$CHECKSUM_FILE]" - device_board_set_upgrade_progress_status -1 - exit 1 + exit_error fi log "[Info] Checksum of $FILE_NAME is OK [$CHECKSUM_FILE]" @@ -320,8 +316,7 @@ if [ $MODE_RO_UPDATE = true ]; then if [ ${RET} -ne 0 ]; then log "[Error] Delta verification unsuccessful" - device_board_set_upgrade_progress_status -1 - exit 1 + exit_error fi log "[Info] Delta verification success"