#!/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