#! /bin/sh
set -e
. /usr/share/debconf/confmodule
keyboard_present () {
local kern kbdpattern class subclass protocol
kern=`uname -r`
case "$kern" in
1*|2.0*|2.1*|2.2*|2.3*|2.4*|2.5*)
return 0; 
;;
esac
[ -f /proc/bus/input/devices ] || return 0
kbdpattern="AT Set \|AT Translated Set\|AT Raw Set"
kbdpattern="$kbdpattern\|Atari Keyboard"
kbdpattern="$kbdpattern\|Amiga Keyboard"
kbdpattern="$kbdpattern\|HIL keyboard"
kbdpattern="$kbdpattern\|ADB keyboard"
kbdpattern="$kbdpattern\|Sun Type"
if grep -i "$kbdpattern" /proc/bus/input/devices >/dev/null; then
return 0
fi
[ -d /sys/bus/usb/devices ] || return 0
for d in /sys/bus/usb/devices/*:*; do
class=$(cat "$d/bInterfaceClass") # 03 = Human Interface Device
subclass=$(cat "$d/bInterfaceSubClass") # 01 = Boot Interface Subclass
protocol=$(cat "$d/bInterfaceProtocol") # 01 = Keyboard
case "$class:$subclass:$protocol" in
03:01:01)
return 0
;;
esac
done
return 1
}
if keyboard_present; then
mkdir -p /target/etc/default
cp -a /etc/default/keyboard /target/etc/default/
LANG=C
export LANG
debconf-copydb -p "^keyboard-configuration/.*$" configdb target_configdb
for template in \
keyboard-configuration/other keyboard-configuration/model keyboard-configuration/layout keyboard-configuration/variant keyboard-configuration/toggle keyboard-configuration/switch keyboard-configuration/altgr keyboard-configuration/compose keyboard-configuration/xkb-keymap keyboard-configuration/modelcode keyboard-configuration/layoutcode keyboard-configuration/variantcode keyboard-configuration/optionscode keyboard-configuration/store_defaults_in_debconf_db 
do
echo keyboard-configuration $template seen true
done | chroot /target debconf-set-selections
apt-install keyboard-configuration || true
apt-install console-setup || true
fi
exit 0
