#! /bin/sh
set -e

if [ ! -e /etc/qcontrol.conf ]; then
	device=$(grep "Hardware[[:space:]]*:" /proc/cpuinfo 2>/dev/null | \
		 head -n1 | sed "s/^[^:]*: //")
	case $device in
	    "QNAP TS-109/TS-209")
		ln -s qcontrol/ts209.lua /etc/qcontrol.conf ;;
	    "QNAP TS-119/TS-219")
		ln -s qcontrol/ts219.lua /etc/qcontrol.conf ;;
	    "QNAP TS-409")
		ln -s qcontrol/ts409.lua /etc/qcontrol.conf ;;
	    "QNAP TS-41x")
		ln -s qcontrol/ts41x.lua /etc/qcontrol.conf ;;
	esac
fi

# Lenny stable update version included custom rules file
if [ -e /etc/udev/rules.d/z60-qcontrol.rules ]; then
	echo "Removing no longer needed udev rules file"
	rm /etc/udev/rules.d/z60-qcontrol.rules
fi

if dpkg-maintscript-helper supports rm_conffile; then
    dpkg-maintscript-helper rm_conffile \
        /etc/default/qcontrol 0.5.1-4~ qcontrol -- "$@"
fi

case "$1" in
    configure)
        if [ -x /usr/sbin/update-initramfs ]; then
            update-initramfs -u
        fi
    ;;
esac

#DEBHELPER#
