#!/bin/sh
#                                           snoopmsg Version 0.4a
#$1 Startzeit (sec)
#$2 /var/bin/msgbox-Timeout (sec)
label1="OK"
label2="Abbruch OSD"
label3="Abbruch Script"
#
#---------------------------------------------------------------------------------------------------------------

stat=

while [ -z "$stat" -o "$stat" = "$label1" ]; do
  if [ -e /tmp/.snoop ]; then
      endsec=`date +"%s"`
      secges=`expr $endsec - $1`
      minges=`expr $secges / 60`
      std=`expr $minges / 60`
      minstd=`expr 60 \* $std`
      min=`expr $minges - $minstd`
      sec=`expr $secges - 60 \* $minges`
      stat=`/var/bin/msgbox msg="Empfangssignal-Auswertung l~auft...~n~nLaufzeit:  $std Std $min min $sec sec" title="snoop" timeout=$2 hide=0 select="$label1,$label2,$label3" order=3 refresh=0 echo=1`
      if [ "$stat" = "$label2" ]; then
          break
      else
          if [ "$stat" = "$label3" ]; then
              killall -q -9 "$3"
              rm /tmp/.snoop >/dev/null
              rm /tmp/snoop* >/dev/null
              if [ "$6" = "-ra" ]; then
                  /bin/pzapit -ra -name "$5" >/dev/null                         # auf Radiosender zurckschalten
              else
                  /bin/pzapit -name "$5" >/dev/null                             # auf Fernsehsender zurckschalten
              fi
              wget -Y off -q -O /dev/null http://localhost/control/rc?unlock    # Fernbedienung einschalten
              sleep 2
              rcsim KEY_HOME >/dev/null
              sleep 1
              if [ "$6" = "-ra" ]; then     
                  wget -Y off -q http://localhost/control/setmode?tv -O /dev/null
                  wget -Y off -q http://localhost/control/setmode?radio-O /dev/null 
              else          
                  wget -Y off -q http://localhost/control/setmode?radio -O /dev/null
                  wget -Y off -q http://localhost/control/setmode?tv -O /dev/null
              fi
              sleep 2
              wget -Y off -q http://localhost/control/volume?$4 -O /dev/null    # Lautstrke wiederherstellen
              break 
          fi
      fi
  else
      break
  fi
done
 