initial commit
[glibc.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' -e 's/iw_IL/he_IL/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 [ -n "$SUPPORTED_LOCALES" ] && [ -n "$DEFAULT_ENVIRONMENT" ]; then
54 if echo "$SUPPORTED_LOCALES" | grep -q -e "\b$DEFAULT_ENVIRONMENT\b" ; then
55 db_set locales/default_environment_locale "$DEFAULT_ENVIRONMENT"
56 fi
57 fi
58
59 STATE=1
60 while [ "$STATE" -ge 0 ]; do
61 case "$STATE" in
62 0)
63 exit 1
64 ;;
65 1)
66 db_input medium locales/locales_to_be_generated || true
67 ;;
68 2)
69 db_get locales/locales_to_be_generated || RET=
70 if expr ", $RET," : ".*, None,.*" >/dev/null 2>&1; then
71 # "None" was a choice in older packages
72 db_set locales/locales_to_be_generated ""
73 RET=
74 elif expr ", $RET," : ".*, All locales,.*" >/dev/null 2>&1; then
75 # When "All locales" is selected, other choices have to be dropped
76 db_set locales/locales_to_be_generated "All locales"
77 RET=$SUPPORTED_LOCALES
78 fi
79 DEFAULT_LOCALES="$(echo $RET | sed -e 's/ [^ ]*,/,/g' -e 's/ [^ ]*$//')"
80 if [ -n "$DEFAULT_LOCALES" ]; then
81 db_subst locales/default_environment_locale locales $DEFAULT_LOCALES
82 db_input medium locales/default_environment_locale || true
83 fi
84 ;;
85 *)
86 break
87 ;;
88 esac
89 if db_go; then
90 STATE=$(($STATE + 1))
91 else
92 STATE=$(($STATE - 1))
93 fi
94 done