#!/bin/sh
#
# Startup script for dansguardian
#
# chkconfig: 35 92 8
# description: A web content filtering plugin for web \
#              proxies, developed to filter using lists of \
#              banned phrases, MIME types, filename \
#              extensions and PICS labling.
# processname: dansguardian
# pidfile: /var/run/dansguardian.pid
# config: /etc/dansguardian/dansguardian.conf

CONFFILELOCATION=/etc/dansguardian/
BINARYLOCATION=/usr/sbin/
PIDDIR=/var/run/


# See how we were called.

case "$1" in
start)
        if [ -f ${BINARYLOCATION}dansguardian ] &&
           [ -f ${CONFFILELOCATION}dansguardian.conf ]; then
                echo -n "Starting dansguardian: "
                if ${BINARYLOCATION}dansguardian 2> /dev/null; then
                        echo -e "\\033[60G\c"
                        echo -e "[ \\033[1;32m\c"
                        echo -e "OK\c"
                        echo -e "\\033[0;39m\c"
                        echo " ]"
                        [ -d /var/lock/subsys ] && touch /var/lock/subsys/dansguardian
                else
                        echo -e "\\033[60G\c"
                        echo -e "[ \\033[1;31m\c"
                        echo -e "FAILED\c"
                        echo -e "\\033[0;39m\c"
                        echo " ]"
                fi
        fi
        ;;
stop)
        echo -n "Shutting down dansguardian: "
        if ${BINARYLOCATION}dansguardian -q 2> /dev/null; then
                echo -e "\\033[60G\c"
                echo -e "[ \\033[1;32m\c"
                echo -e "OK\c"
                echo -e "\\033[0;39m\c"
                echo " ]"
                /bin/rm -f ${PIDDIR}dansguardian.pid
                /bin/rm -f /tmp/.dguardianipc
                [ -d /var/lock/subsys ] && /bin/rm -f /var/lock/subsys/dansguardian
        else
                echo -e "\\033[60G\c"
                echo -e "[ \\033[1;31m\c"
                echo -e "FAILED\c"
                echo -e "\\033[0;39m\c"
                echo " ]"
        fi
        ;;
restart)
        $0 stop
        $0 start
        ;;
status)
        if [ -f ${BINARYLOCATION}dansguardian ]; then
                ${BINARYLOCATION}dansguardian -s
        fi
        ;;
        
*)

        echo "Usage: $0 {start|stop|restart|status}" >&2
        ;;
esac

exit 0
