summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-config/install_functions.sh
blob: fd33e007cac546f14f0ce6aa4ebc346462675aba (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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#!/bin/bash
MYTH_RUN_STATUS="1"
. /etc/profile

disk=$2
mountpoint=new_boot

#-------------------------------------------
MYTHDBUSER=mythtv
MYTHTVPASSWD=mythtv
CMDLINE=$(cat /proc/cmdline)
hostname=`hostname`
MYSQLCMD_C="mysql -u$MYTHDBUSER  -p$MYTHTVPASSWD mythconverg -B --exec"
BASE=""
found_remote=1

function update_db_settings () {

 printhl "  setting database value $1 to $2 for $hostname"
 $MYSQLCMD_C "delete from settings where value='${1}' and hostname=\"$hostname\";"  2>/dev/null
 $MYSQLCMD_C "REPLACE INTO  settings set value='${1}', data='${2}' , hostname=\"$hostname\";" 2>/dev/null
}

function random_theme () {
THEMES="basic-blue
basic-green
basic-red
basic-purple
basic-amber"

theme=($THEMES)                # Read into array variable.

num_themes=${#theme[*]}        # Count how many elements.

pick=${theme[$((RANDOM%num_themes))]}
printhl "   Selected $pick as the theme"
update_db_settings Theme "$pick"
}

function parse_cmdline_2_db(){
    echo $CMDLINE | grep -q displayres
    if [ $? -eq 0 ]
    then
        TEMPVAR=${CMDLINE#*displayres=}
        update_db_settings HostXres $TEMPVAR
    fi

}


function bootsplash_setup (){
    echo $CMDLINE | grep -q splash=silent
    if [ $? -eq 0 ]
    then
        update_db_settings Hostbootsplash 1
    else
        update_db_settings Hostbootsplash 0
    fi
}


function setupremote {
    [ -e $BASE/etc/lircd.conf ] && mv -f $BASE/etc/lircd.conf $BASE/etc/lircd.conf.`date +%Y-%m-%d-%H-%M`
    remotepath="$TEMPLATES/remotes/$remotebucket/$Remotetype"
    if [ -d ${remotepath} ]
    then
            cd ${remotepath}
            for i in lircd*
            do
                    cat $i >> $BASE/etc/lircd.conf
            done
            cp -f lircrc* $BASE/etc/lircrc 2> /dev/null
            [ -e /etc/lircrc ] && chmod 755 /etc/lircrc
            update_db_settings HostRemoteType  "$Remotetype"
            update_db_settings HostRemotebucket "$remotebucket"
            update_db_settings HostRemoteType_${remotebucket}  "$Remotetype"
        #special case for special remote
        printhl "Starting with support for $Remotetype"
        if [ "$Remotetype" == "dvico" ]
        then
            /usr/sbin/lircd  -d /dev/usb/hiddev0 --driver=dvico
        elif [ "$Remotetype" == "Dvico-Dual-Digital4-rev2" ]
        then
            /usr/sbin/lircd -d /dev/input/irremote --driver=devinput
        else
            /usr/sbin/lircd -d /dev/lirc0
        fi
        [ -e /root/.mythtv ] ||  mkdir /root/.mythtv 2>/dev/null
        ln -s /etc/lircrc /root/.mythtv/lircrc 2>/dev/null
    else
        echo "Couldn't open directory ${remotepath}"
    fi
}

function scan_for_hpg_receiver() {
printhl "   Scanning for Hauppauge receiver"
for hpgid in `lspci -nm  -d4444: |cut -d" " -f6-  |tr -d '"'|tr " " :`
do
    line=`grep $hpgid $TEMPLATES/remotes/i2c.id`
    if [ $? -eq 0 ]
    then
        modprobe lirc_i2c
        FoundReceiverType=`echo "$line"|cut -d"|" -f2`
        Remotetype=`echo "$line"|cut -d"|" -f4`
        statusline=`echo "$line"|cut -d"|" -f2,4`
        remotebucket=`echo "$line"|cut -d"|" -f5`
        #echo $remotebucket
        #echo "Found $statusline , $Remotetype"
        echo "Found Hauppauge"
        echo "-------------------"
        echo "  1) Hauppauge black"
        echo "  2) Hauppauge silver"
        echo "  3) hauppauge-grey-g3"
        echo ""
        read -p "Which Hauppauge remote (5 sec): " -t 5 ans
        echo
        if [ "$?" != "0" ]; then
        echo
            echo "Using default $Remotetype"
        else
            case $ans in
                1) Remotetype="hauppauge-black";;
                2) Remotetype="hauppauge-silver";;
                3) Remotetype="hauppauge-grey-g3" ;;
                *) echo "Using default $Remotetype";;
             esac
        fi
        update_db_settings  HostReceiverType $FoundReceiverType
        found_remote=0
        setupremote
        break
    fi
