#! /bin/sh

if qcommand -t; then
	watchdog="no"
	if [ -e /proc/device-tree/model ]; then
		device=$(cat /proc/device-tree/model)
	else
		device=$(grep "Hardware[[:space:]]*:" /proc/cpuinfo 2>/dev/null | \
			 head -n1 | sed "s/^[^:]*: //")
	fi
	case $device in
	    "QNAP TS-109/TS-209")
		mv /etc/qcontrol/ts209.lua /etc/qcontrol.conf ;;
	    "QNAP TS-119/TS-219" | "QNAP TS219 family")
		watchdog="yes"
		mv /etc/qcontrol/ts219.lua /etc/qcontrol.conf ;;
	    "QNAP TS-409")
		mv /etc/qcontrol/ts409.lua /etc/qcontrol.conf ;;
	    "QNAP TS-41x" | "QNAP TS419 family")
		watchdog="yes"
		mv /etc/qcontrol/ts41x.lua /etc/qcontrol.conf ;;
	esac
	rm -rf /etc/qcontrol/

	modprobe -q gpio_keys >/dev/null 2>&1
	sleep 1

	if [ X"$watchdog" = X"yes" ]; then
		qcommand watchdog off
	fi

	qcommand powerled on
	qcommand statusled green1hz
fi
