#!/bin/sh
#
# bcfg2 - bcfg2 configuration client
#
# chkconfig: 345 80 20
# description: bcfg2 is a configuration management system that builds \
#              and installs configuration files served by bcfg2-server. \
#              This is a client that installs the server-provided \
#              configuration.
#

DAEMON=/usr/sbin/bcfg2
PIDFILE=/var/run/bcfg2-agent.pid
prog=$(basename $DAEMON)

# Set default options
#    You can set script specific options with BCFG2_OPTIONS_INIT
PARAMS="-q"
#    Disabled per default
BCFG2_ENABLED=0
BCFG2_INIT=0
BCFG2_AGENT=0

PATH=/sbin:/bin:/usr/bin:/usr/sbin

# Source function library
. /etc/init.d/functions

# Include default startup configuration if exists
test -f /etc/sysconfig/$prog && . /etc/sysconfig/$prog

[ "$BCFG2_ENABLED" -eq 0 ] && exit 0
[ "$BCFG2_INIT" -eq 0 ] && exit 0

if [ "$BCFG2_AGENT" != 0 ]; then
    echo "Bcfg2 no longer supports agent mode, please update your configuration!"
    exit 1
fi

RETVAL=0

start () {
    test -x $DAEMON || exit 5
    echo -n $"Starting $prog: "
    if test $BCFG2_INIT = 1 ; then
        $DAEMON $PARAMS ${BCFG2_OPTIONS_INIT} && success || failure
        RETVAL=$?
        echo
    fi

    return $RETVAL
}

case "$1" in
    start)
        start
        RETVAL=$?
        ;;
    stop|status)
        RETVAL=0
        ;;
    restart|force-reload)
	start
        RETVAL=$?
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart|force-reload}"
        RETVAL=3
esac

exit $RETVAL
