diff --git a/build.sh b/build.sh index 2cae71b..1031d76 100755 --- a/build.sh +++ b/build.sh @@ -24,8 +24,6 @@ export QUILT_REFRESH_ARGS='-p ab' source "$FUNCTIONS_DIR/logging.sh" source "$FUNCTIONS_DIR/dependencies_check.sh" -source "$SCRIPT_DIR/common.sh" - on_chroot() { local proc_fs="$ROOTFS_DIR/proc" local dev_fs="$ROOTFS_DIR/dev" @@ -75,6 +73,40 @@ apply_patches() { popd > /dev/null } +unmount() { + if [ -z "$1" ]; then + DIR=$PWD + else + DIR=$1 + fi + + while mount | grep -q "$DIR"; do + local LOCS + LOCS=$(mount | grep "$DIR" | cut -f 3 -d ' ' | sort -r) + for loc in $LOCS; do + umount "$loc" + done + done +} + +unmount_image() { + sync + sleep 1 + local LOOP_DEVICES + LOOP_DEVICES=$(losetup -j "${1}" | cut -f1 -d':') + for LOOP_DEV in ${LOOP_DEVICES}; do + if [ -n "${LOOP_DEV}" ]; then + local MOUNTED_DIR + MOUNTED_DIR=$(mount | grep "$(basename "${LOOP_DEV}")" | head -n 1 | cut -f 3 -d ' ') + if [ -n "${MOUNTED_DIR}" ] && [ "${MOUNTED_DIR}" != "/" ]; then + unmount "$(dirname "${MOUNTED_DIR}")" + fi + sleep 1 + losetup -d "${LOOP_DEV}" + fi + done +} + if [ "$(id -u)" != '0' ]; then echo 'Please run as root' 1>&2 exit 1 diff --git a/scripts/common.sh b/scripts/common.sh deleted file mode 100644 index 7a2c2d4..0000000 --- a/scripts/common.sh +++ /dev/null @@ -1,36 +0,0 @@ -unmount() { - if [ -z "$1" ]; then - DIR=$PWD - else - DIR=$1 - fi - - while mount | grep -q "$DIR"; do - local LOCS - LOCS=$(mount | grep "$DIR" | cut -f 3 -d ' ' | sort -r) - for loc in $LOCS; do - umount "$loc" - done - done -} - -unmount_image() { - sync - sleep 1 - local LOOP_DEVICES - LOOP_DEVICES=$(losetup -j "${1}" | cut -f1 -d':') - for LOOP_DEV in ${LOOP_DEVICES}; do - if [ -n "${LOOP_DEV}" ]; then - local MOUNTED_DIR - MOUNTED_DIR=$(mount | grep "$(basename "${LOOP_DEV}")" | head -n 1 | cut -f 3 -d ' ') - if [ -n "${MOUNTED_DIR}" ] && [ "${MOUNTED_DIR}" != "/" ]; then - unmount "$(dirname "${MOUNTED_DIR}")" - fi - sleep 1 - losetup -d "${LOOP_DEV}" - fi - done -} - -export -f unmount -export -f unmount_image