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

r1313 - in glibc-package/trunk/debian: . debhelper.in local/manpages local/usr_sbin



Author: barbier
Date: 2006-04-03 21:35:33 +0000 (Mon, 03 Apr 2006)
New Revision: 1313

Added:
   glibc-package/trunk/debian/local/manpages/update-locale.8
   glibc-package/trunk/debian/local/usr_sbin/update-locale
Modified:
   glibc-package/trunk/debian/changelog
   glibc-package/trunk/debian/debhelper.in/locales.config
   glibc-package/trunk/debian/debhelper.in/locales.install
   glibc-package/trunk/debian/debhelper.in/locales.manpages
   glibc-package/trunk/debian/debhelper.in/locales.postinst
Log:
* Move locale variables from /etc/environment into a dedicated
  /etc/default/locale file.  (Closes: #214898, #349503)
* Add a new /usr/sbin/update-locale program to handle this new file.


Modified: glibc-package/trunk/debian/changelog
===================================================================
--- glibc-package/trunk/debian/changelog	2006-04-02 21:56:25 UTC (rev 1312)
+++ glibc-package/trunk/debian/changelog	2006-04-03 21:35:33 UTC (rev 1313)
@@ -2,7 +2,10 @@
 
   [ Denis Barbier ]
   * Add am_pm formatting information to en_NZ.  (Closes: #356328)
-  * Add interlingua locale.  (Closes: #224756)  Thanks Alberto Mardegan
+  * Add interlingua locale.  (Closes: #224756)
+  * Move locale variables from /etc/environment into a dedicated
+    /etc/default/locale file.  (Closes: #214898, #349503)
+  * Add a new /usr/sbin/update-locale program to handle this new file.
 
   [ Aurelien Jarno ]
   * Split out timezone data in a separate package. It's a first step, it

Modified: glibc-package/trunk/debian/debhelper.in/locales.config
===================================================================
--- glibc-package/trunk/debian/debhelper.in/locales.config	2006-04-02 21:56:25 UTC (rev 1312)
+++ glibc-package/trunk/debian/debhelper.in/locales.config	2006-04-03 21:35:33 UTC (rev 1313)
@@ -24,8 +24,9 @@
     LG=/dev/null
 fi
 DEFAULT_ENVIRONMENT=None
-if [ -e /etc/environment ]; then
-    DEFAULT_ENVIRONMENT=$(awk 'BEGIN {lang="None"} /^LANG=/ {gsub("\"", ""); sub("LANG=", ""); lang=$0;} END {print lang}' /etc/environment)
+EE="/etc/default/locale"
+if [ -e "$EE" ]; then
+    DEFAULT_ENVIRONMENT=$(awk 'BEGIN {lang="None"} /^LANG=/ {gsub("\"", ""); sub("LANG=", ""); lang=$0;} END {print lang}' $EE)
 fi
 
 #   Add a newline in case /etc/locale.gen has no trailing newline at EOF

Modified: glibc-package/trunk/debian/debhelper.in/locales.install
===================================================================
--- glibc-package/trunk/debian/debhelper.in/locales.install	2006-04-02 21:56:25 UTC (rev 1312)
+++ glibc-package/trunk/debian/debhelper.in/locales.install	2006-04-03 21:35:33 UTC (rev 1313)
@@ -3,5 +3,6 @@
 debian/tmp-libc/usr/share/locale/locale.alias usr/share/locale
 debian/tmp-libc/usr/share/i18n/* usr/share/i18n
 debian/local/usr_sbin/locale-gen usr/sbin
+debian/local/usr_sbin/update-locale usr/sbin
 debian/local/usr_sbin/validlocale usr/sbin
 DEB_SRCDIR/localedata/README usr/share/doc/locales

Modified: glibc-package/trunk/debian/debhelper.in/locales.manpages
===================================================================
--- glibc-package/trunk/debian/debhelper.in/locales.manpages	2006-04-02 21:56:25 UTC (rev 1312)
+++ glibc-package/trunk/debian/debhelper.in/locales.manpages	2006-04-03 21:35:33 UTC (rev 1313)
@@ -1,3 +1,4 @@
 debian/local/manpages/locale-gen.8
 debian/local/manpages/locale.gen.5
+debian/local/manpages/update-locale.8
 debian/local/manpages/validlocale.8

Modified: glibc-package/trunk/debian/debhelper.in/locales.postinst
===================================================================
--- glibc-package/trunk/debian/debhelper.in/locales.postinst	2006-04-02 21:56:25 UTC (rev 1312)
+++ glibc-package/trunk/debian/debhelper.in/locales.postinst	2006-04-03 21:35:33 UTC (rev 1313)
@@ -2,8 +2,32 @@
 set -e
 
 LG="/etc/locale.gen"
-EE="/etc/environment"
+EE="/etc/default/locale"
 
+#  Until locales 2.3.6-5, locale variables were stored into /etc/environment
+if [ "$1" = "configure" ] && [ -e "/etc/environment" ] && dpkg --compare-versions "$2" lt 2.3.6-5
+then
+    OLDEE="/etc/environment"
+    exist=1
+    if [ ! -e "$EE" ]; then
+        exist=
+        found=
+        echo "#  File generated by update-locale" > $EE
+    fi
+    for i in LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION LC_ALL
+    do
+        if [ -n "$exist" ]; then
+            if grep "^ *$i=" $OLDEE >> $EE; then
+                found=1
+            fi
+        fi
+        sed -i -e "s/^ *$i=/#&/" $OLDEE
+    done
+    if [ -z "$exist" ] && [ -z "$found" ]; then
+        rm -f $EE
+    fi
+fi
+
 if [ "$1" = configure ]; then
 
     . /usr/share/debconf/confmodule
@@ -67,18 +91,11 @@
     if [ -e $EE ]; then
         sed -e '/^ *LANG=/d' $EE > $EE.tmp || true
         #  $EE has to be updated if $SELECTED is empty or 'None'
-        cp -f $EE.tmp $EE
-    else
-        :> $EE.tmp
+        mv -f $EE.tmp $EE
     fi
     if [ -n "$SELECTED" ] && [ "$SELECTED" != "None" ]; then
-        #   Add a newline in case last line does not have one
-        echo >> $EE.tmp
-        echo "LANG=$SELECTED" >> $EE.tmp
-        #   Consecutive blank lines are replaced by a single line
-        cat -s $EE.tmp > $EE
+        update-locale "LANG=$SELECTED"
     fi
-    rm -f $EE.tmp
 fi
 
 #DEBHELPER#

Added: glibc-package/trunk/debian/local/manpages/update-locale.8
===================================================================
--- glibc-package/trunk/debian/local/manpages/update-locale.8	2006-04-02 21:56:25 UTC (rev 1312)
+++ glibc-package/trunk/debian/local/manpages/update-locale.8	2006-04-03 21:35:33 UTC (rev 1313)
@@ -0,0 +1,50 @@
+.TH UPDATE-LOCALE 8 "April 2006" "Debian GNU/Linux"
+.SH "NAME"
+.LP 
+update-locale \- Modify global locale settings
+.SH "SYNTAX"
+.LP 
+update-locale 
+.RI [ OPTIONS ]
+[\fBLANG\fP=\fIlocale\fP]
+[\fBLC_NUMERIC\fP=\fIlocale\fP]
+[...]
+.br
+update-locale 
+.B --remove
+[\fBLANG\fP]
+[\fBLC_NUMERIC\fP]
+[...]
+.SH "DESCRIPTION"
+.LP 
+This program can be called by maintainer scripts when Debian packages are
+installed or removed, it updates the \fB/etc/default/locale\fP file to
+reflect changes in system configuration related to global locale settings.
+Some basic checks are performed to ensure that requested settings are valid.
+.SH "OPTIONS"
+.TP
+.B \-\-help
+Display an help message and exit.
+.TP
+.B \-\-reset
+Variables which are not set on command-line are cleared out.
+.TP
+.B \-\-remove
+Remove variables from locale file.
+.TP
+.B \-\-locale\-file
+File containing locale variables.  (Default:
+.BR /etc/default/locale )
+.TP
+.B \-\-no\-checks
+Do not perform sanity checks on locale variables.
+.SH "FILES"
+.TP 
+.B /etc/default/locale
+File where global locale settings are stored.
+.SH "AUTHOR"
+.LP 
+Denis Barbier <barbier@linuxfr.org>
+.SH "SEE ALSO"
+.LP 
+locale\-gen(8), locale(1)

Added: glibc-package/trunk/debian/local/usr_sbin/update-locale
===================================================================
--- glibc-package/trunk/debian/local/usr_sbin/update-locale	2006-04-02 21:56:25 UTC (rev 1312)
+++ glibc-package/trunk/debian/local/usr_sbin/update-locale	2006-04-03 21:35:33 UTC (rev 1313)
@@ -0,0 +1,125 @@
+#! /usr/bin/perl -w
+
+use strict;
+use Getopt::Long;
+use File::Temp;
+
+my $progname     = "update-locale";
+my $locale_file  = "/etc/default/locale";
+
+my $help         = 0;
+my $reset        = 0;
+my $remove       = 0;
+my $no_checks    = 0;
+
+GetOptions(
+	'reset'        => \$reset,
+	'remove'       => \$remove,
+	'locale-file'  => \$locale_file,
+	'no-checks'    => \$no_checks,
+	'h|help'       => \$help,
+);
+
+sub usage
+{
+	my $rc = shift;
+	print STDERR "Usage: $progname [OPTIONS] [LANG=locale] [LC_NUMERIC=locale] ...
+Options:
+   --help          display this message and exit
+   --reset         ignore variables defined in the locale file
+   --remove        remove variables from locale file
+   --locale-file   file containing locale variables
+                   (Default: /etc/default/locale)
+   --no-checks     do not perform sanity checks on locale variables
+";
+	exit $rc;
+}
+
+$help && usage(0);
+
+#  Process command-line arguments
+my %arg = ();
+my $content = '';
+if (-r $locale_file)
+{
+	#  Read current values
+	open(IN, "<", $locale_file)
+		or die "$progname: Unable to read $locale_file: $!\n";
+	while (<IN>)
+	{
+		$content .= $_;
+		next unless m/^(\w+)=(.*)/;
+		$arg{$1} = $2 unless $reset;
+	}
+	close(IN)
+		or die "$progname: Unable to close $locale_file: $!\n";
+	$content =~ s/^([^#])/#$1/mg;
+	$content .= "\n" unless $content =~ m/\n$/s;
+}
+else
+{
+	$content = "#  File generated by $progname\n";
+}
+for (@ARGV)
+{
+	if (m/(.*?)=(.*)/)
+	{
+		$arg{$1} = $2;
+	}
+	elsif ($remove)
+	{
+		delete $arg{$_};
+	}
+}
+
+my $env = '';
+for (qw(LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION LC_ALL))
+{
+	if (defined $arg{$_} && $arg{$_} ne '')
+	{
+		$env .= " $_=$arg{$_}";
+		$content =~ s/^#[#\s]*$_=.*/$_=$arg{$_}/m or
+			$content .= "$_=$arg{$_}\n";
+	}
+}
+
+#  Sanity checks
+if ($no_checks == 0)
+{
+	#  Check tthat this locale does exist
+	my $charset = `$env locale charmap 2>&1`;
+	die "*** $progname: Error: invalid locale settings: $env\n"
+		if ($charset =~ m/Cannot set/);
+	#  If LANGUAGE is set, its first value must be compatible with LC_MESSAGES
+	if (defined $arg{LANGUAGE})
+	{
+		my $language = $arg{LANGUAGE};
+		$language =~ s/[.:_].*//;
+		my $msg = '';
+		my $var = '';
+		for (qw(LC_MESSAGES LANG LC_ALL))
+		{
+			if (defined $arg{$_})
+			{
+				$var = $_;
+				$msg = $arg{$_};
+			}
+		}
+		die "*** $progname: Error: LANGUAGE ($arg{LANGUAGE}) is not compatible with $var ($msg)\n"
+			if ($msg !~ m/^$language/);
+	}
+}
+
+#  Write locale file
+my ($fh, $filename) = File::Temp::tempfile();
+open(OUT, ">", $filename)
+	or die "$progname: Unable to write $filename: $!\n";
+print OUT $content;
+close(OUT)
+	or die "$progname: Unable to close $filename: $!\n";
+chmod 0644, $filename
+	or die "$progname: Unable to chmod $filename: $!\n";
+rename $filename, $locale_file
+	or die "$progname: Unable to rename $filename into $locale_file: $!\n";
+
+1;


Property changes on: glibc-package/trunk/debian/local/usr_sbin/update-locale
___________________________________________________________________
Name: svn:executable
   + *



Reply to: