Edit: /usr/sbin/locale-gen (4316B)
#!/bin/bash
set -e
LOCALEGEN=/etc/locale.gen
LOCALES=/usr/share/i18n/locales
USER_LOCALES=/usr/local/share/i18n/locales
SUPPORTED=/var/lib/locales/supported.d
ALIASES=/usr/share/locale/locale.alias
[ -s "$LOCALEGEN" ] || exit 0
KEEP=0
IS_LANG=no
ARCHIVE=yes
# Handle command-line options
prev=
while true
do
option="$1"
if [ -n "$prev" ]; then
eval "$prev=\$option"
prev=
continue
fi
case $option in
-h|--help)
cat <
/dev/null || true
done
fi
umask 022
is_entry_ok() {
if [ -z "$locale" ] || [ -z "$charset" ]; then
echo "error: Bad entry '$locale $charset'"
return 1
fi
}
add_to_locale_gen() {
echo "$1" | while read locale; do
if ! grep -q "^[# ]*$locale *\$" $LOCALEGEN; then
echo "# $locale" >> $LOCALEGEN
fi
sed -i -e "0,/^[# ]*$locale *$/ s/^[# ]*$locale *$/$locale/" $LOCALEGEN
done
}
if [ -z "$1" ]; then
GENERATE="`cat $SUPPORTED/* $LOCALEGEN 2>/dev/null || true`"
else
GENERATE=
while [ -n "$1" ]; do
if [ -f "$SUPPORTED/$1" ]; then
GENERATE="$GENERATE\n`cat $SUPPORTED/$1`"
elif [ $IS_LANG = no ] && L=`grep "^${1/%.utf8/.UTF-8} " /usr/share/i18n/SUPPORTED`; then
# convert utf8 to UTF-8 and check if the requested locale exists
GENERATE="$GENERATE\n$L"
add_to_locale_gen "$L"
elif [ $IS_LANG = no ] && L=`grep "^${1%.[uU][tT][fF]*} UTF-8" /usr/share/i18n/SUPPORTED`; then
# recognize 'll_CC.UTF-8' or 'll_CC.utf8' as ll_CC without codeset
GENERATE="$GENERATE\n$L"
add_to_locale_gen "$L"
else
# try to come up with a sensible default
L=`grep -E "^${1}( |[._@][^[:space:]]* )UTF-8" /usr/share/i18n/SUPPORTED || true`
if [ -z "$L" ]; then
echo "Error: '$1' is not a supported language or locale" >&2
exit 1
fi
GENERATE="$GENERATE\n$L"
add_to_locale_gen "$L"
fi
shift
done
fi
echo "Generating locales (this might take a while)..."
echo -e "$GENERATE" | sort -u | while read -r locale charset; do \
if [ -z "$locale" ] || [ "${locale#\#}" != "$locale" ]; then continue; fi
is_entry_ok || continue
if [ "$KEEP" -eq 1 ] && PERL_BADLANG=0 perl -MPOSIX -e 'exit 1 unless setlocale(LC_ALL, $ARGV[0])' "$locale"; then continue; fi
locale_base="${locale%%.*}"
locale_base="${locale_base%%@*}"
locale_at="${locale#*@}"
[ "$locale_at" = "$locale" ] && locale_at= || locale_at="@$locale_at"
printf " %s.%s%s..." "$locale_base" "$charset" "$locale_at"
if [ -e "$USER_LOCALES/$locale" ]; then
input="$USER_LOCALES/$locale"
elif [ -e "$LOCALES/$locale" ]; then
input="$locale"
else
input="$locale_base$locale_at"
if [ -e "$USER_LOCALES/$input" ]; then
input="$USER_LOCALES/$input"
fi
fi
localedef $no_archive -i $input -c -f $charset $locale_alias $locale || :; \
echo " done"
done
echo "Generation complete."