Fix call to log_warning_msg. Thanks to Bradley Smith <brad@brad-smith.co.uk>.
[live-boot-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 fi
48
49 if [ -n "${LOCALE}" ]
50 then
51         locale="${LOCALE}"
52         set_locale="true"
53 fi
54
55 if [ -z "${locale}" ]
56 then
57         # Set a default one
58         locale=en_US.UTF-8
59         set_locale="true"
60 fi
61
62 if [ "${set_locale}" ]
63 then
64         if echo "${locale}" | grep -sqE '^[[:lower:]]{2}$'
65         then
66                 # input is like "locale=it", so we will convert and setup also the keyboard if not already set
67                 if [ -z "${KBD}" ]
68                 then
69                         # FIXME: look if this keyb is supported
70                         KBD="${locale}"
71                         really_export KBD
72                 fi
73
74                 uploc=$(echo "${locale}" | tr '[a-z]' '[A-Z]')
75                 locale="${locale}_${uploc}.UTF-8"
76         fi
77
78         LANG=$(grep "^${locale}" /root/usr/share/i18n/SUPPORTED | grep UTF-8 | sed -e 's, .*,,' -e q)
79
80         language="${LANG%%.UTF-8*}"
81         if [ -d /root/etc/default/kdm.d/ ]
82         then
83
84 cat > /root/etc/default/kdm.d/live-autologin << EOF
85 LANGUAGE=${language}
86 EOF
87
88         elif [ -f /root/etc/kde3/kdm/kdmrc ]
89         then
90                 sed -i -r -e "s/#Language=.*/Language=${language}/" \
91                         /root/etc/kde3/kdm/kdmrc
92         fi
93
94         if [ -z "${LANG}" ]
95         then
96                 log_warning_msg "Locale ${locale} is unsupported."
97                 locale="en_US.UTF-8"
98                 LANG="${locale}"
99         fi
100
101         really_export LANG
102
103         printf 'LANG="%s"\n' "${LANG}" >> /root/etc/default/locale
104         printf 'LANG="%s"\n' "${LANG}" >> /root/etc/environment
105         printf '%s UTF-8\n' "${LANG}" > /root/etc/locale.gen
106         chroot /root /usr/sbin/locale-gen
107 fi
108
109 log_end_msg