#! /bin/sh
# Pre-install script for ‘comixcursors’.
#
# Manpage: ‘dh_installdeb(1)’

set -e

# Summary of ways this script can be called:
#        * <new-preinst> ‘install’
#        * <new-preinst> ‘install’ <old-version>
#        * <new-preinst> ‘upgrade’ <old-version>
#        * <old-preinst> ‘abort-upgrade’ <new-version>
# For details, see <URL:http://www.debian.org/doc/debian-policy/> or
# the ‘debian-policy’ package.

REMOVED_LIST="ComixCursors-Christmas.theme"
ICONDIR=/etc/X11/cursors

remove_omitted_alternatives () {
    # Remove themes installed by previous versions but omitted
    # from this version of the package.

    if ! update-alternatives --quiet --list x-cursor-theme ; then
        # No alternatives installed for ‘x-cursor-theme’, so we're
        # done. We need to test this explicitly to avoid exiting with
        # an error when listing the alternatives.
        return
    fi

    installed_cursor_themes=`update-alternatives --list x-cursor-theme`
    for theme in $REMOVED_LIST ; do
        if echo "$installed_cursor_themes" | grep -q $theme ; then
            update-alternatives --remove $ICONDIR/$theme
            rm -f $ICONDIR/$theme
        fi
    done
}

case "$1" in
    upgrade)
        remove_omitted_alternatives
        ;;

    install|abort-upgrade)
        ;;

    *)
        printf "preinst called with unknown argument ‘%s’\n" "$1" >&2
        exit 1
        ;;

esac
rm -f $ICONDIR/ComixCursors-Christmas.theme

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

#DEBHELPER#

exit 0
