#! /bin/sh
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>
# and Axel Beckert <abe@deuxchevaux.org>.
#
### BEGIN INIT INFO
# Provides:          udhcpd
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start busybox udhcpd at boot time
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/udhcpd
NAME=udhcpd
DESC="very small Busybox based DHCP server"
DHCPD_OPTS="-S" # Additional options given to the server

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

# Include defaults if available
if [ -f /etc/default/udhcpd ] ; then
	. /etc/default/udhcpd
fi

if [ "$DHCPD_ENABLED" = "no" ]; then
    echo $NAME: Disabled. Edit /etc/default/udhcpd to enable it.
    exit 0;
fi

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "
	start-stop-daemon --start --verbose --pidfile /var/run/$NAME.pid \
		--oknodo --exec $DAEMON -- $DHCPD_OPTS
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --verbose --pidfile /var/run/$NAME.pid \
		--oknodo --exec $DAEMON
	echo "$NAME."
	;;
  restart|force-reload)
	$0 stop
	sleep 1
	$0 start	
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
