funtions: add umount_force function

This commit is contained in:
timoxa0 2024-11-02 21:18:26 +05:00
parent 16fb7c36ae
commit ac1c6c511a
2 changed files with 29 additions and 8 deletions

View file

@ -108,9 +108,9 @@ umount_image()
cp ./drop/postinstall "$rootdir/opt/nabu/postinstall" cp ./drop/postinstall "$rootdir/opt/nabu/postinstall"
chmod +x "$rootdir/opt/nabu/postinstall" chmod +x "$rootdir/opt/nabu/postinstall"
umount "$rootdir/boot/efi" umount_force "$rootdir/boot/efi"
umount "$rootdir/boot/simpleinit" umount_force "$rootdir/boot/simpleinit"
umount "$rootdir" umount_force "$rootdir"
rm -d "$rootdir" rm -d "$rootdir"
return 0 return 0
} }
@ -144,11 +144,11 @@ detach_chroot()
rootdir=$(realpath "$1") rootdir=$(realpath "$1")
killall gpg-agent > /dev/null 2>&1 killall gpg-agent > /dev/null 2>&1
umount "$rootdir/proc" > /dev/null 2>&1 umount_force "$rootdir/proc" > /dev/null 2>&1
umount "$rootdir/sys" > /dev/null 2>&1 umount_force "$rootdir/sys" > /dev/null 2>&1
umount "$rootdir/dev/pts" > /dev/null 2>&1 umount_force "$rootdir/dev/pts" > /dev/null 2>&1
umount "$rootdir/dev/shm" > /dev/null 2>&1 umount_force "$rootdir/dev/shm" > /dev/null 2>&1
umount "$rootdir/dev" > /dev/null 2>&1 umount_force "$rootdir/dev" > /dev/null 2>&1
return 0 return 0
} }

View file

@ -23,6 +23,27 @@ mkdir_if_not_exists ()
mkdir "$1" mkdir "$1"
} }
umount_if_mouted()
{
[ ! -d "$1" ] && return 0
if grep -qs "$(realpath "$1")" /proc/mounts; then
umount "$1"
return $?
else
return 0
fi
}
umount_force()
{
[ ! -d "$1" ] && return 0
while true; do
umount_if_mouted "$1" && break
log "Failed to umount $1. Trying again after 3 seconds" ierror
sleep 3
done
}
prepare_env() prepare_env()
{ {
mkdir_if_not_exists "./cache" mkdir_if_not_exists "./cache"