#! /bin/sh

set -e

log() {
	logger -t localization-config-udeb "$@"
}

if [ ! -z ${DEBCONF_DEBUG} ]; then
        DEBUG="--debug"
fi

if [ "$1" ]; then
	ROOT="$1"
	chroot=in-target
	if [ "$2" ]; then
		preinst="--preinst"
	else
		preinst=
	fi
else # for debugging
	ROOT=
	chroot=
	preinst=
fi
export ROOT chroot

UPDATE=/usr/sbin/update-locale-config

log "info: Processing '$LOCALE'"
if [ -x $ROOT$UPDATE ]; then 
	case $LOCALE in
	C|POSIX)
		;;
	?*)
		log "info: Running $UPDATE $preinst $LOCALE"
		$chroot $UPDATE $preinst ${LOCALE} $DEBUG
		;;
	esac
else
	log "error: could not find $ROOT$UPDATE"
	exit 1
fi
log "info: Done processing '$LOCALE'"
