#!/bin/sh
#
# fbsplash	fbsplashed console
#
# chkconfig:	345 98 98
#
# description:	Activate fbsplashed consoles
#
# $Id: splashutils.init,v 1.8 2007/11/06 14:28:31 glen Exp $


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

# Set defaults
RES="`/usr/bin/fbres`"

# Get service config - may override defaults
[ -f /etc/sysconfig/fbsplash ] && . /etc/sysconfig/fbsplash

test -z "${SPLASH_THEME}" && SPLASH_THEME="default"
test -z "${SPLASH_TTYS}" && SPLASH_TTYS="0 1 2 3 4 5 6 7"

start() {
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/fbsplash ]; then
		if [ -e /dev/fbsplash ] && [ -e /proc/sys/kernel/fbsplash ] && [ -f /etc/splash/${SPLASH_THEME}/${RES}.cfg ]; then
			show "Setting framebuffer console images for theme '%s'" $SPLASH_THEME; busy
			for TTY in ${SPLASH_TTYS}; do
				theme="${SPLASH_THEME}"

				if [ -n "${SPLASH_TTY_MAP}" ]; then
					for i in ${SPLASH_TTY_MAP}; do
						if [ "${i%:*}" = "${TTY}" ]; then
							theme="${i#*:}"
						fi
					done

				fi

				/sbin/splash_util --vc="${TTY}" -m v -t "${theme}" -c setcfg 2>/dev/null
				[ "${TTY}" -eq 0 ] && /sbin/splash_util --vc=0 -m v -t "${theme}" -c setpic
				/sbin/splash_util --vc="${TTY}" -c on 2>/dev/null

			done
			ok
			touch /var/lock/subsys/fbsplash
		fi
	else
		msg_already_running fbsplash
	fi
}

stop() {
	if [ -f /var/lock/subsys/fbsplash ]; then
		rm -f /var/lock/subsys/fbsplash
	else
		msg_not_running fbsplash
	fi
}

# See how we were called.
case "$1" in
start)
	start
	;;
stop)
	stop
	;;
restart)
	stop
	start
	;;
*)
	msg_usage "$0 {start|stop|restart}"
	exit 3
esac

exit $RETVAL
