#!/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"
return 0
}
-reboot_to_fota() {
+prepare_reboot_to_fota() {
log "[Info] Write paths..."
touch "$DO_RW_UPDATE_FILE"
log "[Info] calling sync"
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() {
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
#!/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
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
# 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
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() {
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]"
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"