#!/bin/sh

set -e

if [ "$1" = "configure" ] || [ "$1" = "triggered" ] ||
   [ "$1" = "abort-upgrade" ]; then
    touch /usr/lib/xulrunner-##GRE_VERSION##/.autoreg
    rm -f /usr/lib/xulrunner-##GRE_VERSION##/components/compreg.dat \
          /usr/lib/xulrunner-##GRE_VERSION##/components/xpti.dat
    cd /usr/lib/xulrunner-##GRE_VERSION##
    export HOME=`mktemp -d`
    ./run-mozilla.sh ./xpcshell -e "" ||
    rm -f /usr/lib/xulrunner-##GRE_VERSION##/components/compreg.dat \
          /usr/lib/xulrunner-##GRE_VERSION##/components/xpti.dat
    rm -rf "$HOME"
fi

if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] ; then
    update-alternatives --install /usr/bin/xulrunner-stub \
        xulrunner-stub /usr/lib/xulrunner-##GRE_VERSION##/xulrunner-stub 100 \
        --slave /usr/share/man/man1/xulrunner-stub.1.gz xulrunner-stub.1.gz \
        /usr/share/man/man1/xulrunner-stub-##GRE_VERSION##.1.gz
fi

#DEBHELPER#

