#!/bin/sh -e
# Keyboard configuration.
#
# Note that this needs to run before any stuff that might ask for keyboard
# input..
#
# TODO: move to console-tools

if [ "$1" != "new" ]; then
	# Not a new install, so don't set up the keyboard. Presumably it is
	# already set up..
	exit
fi

if [ -e /root/dbootstrap_settings ]; then
        . /root/dbootstrap_settings || true
fi

if [ ! -e /etc/console-tools/default.kmap.gz ]; then
	if [ "$KEYBD" ]; then
		install-keymap /usr/share/keymaps/${KEYBD}.kmap.gz || true
	elif [ "$SERIALCONSOLE" ]; then
		(
			echo console-data purge
			echo console-tools purge
			echo console-tools-libs purge
		) | dpkg --set-selections
	elif [ ! -f /etc/console-tools/default.kmap.gz -a -f /bin/loadkeys ]; then
		dpkg-reconfigure console-data || true
	fi
fi
