#!/bin/sh
set -e

available()
{
	command -v "$1" >/dev/null 2>&1
}

finalize_desktop()
{
	# Menu entries
	if available update-desktop-database
	then
		update-desktop-database /usr/share/applications
	fi
	if available update-menus
	then
		update-menus
	fi
	if available update-app-install
	then
		update-app-install
	fi
	if available update-software-center
	then
		update-software-center
	fi

	# MIME associations
	if available update-mime-database
	then
		update-mime-database /usr/share/mime
	fi

	# Icons
	touch -c /usr/share/icons/hicolor
	if available update-icon-caches
	then
		update-icon-caches -tq /usr/share/icons/hicolor
	elif available gtk-update-icon-cache
	then
		gtk-update-icon-cache -tq /usr/share/icons/hicolor
	fi
}

. /usr/share/debconf/confmodule

case "$1" in
	remove)
		finalize_desktop
		;;
    purge)
		db_get opera/add-deb-source
		if $RET
		then
			# We have added this on installation
			rm -f /etc/apt/sources.list.d/opera.list
			if available apt-key
			then
				! apt-key del 6A423791 >/dev/null 2>&1
				! apt-key del 9D1A0061 >/dev/null 2>&1
			fi
		fi
		db_purge
		;;
esac

exit 0
