#!/bin/sh

. /etc/init.d/shell-utils.sh
. /etc/init.d/splash-utils.sh

DEBUG=0

case "$1" in
  start)
    echo ">>> Starting splash menu..."
    insmod /usr/lib/modules/kir.ko
    insmod /usr/lib/modules/led.ko
    LIST=`ls /dev/input/event*`
    for STR in ${LIST}; do echo "$STR">/dev/null; done;
    /usr/bin/kirconf ${STR} /etc/combined.conf | 2>/dev/null
    insmod /usr/lib/modules/fb.ko
    get_fw_env "boot_msg_off" STR
    if [ "$STR" == "1" ]; then
        echo "disable" > ${NO_LOGGING}
    fi
    get_fw_env "bootTVsystem" STR
    if [ "$STR" == "NTSC" ]; then
            SPLASH_INI=/etc/splash_ntsc.ini
    else
            SPLASH_INI=/etc/splash_pal.ini
    fi
    if [ ! -e /dev/fb0 ] ; then
        mknod /dev/fb0 c 29 0
    fi
    /usr/bin/splash -d -i ${SPLASH_INI}
    to=0
    while [ $to -lt 3000 ] ; do
        if [ -p ${SPLASH_PIPE} ] ; then
            break;
        fi
        to=$((to+100))
        usleep 100000
    done
    ${SPLASH} menu_off
    log "Starting splash..."

    #echo "Done."
    log "Done."
  ;;

  stop)
    #echo -n "Stopping splash..."
    log "Stopping splash..."
    ${SPLASH} esc
    killall splash >/dev/null 2>/dev/null
    rmmod kir
    rmmod fb
    if [ -d /splash ] ; then
        rm /splash/splash.pipe
        umount /splash
    fi
    echo disabled > ${NO_SPLASH}
    echo "Done."
    log "Done."
  ;;

  *)
    echo "Usage: /etc/init.d/splash {start|stop}"
    log "Usage: /etc/init.d/splash {start|stop}"
    exit 1
    ;;
esac

exit 0
