#!/bin/sh
# Last modification: Tue, 18 Nov 1997 20:58:50 +0200
# man postinst
#
# this script is executed after all the files in the package are
# installed: it builds the catman hierarchy and then the database.

set -e

oldcatdir="/var/catman"
catdir="/var/cache/man"

# Permission processing inserted by hand, don't rely on debstd :-(
# moved on top because later progs will be running.
if [ -x "$(which suidregister)" -a -e /etc/suid.conf ]
then
	suidregister -s man-db	/usr/bin/man	man root 4755
	suidregister -s man-db	/usr/bin/mandb	man root 4755
else
	chown man.root	/usr/bin/man /usr/bin/mandb
	chmod	4755	/usr/bin/man /usr/bin/mandb
fi

if	[ ! -e /usr/bin/pager ]
then	if	[ -x /bin/more ]
	then	ln -sf /bin/more /usr/sbin/man-pager
		update-alternatives --install /usr/bin/pager pager /usr/sbin/man-pager 1
	else	echo "  ============================"
		echo "  /usr/bin/pager not found ..."
		echo "  please upgrade your preferred pager"
		echo "  or util-linux at least."
		echo "  ============================"
	fi
fi

# removing all catpages hierarchy
if	[ -d $oldcatdir ]
then	echo "  Removing catpages as well as $oldcatdir hierarchy."
	rm -rf $oldcatdir 2>/dev/null || true
fi
if	[ -d $catdir ]
then	echo "  Removing catpages as well as $catdir hierarchy."
	rm -rf $catdir 2>/dev/null || true
fi

install -d -g root -m 02755 -o man $catdir

if	[ -x "$(which mandb)" ]
then	echo "  Building manual page index in background."
	nice mandb -c 2>/dev/null > /dev/null &
fi

test -x "$(which update-menus)" && update-menus || true

