#!/bin/sh

set -e

multiarch=@multiarch@
old_basedir=/usr/lib/jvm/java-6-openjdk
old_base7dir=/usr/lib/jvm/java-7-openjdk
tools='javaws itweb-settings'

case "$1" in
    upgrade)
        if [ -n "$multiarch" ] && [ -n "$2" ]; then
            for i in $tools; do
                if [ -n "$(update-alternatives --list $i 2>/dev/null | grep ^$old_basedir/)" ]; then
                    update-alternatives --remove $i $old_basedir/jre/bin/$i || true
                fi
            done
            for i in $tools; do
                if [ -n "$(update-alternatives --list $i 2>/dev/null | grep ^$old_base7dir/)" ]; then
                    update-alternatives --remove $i $old_base7dir/jre/bin/$i || true
                fi
            done
        fi
        ;;
esac

#DEBHELPER#

exit 0
