#!/bin/sh

. /usr/share/debconf/confmodule

# Silently exit if we're using a serial console
db_get debian-installer/serial-console
if [ "$RET" != false ]; then
	exit 0
fi

# Set selected keymap in target environment for configuration of console-setup.
# As console-setup does not have a "keep kernel keymap" option there is little
# choice but to force a "us" keymap if no keymap was selected in kbd-chooser
# (at least that matches the kernel keymap). Needs better solution.
db_get console-tools/archs
case $RET in
    no-keyboard|skip-config)
	KEYMAP=us
	;;
    *)
	db_get debian-installer/keymap
	KEYMAP=$RET
	;;
esac

LANG=C chroot /target debconf-set-selections <<EOF
d-i debian-installer/keymap string $KEYMAP
EOF

case $(archdetect) in
    kfreebsd-*|hurd-*)
	apt-install keyboard-configuration || true ;;
    *)
	apt-install console-setup kbd || true ;;
esac

exit 0
