#!/bin/sh
### BEGIN INIT INFO
# Provides:          platform-util
# Required-Start:    kmod bootmisc
# Required-Stop:
# Should-Start:      checkroot
# Should-Stop:
# Default-Start:     S
# Default-Stop:
# Short-Description: Load the Broadcam platform-util.
# Description:       Load the Broadcam platform-util.
### END INIT INFO

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/4.1.20-1.9/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-bcm72604.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
