dvb modules/usbtuner init scripts (af9015)

mtfroz

Vu+ User
Hi all,

This is a proposal for replacement of dvb usb modules init script(delitedtt.sh) which is loaded when enigma2 starts.
I do all this stuff because I wanted to simplify things when using udev rules to add/remove the modules when I added/removed the stick and in order to reload modules/usbtuner when enigma2 restarts or via a separate script.

Also I added two options on modules "dvb_powerdown_on_sleep=0" and "disable_rc_polling=1" which seams to make
modules more stable.

With a few changes the 1st script can be used with other modules .
[To BH team] If you want you can add them on next modules update.

Code:
###############################################
1.  /etc/init.d/dvb-usb-modules.init
###############################################

#!/bin/sh
NAME=af9015
DESC="DVB USB Modules Init helper"
DRVDIR=/lib/modules/dvbt

DVBCOREOPTS="dvb_powerdown_on_sleep=0"
DVBUSBOPTS="disable_rc_polling=1"
DVBUSBAF9015OPTS=""
#"adapter_nr=1"

MODCOUNT=`cat /proc/modules | /bin/grep -c -e "^dvb_usb_af9015"`

set -e

load_modules() {
	echo -n "* Starting $DESC: $NAME... "
	if [ "$MODCOUNT"  = "0" ]; then
		insmod $DRVDIR/tda18271.ko
		insmod $DRVDIR/af9013.ko
		insmod $DRVDIR/mxl5007t.ko
		insmod $DRVDIR/dvb-pll.ko
		insmod $DRVDIR/mc44s803.ko
		insmod $DRVDIR/mt2060.ko
		insmod $DRVDIR/tda18218.ko
		insmod $DRVDIR/mxl5005s.ko
		insmod $DRVDIR/bh-dvb-core.ko $DVBCOREOPTS
		insmod $DRVDIR/dvb-usb.ko $DVBUSBOPTS
		insmod $DRVDIR/qt1010.ko
		#sleep 2
		sleep 1
		insmod $DRVDIR/dvb-usb-af9015.ko $DVBUSBAF9015OPTS
		###
		depmod -Ae
		echo "OK"

		sleep 1
		/etc/init.d/usbtunerd start
	else
		echo "Modules already loaded."
	fi
}

unload_modules() {
	/etc/init.d/usbtunerd stop
        echo -n "* Stopping $DESC: $NAME... "
	if [ "$MODCOUNT"  = "1" ]; then
		rmmod dvb-usb-af9015
		rmmod qt1010
		rmmod dvb-usb
		rmmod bh-dvb-core
		rmmod mxl5005s
		rmmod tda18218
		rmmod mt2060
		rmmod mc44s803
		rmmod dvb-pll
		rmmod mxl5007t
		rmmod af9013
		rmmod tda18271
		echo "OK"
	else
		echo "Modules was not loaded."
	fi
}



case "$1" in
    start)
	load_modules
	;;
    stop)
	unload_modules
        ;;
    restart)
        echo "* Restarting $DESC: $NAME... "
	$0 stop
	$0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac

exit 0


###############################################
2. /etc/init.d/usbtunerd
###############################################

#!/bin/sh
DAEMON=/usr/bin/usbtuner
NAME=usbtuner
DESC="DVB USB Tuner Helper"
ARGS="-n"
ARGS2="-n -a2 -v1";
BHDEV=/dev/blackhole
DOUT=""

test -f $DAEMON || exit 0

set -e

start_tuner()
{

	if [ ! -e "$BHDEV" ]; then
		echo -n "* Creating $BHDEV for $NAME version handling..."
		mknod $BHDEV c 214 0
		echo "OK"
	fi

	echo -n "* Starting $DESC: $NAME... "
	### tuner not works on background (-b)
 	echo -n "OK. " && start-stop-daemon -S -x $DAEMON -- $ARGS | xargs

	if [ -d /dev/dvb/adapter2 ]; then
		echo -n "* Starting $DESC: $NAME for adapter2... "
	 	if [ -f /dev/misc/vtuner1 ]; then
		 	start-stop-daemon -S -x $DAEMON -- $ARGS2 | xargs
	 	else
	 		rm -f /tmp/nim_sockets
	 		sleep 2
	 		let nim=`sed -n "s/NIM Socket \([0-9]*\):/\\1/p" /proc/bus/nim_sockets | tail -n 1`+1
	 		cat /proc/bus/nim_sockets > /tmp/nim_sockets
 		cat <<DELITE >>/tmp/nim_sockets

 			NIM Socket $nim:
 			 	Type: DVB-T
 			 	Name: USB Second Tuner
 			 	Has_Outputs: no
DELITE
	 	fi
		echo "OK."
	fi
}


stop_tuner()
{
	echo -n "* Stopping $DESC: $NAME... "
	if test `pidof $DAEMON`; then
		 echo -n "OK. " && start-stop-daemon -K -x $DAEMON | xargs
	else
		echo "Not running."
	fi
}




case "$1" in
    start)
	start_tuner
        ;;
    stop)
	stop_tuner
	;;
    restart)
	echo "* Restarting $DESC: $NAME... "
	$0 stop
	$0 start
	;;
    *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
	;;
esac

exit 0

####################

3. Change /usr/bin/enigma2.sh :

Code:
#/usr/bin/delitedtt.sh
/etc/init.d/dvb-usb-modules.init restart
 
Top