--- qcontrol-0.4.2.orig/debian/TODO
+++ qcontrol-0.4.2/debian/TODO
@@ -0,0 +1,5 @@
+* Check for gpio_keys module on install; load it and add to /etc/modules
+* Update manpage
+* Update package description
+* File ITP
+* Add useful content to the udeb
--- qcontrol-0.4.2.orig/debian/qcontrol.prerm
+++ qcontrol-0.4.2/debian/qcontrol.prerm
@@ -0,0 +1,11 @@
+#! /bin/sh
+set -e
+
+# For downgrade to versions < 0.4.2
+if [ "$1" = upgrade ] && dpkg --compare-versions "$2" lt 0.4.2; then
+	rm -f /etc/qcontrol.conf
+	mv /etc/qcontrol/ts209.lua /etc/qcontrol.conf
+	rm -rf /etc/qcontrol/
+fi
+
+#DEBHELPER#
--- qcontrol-0.4.2.orig/debian/rules
+++ qcontrol-0.4.2/debian/rules
@@ -0,0 +1,85 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+PACKAGES        = $(shell dh_listpackages -s)
+UDEB_DIRS	= lib/debian-installer-startup.d \
+		  usr/lib/base-installer.d \
+		  usr/lib/finish-install.d
+
+configure: configure-stamp
+configure-stamp:
+	dh_testdir
+
+	touch configure-stamp
+
+
+build: build-arch build-indep
+build-arch: build-stamp
+build-indep: build-stamp
+build-stamp: configure-stamp 
+	dh_quilt_patch
+	dh_testdir
+
+	$(MAKE)
+
+	touch $@
+
+clean:
+	dh_testdir
+	dh_testroot
+	rm -f build-stamp configure-stamp
+
+	$(MAKE) clean
+	rm -f qcontrol.udeb
+
+	dh_quilt_unpatch
+	dh_clean 
+
+install: build
+	dh_testdir
+	dh_testroot
+	dh_clean -k 
+	dh_installdirs
+	dh_install
+
+	# Install the following "manually" as they need a rename
+	$(foreach PACKAGE, $(PACKAGES), \
+		install -m0644 debian/configs/* \
+			debian/$(PACKAGE)/etc/qcontrol; )
+	install -m0755 qcontrol.udeb \
+		debian/qcontrol-udeb/usr/sbin/qcontrol
+	# Install the following "manually" as they need permissions set
+	install -m0755 debian/udeb/qcommand \
+		debian/qcontrol-udeb/usr/sbin/
+	$(foreach UDEB_DIR, $(UDEB_DIRS), \
+		install -m0755 debian/udeb/$$(basename $(UDEB_DIR))/* \
+			debian/qcontrol-udeb/$(UDEB_DIR); )
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+	dh_testdir
+	dh_testroot
+	dh_installchangelogs 
+	dh_installdocs
+	dh_installinit --no-start --no-restart-on-upgrade --update-rcd-params="defaults 99 01"
+	dh_installman
+	dh_link
+	dh_strip
+	dh_compress
+	dh_fixperms
+	dh_installdeb
+	dh_shlibdeps
+	dh_gencontrol
+	dh_md5sums
+	dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
--- qcontrol-0.4.2.orig/debian/control
+++ qcontrol-0.4.2/debian/control
@@ -0,0 +1,35 @@
+Source: qcontrol
+Section: utils
+Priority: optional
+Maintainer: Debian QA Group <packages@qa.debian.org>
+Build-Depends: debhelper (>= 5), quilt (>= 0.46-7~), liblua5.1-0-dev
+Standards-Version: 3.9.2
+Vcs-Git: git://git.debian.org/collab-maint/qcontrol.git
+Vcs-Browser: http://git.debian.org/?p=collab-maint/qcontrol.git
+Homepage: http://qnap.nas-central.org/index.php/PIC_Control_Software
+
+Package: qcontrol
+Architecture: armel
+Depends: ${shlibs:Depends}, ${misc:Depends}, udev (>= 0.141-2)
+Description: hardware control for QNAP Turbo Station devices
+ Allows one to send commands to the microcontroller of supported devices,
+ for example to change leds or sound a buzzer.
+ .
+ Depending on the device it can also monitor for example for button
+ presses or temperature, with events triggering actions defined in the
+ configuration file.
+ .
+ Supported devices at this time are the QNAP TS-109, TS-110, TS-119,
+ TS-209, TS-210, TS-219, TS-219P, TS-409, TS-409U, TS-410, TS-410U,
+ TS-419P and TS-419U but the code is extensible so more devices may
+ be added in future releases.
+ .
+ Warning: the program is in alpha state, use at your own risk.
+
+Package: qcontrol-udeb
+Section: debian-installer
+Architecture: armel
+Depends: ${shlibs:Depends}, ${misc:Depends}, udev-udeb (>= 0.141-2), event-modules
+XC-Package-Type: udeb
+Description: hardware control for QNAP Turbo Station devices
+ Allows one to change status leds or sound the buzzer of supported devices.
--- qcontrol-0.4.2.orig/debian/qcontrol.postinst
+++ qcontrol-0.4.2/debian/qcontrol.postinst
@@ -0,0 +1,25 @@
+#! /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
+
+#DEBHELPER#
--- qcontrol-0.4.2.orig/debian/NEWS
+++ qcontrol-0.4.2/debian/NEWS
@@ -0,0 +1,33 @@
+qcontrol (0.4.2-2) unstable; urgency=low
+
+  * Input device changed
+
+    With udev (0.141-2) the persistent input device created by udev has
+    changed to: /dev/input/by-path/platform-gpio-keys-event.
+
+ -- Frans Pop <fjp@debian.org>  Fri, 21 Aug 2009 01:54:46 +0200
+
+qcontrol (0.4.2-1) unstable; urgency=low
+
+  qcontrol config file compatibility with Linux kernel
+
+  With Debian kernel 2.6.26 and upstream 2.6.27 a change has been made in
+  the values for restart and media buttons. This version of qcontrol uses
+  the *new* values.
+
+  As the daemon function of qcontrol is currently not supported this does
+  not really matter. However, if users want to experiment with the daemon
+  mode and button actions and are using older kernel versions, the following
+  changes should be made in the config file that is used.
+
+  # Values for Debian kernel 2.6.26 and upstream 2.6.27 (or higher)
+    register("evdev", "/dev/input/by-path/platform-gpio-keys-event-",
+        408, "restart_button",
+        133, "media_button")
+
+  # Values for Debian kernel 2.6.25 and upstream 2.6.26
+    register("evdev", "/dev/input/by-path/platform-gpio-keys-event-",
+        116, "restart_button",
+        408, "media_button")
+
+ -- Frans Pop <fjp@debian.org>  Mon, 11 Aug 2008 13:56:30 +0200
--- qcontrol-0.4.2.orig/debian/compat
+++ qcontrol-0.4.2/debian/compat
@@ -0,0 +1 @@
+5
--- qcontrol-0.4.2.orig/debian/qcontrol.1
+++ qcontrol-0.4.2/debian/qcontrol.1
@@ -0,0 +1,128 @@
+.TH QCONTROL 1 "2008-08-10" "Debian Project" ""
+
+.SH NAME
+qcontrol \- Hardware control for QNAP Turbo Station
+
+.SH SYNOPSIS
+\fBqcontrol\fB -d
+.PP
+\fBqcontrol\fB \fIcommand\fP \fIvalue\fP
+
+.SH DESCRIPTION
+The utility can be used to control leds or fan speed, or sound the buzzer.
+As a daemon it can monitor the device for example for button presses or
+temperature values and trigger actions defined in the LUA configuration
+file, for example to power off the system or to modify the fan speed.
+.PP
+Note: the current version does not have a real daemon mode. Caution is
+therefore advised when using qcontrol as a real daemon to monitor and
+control a device.
+.PP
+Currently supported devices are the QNAP TS-109, QNAP TS-110, QNAP TS-119,
+QNAP TS-209, QNAP TS-210, QNAP TS-219, QNAP TS-219P, QNAP TS-409, QNAP
+TS-409U, QNAP TS-410, QNAP TS-410U, QNAP TS-419P and QNAP TS-419U but
+support for additional devices may be added in future releases.
+
+.SH BASIC USAGE
+First a control process needs to be started that opens a socket through
+which the actual commands can be passed. The control proces is be started
+using the \fB\-d\fP option:
+    # qcontrol \-d
+.PP
+Or, to start the control process in a pseudo daemon mode:
+    # qcontrol \-d >/dev/null & disown
+.PP
+After that, the actual commands to control devices can be entered (if the
+first syntax to start the control process was used, this should be done
+from a separate console):
+    # qcontrol <command> <value>
+.PP
+Because the socket file is created in /var/run, all commands must be run
+as root.
+
+.SH OPTIONS
+This program follows the usual GNU command line syntax, with long options
+starting with two dashes (`-').
+An overview of supported options is included below.
+
+.IP "\fB\-d\fP, \fB\-\-daemon\fP"
+Daemon mode; starts the control process.
+
+.IP "\fB\-?\fP, \fB\-\-help\fP"
+Print command help and info.
+
+.IP "\fB\-V\fP, \fB\-\-version\fP"
+Print program version.
+
+.SH SUPPORTED CLIENT COMMANDS
+Below an overview of the supported commands that can be sent using the
+program in client mode, and the allowed values for each.
+
+Commands (these and others) can also be programmed in response to events
+using the LUA configuration file.
+
+For the leds, values including `1hz' and `2hz' will result in the led
+flashing on/off in the default or specified color, with the `hz' value
+determining the speed of the flashes. In the case of `greenred', the led
+will alternate between green and red instead of on and off.
+
+.IP "\fBpowerled\fP"
+Controls the power led (not available on TS-409 and TS-409U).
+
+Values: off | on | 1hz | 2hz
+
+.IP "\fBstatusled\fP"
+Controls the status led.
+
+Values:
+   off | greenon | redon |
+   green1hz | red1hz | greenred1hz |
+   green2hz | red2hz | greenred2hz
+
+.IP "\fBusbled\fP"
+Controls the usb led.
+
+Values: off | on | 8hz
+
+.IP "\fBbuzzer\fP"
+Sounds the buzzer.
+
+Values: short | long
+
+.IP "\fBfanspeed\fP"
+Controls the speed of the fan (if present).
+
+Values: stop | silence | low | medium | high | full
+
+.IP "\fBautopower\fP"
+Controls the automatic power mechanism.
+
+Values: on | off
+
+.SH KNOWN ISSUES
+After running the control process and killing it, the socket file will still
+exist. This will cause the following error when the control process is started
+again: `Error binding to socket: Address already in use'.
+.PP
+The solution is to remove the socket file and then try again:
+    # rm /var/run/qcontrol.sock
+.PP
+The program is not yet very robust against errors in the configuration file.
+
+.SH FILES
+.IP \fB/etc/qcontrol.conf\fP
+LUA configuration file for qcontrol
+.IP \fB/etc/default/qcontrol\fP
+Configuration file for qcontrol init script
+.IP \fB/var/run/qcontrol.sock\fP
+Socket file for communication between daemon precess and client
+
+.SH SEE ALSO
+.IP \fB/usr/share/doc/qcontrol/examples\fP
+Example LUA configuration file containing more advanced commands
+
+.SH AUTHOR
+qcontrol was written by Byron Bradley <byron.bbradley@gmail.com>.
+.PP
+This manual page was written by Frans Pop <fjp@debian.org>
+for the Debian project (but may be used by others).
--- qcontrol-0.4.2.orig/debian/README.source
+++ qcontrol-0.4.2/debian/README.source
@@ -0,0 +1,5 @@
+This package uses quilt to manage all modifications to the upstream
+source. Changes are stored in the source package as diffs in
+debian/patches and applied during the build.
+ 
+See /usr/share/doc/quilt/README.source for a detailed explanation.
--- qcontrol-0.4.2.orig/debian/README.Debian
+++ qcontrol-0.4.2/debian/README.Debian
@@ -0,0 +1,23 @@
+qcontrol for Debian
+---------------------------
+
+The qcontrol program is still in alpha stage. It is for example missing
+a proper daemon mode that would enable it to run permanently in the
+background.
+
+Because of the missing daemon mode, the functionality to monitor temperature
+and control fan speed (TS-209/219/409) has been disabled in the config file.
+See the original config file in ./examples/ for how it could be done.
+
+This Debian package includes an init script that will change the leds and
+sound the buzzer at the end of the boot process and at the beginning of
+the shutdown or reboot process.
+
+The init script only runs the control process as long as needed to make these
+changes. There is no permanently running daemon to listen for commands, which
+means that qcontrol also does not yet respond to button presses.
+
+For further information, see the man page or the upstream webpage:
+   http://qnap.nas-central.org/index.php/PIC_Control_Software
+
+ -- Frans Pop <fjp@debian.org>  Thu, 12 Jun 2008 18:36:54 +0200
--- qcontrol-0.4.2.orig/debian/docs
+++ qcontrol-0.4.2/debian/docs
@@ -0,0 +1,3 @@
+# Upstream README not included as its contents are not relevant
+#README
+debian/README.Debian
--- qcontrol-0.4.2.orig/debian/copyright
+++ qcontrol-0.4.2/debian/copyright
@@ -0,0 +1,34 @@
+This package was debianized by Frans Pop <fjp@debian.org> on
+Sun, 23 Mar 2008 18:14:35 +0100.
+
+It was downloaded from http://byronbradley.co.uk/piccontrol/.
+
+Upstream Author: 
+
+    Byron Bradley <byron.bbradley@gmail.com>
+
+Copyright: 
+
+    Copyright (C) 2007-2008 Byron Bradley
+
+License:
+
+    This package is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+ 
+    This package is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+ 
+    You should have received a copy of the GNU General Public License
+    along with this package; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+On Debian systems, the complete text of the GNU General
+Public License can be found in '/usr/share/common-licenses/GPL'.
+
+The Debian packaging is (C) 2008, Frans Pop <fjp@debian.org> and
+is licensed under the GPL, see above.
--- qcontrol-0.4.2.orig/debian/qcontrol-udeb.dirs
+++ qcontrol-0.4.2/debian/qcontrol-udeb.dirs
@@ -0,0 +1,6 @@
+etc
+etc/qcontrol
+lib/debian-installer-startup.d
+usr/lib/base-installer.d
+usr/lib/finish-install.d
+usr/sbin
--- qcontrol-0.4.2.orig/debian/qcontrol.dirs
+++ qcontrol-0.4.2/debian/qcontrol.dirs
@@ -0,0 +1,3 @@
+etc
+etc/qcontrol
+usr/sbin
--- qcontrol-0.4.2.orig/debian/init.d
+++ qcontrol-0.4.2/debian/init.d
@@ -0,0 +1,159 @@
+#!/bin/bash
+#
+### BEGIN INIT INFO
+# Provides:          qcontrol
+# Required-Start:    $all
+# Required-Stop:     $remote_fs
+# Should-Start:      
+# Should-Stop:       
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Change status leds for QNAP Turbo Station devices
+### END INIT INFO
+
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+
+DAEMON=/usr/sbin/qcontrol
+NAME=qcontrol
+
+PIDFILE=/var/run/$NAME.pid 
+
+test -x $DAEMON || exit 0
+
+. /lib/lsb/init-functions
+
+SOUND_BUZZER=yes
+
+# Include defaults if available
+if [ -f /etc/default/$NAME ] ; then
+	. /etc/default/$NAME
+fi
+
+set -e
+
+SOCKET=/var/run/qcontrol.sock
+
+qcontrol_start() {
+	# Should not already be running, but check anyway
+	local pid="$(pidof qcontrol || true)"
+	if [ -z "$pid" ]; then
+		rm -f $SOCKET
+		qcontrol -d >/dev/null & disown
+		# allow time to startup (read config)
+		sleep 0.5
+		pid=$(pidof qcontrol)
+	fi
+
+	if [ "$pid" ]; then
+		if [ -S $SOCKET ]; then
+			echo $pid
+			return 0
+		else
+			kill -TERM $pid
+		fi
+	fi
+	return 1
+}
+
+# The gpio_keys character device is required with the default
+# Debian configuration file.
+test_event_dev() {
+	if [ ! -c /dev/input/by-path/platform-gpio-keys-event ]; then
+		log_warning_msg "qcontrol error: gpio_keys device not available"
+		return 1
+	fi
+}
+
+case "$1" in
+    start)
+	# Change status led to show green
+	device=$(grep "Hardware[[:space:]]*:" /proc/cpuinfo 2>/dev/null | \
+		 head -n1 | sed "s/^[^:]*: //")
+	case $device in
+	    "QNAP TS-109/TS-209" | "QNAP TS-119/TS-219")
+		test_event_dev || exit 0
+		if pid=$(qcontrol_start); then
+			log_action_msg "System boot completed"
+			# Returns 1 even on success
+			qcontrol statusled greenon || true
+			qcontrol powerled on || true
+			if [ "$SOUND_BUZZER" != no ]; then
+				qcontrol buzzer short || true
+			fi
+
+			# Kill the control process
+			kill -TERM $pid
+			rm -f $SOCKET
+		fi
+		;;
+	    "QNAP TS-409" | "QNAP TS-41x")
+		test_event_dev || exit 0
+		if pid=$(qcontrol_start); then
+			log_action_msg "System boot completed"
+			# Returns 1 even on success
+			qcontrol statusled greenon || true
+			if [ "$SOUND_BUZZER" != no ]; then
+				qcontrol buzzer short || true
+			fi
+
+			# Kill the control process
+			kill -TERM $pid
+			rm -f $SOCKET
+		fi
+		;;
+	    *)
+		log_warning_msg "qcontrol error: device is not supported"
+		;;
+	esac
+	;;
+    stop)
+	# Change status led to show red
+	device=$(grep "Hardware[[:space:]]*:" /proc/cpuinfo 2>/dev/null | \
+		 head -n1 | sed "s/^[^:]*: //")
+	case $device in
+	    "QNAP TS-109/TS-209" | "QNAP TS-119/TS-219")
+		test_event_dev || exit 0
+		if pid=$(qcontrol_start); then
+			log_action_msg "Preparing for shutdown"
+			# Returns 1 even on success
+			if [ "$SOUND_BUZZER" != no ]; then
+				qcontrol buzzer short || true
+			fi
+			qcontrol statusled redon || true
+			qcontrol powerled 1hz || true
+
+			# Kill the control process
+			kill -TERM $pid
+			rm -f $SOCKET
+		fi
+		;;
+	    "QNAP TS-409" | "QNAP TS-41x")
+		test_event_dev || exit 0
+		if pid=$(qcontrol_start); then
+			log_action_msg "Preparing for shutdown"
+			# Returns 1 even on success
+			if [ "$SOUND_BUZZER" != no ]; then
+				qcontrol buzzer short || true
+			fi
+			qcontrol statusled redon || true
+
+			# Kill the control process
+			kill -TERM $pid
+			rm -f $SOCKET
+		fi
+		;;
+	    *)
+		log_warning_msg "qcontrol error: device is not supported"
+		;;
+	esac
+	;;
+    force-stop|restart|force-reload|status|reload)
+	;;
+    *)
+	N=/etc/init.d/$NAME
+	echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
+	exit 1
+	;;
+esac
+
+exit 0
--- qcontrol-0.4.2.orig/debian/manpages
+++ qcontrol-0.4.2/debian/manpages
@@ -0,0 +1 @@
+debian/qcontrol.1
--- qcontrol-0.4.2.orig/debian/qcontrol.install
+++ qcontrol-0.4.2/debian/qcontrol.install
@@ -0,0 +1,2 @@
+qcontrol	usr/sbin/
+config.lua	usr/share/doc/qcontrol/examples/
--- qcontrol-0.4.2.orig/debian/qcontrol.preinst
+++ qcontrol-0.4.2/debian/qcontrol.preinst
@@ -0,0 +1,11 @@
+#! /bin/sh
+set -e
+
+# For upgrade from versions < 0.4.2
+if [ "$2" ] && dpkg --compare-versions "$2" lt 0.4.2 && \
+   [ -f /etc/qcontrol.conf ] && [ ! -L /etc/qcontrol.conf ]; then
+	mkdir -p /etc/qcontrol
+	mv /etc/qcontrol.conf /etc/qcontrol/ts209.lua
+fi
+
+#DEBHELPER#
--- qcontrol-0.4.2.orig/debian/changelog
+++ qcontrol-0.4.2/debian/changelog
@@ -0,0 +1,93 @@
+qcontrol (0.4.2-7) unstable; urgency=medium
+
+  * QA upload.
+  * Set maintainer to QA group
+  * Apply patch from Matthias Klose to fix FTBFS with ld --as-needed 
+    and with multiarched lua (Closes: #643604)
+  * Set urgency to medium due to rc bug fix
+  * Fix lintian detected spelling error in package descriptions
+    (s/Allows\ to/Allows one to/)
+  * Add recommended targets build-arch and build-indep to debian/rules
+  * Add $remote_fs to the Required-Stop of the debian/init.d
+  * Bump standards to 3.9.2 (no furhter changes needed)
+
+ -- Alexander Reichle-Schmehl <tolimar@debian.org>  Wed, 07 Dec 2011 13:51:09 +0100
+
+qcontrol (0.4.2-6) unstable; urgency=low
+
+  * qcontrol-udeb: depend on event-modules instead of input-modules.
+    Closes: #589581
+
+ -- Martin Michlmayr <tbm@cyrius.com>  Tue, 31 Aug 2010 21:59:57 +0100
+
+qcontrol (0.4.2-5) unstable; urgency=low
+
+  * Also add support for TS-419U to udeb. Closes: #557523.
+
+ -- Frans Pop <fjp@debian.org>  Mon, 23 Nov 2009 18:11:02 +0100
+
+qcontrol (0.4.2-4) unstable; urgency=low
+
+  * Let USB headers match default update-rc.d stop levels. Closes: #554796.
+  * Add support for QNAP TS-419U. Closes: #556206.
+    Many thanks to Martin Michlmayr for the patch.
+  * Update supported devices in documentation. Closes: #556210.
+    Thanks to Martin Michlmayr for the patch.
+
+ -- Frans Pop <fjp@debian.org>  Sat, 14 Nov 2009 13:35:41 +0100
+
+qcontrol (0.4.2-3) unstable; urgency=low
+
+  * Remove custom udev rules file added in Lenny update (0.4.2-1lenny1).
+
+ -- Frans Pop <fjp@debian.org>  Thu, 10 Sep 2009 12:15:04 +0200
+
+qcontrol (0.4.2-2) unstable; urgency=low
+
+  * Use quilt to manage patches against upstream.
+  * Update input device for udev (0.141-2). Closes: #524505.
+  * Use bash for the init script as dash does not support disown.
+    Closes: #538321.
+  * Add support for the QNAP TS-119 and TS-219. Closes: #525721.
+    Many thanks to Martin Michlmayr for the patch.
+  * Add support for autopower feature. Closes: #526932.
+    Thanks to Martin Michlmayr for the patch.
+
+ -- Frans Pop <fjp@debian.org>  Fri, 21 Aug 2009 01:55:45 +0200
+
+qcontrol (0.4.2-1) unstable; urgency=low
+
+  * New upstream version:
+    - support for QNAP TS-409 (closes: #491567)
+  * Update config values for restart and media buttons in line with change in
+    Debian kernel 2.6.26 (upstream 2.6.27). Thanks to Martin Michlmayr for
+    alerting me to the change.
+  * udeb: Modify /etc/modules during base-installer instead of finish-install;
+    it is slightly more logical to do this at the same time as installing the
+    package.
+
+ -- Frans Pop <fjp@debian.org>  Mon, 11 Aug 2008 15:21:21 +0200
+
+qcontrol (0.4.1-3) unstable; urgency=low
+
+  * Add gpio_keys to /etc/modules in target instead of D-I environment.
+  * Remove workaround for missing persistent-input rules. It was added
+    in udev 0.124-1.
+
+ -- Frans Pop <fjp@debian.org>  Mon, 14 Jul 2008 17:39:43 +0200
+
+qcontrol (0.4.1-2) unstable; urgency=low
+
+  * Update watch file for rename from piccontrol to qcontrol.
+  * Fix errors in udeb. Closes: #488394.
+  * Add temporary workaround in udeb for #488439 (missing persistent-input
+    rules in udev-udeb).
+  * Improve the way additional scripts are included in the udeb.
+
+ -- Frans Pop <fjp@debian.org>  Thu, 03 Jul 2008 20:21:23 +0200
+
+qcontrol (0.4.1-1) unstable; urgency=low
+
+  * Initial release. Closes: #483721.
+
+ -- Frans Pop <fjp@debian.org>  Thu, 12 Jun 2008 18:46:42 +0200
--- qcontrol-0.4.2.orig/debian/watch
+++ qcontrol-0.4.2/debian/watch
@@ -0,0 +1,9 @@
+# Example watch control file for uscan
+# Rename this file to "watch" and then you can run the "uscan" command
+# to check for upstream updates and more.
+# See uscan(1) for format
+
+# Compulsory line, this is a version 3 file
+version=3
+
+http://byronbradley.co.uk/piccontrol/qcontrol-(.*)\.tar\.gz
--- qcontrol-0.4.2.orig/debian/qcontrol.postrm
+++ qcontrol-0.4.2/debian/qcontrol.postrm
@@ -0,0 +1,8 @@
+#! /bin/sh
+set -e
+
+if [ "$1" = purge ]; then
+	rm -f /etc/qcontrol.conf /etc/qcontrol.conf.dpkg*
+fi
+
+#DEBHELPER#
--- qcontrol-0.4.2.orig/debian/qcontrol.default
+++ qcontrol-0.4.2/debian/qcontrol.default
@@ -0,0 +1,10 @@
+# Defaults for qcontrol initscript
+# sourced by /etc/init.d/qcontrol
+# installed at /etc/default/qcontrol by the maintainer scripts
+
+#
+# This is a POSIX shell fragment
+#
+
+# Set to "no" to suppress the sounding of the buzzer
+#SOUND_BUZZER=no
--- qcontrol-0.4.2.orig/debian/patches/002_Update_config_values_for_restart_and_media_buttons.patch
+++ qcontrol-0.4.2/debian/patches/002_Update_config_values_for_restart_and_media_buttons.patch
@@ -0,0 +1,20 @@
+--- a/config.lua
++++ b/config.lua
+@@ -1,8 +1,8 @@
+ register("ts209")
+ 
+ register("evdev", "/dev/input/event0",
+-         116, "restart_button",
+-         408, "media_button")
++         408, "restart_button",
++         133, "media_button")
+ 
+ function power_button( time )
+ 	os.execute("poweroff")
+@@ -56,4 +56,4 @@
+ 
+ function media_button( time )
+ 	piccmd("usbled", "8hz")
+-end
+\ No newline at end of file
++end
--- qcontrol-0.4.2.orig/debian/patches/004_Support_autopower_feature.patch
+++ qcontrol-0.4.2/debian/patches/004_Support_autopower_feature.patch
@@ -0,0 +1,117 @@
+--- a/ts209.c
++++ b/ts209.c
+@@ -273,6 +273,24 @@
+ 	return 0;
+ }
+ 
++static int ts209_autopower(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "on") == 0)
++		code = 0x48;
++	else if (strcmp(argv[0], "off") == 0)
++		code = 0x49;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
+ int ts209_init(int argc, const char **argv)
+ {
+ 	int err;
+@@ -313,6 +331,11 @@
+ 	                       "Set the usbled, options are:\n"
+ 	                       "\ton\n\t8hz\n\toff\n",
+ 	                       ts209_usbled);
++	err = register_command("autopower",
++	                       "Control the automatic power mechanism",
++	                       "Control the automatic power mechanism, options are:\n"
++	                       "\ton\n\toff\n",
++	                       ts209_autopower);
+ 
+ 	return pthread_create(&ts209_thread, NULL, serial_poll, NULL);
+ }
+--- a/ts219.c
++++ b/ts219.c
+@@ -285,6 +285,24 @@
+ 	return 0;
+ }
+ 
++static int ts219_autopower(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "on") == 0)
++		code = 0x48;
++	else if (strcmp(argv[0], "off") == 0)
++		code = 0x49;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
+ int ts219_init(int argc, const char **argv)
+ {
+ 	int err;
+@@ -325,6 +343,11 @@
+ 	                       "Set the usbled, options are:\n"
+ 	                       "\ton\n\t8hz\n\toff\n",
+ 	                       ts219_usbled);
++	err = register_command("autopower",
++	                       "Control the automatic power mechanism",
++	                       "Control the automatic power mechanism, options are:\n"
++	                       "\ton\n\toff\n",
++	                       ts219_autopower);
+ 
+ 	return pthread_create(&ts219_thread, NULL, serial_poll, NULL);
+ }
+--- a/ts409.c
++++ b/ts409.c
+@@ -263,6 +263,24 @@
+ 	return 0;
+ }
+ 
++static int ts409_autopower(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "on") == 0)
++		code = 0x48;
++	else if (strcmp(argv[0], "off") == 0)
++		code = 0x49;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
+ int ts409_init(int argc, const char **argv)
+ {
+ 	int err;
+@@ -298,6 +316,11 @@
+ 	                       "Set the usbled, options are:\n"
+ 	                       "\ton\n\t8hz\n\toff\n",
+ 	                       ts409_usbled);
++	err = register_command("autopower",
++	                       "Control the automatic power mechanism",
++	                       "Control the automatic power mechanism, options are:\n"
++	                       "\ton\n\toff\n",
++	                       ts409_autopower);
+ 
+ 	return pthread_create(&ts409_thread, NULL, serial_poll, NULL);
+ }
--- qcontrol-0.4.2.orig/debian/patches/series
+++ qcontrol-0.4.2/debian/patches/series
@@ -0,0 +1,6 @@
+001_Statically_compile_lua_for_udeb.patch
+002_Update_config_values_for_restart_and_media_buttons.patch
+003_Add_support_for_ts-119.patch
+004_Support_autopower_feature.patch
+005_Add_support_for_ts-41x.patch
+ld_as_needed.diff
--- qcontrol-0.4.2.orig/debian/patches/001_Statically_compile_lua_for_udeb.patch
+++ qcontrol-0.4.2/debian/patches/001_Statically_compile_lua_for_udeb.patch
@@ -0,0 +1,26 @@
+--- a/Makefile
++++ b/Makefile
+@@ -1,17 +1,20 @@
+ CFLAGS=-Os -Wall -I /usr/include/lua5.1
+ LDFLAGS=-llua5.1 -lpthread
++LDFLAGS_UDEB=-lpthread -lm -ldl
+ SOURCES=qcontrol.c ts209.c ts409.c evdev.c
+ OBJECTS=$(SOURCES:.c=.o)
+ EXECUTABLE=qcontrol
+ 
+-all:	$(SOURCES) $(EXECUTABLE)
++all:	$(SOURCES) $(EXECUTABLE) qcontrol.udeb
+ 	
+ $(EXECUTABLE): $(OBJECTS) 
+ 	$(CC) $(LDFLAGS) $(OBJECTS) -o $@
+ 
++qcontrol.udeb: $(OBJECTS)
++	$(CC) $(LDFLAGS_UDEB) $(OBJECTS) /usr/lib/liblua5.1.a -o $@
++
+ .cpp.o:
+ 	$(CC) $(CFLAGS) $< -o $@
+ 
+ clean:
+-	rm -f $(OBJECTS) $(EXECUTABLE)
+-	
++	rm -f $(OBJECTS) $(EXECUTABLE) qcontrol.udeb
--- qcontrol-0.4.2.orig/debian/patches/003_Add_support_for_ts-119.patch
+++ qcontrol-0.4.2/debian/patches/003_Add_support_for_ts-119.patch
@@ -0,0 +1,371 @@
+--- a/Makefile
++++ b/Makefile
+@@ -1,7 +1,7 @@
+ CFLAGS=-Os -Wall -I /usr/include/lua5.1
+ LDFLAGS=-llua5.1 -lpthread
+ LDFLAGS_UDEB=-lpthread -lm -ldl
+-SOURCES=qcontrol.c ts209.c ts409.c evdev.c
++SOURCES=qcontrol.c ts209.c ts219.c ts409.c evdev.c
+ OBJECTS=$(SOURCES:.c=.o)
+ EXECUTABLE=qcontrol
+ 
+--- a/qcontrol.c
++++ b/qcontrol.c
+@@ -54,11 +54,13 @@
+ struct piccommand **commands;
+ 
+ extern struct picmodule ts209_module;
++extern struct picmodule ts219_module;
+ extern struct picmodule ts409_module;
+ extern struct picmodule evdev_module;
+ 
+ struct picmodule *modules[] = {
+ 	&ts209_module,
++	&ts219_module,
+ 	&ts409_module,
+ 	&evdev_module,
+ 	NULL
+--- /dev/null
++++ b/ts219.c
+@@ -0,0 +1,341 @@
++/*
++ * Copyright (C) 2007-2008  Byron Bradley (byron.bbradley@gmail.com)
++ * Copyright (C) 2008, 2009  Martin Michlmayr (tbm@cyrius.com)
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation, either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
++ */
++
++#include <fcntl.h>
++#include <lua.h>
++#include <lualib.h>
++#include <lauxlib.h>
++#include <pthread.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include <termios.h>
++#include <unistd.h>
++#include <linux/input.h>
++
++#include "picmodule.h"
++
++static int serial;
++static struct termios oldtio, newtio;
++static pthread_t ts219_thread;
++
++static int serial_read(char *buf, int len)
++{
++	int err;
++
++	err = read(serial, buf, len);
++	buf[err] = 0;
++
++	return err;
++}
++
++static int serial_write(char *buf, int len)
++{
++	int err;
++
++	err = write(serial, buf, len);
++
++	return err;
++}
++
++int ts219_read_serial_events()
++{
++	char buf[100];
++	int err = serial_read(buf, 100);
++	if (err < 0)
++		return err;
++	switch (buf[0]) {
++	case 0x40:
++		call_function("power_button", "%d", 3);
++		break;
++	case 0x73:
++	case 0x75:
++	case 0x77:
++	case 0x79:
++		call_function("fan_error", "");
++		break;
++	case 0x74:
++	case 0x76:
++	case 0x78:
++	case 0x7a:
++		call_function("fan_normal", "");
++		break;
++	case 0x80 ... 0x8f: /*  0 - 15 */
++	case 0x90 ... 0x9f: /* 16 - 31 */
++	case 0xa0 ... 0xaf: /* 32 - 47 */
++	case 0xb0 ... 0xbf: /* 48 - 63 */
++	case 0xc0 ... 0xc6: /* 64 - 70 */
++		call_function("temp", "%d", buf[0] - 128);
++		break;
++	case 0x38: /* 71 - 79 */
++		call_function("temp", "%d", 75);
++		break;
++	case 0x39: /* 80 or higher */
++		call_function("temp", "%d", 80);
++		break;
++	default:
++		fprintf(stderr, "(PIC 0x%x) unknown command from PIC\n", buf[0]);
++	}
++
++	return -1;
++}
++
++static void *serial_poll(void *tmp)
++{
++	int err;
++	fd_set rset;
++
++	FD_ZERO(&rset);
++	FD_SET(serial, &rset);
++
++	for (;;) {
++		err = select(serial + 1, &rset, NULL, NULL, NULL);
++		if (err <= 0) {
++			FD_SET(serial, &rset);
++			continue;
++		}
++		ts219_read_serial_events();
++		FD_SET(serial, &rset);
++	}
++
++	return NULL;
++}
++
++static int set_nonblock(int fd)
++{
++	int flags = fcntl(fd, F_GETFL, 0);
++	if (flags < 0)
++		flags = 0;
++	return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
++}
++
++static int serial_open(char *device)
++{
++	char buf[100];
++	int err;
++
++	if ((serial = open(device , O_RDWR)) < 0) {
++		sprintf(buf, "Failed to open %s", device);
++		perror(buf);
++		return -1;
++	}
++	err = set_nonblock(serial);
++	if (err < 0) {
++		perror("Error setting nonblock");
++		return -1;
++	}
++
++	tcgetattr(serial, &oldtio);
++	memset(&newtio, 0, sizeof(newtio));
++
++	newtio.c_iflag |= IGNBRK;
++	newtio.c_lflag &= ~(ISIG | ICANON | ECHO);
++	newtio.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
++	newtio.c_cc[VMIN] = 1;
++	newtio.c_cc[VTIME] = 0;
++	cfsetospeed(&newtio, B19200);
++	cfsetispeed(&newtio, B19200);
++
++	err = tcsetattr(serial, TCSANOW, &newtio);
++	if (err < 0) {
++		sprintf(buf, "Failed to set attributes for %s", device);
++		perror(buf);
++		return -1;
++	}
++
++	return 0;
++}
++
++static void serial_close()
++{
++	tcsetattr(serial, TCSANOW, &oldtio);
++	close(serial);
++}
++
++static int ts219_powerled(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "on") == 0)
++		code = 0x4d;
++	else if (strcmp(argv[0], "1hz") == 0)
++		code = 0x4e;
++	else if (strcmp(argv[0], "2hz") == 0)
++		code = 0x4c;
++	else if (strcmp(argv[0], "off") == 0)
++		code = 0x4b;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
++static int ts219_statusled(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "red2hz") == 0)
++		code = 0x54;
++	else if (strcmp(argv[0], "green2hz") == 0)
++		code = 0x55;
++	else if (strcmp(argv[0], "greenon") == 0)
++		code = 0x56;
++	else if (strcmp(argv[0], "redon") == 0)
++		code = 0x57;
++	else if (strcmp(argv[0], "greenred2hz") == 0)
++		code = 0x58;
++	else if (strcmp(argv[0], "off") == 0)
++		code = 0x59;
++	else if (strcmp(argv[0], "green1hz") == 0)
++		code = 0x5a;
++	else if (strcmp(argv[0], "red1hz") == 0)
++		code = 0x5b;
++	else if (strcmp(argv[0], "greenred1hz") == 0)
++		code = 0x5c;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
++static int ts219_buzz(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "short") == 0)
++		code = 0x50;
++	else if (strcmp(argv[0], "long") == 0)
++		code = 0x51;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
++static int ts219_fanspeed(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "stop") == 0)
++		code = 0x30;
++	else if (strcmp(argv[0], "silence") == 0)
++		code = 0x31;
++	else if (strcmp(argv[0], "low") == 0)
++		code = 0x32;
++	else if (strcmp(argv[0], "medium") == 0)
++		code = 0x33;
++	else if (strcmp(argv[0], "high") == 0)
++		code = 0x34;
++	else if (strcmp(argv[0], "full") == 0)
++		code = 0x35;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
++static int ts219_usbled(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "on") == 0)
++		code = 0x60;
++	else if (strcmp(argv[0], "8hz") == 0)
++		code = 0x61;
++	else if (strcmp(argv[0], "off") == 0)
++		code = 0x62;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
++int ts219_init(int argc, const char **argv)
++{
++	int err;
++
++	if (argc > 0) {
++		printf("%s: module does not take any arguments\n", __func__);
++		return -1;
++	}
++
++	err = serial_open("/dev/ttyS1");
++	if (err < 0)
++		return err;
++
++	err = register_command("statusled",
++	                       "Change the status LED",
++	                       "Change the status LED, options are:\n"
++	                       "\tred2hz\n\tgreen2hz\n\tgreenon\n\tredon\n"
++	                       "\tgreenred2hz\n\toff\n\tgreen1hz\n\tred1hz\n",
++	                       ts219_statusled);
++	err = register_command("powerled",
++	                       "Change the power LED",
++	                       "Change the power LED, options are:\n"
++	                       "\ton\n\toff\n\t1hz\n\t2hz\n",
++	                       ts219_powerled);
++	err = register_command("buzzer",
++	                       "Buzz",
++	                       "Buzz, options are:\n"
++	                       "\tshort\n\tlong\n",
++	                       ts219_buzz);
++	err = register_command("fanspeed",
++	                       "Set the fanspeed",
++	                       "Set the fanspeed, options are:\n"
++	                       "\tstop\n\tsilence\n\tlow\n\tmedium\n"
++	                       "\thigh\n\tfull\n",
++	                       ts219_fanspeed);
++	err = register_command("usbled",
++	                       "Set the usbled",
++	                       "Set the usbled, options are:\n"
++	                       "\ton\n\t8hz\n\toff\n",
++	                       ts219_usbled);
++
++	return pthread_create(&ts219_thread, NULL, serial_poll, NULL);
++}
++
++void ts219_exit(void)
++{
++	serial_close();
++}
++
++struct picmodule ts219_module = {
++	.name           = "ts219",
++	.init           = ts219_init,
++	.exit           = ts219_exit,
++};
--- qcontrol-0.4.2.orig/debian/patches/ld_as_needed.diff
+++ qcontrol-0.4.2/debian/patches/ld_as_needed.diff
@@ -0,0 +1,17 @@
+Index: qcontrol-0.4.2/Makefile
+===================================================================
+--- qcontrol-0.4.2.orig/Makefile	2011-09-27 22:26:10.678891494 +0000
++++ qcontrol-0.4.2/Makefile	2011-09-27 22:28:25.449089162 +0000
+@@ -8,10 +8,10 @@
+ all:	$(SOURCES) $(EXECUTABLE) qcontrol.udeb
+ 	
+ $(EXECUTABLE): $(OBJECTS) 
+-	$(CC) $(LDFLAGS) $(OBJECTS) -o $@
++	$(CC) $(OBJECTS) $(LDFLAGS) -o $@
+ 
+ qcontrol.udeb: $(OBJECTS)
+-	$(CC) $(LDFLAGS_UDEB) $(OBJECTS) /usr/lib/liblua5.1.a -o $@
++	$(CC) $(OBJECTS) /usr/lib/$$(dpkg-architecture -qDEB_HOST_MULTIARCH)/liblua5.1.a $(LDFLAGS_UDEB) -o $@
+ 
+ .cpp.o:
+ 	$(CC) $(CFLAGS) $< -o $@
--- qcontrol-0.4.2.orig/debian/patches/005_Add_support_for_ts-41x.patch
+++ qcontrol-0.4.2/debian/patches/005_Add_support_for_ts-41x.patch
@@ -0,0 +1,398 @@
+diff -urN 1/Makefile qcontrol-0.4.2/Makefile
+--- a/Makefile	2009-11-14 10:18:59.000000000 +0000
++++ b/Makefile	2009-11-14 10:19:39.000000000 +0000
+@@ -1,7 +1,7 @@
+ CFLAGS=-Os -Wall -I /usr/include/lua5.1
+ LDFLAGS=-llua5.1 -lpthread
+ LDFLAGS_UDEB=-lpthread -lm -ldl
+-SOURCES=qcontrol.c ts209.c ts219.c ts409.c evdev.c
++SOURCES=qcontrol.c ts209.c ts219.c ts409.c ts41x.c evdev.c
+ OBJECTS=$(SOURCES:.c=.o)
+ EXECUTABLE=qcontrol
+ 
+diff -urN 1/qcontrol.c qcontrol-0.4.2/qcontrol.c
+--- a/qcontrol.c	2009-11-14 10:18:59.000000000 +0000
++++ b/qcontrol.c	2009-11-14 10:19:58.000000000 +0000
+@@ -56,12 +56,14 @@
+ extern struct picmodule ts209_module;
+ extern struct picmodule ts219_module;
+ extern struct picmodule ts409_module;
++extern struct picmodule ts41x_module;
+ extern struct picmodule evdev_module;
+ 
+ struct picmodule *modules[] = {
+ 	&ts209_module,
+ 	&ts219_module,
+ 	&ts409_module,
++	&ts41x_module,
+ 	&evdev_module,
+ 	NULL
+ };
+diff -urN 1/ts41x.c qcontrol-0.4.2/ts41x.c
+--- a/ts41x.c	1970-01-01 01:00:00.000000000 +0100
++++ b/ts41x.c	2009-11-14 10:20:22.000000000 +0000
+@@ -0,0 +1,364 @@
++/*
++ * Copyright (C) 2007-2008  Byron Bradley (byron.bbradley@gmail.com)
++ * Copyright (C) 2008, 2009  Martin Michlmayr (tbm@cyrius.com)
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation, either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
++ */
++
++#include <fcntl.h>
++#include <lua.h>
++#include <lualib.h>
++#include <lauxlib.h>
++#include <pthread.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include <termios.h>
++#include <unistd.h>
++#include <linux/input.h>
++
++#include "picmodule.h"
++
++static int serial;
++static struct termios oldtio, newtio;
++static pthread_t ts41x_thread;
++
++static int serial_read(char *buf, int len)
++{
++	int err;
++
++	err = read(serial, buf, len);
++	buf[err] = 0;
++
++	return err;
++}
++
++static int serial_write(char *buf, int len)
++{
++	int err;
++
++	err = write(serial, buf, len);
++
++	return err;
++}
++
++int ts41x_read_serial_events()
++{
++	char buf[100];
++	int err = serial_read(buf, 100);
++	if (err < 0)
++		return err;
++	switch (buf[0]) {
++	case 0x40:
++		call_function("power_button", "%d", 3);
++		break;
++	case 0x73:
++	case 0x75:
++	case 0x77:
++	case 0x79:
++		call_function("fan_error", "");
++		break;
++	case 0x74:
++	case 0x76:
++	case 0x78:
++	case 0x7a:
++		call_function("fan_normal", "");
++		break;
++	case 0x80 ... 0x8f: /*  0 - 15 */
++	case 0x90 ... 0x9f: /* 16 - 31 */
++	case 0xa0 ... 0xaf: /* 32 - 47 */
++	case 0xb0 ... 0xbf: /* 48 - 63 */
++	case 0xc0 ... 0xc6: /* 64 - 70 */
++		call_function("temp", "%d", buf[0] - 128);
++		break;
++	case 0x38: /* 71 - 79 */
++		call_function("temp", "%d", 75);
++		break;
++	case 0x39: /* 80 or higher */
++		call_function("temp", "%d", 80);
++		break;
++	default:
++		fprintf(stderr, "(PIC 0x%x) unknown command from PIC\n", buf[0]);
++	}
++
++	return -1;
++}
++
++static void *serial_poll(void *tmp)
++{
++	int err;
++	fd_set rset;
++
++	FD_ZERO(&rset);
++	FD_SET(serial, &rset);
++
++	for (;;) {
++		err = select(serial + 1, &rset, NULL, NULL, NULL);
++		if (err <= 0) {
++			FD_SET(serial, &rset);
++			continue;
++		}
++		ts41x_read_serial_events();
++		FD_SET(serial, &rset);
++	}
++
++	return NULL;
++}
++
++static int set_nonblock(int fd)
++{
++	int flags = fcntl(fd, F_GETFL, 0);
++	if (flags < 0)
++		flags = 0;
++	return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
++}
++
++static int serial_open(char *device)
++{
++	char buf[100];
++	int err;
++
++	if ((serial = open(device , O_RDWR)) < 0) {
++		sprintf(buf, "Failed to open %s", device);
++		perror(buf);
++		return -1;
++	}
++	err = set_nonblock(serial);
++	if (err < 0) {
++		perror("Error setting nonblock");
++		return -1;
++	}
++
++	tcgetattr(serial, &oldtio);
++	memset(&newtio, 0, sizeof(newtio));
++
++	newtio.c_iflag |= IGNBRK;
++	newtio.c_lflag &= ~(ISIG | ICANON | ECHO);
++	newtio.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
++	newtio.c_cc[VMIN] = 1;
++	newtio.c_cc[VTIME] = 0;
++	cfsetospeed(&newtio, B19200);
++	cfsetispeed(&newtio, B19200);
++
++	err = tcsetattr(serial, TCSANOW, &newtio);
++	if (err < 0) {
++		sprintf(buf, "Failed to set attributes for %s", device);
++		perror(buf);
++		return -1;
++	}
++
++	return 0;
++}
++
++static void serial_close()
++{
++	tcsetattr(serial, TCSANOW, &oldtio);
++	close(serial);
++}
++
++static int ts41x_powerled(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "on") == 0)
++		code = 0x4d;
++	else if (strcmp(argv[0], "1hz") == 0)
++		code = 0x4e;
++	else if (strcmp(argv[0], "2hz") == 0)
++		code = 0x4c;
++	else if (strcmp(argv[0], "off") == 0)
++		code = 0x4b;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
++static int ts41x_statusled(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "red2hz") == 0)
++		code = 0x54;
++	else if (strcmp(argv[0], "green2hz") == 0)
++		code = 0x55;
++	else if (strcmp(argv[0], "greenon") == 0)
++		code = 0x56;
++	else if (strcmp(argv[0], "redon") == 0)
++		code = 0x57;
++	else if (strcmp(argv[0], "greenred2hz") == 0)
++		code = 0x58;
++	else if (strcmp(argv[0], "off") == 0)
++		code = 0x59;
++	else if (strcmp(argv[0], "green1hz") == 0)
++		code = 0x5a;
++	else if (strcmp(argv[0], "red1hz") == 0)
++		code = 0x5b;
++	else if (strcmp(argv[0], "greenred1hz") == 0)
++		code = 0x5c;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
++static int ts41x_buzz(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "short") == 0)
++		code = 0x50;
++	else if (strcmp(argv[0], "long") == 0)
++		code = 0x51;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
++static int ts41x_fanspeed(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "stop") == 0)
++		code = 0x30;
++	else if (strcmp(argv[0], "silence") == 0)
++		code = 0x31;
++	else if (strcmp(argv[0], "low") == 0)
++		code = 0x32;
++	else if (strcmp(argv[0], "medium") == 0)
++		code = 0x33;
++	else if (strcmp(argv[0], "high") == 0)
++		code = 0x34;
++	else if (strcmp(argv[0], "full") == 0)
++		code = 0x35;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
++static int ts41x_usbled(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "on") == 0)
++		code = 0x60;
++	else if (strcmp(argv[0], "8hz") == 0)
++		code = 0x61;
++	else if (strcmp(argv[0], "off") == 0)
++		code = 0x62;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
++static int ts41x_autopower(int argc, const char **argv)
++{
++	char code = 0;
++
++	if (argc != 1)
++		return -1;
++
++	if (strcmp(argv[0], "on") == 0)
++		code = 0x48;
++	else if (strcmp(argv[0], "off") == 0)
++		code = 0x49;
++	else
++		return -1;
++
++	return serial_write(&code, 1);
++	return 0;
++}
++
++int ts41x_init(int argc, const char **argv)
++{
++	int err;
++
++	if (argc > 0) {
++		printf("%s: module does not take any arguments\n", __func__);
++		return -1;
++	}
++
++	err = serial_open("/dev/ttyS1");
++	if (err < 0)
++		return err;
++
++	err = register_command("statusled",
++	                       "Change the status LED",
++	                       "Change the status LED, options are:\n"
++	                       "\tred2hz\n\tgreen2hz\n\tgreenon\n\tredon\n"
++	                       "\tgreenred2hz\n\toff\n\tgreen1hz\n\tred1hz\n",
++	                       ts41x_statusled);
++	err = register_command("powerled",
++	                       "Change the power LED",
++	                       "Change the power LED, options are:\n"
++	                       "\ton\n\toff\n\t1hz\n\t2hz\n",
++	                       ts41x_powerled);
++	err = register_command("buzzer",
++	                       "Buzz",
++	                       "Buzz, options are:\n"
++	                       "\tshort\n\tlong\n",
++	                       ts41x_buzz);
++	err = register_command("fanspeed",
++	                       "Set the fanspeed",
++	                       "Set the fanspeed, options are:\n"
++	                       "\tstop\n\tsilence\n\tlow\n\tmedium\n"
++	                       "\thigh\n\tfull\n",
++	                       ts41x_fanspeed);
++	err = register_command("usbled",
++	                       "Set the usbled",
++	                       "Set the usbled, options are:\n"
++	                       "\ton\n\t8hz\n\toff\n",
++	                       ts41x_usbled);
++	err = register_command("autopower",
++	                       "Control the automatic power mechanism",
++	                       "Control the automatic power mechanism, options are:\n"
++	                       "\ton\n\toff\n",
++	                       ts41x_autopower);
++
++	return pthread_create(&ts41x_thread, NULL, serial_poll, NULL);
++}
++
++void ts41x_exit(void)
++{
++	serial_close();
++}
++
++struct picmodule ts41x_module = {
++	.name           = "ts41x",
++	.init           = ts41x_init,
++	.exit           = ts41x_exit,
++};
--- qcontrol-0.4.2.orig/debian/configs/ts41x.lua
+++ qcontrol-0.4.2/debian/configs/ts41x.lua
@@ -0,0 +1,39 @@
+--[[
+	Debian configuration file for qcontrol (LUA syntax)
+	Supports QNAP TS-410, TS-410U, TS-419P and TS-419U.
+--]]
+
+register("ts41x")
+
+-- Requires CONFIG_KEYBOARD_GPIO enabled in the kernel and
+-- the kernel module gpio_keys to be loaded.
+register("evdev", "/dev/input/by-path/platform-gpio-keys-event",
+	408, "restart_button",
+	133, "media_button")
+
+function power_button( time )
+	os.execute("poweroff")
+end
+
+function restart_button( time )
+	os.execute("reboot")
+end
+
+function media_button( time )
+	piccmd("usbled", "8hz")
+end
+
+--[[
+	Fan and temperature control are left disabled until qcontrol
+	gets a proper daemon mode.
+	Empty functions are needed to avoid errors.
+--]]
+function fan_error(  )
+end
+
+function fan_normal(  )
+end
+
+function temp( temp )
+	print("ts41x temperature:", temp)
+end
--- qcontrol-0.4.2.orig/debian/configs/ts409.lua
+++ qcontrol-0.4.2/debian/configs/ts409.lua
@@ -0,0 +1,39 @@
+--[[
+	Debian configuration file for qcontrol (LUA syntax)
+	Supports QNAP TS-409.
+--]]
+
+register("ts409")
+
+-- Requires CONFIG_KEYBOARD_GPIO enabled in the kernel and
+-- the kernel module gpio_keys to be loaded.
+register("evdev", "/dev/input/by-path/platform-gpio-keys-event",
+	408, "restart_button",
+	133, "media_button")
+
+function power_button( time )
+	os.execute("poweroff")
+end
+
+function restart_button( time )
+	os.execute("reboot")
+end
+
+function media_button( time )
+	piccmd("usbled", "8hz")
+end
+
+--[[
+	Fan and temperature control are left disabled until qcontrol
+	gets a proper daemon mode.
+	Empty functions are needed to avoid errors.
+--]]
+function fan_error(  )
+end
+
+function fan_normal(  )
+end
+
+function temp( temp )
+	print("ts409 temperature:", temp)
+end
--- qcontrol-0.4.2.orig/debian/configs/ts209.lua
+++ qcontrol-0.4.2/debian/configs/ts209.lua
@@ -0,0 +1,41 @@
+--[[
+	Debian configuration file for qcontrol (LUA syntax)
+	Supports both QNAP TS-109 and TS-209.
+--]]
+
+register("ts209")
+
+-- Requires CONFIG_KEYBOARD_GPIO enabled in the kernel and
+-- the kernel module gpio_keys to be loaded.
+register("evdev", "/dev/input/by-path/platform-gpio-keys-event",
+	408, "restart_button",
+	133, "media_button")
+
+function power_button( time )
+	os.execute("poweroff")
+end
+
+function restart_button( time )
+	os.execute("reboot")
+end
+
+function media_button( time )
+	piccmd("usbled", "8hz")
+end
+
+--[[
+	Fan and temperature control are left disabled until qcontrol
+	gets a proper daemon mode.
+	Empty functions are needed to avoid errors.
+--]]
+function fan_error(  )
+end
+
+function fan_normal(  )
+end
+
+function temp_low(  )
+end
+
+function temp_high(  )
+end
--- qcontrol-0.4.2.orig/debian/configs/ts219.lua
+++ qcontrol-0.4.2/debian/configs/ts219.lua
@@ -0,0 +1,39 @@
+--[[
+	Debian configuration file for qcontrol (LUA syntax)
+	Supports QNAP TS-110, TS-119, TS-210, TS-219 and TS-219P.
+--]]
+
+register("ts219")
+
+-- Requires CONFIG_KEYBOARD_GPIO enabled in the kernel and
+-- the kernel module gpio_keys to be loaded.
+register("evdev", "/dev/input/by-path/platform-gpio-keys-event",
+	408, "restart_button",
+	133, "media_button")
+
+function power_button( time )
+	os.execute("poweroff")
+end
+
+function restart_button( time )
+	os.execute("reboot")
+end
+
+function media_button( time )
+	piccmd("usbled", "8hz")
+end
+
+--[[
+	Fan and temperature control are left disabled until qcontrol
+	gets a proper daemon mode.
+	Empty functions are needed to avoid errors.
+--]]
+function fan_error(  )
+end
+
+function fan_normal(  )
+end
+
+function temp( temp )
+	print("ts219 temperature:", temp)
+end
--- qcontrol-0.4.2.orig/debian/udeb/qcommand
+++ qcontrol-0.4.2/debian/udeb/qcommand
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+# Wrapper script for qcontrol to execute single commands
+# If called with -t, it only tests if the device is supported
+
+# Test if device is supported
+device=$(grep "Hardware[[:space:]]*:" /proc/cpuinfo 2>/dev/null | \
+	 head -n1 | sed "s/^[^:]*: //")
+case $device in
+    "QNAP TS-109/TS-209" | "QNAP TS-119/TS-219" | "QNAP TS-409" | "QNAP TS-41x")
+	# Success or continue 
+	[ "$1" = "-t" ] && exit 0 || true ;;
+    *)
+	# Failure or silently exit
+	[ "$1" = "-t" ] && exit 1 || exit 0 ;;
+esac
+
+# qcontrol should not be running already; silently exit
+[ -z "$(pidof qcontrol)" ] || exit 0
+
+SOCKET=/var/run/qcontrol.sock
+
+qcontrol_start() {
+	rm -f $SOCKET
+	qcontrol -d >/dev/null &
+	# allow time to startup (read config)
+	sleep 1
+	pid=$(pidof qcontrol)
+
+	if [ "$pid" ]; then
+		if [ -S $SOCKET ]; then
+			echo $pid
+			return 0
+		else
+			kill -TERM $pid
+		fi
+	fi
+	return 1
+}
+
+# The gpio_keys character device is required with the default
+# Debian configuration file.
+test_event_dev() {
+	[ -c /dev/input/by-path/platform-gpio-keys-event ] || return 1
+}
+
+case $device in
+    "QNAP TS-409" | "QNAP TS-41x")
+	if [ "$1" = powerled ]; then
+		exit 0
+	fi ;;
+esac
+
+test_event_dev || exit 0
+if pid=$(qcontrol_start); then
+	# Returns 1 even on success
+	qcontrol "$@" || true
+
+	# Kill the control process
+	kill -TERM $pid
+	rm -f $SOCKET
+fi
+
+exit 0
--- qcontrol-0.4.2.orig/debian/udeb/base-installer.d/10qcontrol
+++ qcontrol-0.4.2/debian/udeb/base-installer.d/10qcontrol
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+if qcommand -t; then
+	# Queue qcontrol for installation on supported devices
+	apt-install qcontrol
+
+	# qcontrol requires the gpio_keys module; add it in /etc/modules
+	printf "\n\n# Required for qcontrol\n" >>/target/etc/modules
+	printf "gpio_keys\n" >>/target/etc/modules
+fi
--- qcontrol-0.4.2.orig/debian/udeb/debian-installer-startup.d/S99qcontrol
+++ qcontrol-0.4.2/debian/udeb/debian-installer-startup.d/S99qcontrol
@@ -0,0 +1,23 @@
+#! /bin/sh
+
+if qcommand -t; then
+	device=$(grep "Hardware[[:space:]]*:" /proc/cpuinfo 2>/dev/null | \
+		 head -n1 | sed "s/^[^:]*: //")
+	case $device in
+	    "QNAP TS-109/TS-209")
+		mv /etc/qcontrol/ts209.lua /etc/qcontrol.conf ;;
+	    "QNAP TS-119/TS-219")
+		mv /etc/qcontrol/ts219.lua /etc/qcontrol.conf ;;
+	    "QNAP TS-409")
+		mv /etc/qcontrol/ts409.lua /etc/qcontrol.conf ;;
+	    "QNAP TS-41x")
+		mv /etc/qcontrol/ts41x.lua /etc/qcontrol.conf ;;
+	esac
+	rm -rf /etc/qcontrol/
+
+	modprobe -q gpio_keys >/dev/null 2>&1
+	sleep 1
+
+	qcommand powerled on
+	qcommand statusled green1hz
+fi
--- qcontrol-0.4.2.orig/debian/udeb/finish-install.d/21qcontrol
+++ qcontrol-0.4.2/debian/udeb/finish-install.d/21qcontrol
@@ -0,0 +1,6 @@
+#! /bin/sh
+
+if qcommand -t; then
+	qcommand powerled 1hz
+	qcommand statusled red1hz
+fi
