#!/bin/sh
VDR_DISABLED_FILE="/_config/status/.vdrdisabled"
VDR_CONSOLE=8
X_CONSOLE=7

rm -f /_config/status/.checkcon
while [ ! -e /_config/status/.checkcon ] ; do
   if [ -f $VDR_DISABLED_FILE ] ; then
      if [ "$(fgconsole)" = "$VDR_CONSOLE" ] ; then
         sleep 2
         if [ "$(fgconsole)" = "$VDR_CONSOLE" ] ; then
            rm -f $VDR_DISABLED_FILE 2> /dev/null
            sh /_config/bin/setscart.sh DVB
         fi
      fi
   else
      if [ "$(fgconsole)" = "$X_CONSOLE" ] ; then
         while [ "$(fgconsole)" = "$X_CONSOLE" ] ; do
            logger -s "Switching to console $VDR_CONSOLE"
            killall -9 chvt > /dev/null 2>&1
            chvt $FGC &
            sleep 1
         done
         sh /_config/bin/setscart.sh DVB
      fi
   fi
   sleep 2
done
rm -f /_config/status/.checkcon

exit
