#! /bin/sh
# postinst script for ghc6
#
# SOURCE: ghc6.postinst.in
set -e

execdir=/usr/bin
libdir=/usr/lib/ghc-@VERSION@
bindir=/usr/lib/bin
mandir=/usr/share/man
vardir=/var/lib/ghc-@VERSION@

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see /usr/doc/packaging-manual/
#
# quoting from the policy:
#     Any necessary prompting should almost always be confined to the
#     post-installation script, and should be protected with a conditional
#     so that unnecessary prompting doesn't happen if a package's
#     installation fails and the `postinst' is called with `abort-upgrade',
#     `abort-remove' or `abort-deconfigure'.

if /usr/bin/ghc --info | grep -q '"Have interpreter","YES"' ; then
    NEED_INTERPRETER="\
            --slave $execdir/runghc runghc $bindir/runghc \
            --slave $execdir/ghci ghci $bindir/ghci \
            --slave $mandir/man1/ghci.1.gz ghci.1.gz $mandir/man1/ghc6.1.gz \
            --slave $mandir/man1/runghc.1.gz runghc.1.gz $mandir/man1/runghc6.1.gz"
fi

case "$1" in
    configure|abort-upgrade|abort-remove|abort-deconfigure)
	if [ -n "$NEED_INTERPRETER" ] ; then
            update-alternatives \
		--install $execdir/runhaskell runhaskell $execdir/runghc6 8600000600 \
		--slave $mandir/man1/runhaskell.1.gz runhaskell.1.gz $mandir/man1/runghc6.1.gz
	fi
        update-alternatives \
            --install $execdir/haskell-compiler haskell-compiler $execdir/ghc6 600 \
            --slave $mandir/man1/haskell-compiler.1.gz haskell-compiler.1.gz $mandir/man1/ghc6.1.gz
        update-alternatives \
            --install $execdir/ghc ghc $bindir/ghc 600 \
            --slave $execdir/ghc-pkg ghc-pkg $bindir/ghc-pkg \
            --slave $execdir/hsc2hs hsc2hs $bindir/hsc2hs \
            --slave $execdir/hp2ps hp2ps $bindir/hp2ps \
            --slave $execdir/hpc hpc $bindir/hpc \
            --slave $mandir/man1/hp2ps.1.gz hp2ps.1.gz $mandir/man1/hp2ps-ghc6.1.gz \
            --slave $mandir/man1/ghc.1.gz ghc.1.gz $mandir/man1/ghc6.1.gz \
	    --slave $mandir/man1/ghc-pkg.1.gz ghc-pkg.1.gz $mandir/man1/ghc-pkg6.1.gz \
            --slave $execdir/hasktags hasktags $bindir/hasktags $NEED_INTERPRETER; \
	ghc-pkg recache
    ;;
    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 0
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
