#!/bin/sh

# Localisation
export TEXTDOMAINDIR="/usr/share/locale"
export TEXTDOMAIN=kanotix-vdr

INSTALLED=""
[ -d /KNOPPIX -o -d /KANOTIX ] || INSTALLED="yes"

if [ -z "$INSTALLED" ]; then
   if grep -q unionfs /proc/mounts; then
      echo Unionfs found.
   else
      echo Activating Unionfs now.
      mkdir -p /tmp/union
      UNION=/KNOPPIX
      [ -d /KANOTIX ] && UNION=/KANOTIX
      mount -t unionfs -o dirs=/tmp/union/:$UNION /none $UNION/ 2>&1 >/dev/null
   fi
fi

NOW=`date +%y-%m-%d_%H:%M:%S`
#DIALOG=Xdialog
DIALOG=dialog

echo $"Please wait ..."
vdr-stop
BACKUPFILE="/var/backups/channels.conf.$NOW"
mv /var/lib/vdr/channels.conf "$BACKUPFILE"
touch /var/lib/vdr/channels.conf

tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15
$DIALOG --clear --title $"Channelscan for dvb-c/t" \
        --menu $"Make your choice:" 15 60 6 \
"w_scan -o3"  $"DVB-T" \
"w_scan -o3 -fc"  $"DVB-C" \
"w_scan -Q -fc"  $"DVB-C modulation type QAM-256" \
"w_scan -R0 -E0 -fc"  $"DVB-C,Radio-, ignore Pay-TV" \
"w_scan -t2 -F"  $"DVB-T with bad reception" 2> $tempfile
answer="$?"
[ "$answer" = 1 ] && exit 1
answer_w_scan=`cat $tempfile`
rm -f $Tempfile
tput clear

$answer_w_scan > /var/lib/vdr/channels.conf
chown vdr.vdr /var/lib/vdr/channels.conf

echo $"/var/lib/vdr/channels.conf done, Backup of existing channels.conf see $BACKUPFILE"

rxvt -C -e vdr-start
echo $"Press any key" && read

