From ac1c6c511a753f1cc17fbd0b2020c88d5e78a1fb Mon Sep 17 00:00:00 2001 From: timoxa0 Date: Sat, 2 Nov 2024 21:18:26 +0500 Subject: [PATCH] funtions: add umount_force function --- common.d/build_functions.sh | 16 ++++++++-------- common.d/functions.sh | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/common.d/build_functions.sh b/common.d/build_functions.sh index 55c6b70..a3505ba 100644 --- a/common.d/build_functions.sh +++ b/common.d/build_functions.sh @@ -108,9 +108,9 @@ umount_image() cp ./drop/postinstall "$rootdir/opt/nabu/postinstall" chmod +x "$rootdir/opt/nabu/postinstall" - umount "$rootdir/boot/efi" - umount "$rootdir/boot/simpleinit" - umount "$rootdir" + umount_force "$rootdir/boot/efi" + umount_force "$rootdir/boot/simpleinit" + umount_force "$rootdir" rm -d "$rootdir" return 0 } @@ -144,11 +144,11 @@ detach_chroot() rootdir=$(realpath "$1") killall gpg-agent > /dev/null 2>&1 - umount "$rootdir/proc" > /dev/null 2>&1 - umount "$rootdir/sys" > /dev/null 2>&1 - umount "$rootdir/dev/pts" > /dev/null 2>&1 - umount "$rootdir/dev/shm" > /dev/null 2>&1 - umount "$rootdir/dev" > /dev/null 2>&1 + umount_force "$rootdir/proc" > /dev/null 2>&1 + umount_force "$rootdir/sys" > /dev/null 2>&1 + umount_force "$rootdir/dev/pts" > /dev/null 2>&1 + umount_force "$rootdir/dev/shm" > /dev/null 2>&1 + umount_force "$rootdir/dev" > /dev/null 2>&1 return 0 } diff --git a/common.d/functions.sh b/common.d/functions.sh index 6aba63e..3b64fd5 100644 --- a/common.d/functions.sh +++ b/common.d/functions.sh @@ -23,6 +23,27 @@ mkdir_if_not_exists () 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() { mkdir_if_not_exists "./cache"