#! /bin/sh
# Copyright (c) 1995-2002 SuSE Linux AG, Nuernberg, Germany.
# All rights reserved.
#
# Author: Holger Mueller <feedback@suse.de>
#
# /etc/init.d/sc_leases2ldap
#
#   and symbolic its link
#
# /(usr/)sbin/rcsc_leases2ldap
#
# LSB compliant service control script; see http://www.linuxbase.org/spec/
# 
# System startup script for leases2ldap
#
### BEGIN INIT INFO
# Provides: sc_leases2ldap
# Required-Start: $remote_fs network $named $syslog $dhcpd
# Required-Stop:  $remote_fs network $named $syslog $dhcpd
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description: insert new workstation into ldap
#	 starts ldap2dns and ldap2dhcp periodically
### END INIT INFO

test -r /etc/smartclient/leases2ldap && . /etc/smartclient/leases2ldap

# Shell functions sourced from /etc/rc.status
. /etc/rc.status

# First reset status of this service
rc_reset

case "$1" in
    start)
        echo -n "Starting leases2ldap "

        if [ -r $LEASES2LDAP_SSH_AGENT ];  then
            echo -n "warning: ssh-agent/leases2ldap seems to run" >&2
        fi

        echo $(ssh-agent -s) > $LEASES2LDAP_SSH_AGENT
        . $LEASES2LDAP_SSH_AGENT > $LEASES2LDAP_LOGFILE
        for private_key in /root/.ssh/id_dsa /root/.ssh/id_rsa; do
            if [ -r ${private_key} ]; then
                ssh-add ${private_key}
            fi
        done
        
        startproc -n $LEASES2LDAP_NICE -l $LEASES2LDAP_LOGFILE $LEASES2LDAP_BIN
        rc_status -v
        ;;
    stop)
        echo -n "Shutting down leases2ldap "
        killproc $LEASES2LDAP_BIN
        rc_status

        if [ -r $LEASES2LDAP_SSH_AGENT ]; then
            . $LEASES2LDAP_SSH_AGENT > $LEASES2LDAP_LOGFILE
            ssh-agent -k > /dev/null
            rm -f $LEASES2LDAP_SSH_AGENT
        fi
        
        rc_status -v
    	;;
    restart)
        $0 stop
        $0 start
        rc_status
        ;;
    status)
        echo -n "Checking for leases2ldap "
        checkproc $LEASES2LDAP_BIN
        rc_status -v
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
        ;;
esac
rc_exit
