Resync with Debian's 1.157.1-1
[live-initramfs-grml.git] / scripts / live-bottom / 14locales
1 #!/bin/sh
2
3 #set -e
4
5 # initramfs-tools header
6
7 PREREQ=""
8
9 prereqs()
10 {
11         echo "${PREREQ}"
12 }
13
14 case "${1}" in
15         prereqs)
16                 prereqs
17                 exit 0
18                 ;;
19 esac
20
21 # live-initramfs header
22
23 if [ -n "${NOLOCALES}" ]
24 then
25         exit 0
26 fi
27
28 . /scripts/live-functions
29
30 log_begin_msg "Setting up locales"
31
32 # Cosmetic line wrapping for output of local-gen
33 echo
34
35 # live-initramfs script
36
37 if [ -e /root/etc/default/locale ]
38 then
39         grep_file=/root/etc/default/locale
40 elif [ -e /root/etc/environment ]
41 then
42         # Old locales policy
43         grep_file=/root/etc/environment
44 fi
45
46 if [ -n "${grep_file}" ]
47 then
48         # use rootfs configured locale
49         locale=$(grep -s 'LANG=' ${grep_file} | sed s/'LANG='// | tr -d '"' )
50 fi
51
52 if [ -n "${LOCALE}" ]
53 then
54         locale="${LOCALE}"
55         set_locale="true"
56 fi
57
58 if [ -z "${locale}" ]
59 then
60         # Set a default one
61         locale=en_US.UTF-8
62         set_locale="true"
63 fi
64
65 if [ "${set_locale}" ]
66 then
67         if echo "${locale}" | grep -sqE '^[[:lower:]]{2}$'
68         then
69                 # input is like "locale=it", so we will convert and setup also the keyboard if not already set
70                 if [ -z "${KBD}" ]
71                 then
72                         # FIXME: look if this keyb is supported
73                         KBD="${locale}"
74                         really_export KBD
75                 fi
76
77                 uploc=$(echo "${locale}" | tr '[a-z]' '[A-Z]')
78                 locale="${locale}_${uploc}.UTF-8"
79         fi
80
81         LANG=
82         language="$(echo ${locale} | cut -d. -f1)"
83         eval $(awk '/^'"${locale}"'/ { print "LANG=" $1 " codepage=" $2; exit; }' /root/usr/share/i18n/SUPPORTED)
84
85         if [ -z "${LANG}" ]
86         then
87                 # Try and fallback to another codepage for this language.
88                 eval $(awk '/^'"${language}"'/ { print "LANG=" $1 " codepage=" $2; exit; }' /root/usr/share/i18n/SUPPORTED)
89
90                 if [ -n "${LANG}" ]
91                 then
92                         log_warning_msg "Choosing locale '${LANG}' as '${locale}' is unsupported."
93                 fi
94         fi
95
96         if [ -z "${LANG}" ]
97         then
98                 log_warning_msg "Locale '${locale}' is unsupported."
99                 codepage="UTF-8"
100                 language="en_US"
101                 locale="${language}.${codepage}"
102                 LANG="${language}.${codepage}"
103         fi
104
105         if [ -d /root/etc/default/kdm.d/ ]
106         then
107                 printf 'LANGUAGE=%s\n' "${LANG}" >> /root/etc/default/kdm.d/live-autologin
108         elif [ -f /root/etc/kde3/kdm/kdmrc ]
109         then
110                 sed -i -r -e "s/#Language=.*/Language=${language}/" \
111                         /root/etc/kde3/kdm/kdmrc
112         fi
113
114         really_export LANG
115
116         printf 'LANG="%s"\n' "${LANG}" >> /root/etc/default/locale
117         printf 'LANG="%s"\n' "${LANG}" >> /root/etc/environment
118         printf '%s %s\n' "${LANG}" "${codepage}" > /root/etc/locale.gen
119
120         if [ -z "${SILENT}" ]
121         then
122                 chroot /root /usr/sbin/locale-gen
123         else
124                 chroot /root /usr/sbin/locale-gen > /dev/null 2>&1
125         fi
126 fi
127
128 log_end_msg