#ident	"@(#)initpkg:init.d/rumounts	1.4.3.2"

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

WALL=/tmp/wall$$

trap '/usr/bin/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}
/sbin/mount  |
	/usr/bin/sort -r  |
	{
		sndmsg=0
		while read fs dummy1 dev mode1 mode2 dummy2
		do
			if [ `echo ${mode1}${mode2} | /usr/bin/grep remote` ]
			then
				echo  "\t${fs}" >>${WALL}
				sndmsg=1
			fi
		done 
		exit ${sndmsg}
	}
sndmsg=$?

if [ ${grace} -ne 0 -a ${sndmsg} -ne 0 ]
then
	/usr/sbin/wall <${WALL}
	/usr/bin/sleep ${grace}
fi
/usr/sbin/rumountall 2>/dev/null
/usr/sbin/rumountall -k
