#!/bin/sh

# global configuration file - see vdr-config for more info
CONFIGFILE="/var/lib/vdr/kanotix-vdr/kanotix-vdr.conf"

# 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

if [ "$(grep ^LanguageMode $CONFIGFILE | cut -d= -f2)" -ne 1 ]; then
    # Set VDR-language automatically
    # source sysconfig to detect the default system language
    [ -f /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
    lang=$(grep ^OSDLanguage /var/lib/vdr/setup.conf | cut -d= -f2)
    [ "$lang" ] && old=$(echo $lang)
    [ -z "$lang" ] && old=0
    new=0 # default language, if detected language is not German
    [ "$LANGUAGE" = "de" ] && new=1
    if [ "$old" != "$new" ]; then
        if [ -z "$lang" ]; then
            echo "OSDLanguage = $new" >> /var/lib/vdr/setup.conf
        else
            perl -pi -e "s/^OSDLanguage =.*$/OSDLanguage = $new/" /var/lib/vdr/setup.conf
        fi
    fi
fi

/etc/init.d/vdr start
/etc/init.d/vdradmin-am start
echo $"Please wait ..."
sleep 10
