[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

r3148 - in glibc-package/trunk/debian: . debhelper.in



Author: aurel32
Date: 2008-10-12 16:02:02 +0000 (Sun, 12 Oct 2008)
New Revision: 3148

Modified:
   glibc-package/trunk/debian/changelog
   glibc-package/trunk/debian/debhelper.in/locales.config
   glibc-package/trunk/debian/debhelper.in/locales.postinst
Log:
  * debhelper.in/locales.config, debhelper.in/locales.postinst: modify
    /etc/locale.gen instead of regenerating it.



Modified: glibc-package/trunk/debian/changelog
===================================================================
--- glibc-package/trunk/debian/changelog	2008-10-06 13:23:13 UTC (rev 3147)
+++ glibc-package/trunk/debian/changelog	2008-10-12 16:02:02 UTC (rev 3148)
@@ -1,3 +1,10 @@
+glibc (2.7-15) unstable; urgency=low
+
+  * debhelper.in/locales.config, debhelper.in/locales.postinst: modify
+    /etc/locale.gen instead of regenerating it.
+
+ -- Aurelien Jarno <aurel32@debian.org>  Sun, 12 Oct 2008 18:00:22 +0200
+
 glibc (2.7-14) unstable; urgency=low
 
   [ Petr Salinger ]

Modified: glibc-package/trunk/debian/debhelper.in/locales.config
===================================================================
--- glibc-package/trunk/debian/debhelper.in/locales.config	2008-10-06 13:23:13 UTC (rev 3147)
+++ glibc-package/trunk/debian/debhelper.in/locales.config	2008-10-12 16:02:02 UTC (rev 3148)
@@ -1,48 +1,59 @@
 #! /bin/sh
 set -e
 
+# Files
+LG="/etc/locale.gen"
+EE="/etc/default/locale"
+
+# Sanitize environnement
+LC_ALL=C
+LANG=C
+
+# Load debconf
 . /usr/share/debconf/confmodule
 db_version 2.0
 db_capb backup multiselect
 
+# Conversion of locales that have been removed 
+convert_locale()
+{
+    echo "$1" | sed -e "s/no_NO/nb_NO/g"
+}
+
 # List of locales provided by the current version
 PROVIDED_LOCALES="__PROVIDED_LOCALES__"
 
 # List of locales provided by the user
 if [ -f /usr/local/share/i18n/SUPPORTED ] ; then
-    USER_LOCALES="$(sed -e 's/#.*//g' /usr/local/share/i18n/SUPPORTED)"
+    USER_LOCALES="$(sed -e '/^[a-zA-Z]/!d' -e 's/ *$//g' /usr/local/share/i18n/SUPPORTED)"
 fi
 
-# List of supported locales
-SUPPORTED_LOCALES=$(echo "$PROVIDED_LOCALES$USER_LOCALES" | sed -e 's/^ *//g' -e 's/ *$//g' | sort -u | tr '\n' ',' | sed -e 's/, */, /g' -e 's/, *$//g')
+# List of locales in /etc/locale.gen
+if [ -e $LG ]; then
+  GEN_LOCALES="$(sed -e '/^[a-zA-Z]/!d' -e 's/ *$//g' $LG)"
+  GEN_LOCALES="$(convert_locale "$GEN_LOCALES")"
+fi
 
+# List of supported locales (PROVIDED_LOCALES + USER_LOCALES + GEN_LOCALES)
+SUPPORTED_LOCALES="$(echo -e "$PROVIDED_LOCALES\n$USER_LOCALES\n$GEN_LOCALES" | grep -v "^$" | sort -u | tr '\n' ',' | sed -e 's/, */, /g' -e 's/, *$//g')"
+
 # Get the list of selected locales from /etc/locale.gen
-SELECTED_LOCALES=
-if [ -L /etc/locale.gen ] && [ "$(readlink /etc/locale.gen)" = /usr/share/i18n/SUPPORTED ]; then
+if [ -L $LG ] && [ "$(readlink $LG)" = "/usr/share/i18n/SUPPORTED" ]; then
     SELECTED_LOCALES="All locales"
-elif [ -e /etc/locale.gen ]; then
-    SELECTED_LOCALES=$(LC_ALL=C sed -e '/^[a-zA-Z]/!d' -e "s/^ *//g" -e 's/ *$//g' -e 's/no_NO/nb_NO/' /etc/locale.gen | sort -u | while read LINE ; do
-        if echo "$SUPPORTED_LOCALES" | grep -q -e "\b$LINE\b" ; then
-	    echo -n "$LINE, "
-        fi
-    done)
-    SELECTED_LOCALES=${SELECTED_LOCALES%%, }
+else
+    SELECTED_LOCALES="$(echo "$GEN_LOCALES" | sort -u | tr '\n' ',' | sed -e 's/, */, /g' -e 's/, *$//g')"
 fi
 
-DEFAULT_ENVIRONMENT=$(cat /etc/environment /etc/default/locale 2>/dev/null | awk 'BEGIN {lang="None"} /^LANG=/ {gsub("\"", ""); sub("LANG=", ""); lang=$0;} END {print lang}')
+DEFAULT_ENVIRONMENT="$(cat /etc/environment /etc/default/locale 2>/dev/null | awk 'BEGIN {lang="None"} /^LANG=/ {gsub("\"", ""); sub("LANG=", ""); lang=$0;} END {print lang}')"
+DEFAULT_ENVIRONMENT="$(convert_locale "$DEFAULT_ENVIRONMENT")"
 
