#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-fs/coda/files/6.0.15/coda-update,v 1.1 2008/07/12 22:31:41 chtekk Exp $

depend() {
	need net auth2
}

checkconfig() {
	if [ ! -e $vicedir/hostname ] ; then
		eerror "Please run vice-setup before starting the service..."
		return 1
	fi
}

we_are_scm() {
	if [ "`cat $vicedir/hostname`" = "`cat $vicedir/db/scm`" ] ; then
		return 0
	else
		return 1
	fi
}

getvicedir() {
        vicedir=`/usr/sbin/codaconfedit server.conf vicedir`
}

start() {
	getvicedir

	checkconfig || return 1

	ebegin "Starting coda-update"

	# Check to see if we are the SCM.
	if we_are_scm ; then
		start-stop-daemon --start --quiet --exec /usr/sbin/rpc2portmap
		start-stop-daemon --start --quiet --exec /usr/sbin/updatesrv
	fi

	start-stop-daemon --start --quiet --exec /usr/sbin/updateclnt

	eend $?
}

stop() {
	ebegin "Stopping coda-update"

	getvicedir

	if we_are_scm ; then
		start-stop-daemon --stop --quiet --exec /usr/sbin/rpc2portmap
		start-stop-daemon --stop --quiet --exec /usr/sbin/updatesrv
	fi

	start-stop-daemon --stop --quiet --exec /usr/sbin/updateclnt

	eend $?
}
