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

/etc/init.d/lircd stop
if [ "$LIRC" = "Tastatur" ] ; then
   logger -s "ADMIN - Tastaturmodus"
   /etc/init.d/lircd stop
   cp /_config/install/vdr/remote.conf /etc/vdr/remote.conf  >/dev/null 2>&1
   rc-update del lircd  >/dev/null 2>&1
   rc-update del irexec  >/dev/null 2>&1

   sed -i $CONFIG/setup.conf -e "s/^mplayer\.ControlMode.*/mplayer\.ControlMode = 1/"
   sed -i /_config/install/vdr/setup.conf -e "s/^mplayer\.ControlMode.*/mplayer\.ControlMode = 1/"
else
   if [ "$LIRC" = "Nexus" ]; then
      logger -s "ADMIN - LIRC: Nexus"
      cp /_config/install/vdr/remote.conf /etc/vdr/remote.conf  >/dev/null 2>&1
      rc-update del lircd  >/dev/null 2>&1
      rc-update del irexec  >/dev/null 2>&1
      $SETVAL PLG_remote 01
   else
      logger -s "ADMIN - LIRC: $LIRC"
      rc-update add lircd boot >/dev/null 2>&1
      rc-update add irexec default >/dev/null 2>&1
      cp /_config/install/vdr/remote.conf /etc/vdr/remote.conf  >/dev/null 2>&1
      if [ -f /_config/install/lircd.conf.$LIRC ] ; then
         sed -i $CONFIG/setup.conf -e "s/^mplayer\.ControlMode.*/mplayer\.ControlMode = 0/"
         sed -i /_config/install/vdr/setup.conf -e "s/^mplayer\.ControlMode.*/mplayer\.ControlMode = 0/"
         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
      /etc/init.d/irexec start
   fi
fi
echo 'Done!'
exit 0

