From 2e3d0d812bc9459adea4b0dbf1b038dbd1e79dc0 Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Tue, 31 Mar 2009 22:07:43 -0500
Subject: LinHES-config: reworked lirc configuration to make it easier to use.

currently hauppauge is broken.
---
 abs/core-testing/LinHES-config/PKGBUILD            |   5 +-
 .../LinHES-config/install_functions.sh             |  22 +-
 abs/core-testing/LinHES-config/ir_config.sh        | 193 +++++++++++++++
 abs/core-testing/LinHES-config/systemconfig.sh     | 264 +++++++--------------
 4 files changed, 306 insertions(+), 178 deletions(-)
 create mode 100644 abs/core-testing/LinHES-config/ir_config.sh

diff --git a/abs/core-testing/LinHES-config/PKGBUILD b/abs/core-testing/LinHES-config/PKGBUILD
index db6314f..f4012c5 100644
--- a/abs/core-testing/LinHES-config/PKGBUILD
+++ b/abs/core-testing/LinHES-config/PKGBUILD
@@ -1,12 +1,12 @@
 pkgname=LinHES-config
 pkgver=1.0
-pkgrel=346
+pkgrel=356
 conflicts=(MythVantage-config MythVantage-config-dev LinHES-config-dev )
 pkgdesc="Install and configure your system"
 depends=(bc libstatgrab  mysql-python expect curl dnsutils parted sg3_utils nmbscan system-templates )
 arch=('i686')
 
