#!/bin/sh
# runvdr: Runs VDR as non-root user
# 
# The DVB driver should be loaded automatically.
#
# Any command line parameters will be passed on to the
# actual "vdr" program.
#
# See the main source file "vdr.c" for copyright information and
# how to reach the author.

VDRPRG="/usr/bin/vdr"
PLGDIR="/usr/lib/vdr"
VIDEODIR="/var/lib/vdr/video"
CONFIGDIR="/var/lib/vdr/config"
STARTDIR="/var/lib/vdr/config/start"

VDRCMD="$VDRPRG -c $CONFIGDIR -v $VIDEODIR -L $PLGDIR"
PLGLST="`ls $PLGDIR | sed -e s/libvdr\-// -e s/\.so.*//`"

for i in $PLGLST; do
    if [ -f "$STARTDIR/$i" ]; then
	VDRCMD="$VDRCMD	-P \"$i `cat \"$STARTDIR/$i\"`\""
    else
	VDRCMD="$VDRCMD	-P $i"
    fi
done

killall -q $VDRPRG
eval $VDRCMD $*
