#!/bin/sh

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

DEBUG=0

case "$1" in
  start)
    echo ">>> Starting splash menu..."
    # check for /dev/fb0 device.
    while [ 1 ]; do
        if [ ! -e /dev/fb0 ] ; then
            log "NO /dev/fb0 device found! retrying..."
            sleep 0.1
            continue
        fi
        break
    done
    log "/dev/fb0 found! Starting splash utility..."
    ${SPLASH_UTILITY_PATH}/splash -d -i ${SPLASH_UTILITY_PATH}/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
    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
