#!/bin/sh
# vim: ts=4:sw=4:et
set -e

#DEBHELPER#

. /usr/share/debconf/confmodule

if [ "$1" != "configure" ] ; then 
    db_stop || true
    exit 0  
fi

INDEX_SCRIPT=/etc/cron.weekly/man2html

if [ -e /var/cache/man2html/ ] \
    && which index++ >/dev/null \
    && [ -x "$INDEX_SCRIPT" ] \
    && [ ! -e /var/cache/man2html/man2html.swish++.index ] \
    && [ ! -e /var/cache/man2html/man2html.swish++.index.tmp ]; then
    db_get man2html/index_manpages || true
    db_stop || true
    if [ "$RET" = "true" ]; then
        tf=`tempfile -p 'm2h-' -s '.swish++.out'`
        echo "Running $INDEX_SCRIPT in the background to index your manpages"
        echo "(redirected to $tf)."
        $INDEX_SCRIPT 2>&1 > "$tf" &
    fi
else
    db_stop || true
fi

exit 0
