#!/bin/sh -e

. /usr/share/debconf/confmodule
test $DEBIAN_SCRIPT_DEBUG && set -v -x

# Check if Snort will be able to run properly
# Obviously, if you are using deprecated preprocessors (checked on config)
# it's not going to work either, but we do not test for that here.
#
# TODO: Maybe it's also best if we could tell dpkg that snort should
# not be started if this fails.
if [ -x /etc/init.d/snort ] ; then
    # Try to find if we are expecting the script to run
    enabled=0
    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
        set +e
        invoke-rc.d --query snort start
        if [ $? -ne 104 ] ; then
        # Disabled, or does not work, do not check the configuration
            enabled=1
        fi
        set -e
    fi
    if [ "$enabled" -eq 0 ] ; then
        set +e
        /etc/init.d/snort config-check >/dev/null 2>&1
        if [ $? -ne 0 ] ; then
            db_input critical snort/config_error || true
            db_go || true
        fi
        set -e
    fi
fi

db_stop

#DEBHELPER# 

exit 0
