]> git.wh0rd.org - home.git/blobdiff - .bin/umount-tree
redshift: add -x option
[home.git] / .bin / umount-tree
index bcf866f2efd2ada9d489ca4d0181cb550f4e126e..a831849982c654352ebb9d43b16fa6c746d4e282 100755 (executable)
@@ -1,22 +1,37 @@
 #!/bin/bash
 
-root=$1
 if [[ -z $1 ]] ; then
        echo "Usage: $0 <root>"
        exit 1
 fi
 
-mounts=$(mount | grep " on ${root%/}/" | awk '{print $3}' | tac)
+prompt=true
+case $1 in
+-y) prompt=false; shift;;
+esac
+
+while [[ $# -gt 0 ]] ; do
+
+root=$1
+shift
+
+mounts=$(gawk -v p="${root%/}" '$2 ~ "^"p { print $2 }' /proc/mounts | tac)
 if [[ -z ${mounts} ]] ; then
        echo "No mounts found ..."
        echo
        mount
-       exit 0
+       continue
 fi
 
 echo "Unmounting: "
 printf '\t%s\n' ${mounts}
 
-printf "OK? [y/N] "
-read v
+if ${prompt} ; then
+       printf "OK? [y/N] "
+       read v
+else
+       v=y
+fi
 [[ ${v} == "y" ]] && sudo umount -v ${mounts}
+
+done