#!/bin/bash
#
# spook      This shell script takes care of starting and stopping
#            standalone spook.
#
# chkconfig: - 60 50
# description: spook is a live streaming daemon, which is the program \
#              that answers incoming streaming service requests.
# processname: spook
# config: /etc/spook.conf

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

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x /usr/local/bin/spook ] || exit 0

RETVAL=0
prog="spook"

start() {
        # Start daemons.

        if [ -f /etc/spook.conf ] ; then
                        echo $"Setting PX-TV402U: "
                        /usr/local/bin/gorecord -duration 6 -input 2 -mode ntsc-j -tvchan ntsc-bcast-jp:6 -bitrate 3000 -nowrite
                        echo
                        echo $"Starting $prog for $site: "
                        daemon /usr/local/bin/spook -c /etc/spook.conf &
                        RETVAL=$?
                        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
                        echo
        else
                RETVAL=1
        fi
        return $RETVAL
}

stop() {
        # Stop daemons.
        echo -n $"Shutting down $prog: "
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
        return $RETVAL
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|reload)
        stop
        start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f /var/lock/subsys/$prog ]; then
            stop
            start
            RETVAL=$?
        fi
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        exit 1
esac

exit $RETVAL