#!/bin/sh
# ATTENTION! Don't edit the file and save it as /lib/dvb/0.9.4/getdvbfirm.
# That file will be removed and replaced with another version.

# tries to reexec with sudo or exec
if [ "`id -u`" != "0" ]; then
   exec sudo "$0" "$@"  || exit 1
fi

tmpdir=~/.dvb-`date +%s`

if ! wget -h> /dev/null ; then
  echo "Wget not installed, please install the wget package first."
  exit 1
fi

if [ -f /lib/dvb/0.9.4/Root ] ; then
  echo "Root file found in /lib/dvb/0.9.4, aborting!"
  exit 1
fi

if [ -f /lib/dvb/0.9.4/Dpram ] ; then
  echo "Dpram file found in /lib/dvb/0.9.4, aborting!"
  exit 1
fi

mkdir -p $tmpdir/DVB
cd $tmpdir
mkdir -p /lib/dvb/0.9.4
ln -s /lib/dvb/0.9.4 DVB/driver
echo "Fetching and extracting http://www.linuxtv.org/download/dvb/siemens_dvb-0.9-latest.tar.gz..."
wget http://www.linuxtv.org/download/dvb/siemens_dvb-0.9.4.tar.gz -O -| gzip -d | tar -x -v DVB/driver/Root DVB/driver/Dpram

cd ~
rm -rf $tmpdir
