#	START NEW ARIX SCCS HEADER
#
#	@(#) umountfsys: version 25.1 created on 12/2/91 at 17:00:01
#
#	Copyright (c) 1990 by Arix Corporation
#	All Rights Reserved
#
#	@(#)umountfsys	25.1	12/2/91 Copyright (c) 1990 by Arix Corporation
#
#	END NEW ARIX SCCS HEADER
#

#	ATT ident	"sadmin:admin/umountfsys	2.8"

#ident	"@(#)sadmin/admin:umountfsys	1.1"

#	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=`seldevice -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
