#! /bin/sh
set -e

. /usr/share/debconf/confmodule
db_capb backup

/usr/lib/oem-config/timezone/tzsetup

# Reconfigure locale according to the selected country. We rely on
# lib/components/timezone.py having set debian-installer/country for us.
db_get debian-installer/country
country="$RET"
db_set mirror/country "$country" || true
db_get debian-installer/locale
newlocale="$(echo "$RET" | sed "s/_[A-Z][A-Z]*/_$country/")"
if grep -q "^${newlocale%%[.@]*}[.@ ]" /usr/share/i18n/SUPPORTED; then
	db_set debian-installer/locale "$newlocale"
	db_fset debian-installer/locale seen true
	# Let localechooser know that we're using the same language as
	# before, so that it doesn't set a default country again.
	db_fset localechooser/languagelist seen false
	rm -f /var/lib/localechooser/preseeded
	PATH="/usr/lib/oem-config/compat:/usr/lib/oem-config/language:$PATH" \
	OVERRIDE_SHOW_ALL_LANGUAGES=1 \
		localechooser
fi
