#!/bin/sh

PREREQ=""

prereqs()
{
	echo "$PREREQ"
}

case $1 in
# get pre-requisites
prereqs)
	prereqs
	exit 0
	;;
esac

# Hook to load keymaps into the initramfs if requested by KEYMAP="y"
if [ "$KEYMAP" != "y" ] && [ "$KEYMAP" != "Y" ]; then
	exit 0
fi

# Step 1 - Basic tools
if [ ! -x /sbin/loadkeys -a ! -r /lib/rc/console/keymap ]; then
	exit 0
fi

. /usr/share/initramfs-tools/hook-functions

copy_exec /sbin/loadkeys /sbin
cp /lib/rc/console/keymap ${DESTDIR}/etc/boottime.kmap
gzip -9 ${DESTDIR}/etc/boottime.kmap

# Step 2 - Check for UTF8 console
if [ ! -x /sbin/kbd_mode ]; then
	exit 0
fi

if [ -r /etc/profile.d/locale ]; then
	env="/etc/profile.d/locale"
else
	exit 0
fi

for var in LANG LC_ALL LC_CTYPE; do
	value=$(egrep "^[^#]*${var}=" $env | tail -n1 | cut -d= -f2)
	eval $var=$value
done

charmap=$(LANG=$LANG LC_ALL=$LC_ALL LC_CTYPE=$LC_CTYPE locale charmap)
if [ "$charmap" = "UTF-8" ]; then
	copy_exec /sbin/kbd_mode /sbin
fi

exit 0
