set -x
fi
+PROGRESS_AFTER_RO=80
+
PATH=/bin:/usr/bin:/sbin:/usr/sbin
FOTA_DIR="/opt/usr/data/fota"
STATUS_DIR="/opt/data/update"
-DOWNLOAD_DELTA="$1"
SCRIPT_UPGRADE_PREPARE_PARTITIONS="upgrade-prepare-partitions.sh"
SCRIPT_UPGRADE_PARTIAL="upgrade-partial.sh"
SCRIPT_UPGRADE_FOTA="upgrade-fota.sh"
# be modified, so they will not be a clone of the current partitions
device_board_clear_partition_ab_cloned
- unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_PARTIAL}"
- unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_FOTA}"
run_script "${FOTA_DIR}/${SCRIPT_UPGRADE_PARTIAL} ${DOWNLOAD_DELTA}"
exit_error
fi
- set_upgrade_status 40
+ set_upgrade_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
- 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_status 80
- log "[Info] RO update: $SCRIPT_NAME success"
- fi
- fi
-
else
log "[Error] Non-A/B upgrade is unsupported"
device_board_set_upgrade_status -1
fi
}
+do_finish() {
+ current_upgrade_status=$(device_board_get_upgrade_status)
+ if [ "$current_upgrade_status" != "$PROGRESS_AFTER_RO" ]; then
+ critical_log "[Error] Cannot finish upgrade - RO Upgrade has not been completed"
+ exit_error
+ 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_status $PROGRESS_AFTER_RO
+ log "[Info] RO update: $SCRIPT_NAME success"
+ fi
+ fi
+}
+
verify_file() {
FILE_PATH="$1"
FILE_NAME=$(basename "$FILE_PATH")
log "[Info] Checksum of $FILE_NAME is OK"
}
-(
-flock 9
+MODE_RO_UPDATE=false
+MODE_FINISH_UPDATE=false
+
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --ro-update)
+ MODE_RO_UPDATE=true
+ ;;
+ --finish)
+ MODE_FINISH_UPDATE=true
+ ;;
+ *)
+ DOWNLOAD_DELTA="$1"
+ ;;
+ esac
+ shift
+done
+
+if [ $MODE_RO_UPDATE = false ] && [ $MODE_FINISH_UPDATE = false ]; then
+ MODE_RO_UPDATE=true
+ MODE_FINISH_UPDATE=true
+fi
-if [ "$#" != "1" ] || [ ! -f "$1" ]; then
- echo "[Error] Usage: $0 path_to_delta.tar[.gz]"
+if [ $MODE_RO_UPDATE = true ] && [ ! -f "$DOWNLOAD_DELTA" ]; then
+ echo "[Error] Usage: $0 [--ro_update <path_to_delta.tar[.gz]>] [--finish]"
exit 1
fi
-prepare_fota_dir
-
-tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" checksum.SHA1
-tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" upgrade-common.inc
-
-. "$FOTA_DIR"/upgrade-common.inc
-upgrade_log_init
-set_script_name_and_log_file "${BASH_SOURCE[0]}"
+(
+if [ $MODE_RO_UPDATE = false ] && [ $MODE_FINISH_UPDATE = true ]; then
+ if ! flock -n 9; then
+ echo "[Error] Upgrade in progress"
+ exit 2
+ fi
+else
+ flock 9
+fi
-verify_file "$FOTA_DIR/upgrade-common.inc"
+# if [ "$#" != "1" ] || [ ! -f "$1" ]; then
+# echo "[Error] Usage: $0 path_to_delta.tar[.gz]"
+# exit 1
+# fi
+if [ $MODE_RO_UPDATE = true ]; then
+ prepare_fota_dir
-verify_file "$0"
-tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" update-info.ini
-verify_file "$FOTA_DIR/update-info.ini"
-tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" delta-verifier
-verify_file "$FOTA_DIR/delta-verifier"
+ tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" checksum.SHA1
-log "[Info] Begin delta verification"
-RET=0
-# '||'' used to stop script form exiting (errexit is set)
-"${FOTA_DIR}/delta-verifier" --update_info_path "$FOTA_DIR/update-info.ini" || RET=$?
+ tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" upgrade-common.inc
+fi
-if [ ${RET} -ne 0 ]; then
- log "[Error] Delta verification unsuccessful"
+if [ ! -f "$FOTA_DIR/upgrade-common.inc" ]; then
+ echo "[Error] upgrade-common.inc not exist"
device_board_set_upgrade_status -1
exit 1
fi
-log "[Info] Delta verification success"
-set_upgrade_status 1
-verify_img "${DOWNLOAD_DELTA}"
-do_update
+ . "$FOTA_DIR"/upgrade-common.inc
+
+if [ $MODE_RO_UPDATE = true ]; then
+ upgrade_log_init
+ set_script_name_and_log_file "${BASH_SOURCE[0]} $*"
+
+ verify_file "$FOTA_DIR/upgrade-common.inc"
+
+ verify_file "$0"
+ unpack_file "${DOWNLOAD_DELTA}" update-info.ini
+ unpack_file "${DOWNLOAD_DELTA}" delta-verifier
+ unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_PARTIAL}"
+ unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_FOTA}"
+
+ log "[Info] Begin delta verification"
+ RET=0
+ # '||'' used to stop script form exiting (errexit is set)
+ "${FOTA_DIR}/delta-verifier" --update_info_path "$FOTA_DIR/update-info.ini" || RET=$?
+ rm -f "${FOTA_DIR}/delta-verifier"
+ rm -f "${FOTA_DIR}/update-info.ini"
+
+ if [ ${RET} -ne 0 ]; then
+ log "[Error] Delta verification unsuccessful"
+ device_board_set_upgrade_status -1
+ exit 1
+ fi
+ log "[Info] Delta verification success"
+
+ set_upgrade_status 1
+ verify_img "${DOWNLOAD_DELTA}"
+ do_update
+fi
+
+if [ $MODE_FINISH_UPDATE = true ]; then
+ set_script_name_and_log_file "${BASH_SOURCE[0]}"
+
+ verify_file "$0"
+ verify_file "$FOTA_DIR/upgrade-common.inc"
+ do_finish
+
+fi
) 9> "$FLOCK_PATH"