#!/sbin/runscript
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/consolefont,v 1.22 2004/02/15 20:15:53 azarah Exp $


depend() {
	need localmount
	after hotplug
}

start() {
	local x=
	local param=
	local sf_param=
	local retval=1
	
	if [ -n "${CONSOLEFONT}" ]
	then
		# Getting additional parameters, ie consoletranslation
		if [ -n "${CONSOLETRANSLATION}" ]
		then
			param="-m ${CONSOLETRANSLATION}"
		fi
		
		# Actually setting font
		if [ -x /bin/setfont ]
		then
			ebegin "Setting user font"

			# We patched setfont to have --tty support ...
			if [ -n "`setfont --help 2>&1 | grep -e '--tty'`" -o \
			     -n "`setfont --help 2>&1 | grep -e '-C'`" ]
			then
				if [ -n "`setfont --help 2>&1 | grep -e '--tty'`" ]
				then
					sf_param="--tty="
				else
					sf_param="-C "
				fi
				
				for x in $(seq 1 "${RC_TTY_NUMBER}")
				do
					# Using DEVFS ?
					if [ -e /dev/.devfsd ] || \
					   [ -e /dev/.udev -a -d /dev/vc ]
					then
						/bin/setfont ${CONSOLEFONT} ${param} \
							${sf_param}/dev/vc/${x} >/dev/null
						retval=$?
					else
						/bin/setfont ${CONSOLEFONT} ${param} \
							${sf_param}/dev/tty${x} >/dev/null
						retval=$?
					fi
				done
			else
				/bin/setfont ${CONSOLEFONT} ${param} >/dev/null
				retval=$?
			fi
		else
			# No console program installed!
			eend 1 "The setfont executable was not found"
			return 1
		fi

		if [ "${retval}" -eq 0 ]
		then
			for x in $(seq 1 "${RC_TTY_NUMBER}")
			do
				# Using DEVFS ?
				if [ -e /dev/.devfsd ] || \
				   [ -e /dev/.udev -a -d /dev/vc ]
				then
					echo -ne "\033(K" >/dev/vc/${x}
				else
					echo -ne "\033(K" >/dev/tty${x}
				fi
			done
		fi
		
		eend ${retval} "Failed to set user font"
	else
		ebegin "Using the default console font"
		eend 0
	fi
	
	return ${retval}
}


# vim:ts=4
