#!/bin/sh
# Description: Installation Script for installing the Linux driver of the WinTV PVR USB2 by Aurelien Alleaume
# see also http://justiceforall.free.fr/pvrusb2.html
# written by Andreas Schopf aka AndyMcCoy (AndyMcCoy@kanotix.de)
# Version History:
# Version       Date            Name            Changes
# 0.1           11.01.2005      AndyMcCoy       First Version
# 0.2           21.01.2005      AndyMcCoy       Welcome, all Kernels
# set -x
# Driver=pvrusb2-dev-07112004
Driver=0.6
DNAME=pvrusb2-$Driver
WINDRV=pvrusb2_23_21351.exe
Kernel_Version=`uname -r`
if test $(id -u) != 0; then
 echo Error: You must be root to run this script!
 echo Try sudo to run this script under Ubuntu
 exit 1
fi

echo "#####################################################"
echo "#   Scriptinstall for WinTV PVR USB2 Driver         #"
echo "#    based on recommends by Aurelien Alleaume       #"
echo "#    Script by AndyMcCoy                            #"
echo "#####################################################"

# if [ "$Kernel_Version" != "2.6.8.1-3-386" ] ; then
#   echo Sorry, Script is designed for Kernel 2.6.8.1-3-386 only
#   exit 2
# fi
cd /tmp
if [ ! -f $DNAME.tar.bz2 ]; then
 wget -Nc http://justiceforall.free.fr/$DNAME.tar.bz2
fi
rm -rf $DNAME
tar -xvjf $DNAME.tar.bz2
 cd $DNAME

# fehlende Headers nachinstallieren
if [ ! -e /lib/modules/$Kernel_Version/build ]; then
  apt-get install linux-headers-$Kernel_Version
fi

# fehlender Kompiler gcc nachinstallieren
if [ ! -e /usr/bin/gcc ]; then
 apt-get install gcc
fi
if [ ! -f $WINDRV ]; then
 wget -Nc http://hauppauge.lightpath.net/software/pvrusb2/$WINDRV
fi

mkdir temp

unzip -d temp $WINDRV

perl extract-firmware.pl temp/HCWUSB2.SYS

# Jetzt kommt das kompilieren und Installieren des Treibers
make
make install

# hotplug und module einbinden
cp pvrusb2.f1 pvrusb2.f2 /usr/lib/hotplug/firmware/
depmod -a
modprobe videodev
modprobe v4l1-compat
modprobe v4l2-common
modprobe pvrusb2

