#!/bin/sh
# prerm script for fglrx
#
# Copyright (C) 2007 Mario Limonciello
# Copyright (C) 2009-2011 Canonical Ltd.

PACKAGE_NAME=#DRIVERNAME#
CVERSION=`dpkg-query -W -f='${Version}' $PACKAGE_NAME | awk -F "-" '{print $1}' | cut -d\: -f2`

remove_dkms_module() {
	echo "Removing all DKMS Modules"
	dkms remove -m $PACKAGE_NAME -v $CVERSION --all > /dev/null
	echo "Done."
}

case "$1" in
	upgrade)
		remove_dkms_module
	;;
	remove)
		remove_dkms_module

		update-alternatives --remove #DEB_HOST_MULTIARCH#_gl_conf /#LDSOCONF#
		update-alternatives --remove #OTHER_ARCH#_gl_conf /#ALTLDSOCONF#

		# Remove PXpress alternatives
		update-alternatives --remove #DEB_HOST_MULTIARCH#_gl_conf /#PXLDSOCONF#
		update-alternatives --remove #OTHER_ARCH#_gl_conf /#ALTPXLDSOCONF#

		# Trigger gmenu so as to update the gnome menu
		dpkg-trigger --by-package=$PACKAGE_NAME gmenucache || true

		# explicit ldconfig due to alternatives
		LDCONFIG_NOTRIGGER=y ldconfig

		# Update the grub gfxpayload blacklist
		if which update-grub-gfxpayload >/dev/null 2>&1; then
		    update-grub-gfxpayload
		fi
	;;
esac

#DEBHELPER#
