#!/bin/sh
# @(#)stop-afp.sh	1.9 revision of 97/03/13  15:44:49
# This is an unpublished work copyright (c) 1989 HELIOS Software GmbH
# 30159 Hannover, Germany

ESDIR=/usr/local/es

USAGE="Usage: $0 [-g grace] [-m message] [now]"
GRACE=""
MESSAGE=""

if test $# -gt 0
then
	while getopts 'g:m:' c
	do
		case $c in
		g)
			GRACE="-g $OPTARG"
			;;
		m)
			MESSAGE="$OPTARG"
			;;
		\?)
			echo $USAGE >&2
			exit 1
			;;
		esac
	done
	shift `expr $OPTIND - 1`
	if test $# -gt 0
	then
		if test "$1" = "now"
		then
			GRACE="-g 0"
		else
			echo $USAGE >&2
			exit 1
		fi
	fi
fi

$ESDIR/etc/afpshutdown $GRACE $MESSAGE

until $ESDIR/etc/forall afpsrv :
do
	if test X"$GRACE" = X
	then
		sleep 30
	else
		sleep 10
	fi
done

$ESDIR/etc/forall ndsrv kill
