#!/bin/sh
# postinst script for disable-jockey-fglrx
#
# 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)
        HANDLER=/usr/share/jockey/handlers/fglrx.py
        DIVERSION=${HANDLER}.orig
        
        # move jockey's fglrx handler out of the way on install
        dpkg-divert --package disable-jockey-fglrx --divert $DIVERSION --rename $HANDLER
        
        # take the jockey orig fglrx handler and patch it.
        cp $DIVERSION $HANDLER
        (cd /usr/share/jockey; patch -p1) <<ENDLINE
*** old/handlers/fglrx.py       2012-06-07 14:48:03.256436255 -0400
--- new/handlers/fglrx.py       2012-06-07 14:48:36.668601938 -0400
*************** class FglrxDriver(XorgDriverHandler):
*** 47,48 ****
--- 47,51 ----
      def available(self):
+         # Disable the driver
+         logging.debug('Disabling the fglrx driver')
+         return False
          # we don't offer fglrx in a life CD environment, as we will run out of
ENDLINE
        ;;

    abort-upgrade|abort-remove|abort-deconfigure)
        ;;
    
    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
        ;;
esac

exit 0