-source=(mythinstall.bin myth_user_call file_time_offset.py install-ui.xml install_proxy.sh install_functions.sh systemconfig.sh install_db_chroot.sh restore_default_settings.sh xconfig.sh timezip.py soundconfig.sh LinHES-release issue MythVantage.sh create_master.sh build_diskless.sh networkconfig.sh timezone.bin autocard.py restore_km_db_chroot.sh README)
+source=(mythinstall.bin myth_user_call file_time_offset.py install-ui.xml install_proxy.sh install_functions.sh systemconfig.sh install_db_chroot.sh restore_default_settings.sh xconfig.sh timezip.py soundconfig.sh LinHES-release issue MythVantage.sh create_master.sh build_diskless.sh networkconfig.sh timezone.bin autocard.py restore_km_db_chroot.sh README ir_config.sh)
 
 install=LinHES.install
 build() {
@@ -27,6 +27,7 @@ build() {
     install -m 0755 install_functions.sh  $MVDIR/bin/install_functions.sh
     install -m 0755 systemconfig.sh  $MVDIR/bin/systemconfig.sh
     install -m 0755 xconfig.sh  $MVDIR/bin/xconfig.sh
+    install -m 0755 ir_config.sh  $MVDIR/bin/ir_config.sh
 #    install -m 0755 live-install.sh $MVDIR/bin/live-install.sh
     install -m 0755 install_db_chroot.sh $MVDIR/bin/install_db_chroot.sh
     install -m 0755 restore_km_db_chroot.sh $MVDIR/bin/restore_km_db_chroot.sh
diff --git a/abs/core-testing/LinHES-config/install_functions.sh b/abs/core-testing/LinHES-config/install_functions.sh
index ddade6d..a57e1bd 100755
--- a/abs/core-testing/LinHES-config/install_functions.sh
+++ b/abs/core-testing/LinHES-config/install_functions.sh
@@ -85,12 +85,30 @@ do
         FoundReceiverType=`echo "$line"|cut -d"|" -f2`
         Remotetype=`echo "$line"|cut -d"|" -f4`
         statusline=`echo "$line"|cut -d"|" -f2,4`
-        echo "Found $statusline , $Remotetype"
+        #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
         setupremote
         break
     fi
-
 done
 }
 
diff --git a/abs/core-testing/LinHES-config/ir_config.sh b/abs/core-testing/LinHES-config/ir_config.sh
new file mode 100644
index 0000000..670f9fa
--- /dev/null
+++ b/abs/core-testing/LinHES-config/ir_config.sh
@@ -0,0 +1,193 @@
+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 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`
+            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
+                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 () {
+    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
+    #--------------------------------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
+            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
+                    ;;
+            Hauppauge) echo "setup hauppauge blaster (lirc_i2c)"
+                    sed -i -e '/.*#blaster/d' ${BASE}/etc/modules.mythvantage
+                    echo "lirc_i2c   #blaster" >> ${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
+    fi
+
+}
+
+function setupir () {
+   if [ ! x$Remotetype = xtinker ]
+   then
+        setup_ir_remote
+        setup_ir_receiver
+        setup_blaster_proto
+        setup_blaster_transmiter
+    fi
+    setup_lcd
+}
\ No newline at end of file
diff --git a/abs/core-testing/LinHES-config/systemconfig.sh b/abs/core-testing/LinHES-config/systemconfig.sh
index 2cb1a0c..72c5287 100755
--- a/abs/core-testing/LinHES-config/systemconfig.sh
+++ b/abs/core-testing/LinHES-config/systemconfig.sh
@@ -213,69 +213,6 @@ Hauppauge) echo "setup hauppauge reciever (lirc_i2c)"
 
 }
 
-function setupremote {
-    case $Remotetype in
-        no_remote) echo "No remote selected"
-                daemon_remove="lircd $daemon_remove"
-                ;;
-        tinker) echo "Remote in tinker mode"
-                ;;
-            *)  echo "Setup remote"
-                mv ${BASE}/etc/lircd.conf ${BASE}/etc/lircd.conf.`date +%Y-%m-%d-%H-%M`
-                cd $TEMPLATES/remotes/$Remotetype
-                for i in lircd*
-                do
-                        cat $i >> ${BASE}/etc/lircd.conf
-                done
-                cp -f lircrc* $BASE/etc/lircrc 2> /dev/null
-                if [ -f $TEMPLATES/LCD/$LCDtype/lircrc ]
-                then
-                    cat $TEMPLATES/LCD/$LCDtype/lircrc >> /etc/lircrc
-                    cat $TEMPLATES/LCD/$LCDtype/lircd.conf >> /etc/lircd.conf
-                fi
-                if [ -f $TEMPLATES/transmit/$Blastertype/lircd.conf ]
-                then
-                    cat $TEMPLATES/transmit/$Blastertype/lircd.conf  >> ${BASE}/etc/lircd.conf
-                fi
-                chmod 755 /etc/lircrc
-                daemon_add="lircd $daemon_add"
-                sv hup lircd
-
-        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
-        if [ ! -e /home/mythtv/.lircrc ]
-        then
-
-            ln -s /etc/lircrc /home/mythtv/.lircrc 2> /dev/null
-        fi
-
-
-                ;;
-esac
-
-}
-
-function setupblaster {
-        #cd $TEMPLATES/transmit/$Blastertype
-        #for i in lircd*
-        #do
-        #       cat lircd.conf  >> ${BASE}/etc/lircd.conf
-        #done
-    #  REMOTE_NAME${BASE}/usr/bin/change_chan.sh=`grep name lircd.conf* |awk -F" " ' { print $2 } '`
-        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
-        setupremote
-
-}
 
 function setupevrouter {
     if [  x$UseEvrouter  = x1 ]
@@ -302,46 +239,6 @@ function setupevrouter {
 
 }
 
-function setupLCD {
-case x$LCDtype in
-    xtinker) echo "do nothing"
-            ;;
-    xno_lcd) echo "disabling lcd"
-            sv down 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 [ -f $TEMPLATES/LCD/$LCDtype/lircrc ]
-            then
-                setupremote
-            fi
-            ;;
-    esac
-
-}
-
 
 
 function scrubnfs {
@@ -479,6 +376,7 @@ install="$pkglistinstall $install"
 remove="$pkglistremove $remove"
 
 }
+
 function LCDcheck () {
 case x$LCDtype in
     xtinker) echo "do nothing lcd "
@@ -1239,6 +1137,12 @@ case $i in
         daemon_add=$ser_daemon_add
         daemon_remove=$ser_daemon_remove
         ;;
+     screensaver)
+        showscreensaver="true"
+        ;;
+     ir)
+        showir="true"
+        ;;
 
     this_is_install) MV_NEW_INSTALL="true"
         ;;
@@ -1290,86 +1194,85 @@ fi
 
 if [ x$showhost = "xtrue" ]
 then
-case $SystemType in
-    Standalone)
-            setupntp 1
-            services
-            if [ x$hosttypechange = "xtrue" ]
-            then
-            setup_db
-            fi
-            if [ -f   ${BASE}/etc/avahi/services/mysql.service     ]
-            then
-                        rm -f ${BASE}/etc/avahi/services/mysql.service
-                        sudo sv restart avahi
-            fi
+    . $MV_ROOT/bin/ir_config.sh
+    setupir
+    case $SystemType in
+        Standalone)
+                setupntp 1
+                services
+
+                if [ x$hosttypechange = "xtrue" ]
+                then
+                    setup_db
+                fi
+                if [ -f   ${BASE}/etc/avahi/services/mysql.service     ]
+                then
+                            rm -f ${BASE}/etc/avahi/services/mysql.service
+                            sudo sv restart avahi
+                fi
 
-            install="mysql mythdb-initial  avahli portmap nfslock local-website $ser_install"
+                install="mysql mythdb-initial  avahli portmap nfslock local-website $ser_install"
+                remove="none $ser_remove"
 
+                daemon_add="mysql  mythbackend  avahi portmap nfslock netfs lighttpd $ser_daemon_add"
+                daemon_remove="none $ser_daemon_remove"
 
-            remove="none $ser_remove"
+                ;;
+        Master_backend)
+                setupntp 1
+                services
 
-            daemon_add="mysql  mythbackend  avahi portmap nfslock netfs lighttpd $ser_daemon_add"
-            daemon_remove="none $ser_daemon_remove"
+                if [  !  -f   ${BASE}/etc/avahi/services/mysql.service     ]
+                then
+                            mkdir  ${BASE}/etc/avahi/services
+                            cp $TEMPLATES/mysql.service  ${BASE}/etc/avahi/services/mysql.service
+                            sudo sv restart  avahi
+                fi
 
-    ;;
-Master_backend)
-            setupntp 1
-            services
+                install="mysql  mythdb-initial avahi portmap nfslock local-website myth2ipod mythtv-status $ser_install  "
+                remove="$ser_remove"
 
-            if [  !  -f   ${BASE}/etc/avahi/services/mysql.service     ]
-            then
-                        mkdir  ${BASE}/etc/avahi/services
-                        cp $TEMPLATES/mysql.service  ${BASE}/etc/avahi/services/mysql.service
-                        sudo sv restart  avahi
-            fi
+                daemon_add="mysql mythbackend  avahi   portmap nfslock netfs lighttpd $ser_daemon_add"
+                daemon_remove="$ser_daemon_remove"
+                ;;
+        Slave_backend)
+                setupntp 0
+                services
+                if [ x$hosttypechange = "xtrue" ]
+                then
+                setup_db
+                fi
+                if [    -f   ${BASE}/etc/avahi/services/mysql.service     ]
+                then
+                            rm -f ${BASE}/etc/avahi/services/mysql.service
+                            sudo sv restart  avahi
+                fi
 
-            install="mysql  mythdb-initial avahi portmap nfslock local-website myth2ipod mythtv-status $ser_install  "
-            remove="$ser_remove"
+                #cp $TEMPLATES/mysql.service  ${BASE}/etc/avahi/services/mysql.service
+                install="mysql  avahi  local-website portmap nfslock $ser_install  "
+                remove=" $ser_remove"
 
-            daemon_add="mysql mythbackend  avahi   portmap nfslock netfs lighttpd $ser_daemon_add"
-            daemon_remove="$ser_daemon_remove"
-    ;;
-    Slave_backend)
+                daemon_add="mythbackend avahi portmap nfslock netfs lighttpd $ser_daemon_add"
+                daemon_remove="$ser_daemon_remove"
+                ;;
+        Frontend_only)
+            #Add values for services
             setupntp 0
             services
-            if [ x$hosttypechange = "xtrue" ]
-            then
-            setup_db
-            fi
-            if [    -f   ${BASE}/etc/avahi/services/mysql.service     ]
-            then
-                        rm -f ${BASE}/etc/avahi/services/mysql.service
-                        sudo sv restart  avahi
-            fi
+            if [  -f   ${BASE}/etc/avahi/services/mysql.service     ]
+                then
+                            rm -f ${BASE}/etc/avahi/services/mysql.service
+                            sudo sv restart  avahi
+                fi
 
-            #cp $TEMPLATES/mysql.service  ${BASE}/etc/avahi/services/mysql.service
-            install="mysql  avahi  local-website portmap nfslock $ser_install  "
-            remove=" $ser_remove"
+            install="libmysqlclient mysql-clients portmap nfslock avahi local-website $ser_install"
+            remove="mysql mythweb$postfix $ser_remove"
 
-            daemon_add="mythbackend avahi portmap nfslock netfs lighttpd $ser_daemon_add"
-            daemon_remove="$ser_daemon_remove"
+            daemon_add="avahi portmap nfslock netfs lighttpd $ser_daemon_add "
+            daemon_remove="mysql   mythbackend  $ser_daemon_remove"
     ;;
-    Frontend_only)
-        #Add values for services
-        setupntp 0
-        services
-        if [  -f   ${BASE}/etc/avahi/services/mysql.service     ]
-            then
-                        rm -f ${BASE}/etc/avahi/services/mysql.service
-                        sudo sv restart  avahi
-            fi
-
-        install="libmysqlclient mysql-clients portmap nfslock avahi local-website $ser_install"
-        remove="mysql mythweb$postfix $ser_remove"
-
-        daemon_add="avahi portmap nfslock netfs lighttpd $ser_daemon_add "
-        daemon_remove="mysql   mythbackend  $ser_daemon_remove"
-;;
-
-
-esac
-#setupSyslog
+    esac
+    #setupSyslog
 
 fi
 
@@ -1384,7 +1287,10 @@ if [ x$showhost = "xtrue" ]
 then
     setupmysqlnetwork
     setupmysql
-    setupremote
+
+    #setupremote
+    #REMOTE FIND ME JM
+
     #grab the new dbhost key
     #/usr/bin/grabkey.py
 fi
@@ -1449,14 +1355,24 @@ then
     setuphobbitclient
     setupreceiver
     setupevrouter
-    setupblaster
-    setupLCD
+    #setupblaster
+    #setupLCD
     setupDNSMASQ
-    setupscreensaver
+
 
 
 fi
 
+if [ x$showscreensaver  = xtrue ]
+then
+     setupscreensaver
+fi
+
+if [ x$showir = xtrue ]
+then
+    . $MV_ROOT/bin/ir_config.sh
+    setupir
+fi
 
 daemons
 #add check for lcd, and restart if needed.
-- 
cgit v0.12