summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/LinHES-config/ir_config.sh
blob: f4c99b9d266e67d9153831f0f3cf347c59c3f4e2 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
function include_lirc () {
    config_file=$1
    include_file=$2
    grep -q  ${include_file} ${config_file}
    if [ $? = 0 ]
    then
        echo ${include_file} already present
    else
        echo "include \"${include_file}\"" >> $config_file
    fi

}

function unload_all_lirc () {
    sv stop lircd
    killall -9 lircd
    modprobe -r $(lsmod |grep ^lirc |awk '{print $1}')
}

function udev_trigger () {
    udevadm settle
    udevadm trigger
    udevadm settle
    udevadm trigger
}



function setup_ir_remote {
    case $Remotetype in
        no_remote) echo "No remote selected"
                  daemon_remove="lircd $daemon_remove"
            ;;

        tinker) echo "Remote in tinker mode"
            ;;

        *)  echo "Start of ir_remote setup"
            #make backup copy
            mv ${BASE}/etc/lircd.conf ${BASE}/etc/lircd.conf.`date +%Y-%m-%d-%H-%M`
            mv ${BASE}/etc/lircrc ${BASE}/etc/lircrc.`date +%Y-%m-%d-%H-%M`
            if [ $HostBlasterType = pvr150 ]
            then
                Remotetype=hauppauge-blaster
            fi

            cd $TEMPLATES/remotes/$Remotetype
            for i in lircd*
            do
                include_lirc ${BASE}/etc/lircd.conf $TEMPLATES/remotes/$Remotetype/$i
            done

            for i in lircrc*
            do
                include_lirc ${BASE}/etc/lircrc $TEMPLATES/remotes/$Remotetype/$i
            done

            chmod 755 /etc/lircrc
            daemon_add="lircd $daemon_add"
            #standard location for mythtv lircrc
            if [ ! -e /home/mythtv/.mythtv/lircrc ]
            then
                if [ ! -d /home/mythtv/.mythtv ]
                then
                    mkdir /home/mythtv/.mythtv
                    chown mythtv:mythtv /home/mythtv/.mythtv
                fi
                ln -s /etc/lircrc /home/mythtv/.mythtv/lircrc 2> /dev/null
            fi
            #standard location for lircrc
            if [ ! -e /home/mythtv/.lircrc ]
            then
                ln -s /etc/lircrc /home/mythtv/.lircrc 2> /dev/null
            fi
#             echo "Sending hup to lircd"
#             sv hup lircd
            ;;
    esac

}
function setup_ir_receiver () {
    echo "setup_ir_receiver"
    case $ReceiverType in
    Serial) echo "setup serial lirc"
            sed -i -e '/.*#lirc/d' ${BASE}/etc/modules.mythvantage
            echo "lirc_serial   #lirc" >> ${BASE}/etc/modules.mythvantage
            load-modules-mythvantage.sh
            ;;
    Usb-imon) echo "setup receiver-usb-imon"
            sed -i -e '/.*#lirc/d' ${BASE}/etc/modules.mythvantage
            echo "lirc_imon     #lirc" >> ${BASE}/etc/modules.mythvantage
            load-modules-mythvantage.sh
            ;;
    Hauppauge) echo "setup hauppauge reciever (lirc_i2c)"
            sed -i -e '/.*#lirc/d' ${BASE}/etc/modules.mythvantage
            echo "lirc_i2c   #lirc" >> ${BASE}/etc/modules.mythvantage
            cp_and_log $TEMPLATES/modules/lirc_i2c.conf ${BASE}/etc/modprobe.d/lirc_i2c.conf
            rmmod lirc_i2c 2>/dev/null
            load-modules-mythvantage.sh
            ;;
        *)   sed -i -e '/.*#lirc/d' ${BASE}/etc/modules.mythvantage
            ;;
    esac


}

