IMAGE_RELEASE=${FALSE}
+# maybe mounted dirs
+MOUNTED_DIRS="/proc" "/sys" "dev/pts" "dev/shm" "dev" "run" "tmp" ""
+
+
# Functions
log() {
cleanup_stage_1() {
- # Unmount image
- umount ${IMAGE_MOUNT_DIR}
+
+ local mounted_dir
+ for mounted_dir in ${MOUNTED_DIRS}
+ do
+
+ if is_mounted "${IMAGE_MOUNT_DIR}${mounted_dir}"; then
+ umount "${IMAGE_MOUNT_DIR}${mounted_dir}"
+ else
+ log DEBUG "${IMAGE_MOUNT_DIR}${mounted_dir} is not mounted"
+ fi
+ done
+
# Remove partition from the kernel table.
partx -d ${outlo}p1
}
+is_mounted() {
+ local mounted_dir=${1}
+
+ if [ ! -d ${mounted_dir} ]; then
+ log ERROR "Is not a directory ${mounted_dir}"
+ return ${FALSE}
+ else
+ mountpoint ${mounted_dir}
+ fi
+}
+
cleanup_stage_2() {
+ #Check that nothing is mounted in working dir
+ local mounted_dir
+ for mounted_dir in ${MOUNTED_DIRS}
+ do
+
+ if is_mounted "${IMAGE_MOUNT_DIR}${mounted_dir}"; then
+ log ERROR "${IMAGE_MOUNT_DIR}${mounted_dir} is still mounted"
+ return ${EXIT_ERROR}
+ else
+ log DEBUG "${IMAGE_MOUNT_DIR}${mounted_dir} is not mounted"
+
+ fi
+ done
+
# Drop working dir
if [ -d "${WORKING_DIR}" ]; then
rm -dfR "${WORKING_DIR}"