#!/bin/bash
#
#	/etc/init.d/acpid
#
# Starts the upnp daemon
#
# chkconfig: - 99 1 
# description: UPnP daemon
# processname: upnpd

test -e /etc/sysconfig/UPnP || exit 0

# Source function library.
. /etc/init.d/functions

# Load config.
. /etc/sysconfig/UPnP

DAEMON=UPnP
PROGNAME=upnpd

RETVAL=0

#
# See how we were called.
#

start() {
	# Check if it is already running
	if [ ! -f /var/lock/subsys/$PROGNAME ]; then
	    echo -n "Starting $DAEMON daemon: "
	    /sbin/route add -net 239.0.0.0 netmask 255.0.0.0 $INSIDE
	    daemon /usr/bin/$PROGNAME $OUTSIDE $INSIDE
	    RETVAL=$?
	    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$PROGNAME
	    echo
	fi
	return $RETVAL
}

stop() {
	echo -n "Stopping $DAEMON daemon: "
	killproc /usr/sbin/$PROGNAME
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$PROGNAME
	/sbin/route del -net 239.0.0.0 netmask 255.0.0.0 $INSIDE
	echo
        return $RETVAL
}


restart() {
	stop
	start
}	

case "$1" in
start)
	start
	;;
stop)
	stop
	;;
restart)
	restart
	;;
condrestart)
	if [ -f /var/lock/subsys/$PROGNAME ]; then
	    restart
	fi
	;;
status)
	status $PROGNAME
	;;
*)
	INITNAME=`basename $0`
	echo "Usage: $INITNAME {start|stop|restart|condrestart|status}"
	exit 1
esac

exit $RETVAL
