#!/bin/sh
splash_init=initsplash
splash_exe=/sbin/splash.sh
[ -z "$splash_proc" ] && splash_proc=/proc/splash
[ -z "$splash_cfg" ] && splash_cfg=/etc/bootsplash/

initsplash() {
    [ -f /etc/sysconfig/bootsplash ] && source /etc/sysconfig/bootsplash
    [ -n $SPLASH ] && splash_rc=$SPLASH
    [ -n $THEME ] && theme=$THEME
    [ -x $splash_exe ] || splash_rc=no
    if [ -e "$splash_proc" ]; then 
	 grep -iwqs off "$splash_proc" && splash_rc=no
    else
	splash_rc=no
    fi	    

    is_yes "$splash_rc" && export splash_rc=yes
    [ -d $splash_cfg/themes ] || splash_rc=
    if is_yes "$splash_rc" && [ -n $theme ];then
	[ ! -d $splash_cfg/themes/$theme ] && splash_theme=current
	
	splash_res=`fbresolution`
	tmpval=$LOGO_CONSOLE
        if [ -f /etc/bootsplash/themes/$theme/config/bootsplash-$splash_res.cfg ]; then
	    function box() { true; } # ignore box descriptions in the config file
            . /etc/bootsplash/themes/$theme/config/bootsplash-$splash_res.cfg
	fi

	if [[ $tmpval != "theme" ]];then
	    LOGO_CONSOLE=$tmpval
	fi
    fi
    if [ -z "$1" ]; then
    set `/sbin/runlevel`
        runlevel=$2
        previous=$1
    else
	runlevel=$1
	previous=N
    fi
    nbservices=0
    # 
    # for small dir, it is faster than echo /etc/rc$runlevel.d/* | wc -w
    #
    for i in /etc/rc$runlevel.d/*
    do
	a=$[splash_nbservices++]
    done
    for i in /etc/rc$runlevel.d/*.rpm*
    do
	a=$[splash_nbservices--]
    done
    a=$[splash_nbservices++]
    # this is the number of step in rc.sysinit, could be ajusted
    [[ "$previous" = "N" ]] && splash_nbservices=$(($splash_nbservices+9)) && splash_progress=8
    PROMPT=
    export splash_nbservices splash_res splash_theme progress_enable splash_progress splash_rc LOGO_CONSOLE PROMPT
}

