#!/bin/sh
#
# Author: Petter Reinholdtsen <pere@hungry.com>
# Date:   2001-11-25
#
# Run cfengine on config files in /etc/cfengine/debian-edu/.  Used by the
# Debian Edu project.

basedir=/etc/cfengine/debian-edu
masterhost=cfengine
if [ -x /usr/sbin/cfagent ] ; then 
  binary=/usr/sbin/cfagent
else
  binary=/usr/bin/cfengine
fi
flagfile=/etc/inittab.real

if [ ! -f $flagfile ] ; then
    touch $flagfile
    flagfilecreated=yes
fi

cd $basedir || exit 1

test -x $binary || exit 2

CFINPUTS="$basedir"
export CFINPUTS

# Extra sync, sleep and calling twice to work around
# problem with cfengine during installation.
sync; sleep 1
$binary -v -f cfengine.conf $@
sync; sleep 1
$binary -v -f cfengine.conf $@
sync

if [ "$flagfilecreated" = "yes" ] ; then
    rm $flagfile
fi
