# Handle the incoming configuration files:
config() {
  NEW="$1"
  OLD="`dirname $NEW`/`basename $NEW .new`"
  # If there's no config file by that name, mv it over:
  if [ ! -r $OLD ]; then
    mv $NEW $OLD
  elif [ "`cat $OLD | md5sum`" = "`cat $NEW | md5sum`" ]; then # toss the redundant copy
    rm $NEW
  fi
  # Otherwise, we leave the .new copy for the admin to consider...
}

# Check for ossec accounts here
if ! grep ^ossec: /etc/group 2>&1 > /dev/null; then
  groupadd -g 302 ossec
fi
if ! grep ^ossec: /etc/passwd 2>&1 > /dev/null; then
  useradd -d /var/ossec -s /bin/false -u 302 -g 302 -c "Ossec" ossec
  passwd -l ossec &>/dev/null
fi
if ! grep ^ossecm: /etc/passwd 2>&1 > /dev/null; then
  useradd -d /var/ossec -s /bin/false -u 303 -g 302 -c "Ossec" ossecm
  passwd -l ossecm &>/dev/null
fi
if ! grep ^ossecr: /etc/passwd 2>&1 > /dev/null; then
  useradd -d /var/ossec -s /bin/false -u 304 -g 302 -c "Ossec" ossecr
  passwd -l ossecr &>/dev/null
fi

config etc/rc.d/rc.ossec.new
config var/ossec/etc/ossec.conf.new
config var/ossec/etc/internal_options.conf.new
config var/ossec/etc/local_decoder.xml.new
config var/ossec/rules/local_rules.xml.new

# vim:set ts=2 sw=2 et:
