summaryrefslogtreecommitdiffstats
path: root/abs/core/runit-scripts/runitscripts/services/remotes/run
blob: 35d3f80debed9e5c34353efaa30ad03fc97506ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/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

echo "`date` --- run started" >> $LOG


. /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"
    echo $CMD >>$LOG
    exec $CMD >>$LOG 2>>$LOG
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 >>$LOG
    exec $CMD >>$LOG 2>>$LOG
elif [ x$ReceiverType = "xSiliconDust_HDHR" ]
then
    # if using the SiliconDust_HDHR as an I/R Receiver
    CMD="/usr/sbin/lircd -H udp -d 5000 -n"
    printhl "   Using SiliconDust on port 5000"
    echo $CMD >>$LOG
    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 >>$LOG
        exec $CMD >>$LOG 2>>$LOG
        LASTCMD="--connect=localhost:876$i   $LASTCMD    "
    done

    echo $LASTCMD >>$LOG

    if [ -f /etc/remote.run ]
    then
        #program must not terminate.

        stat_runit "Starting remotes from /etc/remote.run"
        echo "Starting remotes from /etc/remote.run" >>$LOG
        exec /etc/remote.run    $LASTCMD >>$LOG 2>>$LOG
    else
        echo "Disable in kernel remote driver" >>$LOG
        in_kernel_support "disable"
        LCMD="/usr/sbin/lircd -r -n -d /dev/lirc0 --output /var/run/lirc/lircd  $LASTCMD"
        echo $LCMD >>$LOG
        exec $LCMD >>$LOG 2>>$LOG
    fi
fi