#!/bin/bash
#
source /etc/conf.d/vdr
source /etc/conf.d/vdr.admin.cfg

CONTROL_MODE=1
/etc/init.d/lircd stop
/etc/init.d/activylircd stop
rc-update del activylircd boot >/dev/null 2>&1
$SETVAL PLG_lircrc 0

if [ "$LIRC" = "Tastatur" ] ; then
   logger -s "ADMIN - Tastaturmodus"
   rc-update del lircd  >/dev/null 2>&1
   BOARD=$(/_config/bin/query_mb.sh)
   if [ "$BOARD" = "ACTIVY" ] ; then
      rc-update add activylircd boot >/dev/null 2>&1
      rc-update add irexec default >/dev/null 2>&1
      /etc/init.d/activylircd start
      /etc/init.d/irexec start
      CONTROL_MODE=0
#      $SETVAL PLG_lircrc 1
   else
#      $SETVAL PLG_lircrc 0
      rc-update del irexec  >/dev/null 2>&1
   fi   
else
   if [ "$LIRC" = "Nexus" ]; then
      logger -s "ADMIN - LIRC: Nexus"
      rc-update del lircd  >/dev/null 2>&1
      rc-update del irexec  >/dev/null 2>&1
      $SETVAL PLG_remote 1
#      $SETVAL PLG_lircrc 0
   else
      logger -s "ADMIN - LIRC: $LIRC"
      if [ -f /_config/install/lircd.conf.$LIRC ] ; then
         cp -f /_config/install/lircd.conf.$LIRC /etc/lircd.conf  >/dev/null 2>&1
      else
         if [ "$LIRC" != "Other" ]  ; then
            echo "Unknown LIRC parameter $1"
            exit 1
         fi
      fi
      CONTROL_MODE=0
#      $SETVAL PLG_lircrc 1
      rc-update add lircd boot >/dev/null 2>&1
      rc-update add irexec default >/dev/null 2>&1
      /etc/init.d/lircd start
      /etc/init.d/irexec start
   fi
fi
sed -i $CONFIG/setup.conf -e "s/^mplayer\.ControlMode.*/mplayer\.ControlMode = ${CONTROL_MODE}/"
echo 'Done!'
exit 0