function setup_lcd () {
    case x$LCDtype in
        xtinker) echo "do nothing"
                ;;
        xno_lcd) echo "disabling lcd"
                sv down lcdd
                #sometimes it doesn't want to die
                killall -9 LCDd
                load-modules-mythvantage.sh  UNLOAD LCD
                sed -i -e '/.*#LCD/d' ${BASE}/etc/modules.mythvantage
                daemon_remove="lcdd $daemon_remove"
                ;;
            x) echo "empty lcd" ;;

            *) echo "setup lcd"
                if [ -f $TEMPLATES/LCD/$LCDtype/modules  ]
                then
                    sed -i -e '/.*#LCD/d' ${BASE}/etc/modules.mythvantage
                    cat $TEMPLATES/LCD/$LCDtype/modules >> ${BASE}/etc/modules.mythvantage
                #should also modprobe
                fi


                if [ -f $TEMPLATES/LCD/$LCDtype/LCDd.conf ]
                then
                    cp_and_log  $TEMPLATES/LCD/$LCDtype/LCDd.conf /etc
                # install="lcdproc $install"
                    daemon_add="lcdd $daemon_add"
                    load-modules-mythvantage.sh
                    RESTART_FE="true"
                    RESTART_LCD="true"
                fi
                #check if lirc capable,if so then call setupremote
                #if not in tinker mode check for remote
                if [ ! x$Remotetype = xtinker ]
                then
                    if [ -f $TEMPLATES/LCD/$LCDtype/lircrc ]
                    then
                        cd $TEMPLATES/LCD/$LCDtype
                        for i in lircd*
                        do
                            include_lirc ${BASE}/etc/lircd.conf $TEMPLATES/LCD/$LCDtype/$i
                        done

                        for i in lircrc*
                        do
                            include_lirc ${BASE}/etc/lircrc $TEMPLATES/LCD/$LCDtype/$i
                        done
                        cd -
                    fi
                fi
                ;;
        esac
}

function setup_blaster_proto () {
    if [ ! $HostBlasterType = pvr150 -a ! $HostBlasterType = None ]
    then
        for i in `seq $Hostnumblaster`
        do
            TEMP=HostTransmitproto_$i
            eval proto=\$${TEMP}
            if [ -f $TEMPLATES/transmit/${proto}/lircd.conf ]
            then
                include_lirc  ${BASE}/etc/lircd.conf $TEMPLATES/transmit/${proto}/lircd.conf
            fi
        done
    fi
    #--------------------------------REVISIT THIS------------------------
        #sed -e "s/^REMOTE_NAME=.*$/REMOTE_NAME=${Blastertype} /" $TEMPLATES/change_chan.sh > #${BASE}/usr/bin/change_chan.sh
        #chmod 755 ${BASE}/usr/bin/change_chan.sh
        #channel change script change
}

function setup_blaster_transmiter () {
    echo "setup_blaster_transmiter"
    #if it's Reciever type, then these modules have already been loaded.
    if [ ! x$HostBlasterType = xReceiver ]
    then
        case $HostBlasterType in
            None) echo "no blaster"
                  sed -i -e '/.*#blaster/d' ${BASE}/etc/modules.mythvantage
                  ;;
            Serial) echo "setup serial lirc blaster"
                    sed -i -e '/.*#blaster/d' ${BASE}/etc/modules.mythvantage
                    echo "lirc_serial   #blaster" >> ${BASE}/etc/modules.mythvantage
                    load-modules-mythvantage.sh
                    ;;
            pvr150) echo "setup hauppauge blaster (lirc_pvr150)"
                    sed -i -e '/.*#blaster/d' ${BASE}/etc/modules.mythvantage
                    sed -i -e '/.*#lirc/d' ${BASE}/etc/modules.mythvantage
                    echo "lirc_pvr150   #blaster" >> ${BASE}/etc/modules.mythvantage
                    echo "lirc_pvr150   #lirc" >> ${BASE}/etc/modules.mythvantage
                    #cp_and_log $TEMPLATES/modules/lirc_i2c.conf ${BASE}/etc/modprobe.d/lirc_i2c.conf
                    rmmod lirc_i2c 2>/dev/null
                    load-modules-mythvantage.sh
                    ;;
                *)   sed -i -e '/.*#blaster/d' ${BASE}/etc/modules.mythvantage
                    ;;
        esac
    fi

}

function setupir () {
   if [ ! x$Remotetype = xtinker ]
   then
        setup_ir_remote
        setup_ir_receiver
        unload_all_lirc
        setup_blaster_proto
        setup_blaster_transmiter
        RESTART_FE="true"
        load-modules-mythvantage.sh
        udev_trigger
        sleep 1
        sv start lircd

    fi
    setup_lcd
}