#!/bin/sh -e

DEBIAN_FRONTEND=noninteractive
export DEBIAN_FRONTEND

chroot $TARGET apt-get -y install locales
chroot $TARGET apt-get clean

if test -n "$generate_locales"; then
	(
		echo "locales	locales/locales_to_be_generated	multiselect	$generate_locales"
		if test -n "$default_locale"; then
			echo "locales	locales/default_environment_locale	select	$default_locale"
		fi
	) | chroot $TARGET /usr/bin/debconf-set-selections

	chroot $TARGET dpkg-reconfigure --frontend=noninteractive locales
fi

if test -n "$update_locale"; then
	if test -x $TARGET/usr/sbin/update-locale; then
		chroot $TARGET /usr/sbin/update-locale $update_locale
	else
		# in the ages before etch and /etc/default/locale
		# this went to /etc/environment ...
		for var in $update_locale ; do
			echo "$var" >> $TARGET/etc/environment
		done
	fi
fi
