Move unmounting functions to main script
This commit is contained in:
parent
7f5a5b0dbc
commit
0278187a19
2 changed files with 34 additions and 38 deletions
36
build.sh
36
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
|
||||
|
|
|
@ -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
|
Reference in a new issue