#!/bin/sh

if test "$UID" = "0"; then
	# running as root anyway, don't need sudo
	INSMOD="/sbin/insmod"
	RMMOD="/sbin/rmmod"
else
	INSMOD="sudo /sbin/insmod"
	RMMOD="sudo /sbin/rmmod"
fi

# handy functions for rmmod/insmod
function xrmmod () {
	grep -qe "^$1" /proc/modules || return
	echo rmmod $1
	$RMMOD $1 || exit 1
}
function xinsmod () {
	echo insmod $*
	$INSMOD $* || exit 1
}

# prepare for crashing the box -- flush dirty buffers
sync; sleep 1; sync

# kill old modules ...
xrmmod bttv
xrmmod msp3400
xrmmod tuner
xrmmod i2c-dev
xrmmod algo-bit
xrmmod i2c
xrmmod videodev

# ... and load the new ones
xinsmod ../mod/i2c.o
xinsmod videodev
xinsmod ../mod/algo-bit.o test=1 scan=0
xinsmod ../mod/i2c-dev.o
xinsmod tuner		debug=0 type=5 
xinsmod msp3400		debug=0
xinsmod bttv		radio=0,1 remap=0xffc,0xffd vidmem=0xff0
