#!/bin/sh

# Start
if [ $(id -u) != 0 ] ; then 
	echo "Only root can run this script! "
	exit 1
fi

clear
echo
echo "====================================================="
echo
echo "this script delete's VDR and install VDR again"
echo "with xineliboutput and other plugins"
echo "-----------------------------------------------------"
echo
echo "maybe you should save this files/dir's bevor"
echo "-----------------------------------------------------"
echo "/etc/default/vdr"
echo "/etc/default/vdradmin-am"

echo "/usr/share/vdr"
echo "/etc/vdr"
echo "/var/lib/vdr"
echo "/usr/lib/vdr"
echo
echo "if you want install the VDR type <y>"
read answer

if [ "$answer" = "y" ]; then
	/etc/init.d/vdr stop
	apt-get update
	COLUMNS=200 dpkg -l|awk '/vdr/{print $2}'|grep -v -e dvdrtools -e libdvdread3|xargs -r apt-get remove --purge --yes

	rm -rf /var/lib/vdr /etc/vdr /etc/default/vdr*

	apt-get install --yes sidux-vdr sidux-vdr-server-extra xineliboutput-sxfe xineliboutput-fbfe
	perl -pi -e 's%.*(--noremote).*%# $1%;s%.*(--primary).*%$1%' /etc/vdr/plugins/plugin.xineliboutput.conf
	perl -pi -e 's%(ENABLED=).*%${1}1%' /etc/default/vdr /etc/default/vdradmin-am
	/etc/init.d/vdr restart
	/etc/init.d/vdradmin-am restart
fi