#!/bin/sh
#
# chkconfig:    2345 75 99
# description:  Load keytable

# This must be executed *after* /usr is mounted.
# This means is /usr is NFS-mounted, it needs to
# run after networking and NFS mounts are up.

[ -f /etc/sysconfig/keyboard ] || exit 0

[ -f /usr/bin/loadkeys ] || exit 0

case "$1" in
  start|restart)
	# Load the proper keymap
	echo -n "Loading keymap: "
	. /etc/sysconfig/keyboard

	if [ ${KEYTABLE:-bogus} != "bogus" ]; then
	   loadkeys $KEYTABLE
	   if [ -z "$CHARSET" ]; then 
		CHARSET=`grep ^charset $KEYTABLE | cut -d' ' -f2 | tr '\"' ' ' | tr -d ' '`
	   fi
	   case $CHARSET in
		iso-8859-1) CHARSET=latin1;;
		iso-8859-2) CHARSET=latin2;;
		iso-8859-3) CHARSET=latin3;;
		iso-8859-4) CHARSET=latin4;;
		iso-8859-7) CHARSET=8859_7;;
		iso-8859-8) CHARSET=8859_8;;
		iso-8859-15) CHARSET=latin1;;
		latin0) CHARSET=latin1;;
		latin1) CHARSET=latin1;;
		latin2) CHARSET=latin2;;
		latin3) CHARSET=latin3;;
		latin4) CHARSET=latin4;;
		*) CHARSET=latin;;
	   esac
	   loadkeys compose.${CHARSET}
	fi
	if [ "$NUMLOCK" = "on" ]; then
		for t in 1 2 3 4 5 6; do
			setleds -D +num < /dev/tty$t > /dev/null
		done
	fi
	if [ "$BACKSPACE" = "Delete" ]; then
		echo "keycode 14 = Delete" | loadkeys
	else
		echo "keycode 14 = BackSpace" | loadkeys
	fi
	;;
  stop)
	;;
  *)
        echo "Usage: keytable {start|stop|restart}"
	exit 1
esac

exit 0
