#!/bin/sh

# Source debconf library.
. /usr/share/debconf/confmodule


# Linux Mint 13 Maya
if [ $(grep 'packages.linuxmint.com' /etc/apt/sources.list | grep -c maya) -eq 1 ]
then
	rm /etc/init/m23-xorg-configurator*
else
	# Linux Mint 17 Qiana
	if [ $(grep 'packages.linuxmint.com' /etc/apt/sources.list | grep -c qiana) -gt 0 ] || [ $(grep -c 'Xenial' /etc/issue) -gt 0 ]
	then
		# Remove sysvinit files
		find /etc/rc* | grep hwcheck$ | xargs rm 2> /dev/null
	else
		#Check, if the system uses upstart (Ubuntu)
		if [ `dpkg --get-selections | grep upstart | grep -c -v deinstall` -gt 0 ]
		then
			find /etc/rc* | grep hwcheck$ | xargs rm 2> /dev/null
			find /etc/rc* | grep m23-xorg-configurator$ | xargs rm 2> /dev/null
		fi
	fi
fi

if [ $(lsb_release -c -s) = 'xenial' ]
then
	# Remove upstart files
	rm /etc/init/m23*

	find /etc/rc* | grep m23-xorg-configurator$ | xargs rm 2> /dev/null

	# Use a special version for xenial
	mv /tmp/m23-xorg-configurator-xenial /etc/init.d/m23-xorg-configurator

	# Make sure the sysVinit files are created in the correct runlevels
	update-rc.d m23-xorg-configurator defaults
	systemctl enable m23-xorg-configurator
fi

db_stop
