#ident	"@(#)initpkg:common/cmd/initpkg/init.d/rumounts	1.4.7.5"

if [ -z "$LC_ALL" -a -z "$LC_MESSAGES" ]
then
	if [ -z "$LANG" ]
	then
		LNG=`defadm locale LANG 2>/dev/null`
		if [ "$?" != 0 ]
		then LANG=C
		else eval $LNG
		fi
	fi
	export LANG
fi
LABEL="UX:$0"
CAT=uxrc

usage()
{
SEC=`gettxt $CAT:45 "seconds"`
USAGE="$0 [{ -g <$SEC> | stop }]"
pfmt -l $LABEL -s action -g $CAT:4 "Usage: %s\n" "$USAGE"
exit 1
}

#	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
		;;
	* )
		usage
		;;
	esac
	shift
done


if [ ${grace} -ne 0 ]
then
	pfmt -l $LABEL -s info -g $CAT:46 "The following resources will be removed from the system in %s seconds: \n" ${grace} 2>${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 [ ${sndmsg} -ne 0 ]
	then
		/usr/sbin/wall <${WALL}
		/usr/bin/sleep ${grace}
	fi
fi
/usr/sbin/rumountall 2>/dev/null
/usr/sbin/rumountall -k
