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