#! /bin/sh -e
# If possible, report the intended installation locale rather than the
# current locale. Used by console-setup.
# This must not be installed in /usr/lib/ubiquity/compat; debconf calls
# locale itself, so a locale wrapper cannot source the debconf confmodule.

if [ "$1" = charmap ]; then
	# Force charmap to UTF-8.
	echo UTF-8
	exit 0
fi

LOCALE="$(debconf-get debian-installer/locale || true)"

TEXT="$(PATH=/usr/sbin:/usr/bin:/sbin:/bin locale "$@")"
if [ "$LOCALE" ]; then
	printf '%s\n' "$TEXT" | sed "s/=.*/=$LOCALE/"
else
	printf '%s\n' "$TEXT"
fi

exit 0
