#! /bin/sh
set -e

# Modify the following script for Lenny compatibility
file=/usr/lib/post-base-installer.d/20kbd-chooser

[ -f $file ] || exit 0

if grep -q "^CHARMAP=" $file; then
	exit 0
fi

# For Lenny we also need to set the charmap (based on the encoding
# of the locale selected for the target system)

sed -i '/debconf-set-selections/ i\
# Set charmap for Lenny version of console-setup\
db_get debian-installer/locale\
CHARMAP="$(LC_ALL=$RET chroot /target locale charmap)"\
' $file

sed -i '/debconf-set-selections/ a\
d-i debian-installer/charmap string $CHARMAP' $file
