#! /bin/sh
#
# skeleton	example file to build /etc/init.d/ scripts.
#		This file should be used to construct scripts for /etc/init.d.
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian GNU/Linux
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.8  03-Mar-1998  miquels@cistron.nl
#
# This file was automatically customized by dh-make on #DATE#

PATH=/bin:/usr/bin:/sbin:/usr/sbin
rpc2portmap=/usr/sbin/rpc2portmap
updateclnt=/usr/sbin/updateclnt
updatesrv=/usr/sbin/updatesrv
DESC="Coda update servers"
SERVER="coda-update"

FLAGS="defaults 40"
 
test -f /etc/coda/server.conf && . /etc/coda/server.conf
VICE=/var/lib/vice

if [ -f $VICE/db/scm ] ; then
	SCM=`cat $VICE/db/scm`
else
	exit 0
fi
HOST=`hostname`

test -f $UPDATECLNT || exit 0
test $SCM != $HOST -o -f $RPC2PORTMAP || exit 0
test $SCM != $HOST -o -f $UPDATESRV || exit 0

servers () {
  	if [ $SCM = $HOST ] ; then
		for DAEMON in rpc2portmap updatesrv ; do
			eval "start-stop-daemon --$1 --quiet \
					--pidfile /var/run/$SERVER-$DAEMON.pid --exec \$$DAEMON"
			echo -n "$DAEMON "
		done
	fi
    start-stop-daemon --$1 --quiet \
		--pidfile /var/run/$SERVER-updateclnt.pid --exec $UPDATECLNT
	echo -n "updateclnt"
}

case "$1" in
	start)
		echo -n "Starting $DESC: "
		servers $1
		echo "."
	;;
	stop)
		echo -n "Stopping $DESC: "
		servers $1
		echo "."
	;;
	restart|force-reload)
		$0 stop
		sleep 1
		$0 start
	;;
	*)
		echo "Usage: /etc/init.d/coda-update {start|stop|restart|force-reload}"
		exit 1
		;;
esac

exit 0
