#!/bin/sh
[ -f /etc/bluedsl.conf ] && . /etc/bluedsl.conf
. /etc/autoconf.conf

case $1 in
    start)
	if [ ! "$ENABLE_PRINT_SERVER" = "1" ] ; then
	    echo "Printserver not starting : \$ENABLE_PRINT_SERVER = $ENABLE_PRINT_SERVER"
	    exit 0
	fi
        echo "Starting print_server"
        rmmod printer
        modprobe printer.o
        rm -f /var/run/printer0
        if [ ! -z "$CONFIG_LPDSRV" ]; then
            lpdsrv -f lp:/dev/usb/lp0 -o /dev/usb/lp0
        fi
        if [ ! -z "$CONFIG_P910ND" ]; then
            if [ -f "/var/run/p9100d.pid" ] ; then
               echo "Already launched"
               exit 1
            fi
            mkdir -p /var/lock
            p910nd -f /dev/usb/lp0 -b 0 &
        fi
         
         
	;;
    stop)    
         if [ ! -z "$CONFIG_P910ND" ]; then
                pid_file="/var/run/p9100d.pid"
                if [-f $pid_file ]; then
                  kill $(cat $pid_file)
                  rm -f $pid_file
                else
                  killall p9100d
                fi
         fi
    	if [ ! -z "$CONFIG_LPDSRV" ]; then
		kill $(cat "/var/run/lpdsrv.pid")
		rm -f "/var/run/lpdsrv.pid"	 
	fi;
        rm -f /var/run/printer0
	;;
    status)
	[ ! -z "$CONFIG_LPDSRV" ] && lpdsrv -status
	;;
    *)
	echo "do nothing"
	;;
esac



