OSDN Git Service

[fix] : FIxed them bug that script will unmount all mountpoint
authorhayao <hayao@fascode.net>
Thu, 15 Apr 2021 13:04:56 +0000 (22:04 +0900)
committerhayao <hayao@fascode.net>
Thu, 15 Apr 2021 13:04:56 +0000 (22:04 +0900)
build.sh

index 637da6f..36185c2 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -197,12 +197,19 @@ _mount() { if ! mountpoint -q "${2}" && [[ -f "${1}" ]] && [[ -d "${2}" ]]; then
 # Unmount chroot dir
 umount_chroot () {
     local _mount
-    if [[ ! -v build_dir ]] || [[ "${build_dir}" = "" ]]; then
+    if [[ ! -v "build_dir" ]] || [[ "${build_dir}" = "" ]]; then
         msg_error "Exception error about working directory" 1
     fi
-    for _mount in $(cat /proc/mounts | getclm 2 | grep "$(realpath ${build_dir})" | tac | grep -xv "$(realpath ${build_dir})/${arch}/airootfs"); do
-        msg_info "Unmounting ${_mount}"
-        _umount "${_mount}" 2> /dev/null
+    if [[ ! -d "${build_dir}" ]]; then
+        return 0
+    fi
+    for _mount in $(cat "/proc/mounts" | getclm 2 | grep "$(realpath -s ${build_dir})" | tac | grep -xv "$(realpath -s ${build_dir})/${arch}/airootfs"); do
+        if echo "${_mount}" | grep "${work_dir}" > /dev/null 2>&1 || echo "${_mount}" | grep "${script_path}" > /dev/null 2>&1 || echo "${_mount}" | grep "${out_dir}" > /dev/null 2>&1; then
+            msg_info "Unmounting ${_mount}"
+            _umount "${_mount}" 2> /dev/null
+        else
+            msg_error "It is dangerous to unmount a directory that is not managed by the script."
+        fi
     done
 }