chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / debian / debhelper.in / locales.config
1 #! /bin/sh
2 set -e
3
4 # Files
5 LG="/etc/locale.gen"
6 EE="/etc/default/locale"
7
8 # Sanitize environnement
9 LC_ALL=C
10 LANG=C
11
12 # Load debconf
13 . /usr/share/debconf/confmodule
14 db_version 2.0
15 db_capb backup multiselect
16
17 # Conversion of locales that have been removed 
18 convert_locale()
19 {
20     echo "$1" | sed -e "s/no_NO/nb_NO/g" -e 's/ks_IN/ks_IN@devanagari/g'
21 }
22
23 # List of locales provided by the current version
24 PROVIDED_LOCALES="__PROVIDED_LOCALES__"
25
26 # List of locales provided by the user
27 if [ -f /usr/local/share/i18n/SUPPORTED ] ; then
28     USER_LOCALES="$(sed -e '/^[a-zA-Z]/!d' -e 's/ *$//g' /usr/local/share/i18n/SUPPORTED)"
29 fi
30
31 # List of locales in /etc/locale.gen
32 if [ -e $LG ]; then
33   GEN_LOCALES="$(sed -e '/^[a-zA-Z]/!d' -e 's/ *$//g' $LG)"
34   GEN_LOCALES="$(convert_locale "$GEN_LOCALES")"
35 fi
36
37 # List of supported locales (PROVIDED_LOCALES + USER_LOCALES + GEN_LOCALES)
38 SUPPORTED_LOCALES="$(printf '%s\n' "$PROVIDED_LOCALES" "$USER_LOCALES" "$GEN_LOCALES" | grep -v "^$" | sort -u | tr '\n' ',' | sed -e 's/, */, /g' -e 's/, *$//g')"
39 db_subst locales/locales_to_be_generated locales "$SUPPORTED_LOCALES"
40
41 # Get the list of selected locales from /etc/locale.gen
42 if [ -e /etc/locale.gen ]; then
43     if [ -L $LG ] && [ "$(readlink $LG)" = "/usr/share/i18n/SUPPORTED" ]; then
44         SELECTED_LOCALES="All locales"
45     else
46         SELECTED_LOCALES="$(echo "$GEN_LOCALES" | sort -u | tr '\n' ',' | sed -e 's/, */, /g' -e 's/, *$//g')"
47     fi
48     db_set locales/locales_to_be_generated "$SELECTED_LOCALES"
49 fi
50
51 DEFAULT_ENVIRONMENT="$(cat /etc/environment /etc/default/locale 2>/dev/null | awk '/^LANG=/ {gsub("\"", ""); sub("LANG=", ""); lang=$0;} END {print lang}')"
52 DEFAULT_ENVIRONMENT="$(convert_locale "$DEFAULT_ENVIRONMENT")"
53 if ! echo "$SUPPORTED_LOCALES" | grep -q -e "\b$DEFAULT_ENVIRONMENT\b" ; then
54     db_set locales/default_environment_locale "$DEFAULT_ENVIRONMENT"
55 fi
56
57 STATE=1
58 while [ "$STATE" -ge 0 ]; do
59     case "$STATE" in
60     0)
61         exit 1
62         ;;
63     1)
64         db_input medium locales/locales_to_be_generated || true
65         ;;
66     2)
67         db_get locales/locales_to_be_generated || RET=
68         if expr ", $RET," : ".*, None,.*" >/dev/null 2>&1; then
69             # "None" was a choice in older packages
70             db_set locales/locales_to_be_generated ""
71             RET=
72         elif expr ", $RET," : ".*, All locales,.*" >/dev/null 2>&1; then
73             # When "All locales" is selected, other choices have to be dropped
74             db_set locales/locales_to_be_generated "All locales"
75             RET=$SUPPORTED_LOCALES
76         fi
77         DEFAULT_LOCALES="$(echo $RET | sed -e 's/ [^ ]*,/,/g' -e 's/ [^ ]*$//')"
78         if [ -n "$DEFAULT_LOCALES" ]; then
79             db_subst locales/default_environment_locale locales $DEFAULT_LOCALES
80             db_input medium locales/default_environment_locale || true
81         fi
82         ;;
83     *)
84         break
85         ;;
86     esac
87     if db_go; then
88         STATE=$(($STATE + 1))
89     else
90         STATE=$(($STATE - 1))
91     fi
92 done