#!/bin/sh
# postinst script for mog
#
# see: dh_installdeb(1)

set -e

# 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>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
    configure)
        ## first time install, no need for warnings
        [ -z "$2" ] && continue

        ## get SVN version number from old install
        oldsvn=`echo "$2" | awk -F"-" '{print $2}' | sed "s/[^0-9]//g"`
        echo "Previous version: \"$oldsvn\""

        ## give warning if svn version number is not known or less than this version (1305)
        if [ -n "$2" -a -z "$oldsvn" ] || [ "$oldsvn" -lt 1305 ]; then
            ## find either zenity (Gnome) or kdialog (KDE)
            ZENITY=`whereis -b zenity | awk '{print $2}'`
            KDIALOG=`whereis -b kdialog | awk '{print $2}'`

            ## messagebox information
            TITLE="Maze of Galious 0.63"
            MSG="Please remove your old configuration file from\n\n     \$HOME/.mog/MoG.cfg\n\nor the game might crash during startup.\n\n(removing your old configuration file will start\nthe game with all default values)"

            ## show nice messagebox
            if [ -n "$ZENITY" ]; then
                $ZENITY --title "$TITLE" --warning --text "$MSG"
            elif [ -n "$KDIALOG" ]; then
                $KDIALOG --title "$TITLE" --msgbox "$MSG"
            else
                echo "**************************************************"
                echo
                echo "  PLEASE REMOVE ANY OLD \$HOME/.mog/MoG.cfg FILE  "
                echo
                echo "         (your game might crash otherwise!)       "
                echo
                echo "**************************************************"
            fi
        fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

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

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



exit 0


