#!/bin/sh

[ -z "$DURING_INSTALL" ] || exit 0
[ -z "$FAKEROOTKEY" ] || exit 0

lockdir=/var/lock/makewhatis/lockdir

exit_handler()
{
        local rc=$?
        trap - EXIT
        rm -rf -- "$lockdir"
        exit $rc
}

pidfile="$lockdir/pid"
if ! mkdir -m700 -- "$lockdir"; then
        [ ! -s "$pidfile" ] ||
                echo "makewhatis is already running, pid=`cat "$pidfile"`"
	exit 1
fi

trap exit_handler SIGHUP SIGPIPE SIGINT SIGQUIT SIGTERM EXIT

echo $$ >"$pidfile"

su -l cacheman -s /bin/sh -c '/usr/sbin/makewhatis -u'
