#!/bin/sh
#
# Copyright (c) 2000 SuSE GmbH Nuernberg, Germany.
# All rights reserved.
#
# Author: Ralf Doppelstein  <ralf.doppelstein@suse.de>, 2001
#
# /etc/init.d/sc_ldap2lpadmin

### BEGIN INIT INFO
# Provides:          sc_ldap2lpadmin
# Required-Start:    cupsd sc_mkwsconfig
# Should-Start:      sc_rsyncDeltaImages
# Required-Stop:     $null
# Should-Stop:       $null
# Default-Start:     3 5
# Default-Stop:
# Description:       create printer queues from LDAP information
### END INIT INFO

SC_BIN=/usr/sbin/sc_ldap2lpadmin.pl

. /etc/rc.status
. /etc/smartclient/base

base=${0##*/}
link=${base#*[SK][0-9][0-9]}

# Reset status of this service
rc_reset
case "$1" in
    start)
        echo -n "Creating SmartClient printer queues "
        # cups needs some time to get accessable. wait for it.
        count=1
        while ! lpstat 2> /dev/null; do
            echo -n "."
            sleep 1
            count=$(expr $count + 1)
            if [ $count -gt 15 ]; then
                echo -n " cannot connect to server"
                rc_failed
                rc_exit
            fi
        done
        if ! /usr/bin/sc_check_net 2> $ALL_LOG_DIR/$base; then
            rc_status -s
            rc_exit
        fi
        $SC_BIN > $ALL_LOG_DIR/$base 2>&1
        rc_status -v
        ;;
    stop)
        ;;
    status)
        echo "Checking SmartClient printer configuration "
        lpstat -v
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac
rc_exit
