| 1 |
#! /bin/sh |
| 2 |
set -e |
| 3 |
|
| 4 |
# Files |
| 5 |
LG="/etc/locale.gen" |
| 6 |
EE="/etc/locale.conf" |
| 7 |
LEGACY_EE="/etc/default/locale" |
| 8 |
|
| 9 |
# Sanitize environnement |
| 10 |
LC_ALL=C |
| 11 |
LANG=C |
| 12 |
|
| 13 |
if [ "$1" = configure ]; then |
| 14 |
# Transition to /etc/locale.conf |
| 15 |
if [ -f "$LEGACY_EE" ] && [ ! -L "$LEGACY_EE" ] && [ ! -e "$EE" ]; then |
| 16 |
mv "$LEGACY_EE" "$EE" |
| 17 |
fi |
| 18 |
if [ ! -e "$LEGACY_EE" ]; then |
| 19 |
ln -sfr "$EE" "$LEGACY_EE" |
| 20 |
fi |
| 21 |
|
| 22 |
# Load debconf |
| 23 |
. /usr/share/debconf/confmodule |
| 24 |
db_version 2.0 |
| 25 |
|
| 26 |
db_get locales/default_environment_locale && DEFAULT_ENVIRONMENT="$RET" |
| 27 |
db_get locales/locales_to_be_generated && SELECTED_LOCALES=$RET |
| 28 |
SELECTED_LOCALES="$(echo $SELECTED_LOCALES | sed -e 's/, /\n/g')" |
| 29 |
|
| 30 |
if [ "$SELECTED_LOCALES" = "All locales" ]; then |
| 31 |
[ -e $LG ] && rm -f $LG |
| 32 |
ln -s /usr/share/i18n/SUPPORTED $LG |
| 33 |
else |
| 34 |
[ -L $LG ] && [ "$(readlink $LG)" = "/usr/share/i18n/SUPPORTED" ] && rm -f $LG |
| 35 |
if [ ! -e $LG ] ; then |
| 36 |
cat > $LG << EOF |
| 37 |
# This file lists locales that you wish to have built. You can find a list |
| 38 |
# of valid supported locales at /usr/share/i18n/SUPPORTED, and you can add |
| 39 |
# user defined locales to /usr/local/share/i18n/SUPPORTED. If you change |
| 40 |
# this file, you need to rerun locale-gen. |
| 41 |
# |
| 42 |
|
| 43 |
EOF |
| 44 |
fi |
| 45 |
|
| 46 |
# Comment previous defined locales |
| 47 |
sed -i -e 's/^ *[a-zA-Z]/# &/' $LG |
| 48 |
|
| 49 |
# Get list of supported locales |
| 50 |
if [ -f "/usr/local/share/i18n/SUPPORTED" ] ; then |
| 51 |
SUPPORTED_LOCALES="$(sed -e '/^[a-zA-Z]/!d' -e 's/ *$//g' /usr/share/i18n/SUPPORTED /usr/local/share/i18n/SUPPORTED | sort -u)" |
| 52 |
else |
| 53 |
SUPPORTED_LOCALES="$(sed -e '/^[a-zA-Z]/!d' -e 's/ *$//g' /usr/share/i18n/SUPPORTED | sort -u)" |
| 54 |
fi |
| 55 |
|
| 56 |
# Make sure all locales exist in locales.gen |
| 57 |
echo "$SUPPORTED_LOCALES" | while read locale ; do |
| 58 |
if ! grep -q "^[# ]*$locale *\$" $LG; then |
| 59 |
echo "# $locale" >> $LG |
| 60 |
fi |
| 61 |
done |
| 62 |
|
| 63 |
# Uncomment selected locales |
| 64 |
echo "$SELECTED_LOCALES" | while read locale ; do |
| 65 |
sed -i -e "0,/^[# ]*$locale *$/ s/^[# ]*$locale *$/$locale/" $LG |
| 66 |
done |
| 67 |
fi |
| 68 |
|
| 69 |
# Update requested locales if locales-all is not installed |
| 70 |
if [ "$(dpkg-query -W -f='${db:Status-Want}' locales-all 2>/dev/null)" = 'install' ] ; then |
| 71 |
echo "locales-all installed, skipping locales generation" |
| 72 |
else |
| 73 |
locale-gen |
| 74 |
fi |
| 75 |
|
| 76 |
if ! [ -e $EE ] || [ -n "$DEBCONF_RECONFIGURE" ] ; then |
| 77 |
# Remove previous definitions |
| 78 |
update-locale --no-checks LANG |
| 79 |
|
| 80 |
# Set default LANG environment variable |
| 81 |
if [ -n "$DEFAULT_ENVIRONMENT" ] && [ "$DEFAULT_ENVIRONMENT" != "None" ]; then |
| 82 |
update-locale "LANG=$DEFAULT_ENVIRONMENT" |
| 83 |
fi |
| 84 |
fi |
| 85 |
fi |
| 86 |
|
| 87 |
#DEBHELPER# |
| 88 |
|
| 89 |
exit 0 |