#! /bin/sh -e
#
# postinst script for the Debian @PVER@-base package.
# Written 1998 by Gregor Hoffleit <flight@debian.org>.
#

PACKAGE=`basename $0 .postinst`
DIRLIST="@SCRIPTDIR@"

# remove unconditionally
update-alternatives --remove python /usr/bin/python@VER@ || true

case "$1" in
    configure|abort-upgrade|abort-remove|abort-deconfigure)

        for i in $DIRLIST ; do
	    if [ "$DEBIAN_FRONTEND" != noninteractive ]; then
		echo "Compiling python modules in $i ..."
	    fi
            /usr/bin/python@VER@ @SCRIPTDIR@/compileall.py -q $i
	    if [ "$DEBIAN_FRONTEND" != noninteractive ]; then
		echo "Compiling optimized python modules in $i ..."
	    fi
            /usr/bin/python@VER@ -O @SCRIPTDIR@/compileall.py -q $i
        done

        # Create empty directories in /usr/local
        if [ ! -e /usr/local/lib/python@VER@ ]; then
            mkdir -p /usr/local/lib/python@VER@ 2> /dev/null || true
            chmod 2775 /usr/local/lib/python@VER@ 2> /dev/null || true
            chown root:staff /usr/local/lib/python@VER@ 2> /dev/null || true
        fi
        if [ ! -e /usr/local/lib/python@VER@/site-packages ]; then
            mkdir -p /usr/local/lib/python@VER@/site-packages 2> /dev/null || true
            chmod 2775 /usr/local/lib/python@VER@/site-packages 2> /dev/null || true
            chown root:staff /usr/local/lib/python@VER@/site-packages 2> /dev/null || true
        fi

	# Install a symlink for /usr/doc/@PVER@
        ##if [ -d /usr/doc -a ! -e /usr/doc/@PVER@ -a -d /usr/share/doc/@PVER@ ]; then
        ##    ln -sf ../share/doc/@PVER@ /usr/doc/@PVER@
        ##fi
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

if [ "$1" = "configure" ]; then
	ldconfig
fi

#DEBHELPER#


exit 0
