#	ATT:#ident	"initpkg:init.d/rumounts	1.3"	
	
#ident	"@(#)initpkg/init.d:rumounts	25.1"


#	Unmounts all remote file resources with warning period.
#	Note: written to depend on as few commands as possible.

WALL=/tmp/wall$$

trap 'rm -f ${WALL}' 0 1 2 3 15

grace=60	# grace period

while [ $# -ge 1 ]
do
	case "$1" in
	-g )
		shift
		grace=$1
		;;
	stop)			# executed by an rc? script
		grace=0		# warning was sent by shutdown
		;;
	* )
		echo >&2 "Usage:  $0 [{ -g <seconds> | stop }]"
		exit 1
		;;
	esac
	shift
done


echo "the following resources will be removed from the system\
 in ${grace} seconds: " >${WALL}
/etc/mount  |
	/bin/sort -r  |
	{
		sndmsg=0
		while read fs dummy1 dev mode1 mode2 dummy2
		do
			if [ `echo ${mode1}${mode2} | grep remote` ]
			then
				echo  "\t${fs}" >>${WALL}
				sndmsg=1
			fi
		done 
		exit ${sndmsg}
	}
sndmsg=$?

set `who -r`
if [ ${grace} -ne 0 -a ${sndmsg} -ne 0 ]
then
	/etc/wall <${WALL}
	/bin/sleep ${grace}
fi
/etc/rumountall -k
