-#!/bin/bash
+#!/bin/bash
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
SYNC="/bin/sync"
HAL_MNT="hal"
BTRFS="/usr/sbin/btrfs"
+exit_handler() {
+ if [ $? -ne 0 ]; then
+ echo "[Error] Failure to create checkpoint. Reboot."
+ reboot -f
+ exit 1
+ fi
+ echo "[Debug] Checkpoint created"
+}
+
get_partition_id() {
PART_ROOTFS=$("$BLKID" --match-token PARTLABEL=rootfs -o device || "$BLKID" --match-token LABEL=rootfs -o device)
PART_SYSTEM_DATA=$("$BLKID" --match-token PARTLABEL=system-data -o device || "$BLKID" --match-token LABEL=system-data -o device)
DM_NUMBER=$(($("${STAT}" -c "0x%T" $(readlink -f ${BOWDEV_PATH}))))
echo 1 > /sys/block/dm-${DM_NUMBER}/bow/state
- echo "[Debug] Mounted ${PARTITION} as DM-BOW"
+ if [ "$(</sys/block/dm-${DM_NUMBER}/bow/state)" = "1" ]; then
+ echo "[Debug] Mounted ${PARTITION} as DM-BOW"
+ return 0
+ else
+ echo "[Error] Failure to create checkpoint for ${PARTITION}"
+ return 1
+ fi
}
mount_f2fs_partition() {
LABEL=${1}
PARTITION=${2}
DIRECTORY=${3}
- "${MOUNT}" -o checkpoint=disable ${PARTITION} ${DIRECTORY}
- echo "[Debug] Mounted ${PARTITION} as F2FS checkpoint=disable"
+ if "${MOUNT}" -o checkpoint=disable ${PARTITION} ${DIRECTORY}; then
+ echo "[Debug] Mounted ${PARTITION} as F2FS checkpoint=disable"
+ return 0
+ else
+ echo "[Error] Failure to mount partition ${PARTITION}"
+ return 1
+ fi
}
mount_btrfs_partition() {
"$UMOUNT" "${DIRECTORY}"
"$MOUNT" -o rw "${PARTITION}" "${DIRECTORY}"
echo "[Debug] Mounted ${PARTITION} as btrfs"
+ return 0
}
mount_checkpoint_partition() {
else
mount ${PARTITION} ${DIRECTORY}
fi
+ return $?
}
+trap exit_handler EXIT
+
get_partition_id
-mount_checkpoint_partition system-data ${PART_SYSTEM_DATA} /${SYSTEM_DATA_MNT}
+mount_checkpoint_partition system-data ${PART_SYSTEM_DATA} /${SYSTEM_DATA_MNT} || exit 1
if [ ! -z "${PART_USER}" ]; then
- mount_checkpoint_partition user ${PART_USER} /${USER_MNT}
+ mount_checkpoint_partition user ${PART_USER} /${USER_MNT} || exit 1
fi
if [ ! -z "${PART_HAL}" ] && [ ! -d "/${HAL_MNT}/lib" ]
then
# Workaround code to check whether /hal/lib directory is exist
- mount_checkpoint_partition hal ${PART_HAL} /${HAL_MNT}
+ mount_checkpoint_partition hal ${PART_HAL} /${HAL_MNT} || exit 1
fi
+
+exit 0