#!/sbin/runscript

# source our config
source /etc/conf.d/bootsplash.conf

if [ -z "${BOOTSPLASH_THEME}" ]
then
    BOOTSPLASH_THEME=default
fi

depend() {
	# run after local so that the boot time splash image
	# is visible for as long as possible
	need local
}

box () {
	# dummy function to handle sourcing of bootsplash config file
	return;
}

start() {
	# Only do this if the kernel has support
	if [ -f /proc/splash ]
	then
		ebegin "Setting Console frame buffer images"
		
		# get console resolution
		RESOLUTION=$(/sbin/fbresolution)

		# switch to a usable image on all consoles
		for TTY in `seq 0 5`
		do
			/sbin/splash -s -u $TTY -n /etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-${RESOLUTION}.cfg
		done

		eend $? "Failed to set frame buffer console images"
	fi
}

stop() {

	CHVT=$(which chvt)

	# Stop doesn't really stop, it actually changes the image
	# on vt1 back to the bootsplash image.

	# Only do this if the kernel has support
	if [ -f /proc/splash ]
	then
		ebegin "Setting Console frame buffer images"

		# source bootsplash config
		source /etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-$(/sbin/fbresolution).cfg

		# Put bootsplash image up
		/sbin/splash -s -u 0 /etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-$(/sbin/fbresolution).cfg

		# ensure "silent" image is displayed
		echo "silent" > /proc/splash

		# switch to vt1 (must be &'d otherwise script hangs)
		${CHVT} 1 &
		
		# print a nice message
		# /sbin/fbtruetype ........
		
		eend $? "Failed to set frame buffer console images"	
	fi
}
