#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin
+SCRIPT_NAME="clone_partitions.sh"
+
+#------------------------------------------------
+# critical_log msg [file]
+#------------------------------------------------
+critical_log() {
+ # log format: [script_name][tag]actual_log
+ LOG="[${SCRIPT_NAME}]$1"
+ dlogsend -k "$LOG"
+ if [ "$2" != "" ]; then
+ echo "$LOG" >> "$2"
+ fi
+ echo "$LOG"
+}
+
+#------------------------------------------------
+# log msg [file]
+#------------------------------------------------
+log() {
+ # log format: [script_name][tag]actual_log
+ LOG="[${SCRIPT_NAME}]$1"
+ if [ "$2" != "" ]; then
+ echo "$LOG" >> "$2"
+ fi
+ echo "$LOG"
+}
+
set -o errexit
trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
set -o errtrace -e -o pipefail
fi
if [ "$(device_board_get_partition_ab_cloned)" -eq "1" ]; then
- echo "[Info] Partitions already cloned"
+ log "[Info] Partitions already cloned"
exit 0
fi
if /usr/libexec/upgrade-support/upgrade-prepare-partitions.sh; then
- echo "[Info] Partitions have been cloned"
+ log "[Info] Partitions have been cloned"
device_board_set_partition_ab_cloned
else
- echo "[Error] Partitions have not been cloned"
+ critical_log "[Error] Partitions have not been cloned"
fi
CONFIG_FILE="update.cfg"
SET_UPGRADE_STATUS="/usr/bin/device_board_set_upgrade_status"
+#------------------------------------------------
+# critical_log msg [file]
+#------------------------------------------------
+critical_log() {
+ # log format: [script_name][tag]actual_log
+ LOG="[${SCRIPT_NAME}]$1"
+ dlogsend -k "$LOG"
+ if [ "$2" != "" ]; then
+ echo "$LOG" >> "$2"
+ fi
+ echo "$LOG"
+}
+
+critical_flog() {
+ critical_log "$1" "$LOG_FILE"
+}
+
#------------------------------------------------
# log msg [file]
#------------------------------------------------
mount() {
if should_mount_rootfs; then
if ! mount_partition rootfs "$FOTA_UPDATE_PREFIX" "rw"; then
- flog "[Error] Unable to mount rootfs"
+ critical_flog "[Error] Unable to mount rootfs"
return 1
fi
else
mkdir -p "$FOTA_UPDATE_PREFIX/opt"
fi
if ! mount_partition system-data "$FOTA_UPDATE_PREFIX/opt" "rw"; then
- flog "[Error] Unable to mount opt"
+ critical_flog "[Error] Unable to mount opt"
return 1
fi
untrap
flog "[Info] Switching board partition from $CURRENT_AB, to $NEXT_AB"
if ! device_board_switch_partition $NEXT_AB; then
- flog "[Error] Failed to switch board slot to $NEXT_AB"
+ critical_flog "[Error] Failed to switch board slot to $NEXT_AB"
exit 1
fi
/bin/sync
flog "[Info] Rebooting to fota"
if ! /sbin/reboot fota; then
- flog "[Error] Failed to reboot fota"
+ critical_flog "[Error] Failed to reboot fota"
exit 1
fi
}
flog "[Info] Switching board partition from $CURRENT_AB, to $NEXT_AB"
if ! device_board_switch_partition $NEXT_AB; then
- flog "[Error] Failed to switch board slot to $NEXT_AB"
+ critical_flog "[Error] Failed to switch board slot to $NEXT_AB"
exit 1
fi
/bin/sync
flog "[Info] Rebooting to fota"
if ! /sbin/reboot fota; then
- flog "[Error] Failed to reboot fota"
+ critical_flog "[Error] Failed to reboot fota"
exit 1
fi
}
/bin/tar xvfp "$DELTA_TAR" -C "$FOTA_DIR" "$CONFIG_FILE"
if [ ! -e "$FOTA_DIR/$CONFIG_FILE" ]; then
- log "[Error] There is no $CONFIG_FILE" "$LOG_FILE"
+ critical_log "[Error] There is no $CONFIG_FILE" "$LOG_FILE"
return
fi
# go to fota mode
log "[Info] Go TOTA update..." "$LOG_FILE"
if ! /sbin/reboot fota; then
- log "[Error] Failed to reboot fota" "$LOG_FILE"
+ critical_log "[Error] Failed to reboot fota" "$LOG_FILE"
exit 100
fi
unpack_file "$DELTA_TAR" "$CONFIG_FILE"
upgrade_images "$DELTA_TAR"
if ! prepare_for_ua; then
- flog "[Error] Unable to prepare_for_ua"
+ critical_flog "[Error] Unable to prepare_for_ua"
cleanup
exit_error
fi
if ! run_setup_script "$DELTA_TAR"; then
- flog "[Error] Unable to run_setup_script"
+ critical_flog "[Error] Unable to run_setup_script"
cleanup
exit_error
fi
if ! run_ro_update; then
- flog "[Error] Unable to run_ro_update"
+ critical_flog "[Error] Unable to run_ro_update"
cleanup
exit_error
fi