#!/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 /usr/bin/dvb_server -- &

        mknod -m a=rw /dev/brcm0 c 30 0

        start-stop-daemon --start --quiet --exec /usr/bin/init_client $DRV_PATH/dvb-bcm.ko $DRV_PATH/brcmfb.ko -- &
    fi

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

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

exit 0
