#!/bin/sh

if [ -e /sys/class/net/sys0 ]; then
	ifconfig sys0 up
fi

case "$1" in
	start)
		# first boot?
		[ -f /etc/dropbear/dropbear_rsa_host_key ]
		echo -n "Starting  vuplus-platform-util"
		if [ ! -e /dev/brcm0 ]; then
			DRV_PATH=/lib/modules/`uname -r`/extra
			insmod $DRV_PATH/procmk.ko
			insmod $DRV_PATH/bcm_event.ko
			insmod $DRV_PATH/dvb_base.ko

			start-stop-daemon --start --quiet --exec /bin/dvb_server -- &
			mknod -m a=rw /dev/brcm0 c 30 0
			start-stop-daemon --start --quiet --exec /bin/init_client $DRV_PATH/dvb-bcm7444.ko $DRV_PATH/brcmfb.ko -- &
		fi

		while [ ! -c /dev/fb0 ]; do
			usleep 100000
		done

		if [ -e /bin/initfb ]; then
			/bin/initfb $(sed -n 's/osd_resolution=//p' /var/tuxbox/config/neutrino.conf)
		fi

		echo "."
		;;
	stop)
		;;
	restart)
		;;
	*)
		echo "Usage: /etc/init.d/vuplus-platform-util {start|stop|restart}"
		exit 1
esac

exit 0