-# Convert no_NO locales to nb_NO
-DEFAULT_ENVIRONMENT=$(echo "$DEFAULT_ENVIRONMENT" | sed -e "s/no_NO/nb_NO/")
-
 if ! echo "$SUPPORTED_LOCALES" | grep -q -e "\b$DEFAULT_ENVIRONMENT\b" ; then
-    DEFAULT_ENVIRONMENT=None
+    DEFAULT_ENVIRONMENT="None"
 fi
 
-if [ -e /etc/locale.gen ]; then
-    db_set locales/locales_to_be_generated "${SELECTED_LOCALES}"
-    db_set locales/default_environment_locale "${DEFAULT_ENVIRONMENT}"
-fi
-db_subst locales/locales_to_be_generated locales "${SUPPORTED_LOCALES}"
+db_set locales/locales_to_be_generated "$SELECTED_LOCALES"
+db_set locales/default_environment_locale "$DEFAULT_ENVIRONMENT"
+db_subst locales/locales_to_be_generated locales "$SUPPORTED_LOCALES"
 
 STATE=1
 while [ "$STATE" -ge 0 ]; do
@@ -64,7 +75,7 @@
             db_set locales/locales_to_be_generated "All locales"
             RET=$SUPPORTED_LOCALES
         fi
-        DEFAULT_LOCALES=$(echo $RET | sed -e 's/ [^ ]*,/,/g' -e 's/ [^ ]*$//')
+        DEFAULT_LOCALES="$(echo $RET | sed -e 's/ [^ ]*,/,/g' -e 's/ [^ ]*$//')"
         if [ -n "$DEFAULT_LOCALES" ]; then
             db_subst locales/default_environment_locale locales $DEFAULT_LOCALES
             db_input medium locales/default_environment_locale || true

Modified: glibc-package/trunk/debian/debhelper.in/locales.postinst
===================================================================
--- glibc-package/trunk/debian/debhelper.in/locales.postinst	2008-10-06 13:23:13 UTC (rev 3147)
+++ glibc-package/trunk/debian/debhelper.in/locales.postinst	2008-10-12 16:02:02 UTC (rev 3148)
@@ -1,52 +1,57 @@
 #! /bin/sh
 set -e 
 
+# Files
 LG="/etc/locale.gen"
 EE="/etc/default/locale"
 
-# List of locales provided by the current version
-PROVIDED_LOCALES="__PROVIDED_LOCALES__"
+# Sanitize environnement
+LC_ALL=C
+LANG=C
 
-# List of locales provided by the user
-if [ -f /usr/local/share/i18n/SUPPORTED ] ; then
-    USER_LOCALES="$(sed -e 's/#.*//g' /usr/local/share/i18n/SUPPORTED)"
-fi
-
-# List of supported locales
-SUPPORTED_LOCALES=$(echo "$PROVIDED_LOCALES$USER_LOCALES" | sed -e 's/^ *//g' -e 's/ *$//g' | sort -u | tr '\n' ',' | sed -e 's/, */, /g' -e 's/, *$//g')
-
-
 if [ "$1" = configure ]; then
-
+    # Load debconf
     . /usr/share/debconf/confmodule
     db_version 2.0
 
+    SUPPORTED_LOCALES="$(sed -e '/^[a-zA-Z]/!d' -e 's/ *$//g' /usr/share/i18n/SUPPORTED /usr/local/share/i18n/SUPPORTED | sort -u)"
+
+    db_get locales/default_environment_locale && DEFAULT_ENVIRONMENT="$RET"
     db_get locales/locales_to_be_generated && SELECTED_LOCALES=$RET
-    db_get locales/default_environment_locale && DEFAULT_ENVIRONMENT="$RET"
+    SELECTED_LOCALES="$(echo $SELECTED_LOCALES | sed -e 's/, /\n/g')"
 
     if [ "$SELECTED_LOCALES" = "All locales" ]; then
         [ -e $LG ] && rm -f $LG
         ln -s /usr/share/i18n/SUPPORTED $LG
     else
-        cat > $LG << EOF
+        [ -L $LG ] && [ "$(readlink $LG)" = "/usr/share/i18n/SUPPORTED" ] && rm -f $LG
+        if [ ! -e $LG ] ; then
+            cat > $LG << EOF
 # This file lists locales that you wish to have built. You can find a list
 # of valid supported locales at /usr/share/i18n/SUPPORTED, and you can add
-# user defined locales to /usr/locale/share/i18n/SUPPORTED. If you change
+# user defined locales to /usr/local/share/i18n/SUPPORTED. If you change
 # this file, you need to rerun locale-gen.
 #
 
 EOF
-        IFS=","
-        for LOCALE in $SUPPORTED_LOCALES ; do
-	    LOCALE=${LOCALE## }
-            if echo "$SELECTED_LOCALES" | grep -q "\b$LOCALE\b" ; then
-                echo "$LOCALE" >> $LG
-            else
-                echo "# $LOCALE" >> $LG
-            fi
+        fi
+
+        # Comment previous defined locales
+        sed -i -e 's/^[a-zA-Z]/#&/' $LG
+
+        # Make sure all locales exists in locales.gen
+        echo "$SUPPORTED_LOCALES" | while read locale ; do
+           if ! grep -q "^# *$locale *\$" $LG; then 
+             echo "# $locale" >> $LG
+           fi
         done
-        IFS=" "
+
+        # Uncomment selected locales
+        echo "$SELECTED_LOCALES" | while read locale ; do
+            sed -i -e "s/# *$locale *$/$locale/" $LG
+        done
     fi
+
     # Update requested locales if locales-all is not installed
     if [ -f /usr/lib/locales-all/supported.tar.lzma ] ; then
         echo "locales-all installed, skipping locales generation"


Reply to: