#!/bin/sh
#
# adzapcheck.sh
#
# source: vdr-plugin adzap

PATH=$PREFIX/bin:$PREFIX/sbin:$PATH

rm -f /tmp/adzap.run

at now <<EOT
if ping -c 1 www.werbesignal.dyndns.org ; then
    cmd()
    {
      lynx \
        -dump http://www.werbesignal.dyndns.org/Werbesignal_client.php | \
	   tr -d ' ' | \
	     grep ^"\$(echo \$@ | \
		sed -e 's:NEUN LIVE Television:9Live:' \
		    -e 's:Das Erste:ARD:' \
		    -e 's:DSF:DSF:' \
		    -e 's:Eurosport:EuroSport:' \
		    -e 's:KABEL1:Kabel 1:' \
		    -e 's:n-tv:NTV:' \
		    -e 's:ProSieben:Pro7:' \
		    -e 's:RTL Television:RTL:' \
		    -e 's:RTL2:RTL II:' \
		    -e 's:SAT.1:Sat.1:' \
		    -e 's:Super RTL:Super RTL:' \
		    -e 's:VOX:VOX:' \
		    -e 's: ::g')WerbungANseit[0-9]"
    }
    if [ -n "\$(cmd $1)" ] ; then
	date > /tmp/adzap.run
	while [ -a /tmp/adzap.run -a -n "\$(cmd $1)" ] ; do
	    sleep 1s
	done
	if [ -a /tmp/adzap.run ] ; then
	    svdrpsend.pl CHAN "$1"
	    rm -f /tmp/adzap.run
	fi
    fi
else
    svdrpsend.pl MESG "check your www connection..."
fi \
> /dev/null 2>&1
EOT

sleep 2s