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

#	Copyright (c) 1984 AT&T
#	  All Rights Reserved

#	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#	The copyright notice above does not evidence any
#	actual or intended publication of such source code.

#ident	"$Header: umountall.sh 1.10 90/10/24 $@(#)initpkg:./umountall.sh	1.4"
cat << 'END_OF_UMOUNTALL' > umountall
#! /bin/sh
#	Unmounts all but the root, "/", file system.
#	Note: written to depend on as few commands as possible.

mounttype=
kill=
while [ $# -ge 1 ]
do
	case "$1" in
	-k )
		if [ ! -x /etc/fuser ]
		then
			echo >&2 "$0:  -k option not available.  No /etc/fuser found."
			exit 1
		fi
		kill=yes
		shift
		;;
	-f )
		mounttype=$2
		shift 2
		;;
	* )
		echo >&2 "usage:  $0 [ -k ] [ -f <fstype> ]
-k	kill processes with files open in each file system before unmounting."
		exit 1
	esac
done

	#	Read mnttab (instead of /etc/mount output) to
	#	get the fstype.  Keep a list of mountpoints for
	#	the specified fstype.

	list=` sort -r +1 -2 /etc/mnttab |
	while read dev fs fstype fsflags dummy
	do
		if [ -n "${mounttype}" -a "${fstype}" != "${mounttype}" ]
		then
			continue
		fi

		case "${fs}" in
		/  |  '' )
			continue
			;;
		* )
			echo "${fs} "
			;;
		esac
	done`

	#	if list is empty, nothing to umount

	if [ -z "${list}" ]
	then
		exit 0
	fi

	#	kill processes holding mountpoings busy

	if [ ${kill} ]
	then
		for fs in ${list}
		do
			echo ${fs} | xargs /etc/fuser -kc
		done

		# wait for output to drain
		sleep 15
	fi

	#	Finally unmount all filesystems

	for fs in ${list}
	do
		/etc/umount ${fs}
	done
END_OF_UMOUNTALL
