#!/bin/sh
source /etc/conf.d/vdr.admin.cfg

VAL=$2
NAME=$1

NLINE=`cat $ADMIN_CFG_FILE | grep ":$NAME:"`

if [ "$NLINE" = "" ] ; then
   echo "AdmVar: <$NAME> not found"
   exit 1
fi

TYPE=`echo $NLINE | cut -f 4 -d ":"`
OLDVAL=`echo $NLINE | cut -f 3 -d ":"`
if [ "$TYPE" = "L" ] ; then
   ALL_VAL=`echo $NLINE | cut -f 6 -d ":" | sed 's/,/ /g'`
   IDX=0
   for i in $ALL_VAL ; do
      if [ "${i}" = "$VAL" ] ; then
	 VAL=$IDX
      fi
      IDX=$(($IDX+1))
   done
fi

set -x
sed -i $ADMIN_CFG_FILE -e "s/\:$NAME\:$OLDVAL\:/\:$NAME\:$VAL\:/"