UpdateIconCache()
{
	if [ -f /usr/bin/gtk-update-icon-cache ]
	then
		echo -n "updating hicolor icon cache..."
		if gtk-update-icon-cache -f -t /usr/share/icons/hicolor > /dev/null 2>&1 ; then
			echo " done."
		else
			echo " failed."
		fi
	fi
	if [ -f /usr/bin/gtk-update-icon-cache-3.0 ]
	then
		echo -n "updating hicolor icon cache gtk+3..."
		if gtk-update-icon-cache-3.0 -f -t /usr/share/icons/hicolor > /dev/null 2>&1 ; then
			echo " done."
		else
			echo " failed."
		fi
	fi
}

post_install()
{
	/usr/sbin/useradd -M -u 42 -d /var/lib/gdm -s /sbin/nologin -r gdm > /dev/null 2>&1
	/usr/sbin/usermod -d /var/lib/gdm -s /sbin/nologin gdm >/dev/null 2>&1
	# ignore errors, as we can't disambiguate between gdm already existe

	chown -R gdm:gdm /var/lib/gdm &> /dev/null
	chown root:gdm /var/log/gdm &> /dev/null
	echo -n "updating scrollkeeper catalogue... "
	rarian-sk-update -q > /dev/null 2>&1
	echo "done."
	
	UpdateIconCache
	glib-compile-schemas /usr/share/glib-2.0/schemas &>/dev/null
	dconf update

	if [ ! -h /etc/systemd/system/display-manager.service ]; then
		systemctl enable gdm.service
	fi
}

post_upgrade()
{
	post_install

	systemctl daemon-reload >/dev/null 2>&1
}


pre_remove()
{
	systemctl --no-reload disable gdm.service >/dev/null 2>&1
}

post_remove()
{
	echo -n "updating scrollkeeper catalogue... "
	rarian-sk-update -q > /dev/null 2>&1
	echo "done."
	dconf update
	UpdateIconCache
	systemctl daemon-reload >/dev/null 2>&1
}

op=$1
shift

$op $*

# vim: ft=sh
