3 trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
4 set -o errtrace -e -o pipefail
7 if [ ! -z "${UPGRADE_DEBUG}" ]; then
11 PATH=/bin:/usr/bin:/sbin:/usr/sbin
12 FOTA_DIR="/opt/usr/data/fota"
14 . "$FOTA_DIR"/upgrade-common.inc
16 FOTA_UPDATE_PREFIX="/run/upgrade-sysroot"
17 VERSION_FILE="$FOTA_UPDATE_PREFIX/opt/etc/version"
19 SCRIPT_NAME="upgrade-fota.sh"
20 LOG_FILE="/tmp/update-fota.log"
28 rm -f -- "$FOTA_DIR"/upgrade-common.inc
29 rm -f -- "$FOTA_DIR/$SCRIPT_NAME"
30 rm -f -- "$FOTA_DIR/$CONFIG_FILE"
31 rm -f -- "$FOTA_DIR/upgrade-trigger.sh"
32 rm -f -- "$FOTA_DIR/checksum.SHA1"
36 # We need to mount the system-data partition to update /opt/etc/version and
37 # create a .do_rw_update file
38 mkdir -p "$FOTA_UPDATE_PREFIX/opt"
40 if ! mount_partition system-data "$FOTA_UPDATE_PREFIX/opt" "rw"; then
41 critical_flog "[Error] Unable to mount opt"
48 flog "[Info] Write paths..."
49 touch "$DO_RW_UPDATE_FILE"
50 flog "[Info] calling sync"
52 flog "[Info] Switching board partition from $CURRENT_AB, to $NEXT_AB"
53 if ! device_board_switch_partition $NEXT_AB; then
54 critical_flog "[Error] Failed to switch board slot to $NEXT_AB"
59 flog "[Info] Rebooting to fota"
61 # System will reboot, so the script will be aborted. We don't want this to be
62 # treated as an error.
65 if ! /sbin/reboot fota; then
66 critical_flog "[Error] Failed to reboot fota"
71 prepare_fota_update_dir() {
72 mkdir -p ${FOTA_UPDATE_PREFIX}
75 prepare_fota_update_dir
76 check_ab_partition_scheme
77 check_used_block_device
82 if ! write_version_info "$VERSION_FILE"; then
87 critical_log "RO update: $SCRIPT_NAME success" "$LOG_FILE"
89 if ! reboot_to_fota; then