#! /bin/sh
#
# |-----------------------------------------------------------|
# | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
# | All Rights Reserved                                       |
# |-----------------------------------------------------------|
# |          Restricted Rights Legend                         |
# | Use, duplication, or disclosure by the Government is      |
# | subject to restrictions as set forth in                   |
# | subparagraph (c)(1)(ii) of the Rights in Technical        |
# | Data and Computer Software Clause of DFARS 252.227-7013.  |
# |         MIPS Computer Systems, Inc.                       |
# |         950 DeGuigne Avenue                               |
# |         Sunnyvale, California 94088-3650, USA             |
# |-----------------------------------------------------------|
#
# $Header: umountall,v 1.12.2.1 92/06/24 13:35:52 marker Exp $

#	Unmounts all but the root, "/", file system.
#	Note: written to depend on as few commands as possible.

USAGE="usage:  $0 [ -k ]
-k	kill processes with files open in each file system before unmounting."

KILL=false

#
# Parse options.
#
while [ $# -gt 0 ]
do
	case "$1" in
	-k )	KILL=true; shift ;;
	-*)	echo >&2 "$USAGE"; exit 1;;
	* )	break;
	esac
done

if $KILL && [ ! -x /etc/fuser ] 
then
	echo >&2 "$0: -k option not available.  No /etc/fuser found."
	exit 1
fi

#
# Args
#
if [ $# != 0 ]
then
	echo >&2 "$USAGE"; 
	exit 1;
fi

#
# Unmount everything.  
#
# First try "umount -a".  
# If "-k", then use fuser on whatever remains.
#

/etc/umount -a

if $KILL
then
	/etc/mount |	
	# ... |
		while read DEV DUMMY1 FS DUMMY2 TYPE DUMMY3 MODE 
		do
			case "$FS" in
			/)	continue 
				;;
			* )	/etc/fuser -k $DEV
				sleep 10
				/etc/umount $DEV
				;;
			esac
		done 
fi
