#!/bin/bash
#

OUT=/etc/netsaint/plugins-auto.cfg
cat >$OUT <<EOT
# This file was autogenerated on `date` and
# should not be manually altered. Use update-netsaint to
# build this file. If you need to add a command specification, edit
# /etc/netsaint/command.cfg
# If you need to change the configuration of a command, it's better
# to look in /usr/share/netsaint/pluginconfig/*.cfg and copy the command
# to /etc/netsaint/command.cfg and give it a new name.
#

EOT

# Either
for f in /usr/share/netsaint/pluginconfig/*.cfg ; do
  if [ -f $f ] ; then # to avoid getting * literally if no match
    echo "# Included from $f" >>$OUT
    cat $f >>$OUT
    echo >>$OUT
  fi
done

if [ ! -s /etc/netsaint/command.cfg ]; then
    echo "Created an empty command.cfg file, because no plugin configs"
    echo "found in /usr/share/netsaint/pluginconfig. Won't reload netsaint."
    exit 0
else
    if [ "$1" != "--no-reload" ] ; then
	/etc/init.d/netsaint reload
    fi
fi
