#!/bin/sh
# insmod modules from current directory without having to install them first
# KERNELVER=`uname -r`
# KERNELDIR="/lib/modules/$KERNELVER/misc"

sync

case "$1" in
    load)
        if ! lsmod | grep -q "^$(echo dvb_ttpci|sed -e 's/-/_/g') " > /dev/null 2>&1; then    
        echo -n -e "\nInserting DVB modules into kernel\n"
        # make sure input stuff is there for IR remote controls
        # modprobe input
        # modprobe evdev
        # modprobe crc32
        # vide4linux for av7110 based "full featured" cards
        # modprobe videodev
        # insmod $KERNELDIR/v4l1-compat.o
        # insmod $KERNELDIR/v4l2-common.o
        # insmod $KERNELDIR/video-buf.o
        # DVB core
        # insmod $KERNELDIR/dvb-core.o
        # frontend drivers
        # insmod $KERNELDIR/stv0299.o
        # modprobe stv0299
        # saa7146 based siemens/technotrend/hauppauge cards
        # insmod $KERNELDIR/saa7146.o
        # insmod $KERNELDIR/saa7146_vv.o
        # insmod $KERNELDIR/ttpci-eeprom.o
        # insmod $KERNELDIR/dvb-ttpci.o
        modprobe dvb-ttpci vidmode=1
        modprobe budget
        modprobe budget_av
        modprobe budget_ci
        # modprobe b2c2_flexcop_pci
        echo
        else
        echo -e "DVB Drivers already loaded..\n"
        fi
        ;;
    debug)
        if ! lsmod | grep -q "^$(echo dvb_ttpci|sed -e 's/-/_/g') " > /dev/null 2>&1; then
        echo -n -e "\nInserting DVB modules (debug) into kernel\n"
        # modprobe videodev
        # modprobe crc32
        # insmod $KERNELDIR/v4l1-compat.o
        # insmod $KERNELDIR/v4l2-common.o
        # insmod $KERNELDIR/video-buf.o
        # insmod $KERNELDIR/dvb-core.o
        # insmod $KERNELDIR/stv0299.o
        # modprobe stv0299
        # insmod $KERNELDIR/saa7146.o
        # insmod $KERNELDIR/saa7146_vv.o
        # modprobe saa7146_vv
        # insmod $KERNELDIR/ttpci-eeprom.o
        # insmod $KERNELDIR/dvb-ttpci.o debug=247
        modprobe dvb-ttpci debug=247
        echo
        else
        echo -e "DVB Drivers already loaded..\n"
        fi
        ;;
    unload)
        if lsmod | grep -q "^$(echo dvb_ttpci|sed -e 's/-/_/g') " > /dev/null 2>&1; then
        echo -n -e "\nRemoving DVB modules from kernel\n"
        rmmod dvb-ttpci 
        rmmod budget budget_av budget_ci 
        rmmod budget-core ttpci-eeprom

# frontends
        rmmod ves1x93 sp8870 stv0299 ves1820 l64781 tda8083 stv0297 tda1004x
                        

# chips and helpers
        rmmod saa7146_vv saa7146 video-buf dvb-core 

        echo
        else
        echo -e "DVB Drivers not loaded..\n"
        fi
        ;;
    reload)
        $0 unload && $0 load
        ;;
    *)
        echo "Usage$0 {load|unload|debug|reload}"
        exit 1
esac

sync