#!/bin/sh
#
# Author: Jochen Schaefer, Stephan Dühr, Jörg Steffens
#
### BEGIN INIT INFO
# Provides: sc_password_generator
# Required-Start: $remote_fs network
# Should-Start: ldap
# Required-Stop: $remote_fs
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Description: generates one-time LDAP passwords for SmartClients
### END INIT INFO

# source config files
. /etc/smartclient/base
. /etc/smartclient/password_generator

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
test -x $PASSWORD_DAEMON || { echo "$PASSWORD_DAEMON not installed"; 
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }

# source status functions
. /etc/rc.status

# Reset status of this service
rc_reset


case "$1" in
    start)
        echo -n "Starting SmartClient password_generator "
	/sbin/startproc $PASSWORD_DAEMON $PASSWORD_DAEMON_OPTIONS

	# Remember status and be verbose
	rc_status -v
        ;;
    stop)
 	echo -n "Shutting down SmartClient password_generator "

        killproc -TERM $PASSWORD_DAEMON

	# Remember status and be verbose
	rc_status -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
        ;;
    status)
	echo -n "Checking for service SmartClient password_generator  "
	## Check status with checkproc(8), if process is running
	## checkproc will return with exit status 0.

	# NOTE: checkproc returns LSB compliant status values.
	checkproc $PASSWORD_DAEMON
	# NOTE: rc_status knows that we called this init script with
	# "status" option and adapts its messages accordingly.
	rc_status -v
	;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
esac
rc_exit
