#! /bin/bash
#
# chkconfig: 345 01 99
# System startup script for console splash screens, version 0.01
#

test -f /proc/splash || exit 0

# Source function library.
. /etc/init.d/functions

SourceIfNotEmpty /etc/sysconfig/bootsplash

[ "$SPLASH" != no ] ||
    exit

[ "$THEME" != no ] ||
    exit



RETVAL=0

disable()
{
  echo "0" >/proc/splash
}
status()
{
  cat /proc/splash
}
start()
{
	test -x /bin/splash || exit 1
	local splashv=`cat /proc/splash` 
	local res="${splashv##*, }"
	test "$splashv" != "$res" || exit 1
	res="${res%)*}"
	if [ -f /usr/share/splash/vtsplash-[0-9]-$res.cfg ]; then
	    for splcfg in /usr/share/splash/vtsplash-[0-9]-$res.cfg \
		/usr/share/splash/vtsplash-[0-9][0-9]-$res.cfg; do
		    test -f $splcfg || continue
		    local spljpg="${splcfg%.cfg}.jpg"
		    test -f $spljpg || continue
		    local unit="${splcfg#/usr/share/splash/vtsplash-}"
		    unit="${unit%%-*}"
		    action "Setting up splash screen #$unit ($res):" /bin/splash -s -u "$unit" "$splcfg"
	    done
	else
	    splcfg="/usr/share/splash/themes/$THEME/config/bootsplash-$res.cfg"
	    [ -f "$splcfg" ] &&
		action "Setting up splash screen #0 ($res):" /bin/splash -s "$splcfg"
	fi
}

case "$1" in
	start|restart|reload)
		start
		;;
	stop)
		;;
	disable)
		disable
		;;
	status)
		status
		;;
	*)
		echo "Usage: ${0##*/} {start|stop|disable|status|reload|restart}"
		RETVAL=1
esac

exit $RETVAL