done
}


function scan_for_usb_remote () {
#found_remote=1
printhl "   Scanning for usb receiver/remote"
while read line
do
    USBID=`echo "$line"|cut -d"|"  -f1`
    lsusb -d "$USBID" > /dev/null 2>/dev/null
    if [ $? -eq 0 ]
    then
        Remotetype=`echo "$line"|cut -d"|" -f2`
        remotebucket=`echo "$line"|cut -d"|" -f4`
        printhl  "Found $Remotetype"
        setupremote
        found_remote=0
        break
    fi
done <$BASE/$TEMPLATES/remotes/receiver_usb.id
if [ $found_remote -eq 1 ]
then
    scan_for_hpg_receiver
fi
# printhl "   Scanning for TatIR"
# if lsusb | grep 04d8:0004 > /dev/null 2>/dev/null
# then
# 	/usr/bin/PyroUsb.py > /dev/null 2>&1 &
# fi

if [ $found_remote -eq 1  ]
then
#No remote found_remote
     update_db_settings HostRemoteType  "no_remote"
     update_db_settings HostRemotebucket "favorites"
     update_db_settings HostRemoteType_favorites  "no_remote"
fi

}

function rest_of_network () {
    #netmask
    echo $CMDLINE | grep -q cnetmask
    if [ $? -eq 0 ]
    then
        TEMPVAR=${CMDLINE#*cnetmask=}
        NETMASK=${TEMPVAR%% *}
        /sbin/ifconfig eth0 $IP netmask $NETMASK
        nm=`/usr/bin/nmconv.py -obits  $NETMASK`
        NETMASK="/$nm $NETMASK"
        #echo $NETMASK
        update_db_settings HostNETMASK${MYTHDEFAULT} "$NETMASK"
    else
        printhl "   Netmask not found"
    fi
    #gateway
    echo $CMDLINE | grep -q cgateway
    if [ $? -eq 0 ]
    then
        TEMPVAR=${CMDLINE#*cgateway=}
        GATEWAY=${TEMPVAR%% *}
        /sbin/route add default  gw $GATEWAY
        update_db_settings HostGW${MYTHDEFAULT} "$GATEWAY"
    else
        printhl  "  Gateway not found"
    fi

    #dns
    echo $CMDLINE | grep -q cdns
    if [ $? -eq 0 ]
    then
        TEMPVAR=${CMDLINE#*cdns=}
        DNS=${TEMPVAR%% *}
        echo "nameserver $DNS" >> /etc/resolv.conf
        update_db_settings HostDNS${MYTHDEFAULT} "$DNS"
        else
            printhl "    DNS not found"
    fi
    echo $CMDLINE | grep -q chostname
    if [ $? -eq 0 ]
    then
        TEMPVAR=${CMDLINE#*chostname=}
        MYHOST=${TEMPVAR%% *}
        update_db_settings HostMyhostname "$MYHOST"
        else
            printhl "    hostname not found"
    fi
}

function init_network {
    echo $CMDLINE |grep -q cnetdev
    if [ $? -eq 0 ]
    then
        TEMPVAR=${CMDLINE#*cnetdev=}
        MYTHDEFAULT=${TEMPVAR%% *}
    else
        MYTHDEFAULT="eth0"
    fi

    echo $CMDLINE | grep -q ip
    if [ $? -eq 0 ]
    then
        update_db_settings HostDefaulteth0 0
        update_db_settings HostDefault${MYTHDEFAULT} 1

        update_db_settings HostActiveonbooteth0 0
        update_db_settings HostActiveonboot${MYTHDEFAULT} 1
        update_db_settings HostNetDevice ${MYTHDEFAULT}

        TEMPVAR=${CMDLINE#*cip=}
        IP=${TEMPVAR%% *}
        if [ "$IP" == "dhcp" ]
        then
            /sbin/dhcpcd $MYTHDEFAULT
            update_db_settings HostUseDHCP${MYTHDEFAULT} 0
        else
            /sbin/ifconfig ${MYTHDEFAULT} $IP
            update_db_settings HostUseDHCP${MYTHDEFAULT} 1
            update_db_settings HostIP${MYTHDEFAULT} "$IP"
            rest_of_network
        fi
    fi




}

function dev_up_check(){
    /sbin/ifconfig $1 1>/dev/null 2>/dev/null
    status=$?
    if [ $status -eq 1 ]
    then
        return 0
    else
        devip=`/sbin/ifconfig  | grep -C1 $1| grep inet|grep -v inet6  | cut -d: -f2 | awk '{ print $1}'`
        if [  "x$devip" = "x" ]
        then
            return 1
        else
            return 0
        fi
    fi
}

function request_dhcp(){
    echo $CMDLINE |grep -q cnetdev
    if [ $? -eq 0 ]
    then
        TEMPVAR=${CMDLINE#*cnetdev=}
        MYTHDEFAULT_NET=${TEMPVAR%% *}
    else
        MYTHDEFAULT_NET="eth0"
    fi
    for ndev in eth0 eth1 wlan0 wlan1 ath0
    do
        dev_up_check $ndev
        status=$?
        if [ $status -eq 1 ]
        then
            #interface is down, lets see if dhcp responds
            dhcpcd -Td -t2 $ndev -h "" > /tmp/dhcpinfo.$ndev 2>/dev/null
            #check for hostname here

            TEMPVAR=`grep new_ip_address /tmp/dhcpinfo.$ndev |cut -d\= -f2`
            if [ ! x$TEMPVAR = x ]
            then
                update_db_settings HostIP$ndev "$TEMPVAR"
                TEMPVAR=`grep new_subnet_mask /tmp/dhcpinfo.$ndev |cut -d\= -f2`
                nm=`/usr/bin/nmconv.py -obits  $TEMPVAR`
                TEMPVAR="/$nm    $TEMPVAR"
                update_db_settings HostNETMASK$ndev "$TEMPVAR"
                TEMPVAR=`grep new_routers /tmp/dhcpinfo.$ndev |cut -d\= -f2`
                update_db_settings HostGW$ndev "$TEMPVAR"
                TEMPVAR=`grep new_domain_name_servers /tmp/dhcpinfo.$ndev |cut  -d\= -f2| tr -d \"|tr -d \'|cut -d" " -f 1`
                update_db_settings HostDNS$ndev "$TEMPVAR"
            fi
        fi
    done
    TEMPVAR=`grep new_host_name /tmp/dhcpinfo.$MYTHDEFAULT_NET |cut -d\= -f2`
    if [ ! x$TEMPVAR = x ]
    then
        update_db_settings HostMyhostname "$TEMPVAR"
    fi

}

function in_kernel_support() {
    #lifted from mythbuntu
    #For disabling other protocols, adjust to the new location in 2.6.37.    91
    if [ -d /sys/class/rc ] && [ "$(ls -A /sys/class/rc)" ]
    then
        LCDDSTOP=0
        if [ -d /service/lcdd ]; then
            sv stop lcdd
            LCDDSTOP=1
        fi
        for file in `find /sys/class/rc/*/ -name protocols`
        do
            if [ "$1" = "disable" ]
            then
                echo "lirc" > $file
            else
                echo "none" > $file
                for protocol in `cat $file`; do
                echo "+${protocol}" > $file
                done
            fi
        done
        if [ $LCDDSTOP -eq 1 ]; then
            sv start lcdd
        fi
    fi
}



function init_remote {
    mkdir -p /var/run/lirc

    echo $CMDLINE | grep -q remoteport
    if [ $? -eq 0 ]
    then
        TEMPVAR=${CMDLINE#*remoteport=}
        REMOTEPORT=${TEMPVAR%% *}
        #port was given assume we are using a serial receiver
        ReceiverType="Serial"
    if [ x"$ReceiverType" = "xSerial" ]
    then
        if [ -e /dev/$REMOTEPORT ]
        then
            /usr/bin/setserial /dev/$REMOTEPORT uart none
            /sbin/modprobe lirc_serial
            update_db_settings HostReceiverType Serial
            update_db_settings HostSerialPortlirc "$REMOTEPORT"
        fi
    fi

    fi
    in_kernel_support "disable"

    echo $CMDLINE | grep -q remotebucket
    if [ $? -eq 0 ]
    then
        TEMPVAR=${CMDLINE#*remotebucket=}
        remotebucket=${TEMPVAR%% *}
    else
        remotebucket="favorites"
    fi



    echo $CMDLINE | grep -q remote
    if [ $? -eq 0 ]
    then
        TEMPVAR=${CMDLINE#*remote=}
        Remotetype=${TEMPVAR%% *}

        setupremote
    else
        scan_for_usb_remote
    fi
}

function home_check(){
    #This bit of code is used to determine where mythhome is located
    if [ x$MYTHHOME = x ]
    then
    . /etc/profile.d/MythVantage.sh
    fi

    if [ x$MYTHHOME = x ]
    then
        echo "MYTHHOME not defined!"
        exit 1
    fi

    }

#-----------------------