21025693febfce39ab1b9e94d5ecad901b074309
[live-boot-grml.git] / scripts / live-bottom / 14locales
1 #! /bin/sh
2
3 PREREQ=""
4 DESCRIPTION="Setting up locales..."
5
6 . /scripts/live-functions
7
8 prereqs()
9 {
10        echo "$PREREQ"
11 }
12
13 case $1 in
14 # get pre-requisites
15 prereqs)
16        prereqs
17        exit 0
18        ;;
19 esac
20
21 log_begin_msg "$DESCRIPTION"
22
23 if [ -e /root/etc/default/locale ]; then
24     grep_file=/root/etc/default/locale
25 elif [ -e /root/etc/environment ]; then # Old locales policy
26     grep_file=/root/etc/environment
27 fi
28
29 if [ -n "${grep_file}" ]; then
30     # use rootfs configured locale
31     locale=$(grep -s 'LANG=' ${grep_file} | sed s/'LANG='// | tr -d '"' )
32 else
33     grep_file=/root/etc/default/locale
34 fi
35
36 if [ -n "${LOCALE}" ]; then
37     locale="${LOCALE}"
38     set_locale="true"
39 fi
40
41 if [ -z "${locale}" ]; then
42     # Set a default one
43     locale=en_US.UTF-8
44     set_locale="true"
45 fi
46
47 if [ "${set_locale}" ]; then
48     if echo "${locale}" | grep -sqE '^[[:lower:]]{2}$' ; then
49         # input is like "locale=it", so we will convert and setup also the keyboard if not already set
50         if [ -z "${KBD}" ]; then
51             # FIXME: look if this keyb is supported
52             KBD="${locale}"
53             really_export KBD
54         fi
55         uploc=$(echo "${locale}" | tr '[a-z]' '[A-Z]')
56         locale="${locale}_${uploc}.UTF-8"
57     fi
58     LANG=$(grep "^${locale}" /root/usr/share/i18n/SUPPORTED | grep UTF-8 |sed -e 's, .*,,' -e q)
59     if [ -z "${LANG}" ]; then
60         log_warning_message "Locale ${locale} is unsupported."
61         locale="en_US.UTF-8"
62         LANG="${locale}"
63     fi
64
65     really_export LANG
66
67     if [ "${BUILD_SYSTEM}" == "Ubuntu" ]; then
68         printf 'LANG="%s"\n' "${LANG}" > "${grep_file}"
69         chroot /root /usr/sbin/locale-gen "${LANG}"
70         live-preseed /root debian-installer/locale "${locale}"
71     else
72         printf 'LANG=%s\n' "${LANG}" > "${grep_file}"
73         printf '%s UTF-8\n' "${LANG}" > /root/etc/locale.gen
74         chroot /root /usr/sbin/locale-gen
75     fi
76 fi
77
78 log_end_msg