#!/bin/sh
#
# $Id: dhcp-relay.init.d,v 1.3.2.3 2003/09/10 19:49:21 peloy Exp $
#

test -x /usr/sbin/dhcrelay || exit 0

# It is not safe to start if we don't have a default configuration...
if [ ! -f /etc/default/dhcp-relay ]; then
	echo "/etc/default/dhcp-relay does not exist! - Aborting..."
	exit 0
fi

# Read init script configuration (interfaces the daemon should listen on
# and the DHCP server we should forward requests to.)
. /etc/default/dhcp-relay

if [ "$DHCP_SERVERS" = "" ]; then
	echo "No DHCP servers configured! Edit /etc/default/dhcp-relay."
	exit 0
fi

# Build command line for interfaces (will be passed to dhrelay below.)
IFCMD=""
if test "$INTERFACES" != ""; then
	for I in $INTERFACES; do
		IFCMD=${IFCMD}"-i "${I}" "
	done
fi

DHCRELAYPID=/var/run/dhcrelay.pid

case "$1" in
	start)
		start-stop-daemon --start --quiet --pidfile $DHCRELAYPID \
			--exec /usr/sbin/dhcrelay -- -q $OPTIONS $IFCMD \
			$DHCP_SERVERS
		;;
	stop)
		start-stop-daemon --stop --quiet --pidfile $DHCRELAYPID
		;;
	restart | force-reload)
		$0 stop
		sleep 2
		$0 start
		;;
	*)
		echo "Usage: /etc/init.d/dhcp-relay {start|stop|restart|force-reload}"
		exit 1 
esac

exit 0
