Initial checkin
[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 # live-initramfs script
33
34 if [ -e /root/etc/default/locale ]
35 then
36         grep_file=/root/etc/default/locale
37 elif [ -e /root/etc/environment ]
38 then
39         # Old locales policy
40         grep_file=/root/etc/environment
41 fi
42
43 if [ -n "${grep_file}" ]
44 then
45         # use rootfs configured locale
46         locale=$(grep -s 'LANG=' ${grep_file} | sed s/'LANG='// | tr -d '"' )
47 else
48         grep_file=/root/etc/default/locale
49 fi
50
51 if [ -n "${LOCALE}" ]
52 then
53         locale="${LOCALE}"
54         set_locale="true"
55 fi
56
57 if [ -z "${locale}" ]
58 then
59         # Set a default one
60         locale=en_US.UTF-8
61         set_locale="true"
62 fi
63
64 if [ "${set_locale}" ]
65 then
66         if echo "${locale}" | grep -sqE '^[[:lower:]]{2}$'
67         then
68                 # input is like "locale=it", so we will convert and setup also the keyboard if not already set
69                 if [ -z "${KBD}" ]
70                 then
71                         # FIXME: look if this keyb is supported
72                         KBD="${locale}"
73                         really_export KBD
74                 fi
75
76                 uploc=$(echo "${locale}" | tr '[a-z]' '[A-Z]')
77                 locale="${locale}_${uploc}.UTF-8"
78         fi
79
80         LANG=$(grep "^${locale}" /root/usr/share/i18n/SUPPORTED | grep UTF-8 | sed -e 's, .*,,' -e q)
81
82         if [ -z "${LANG}" ]
83         then
84                 log_warning_message "Locale ${locale} is unsupported."
85                 locale="en_US.UTF-8"
86                 LANG="${locale}"
87         fi
88
89         really_export LANG
90
91         printf 'LANG=%s\n' "${LANG}" > "${grep_file}"
92         printf '%s UTF-8\n' "${LANG}" > /root/etc/locale.gen
93         chroot /root /usr/sbin/locale-gen
94 fi
95
96 log_end_msg