#	ATT ident	"sadmin:admin/umountfsys	2.8"

#ident	"%Z%sadmin/admin:%M%	%I%"

#	Unmount a removable medium file system.
#help#
#help#	Umountfsys unmounts a file system, allowing you to remove the medium.

#!	chmod +x ${file}
PATH=/bin:/usr/bin:/usr/lbin:/etc

flags="-qq -k$$"
trap 'exit 0' 1 2 15

unset umountit patterns

while getopts p:y c 
do
	case "$c" in
	p )
		patterns=$OPTARG
		;;
	y )
		umountit=yes
		;;
	\? )
		echo >&2 "Usage:  `basename $0` [ -p pattern ] [ -y ]
-y	unmount the file system without asking any questions"
		exit 1
		;;
	esac
done

shift `expr $OPTIND - 1`
if [ $# != 0 ]
then
	echo >&2 "Usage:  `basename $0` [ -p pattern ] [ -y ]
-y	unmount the file system without asking any questions"
	exit 1
fi

dir=${0}.d
if [ -z "${patterns}"  -a  -d ${dir} ]
then
	patterns=`ls ${dir} 2>/dev/null`
fi

bddrive=`selectdevice -b $$ /dev/dsk ${patterns}`

if [ -n "${patterns}" ]
then
	. ${dir}/`selpattern ${bddrive}`
fi

mounted=`/etc/mount | sed -n "\\;${bddrive};s;^\([^ ]*\) on ${bddrive} .*;\1;p"`

if [ -z "${mounted}" ]
then
	echo "No file system is mounted on ${bddrive}."
	exit 0
fi
if test ${umountit}  ||  checkyn ${flags} -f "Do you wish to unmount '${mounted}'?"
then
	diskumount  ${bddrive} ${mounted}  ||
		echo "	Correct the problem and try again."
fi
