#!/bin/sh
#
# fbsetfont	Framebuffer post initialization
#
# chkconfig: 345 33 67
# description:	Framebuffer post initialization.
# config: /etc/sysconfig/framebuffer

WITHOUT_RC_COMPAT=1

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

# Default log device.
LOGDEVICE=/dev/tty12

# Path to fbset program.
FBSET=/usr/sbin/fbset

# Parse framebuffer config.
SourceIfNotEmpty /etc/sysconfig/framebuffer && is_yes "$ENABLE" || exit 0

LOCKFILE=/var/lock/subsys/fbsetfont
RETVAL=0

start()
{
	# Initializing ttys.
	sed -ne 's,^\([0-9]\+\):[0-9]\+:respawn:/sbin/mingetty.*,/dev/tty\1,pg' </etc/inittab |
		while read t; do
			[ ! -c "$t" ] || : >>"$t"
		done
	for i in $TTYS; do
		t="/dev/tty$i"
		[ ! -c "$t" ] || : >>"$t"
	done

	# Setup videomode if requested.
	if [ -n "$MODE" -a -x "$FBSET" ]; then
		: >>"$LOGDEVICE"
		"$FBSET" -a "$MODE" >>"$LOGDEVICE" 2>&1
	fi

	# Update system font.
	if [ -n "$MODULE" ] || [ -n "$MODE" -a -x "$FBSET" ]; then
		sed -ne 's,^\([0-9]\+\):[0-9]\+:respawn:/sbin/mingetty.*,/dev/tty\1,pg' </etc/inittab |
			while read t; do
				[ ! -c "$t" ] ||
					ExecIfExecutable /sbin/setsysfont <"$t" >>"$t" 2>&1
			done
		for i in $TTYS; do
			t="/dev/tty$i"
			[ ! -c "$t" ] ||
				ExecIfExecutable /sbin/setsysfont <"$t" >>"$t" 2>&1
		done
	fi
	touch "$LOCKFILE"
}

# See how we were called.
case "$1" in
	start|reload|restart|condrestart|condreload)
		start
		;;
	stop|condstop)
		rm -f "$LOCKFILE"
		;;
	status)
		;;
	*)
		msg_usage "${0##*/} {start|stop}"
		RETVAL=1
esac

exit $RETVAL
