#! /bin/sh
# postrm script fglrx
#
# see: dh_installdeb(1)
#
# Copyright (C) 2007 Mario Limonciello
# Copyright (C) 2009-2011 Canonical Ltd.

set -e

# summary of how this script can be called:
#        * <postrm> `remove'
#        * <postrm> `purge'
#        * <old-postrm> `upgrade' <new-version>
#        * <new-postrm> `failed-upgrade' <old-version>
#        * <new-postrm> `abort-install'
#        * <new-postrm> `abort-install' <old-version>
#        * <new-postrm> `abort-upgrade' <old-version>
#        * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
# for details, see /usr/share/doc/packaging-manual/

PKGNAME=#DRIVERNAME#
BLACKLIST_FILE=/etc/modprobe.d/blacklist-fglrx.conf
COMMON_FILE=/usr/lib/fglrx/dri/fglrx_dri.so

case "$1" in
    remove)
        # NOTE: Only remove the blacklist if no other fglrx package
        #is installed.
        if [ ! -e $COMMON_FILE ]; then
            # Remove blacklist file
            rm -f $BLACKLIST_FILE
        fi

        # This will preserve the etc directory
        rm -f /#PKGLIBDIR#/*  2>/dev/null || true
        rm -Rf /#PKGLIBDIR32#
        rm -Rf /#PXDIR#
        rm -Rf /#PXDIR32#

        # Update initramfs, in case we were loaded into it
        /usr/sbin/update-initramfs -u
        ;;

    purge)
        # NOTE: Only purge if no other fglrx package is installed.
        if [ ! -e $COMMON_FILE ]; then
            rm -Rf /#PKGLIBDIR#

            # NOTE: Usually generated by dh_installinit, but because two
            # packages are providing the same initscript, this needs some
            # manual handling.
            update-rc.d atieventsd remove >/dev/null
        fi
        ;;

    upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
        ;;

    *)
        echo "postrm called with unknown argument \`$1'" >&2
        exit 0

esac

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

#DEBHELPER#
