#! /bin/sh

# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.

#ident	"$Header: umountfsys 1.4 89/10/11 $@(#)sadmin:admin/umountfsys	2.8"
#	Unmount a file system.
#help#
#help#	Umountfsys unmounts a file system.

#!	chmod +x ${file}

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

unset disklabelarg umountit patterns

while getopts p:y c 
do
	case "$c" in
	p )
		patterns=$OPTARG
		;;
	y )
		disklabelarg=-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

ddrive=`selectdevice -b $$ /dev/dsk ${patterns}`
ndrive=`drivename ${ddrive}`

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

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

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