Adding casper 1.77+debian-2.
[live-boot-grml.git] / scripts / casper-bottom / 14locales
index 0d4e171..12cfc4b 100755 (executable)
@@ -3,7 +3,7 @@
 PREREQ=""
 DESCRIPTION="Setting up locales..."
 
-. /scripts/functions
+. /scripts/casper-functions
 
 prereqs()
 {
@@ -21,32 +21,53 @@ esac
 log_begin_msg "$DESCRIPTION"
 
 if [ -e /root/etc/default/locale ]; then
-       grep_file=/root/etc/default/locale
-       locale=$(grep 'LANG=' ${grep_file} | sed s/'LANG='// | tr -d '"' ) 
+    grep_file=/root/etc/default/locale
 elif [ -e /root/etc/environment ]; then # Old locales policy
-       grep_file=/root/etc/environment
+    grep_file=/root/etc/environment
+fi
+
+if [ -n "${grep_file}" ]; then
+    locale=$(grep -s 'LANG=' ${grep_file} | sed s/'LANG='// | tr -d '"' )
+else
+    grep_file=/root/etc/default/locale
 fi
 
 # commandline
-for x in $(cat /proc/cmdline); do
-       case $x in
-               debian-installer/locale=*)
-                       locale=${x#debian-installer/locale=}
-                       set_locale="true"
-                       ;;
-       esac
-done
+if [ ! -z "${LOCALE}" ]; then
+    locale="${LOCALE}"
+    set_locale="true"
+fi
 
 if [ -z "${locale}" ]; then
-       # Set a default one
-       locale=en_US.UTF-8
-       set_locale="true"
+    # Set a default one
+    locale=en_US.UTF-8
+    set_locale="true"
 fi
 
 if [ "${set_locale}" ]; then
-       LANG=$(grep "^${locale}" /root/usr/share/i18n/SUPPORTED | grep UTF-8 |sed -e 's, .*,,' -e q)
-       printf 'LANG="%s"\n' "${LANG}" >> "${grep_file}" 
-       chroot /root /usr/sbin/locale-gen "${LANG}"
+    if echo "${locale}" | grep -sqE '^[[:lower:]]{2}$' ; then
+        # input is like "locale=it", so we will convert and setup also the keyboard
+        if [ -z "${KBD}" ]; then
+            # FIXME: look if this keyb is supported
+            KBD="${locale}"
+        fi
+        uploc=$(echo "${locale}" | tr '[a-z]' '[A-Z]')
+        locale="${locale}_${uploc}.UTF-8"
+    fi
+    LANG=$(grep "^${locale}" /root/usr/share/i18n/SUPPORTED | grep UTF-8 |sed -e 's, .*,,' -e q)
+
+    if [ -z "${LANG}" ]; then
+        log_warning_message "Locale ${locale} is unsupported."
+    fi
+
+    if [ "${BUILD_SYSTEM}" == "Debian" ]; then
+        printf 'LANG=%s\n' "${LANG}" >> "${grep_file}"
+        printf '%s UTF-8\n' "${LANG}" >> /root/etc/locale.gen
+        chroot /root /usr/sbin/locale-gen
+    else
+        printf 'LANG="%s"\n' "${LANG}" > "${grep_file}"
+        chroot /root /usr/sbin/locale-gen "${LANG}"
+    fi
 fi
 
 log_end_msg