#!/bin/sh
# Debconf Config Script for samhain
# 
# We do not do much here, just ask the admin if he wants to
# initialise the database if it does not exit and
# in this case, create it and warn that it takes a while.
#

set -e

# Let's use debconf.
. /usr/share/debconf/confmodule

# Suggest creating the integrity database if it does not exist
if [ ! -f /var/lib/samhain/samhain_file ] ; then
    db_input medium samhain/init-database || true
    db_go

    db_get samhain/init-database
    if [ "$RET" = "true" ]; then
        # Show note.
        db_input medium samhain/init-log || true
        db_go
        # echo "Creating integrity database (this can take some minutes)."
        samhain -t init >>/var/log/samhain/samhain-init.log 2>&1
        if [  ! -f /var/lib/samhain/samhain_file ] ; then
            echo "Database could not be created. Review the /var/log/samhain/samhain-init.log logfile to understand why. We will continue with package configuration but the samhain service will probably fail to start" >&2
        fi
    fi

fi

exit 0
