From a923391ea01326947663693e8a1099fc8de5a3f3 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Sat, 10 Mar 2012 12:24:39 -0600
Subject: runit-scripts: add remotes service. refs #821

---
 abs/core/runit-scripts/PKGBUILD                    |   2 +-
 .../runitscripts/services/remotes/finish           |  21 ++++
 .../runitscripts/services/remotes/run              | 125 +++++++++++++++++++++
 3 files changed, 147 insertions(+), 1 deletion(-)
 create mode 100755 abs/core/runit-scripts/runitscripts/services/remotes/finish
 create mode 100755 abs/core/runit-scripts/runitscripts/services/remotes/run

diff --git a/abs/core/runit-scripts/PKGBUILD b/abs/core/runit-scripts/PKGBUILD
index b84f74d..7e0a71c 100755
--- a/abs/core/runit-scripts/PKGBUILD
+++ b/abs/core/runit-scripts/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=runit-scripts
 pkgver=2.1.1
-pkgrel=55
+pkgrel=56
 pkgdesc="collection of startup scripts for runit"
 url="http://smarden.org/runit/"
 license="BSD"
diff --git a/abs/core/runit-scripts/runitscripts/services/remotes/finish b/abs/core/runit-scripts/runitscripts/services/remotes/finish
new file mode 100755
index 0000000..ac04a33
--- /dev/null
+++ b/abs/core/runit-scripts/runitscripts/services/remotes/finish
@@ -0,0 +1,21 @@
+#!/bin/bash
+export TERM=linux
+. /etc/rc.conf
+. /etc/rc.d/functions
+. /usr/MythVantage/bin/install_functions.sh
+
+killall -9 lircd 2>/dev/null
+rm -f /var/run/lirc*.pid
+[ -e /etc/sv/remotes/.runtime ] || mkdir -p /etc/sv/remotes/.runtime
+touch /etc/sv/remotes/.runtime/`date +%s`
+numfiles=`/usr/bin/file_time_offset.py   -s4 -d/etc/sv/remotes/.runtime `
+if [ $numfiles -gt 3 ]
+then
+	 rm -f /etc/sv/remotes/.runtime/* 2>/dev/null
+	 sv stop remotes
+	 printhl "    remotes is not able to start, disabling it"
+fi
+
+
+
+in_kernel_support "enable"
diff --git a/abs/core/runit-scripts/runitscripts/services/remotes/run b/abs/core/runit-scripts/runitscripts/services/remotes/run
new file mode 100755
index 0000000..d32b09e
--- /dev/null
+++ b/abs/core/runit-scripts/runitscripts/services/remotes/run
@@ -0,0 +1,125 @@
+#!/bin/bash
+
+exec 2>&1
+export TERM=linux
+
+. /etc/rc.conf
+. /etc/rc.d/functions
+. /usr/MythVantage/bin/install_functions.sh
+
+LOG=/tmp/remotes.log
+
+if [ -f $LOG ]
+then
+    rm -f $LOG
+fi
+
+
+
+
+
+#What is done in this file may not be enough to start your specific remote
+#If that is true of your remote place your remote startup commands in:
+# /etc/remotes.sh
+#Anything in that file will be used and the rest of this file is ignored
+
+if [ -f /etc/remotes.sh ]
+then
+    #program must not terminate.
+
+    stat_runit "Starting remotes from /etc/remotes.sh"
+
+    /etc/remotes.sh
+else
+    . /etc/systemconfig
+    stat_runit "Starting remotes"
+
+    [ -e /etc/sv/remotes/.runtime ] || mkdir -p /etc/sv/remotes/.runtime
+    [ -e /var/run/lirc ] || mkdir -p /var/run/lirc
+
+    num_lirc=`ls -la /dev/lirc[0-9] 2>/dev/null |wc -l `
+    num_lirc=$((num_lirc-1))
+
+    serial_port=""
+
+    if [ x$ReceiverType = xSerial ]
+    then
+        serial_port=$ReceiverSerialport
+    elif [ x$HostBlasterType = xSerial ]
+    then
+        serial_port=$HostSerialPort_blasterlirc
+    fi
+
+    if [ -n "$serial_port" ]
+    then
+        #/dev/ttyS0 (COM1), port 0x3f8, irq 4
+        #/dev/ttyS1 (COM2), port 0x2f8, irq 3
+        #/dev/ttyS2 (COM3), port 0x3e8, irq 4
+        #/dev/ttyS3 (COM4), port 0x2e8, irq 3
+
+        case $serial_port in
+        ttyS0)
+               FLAGS="io=0x3f8  irq=4"
+               ;;
+        ttyS1)
+               FLAGS="io=0x2f8  irq=3"
+               ;;
+        ttyS2)
+               FLAGS="io=0x3e8  irq=4"
+               ;;
+        ttyS3)
+               FLAGS="io=0x2e8  irq=3"
+               ;;
+        esac
+        /usr/bin/setserial /dev/$serial_port uart none
+        sleep 0.5
+        /sbin/modprobe lirc_serial $FLAGS
+        sleep 0.5
+    fi
+
+    if [ x$HostBlasterType = xCommandIR -o x$ReceiverType = xCommandIR ]
+    then
+        CMD="/usr/sbin/lircd -r -n  --driver=commandir"
+        printhl "   Using commandir"
+        $CMD >>$LOG 2>>$LOG
+        #echo $CMD
+    elif [ x$HostBlasterType = xiguanaIR-usb -o x$ReceiverType = xiguanaIR-usb ]
+    then
+        sv start igdaemon
+        CMD="/usr/sbin/lircd -r -n  --driver=iguanaIR"
+        printhl "       Using iguanaIR usb"
+        #echo $CMD
+        $CMD >>$LOG 2>>$LOG
+    elif [ x$ReceiverType = "xSiliconDust_HDHR" ]
+    then
+        # if using the SiliconDust_HDHR as an I/R Receiver
+        printhl "   Using SiliconDust on port 5000"
+        CMD="/usr/sbin/lircd -H udp -d 5000 -n"
+        exec $CMD >>$LOG 2>>$LOG
+    else
+        LASTCMD=""
+
+        for i in `seq 1 $num_lirc`
+        do
+            CMD="/usr/sbin/lircd -r -d /dev/lirc$i --output=/var/run/lirc/lircd$i --pidfile=/var/run/lircd$i.pid --listen=876$i"
+            printhl "   Device $i"
+            #echo $CMD
+            $CMD >>$LOG 2>>$LOG
+            LASTCMD="--connect=localhost:876$i   $LASTCMD    "
+        done
+
+        if [ -f /etc/remote.run ]
+        then
+            #program must not terminate.
+
+            stat_runit "Starting remotes from /etc/remote.run"
+
+            /etc/remote.run
+        else
+            in_kernel_support "disable"
+            LCMD="/usr/sbin/lircd -r -n -d /dev/lirc0 --output /var/run/lirc/lircd  $LASTCMD"
+            #echo $LCMD
+            exec $LCMD >>$LOG 2>>$LOG
+        fi
+    fi
+fi
-- 
cgit v0.12