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

Re: localising base-config - end game



[Eduard Bloch]
> A while ago, you discussed on debian-boot about better boot-floppies and
> base-config localisation.

Yes.  I even submitted some patches, bug #135565 "base-config:
Improved handling of LANG and LANGUAGE during install".  Joey said the
patches looked sane, but wanted me to test them properly before he
would accept them.  I've tested it some more, and founds some typos in
the process.  I also discovered a blocker with debootstrap.  It will
only load the base-config package from 'main' or 'non-US/main', while
my packages naturally ends up in 'local'.  This is bug #116801
"debootstrap: does not allow local branch only consults main branch of
archive", which include a patch I've begged aj to commit.

The patch probably needs more testing. :-)

> I did the same thing, but due to lack of time and more important
> tasks, this was not possible. Now, some weeks later, we created some
> infrastructure (*) and you discussed about possible implementations
> (patches attached). So the concret plans of mine:
> 
>  - add additional prompt, asking the user about keeping the locale

Ideally, the install system should do this automatically, but if it is
easier to get the required patches accepted with an extra question, I
all for it.
>  - the configuration and locales generation is done by base-config in
>    the beginning

Or it should be done by termwrap before starting base-config.  It will
be needed if the suggested change to termwrap is used, checking the
charset of the given locale before starting the required terminal.

>  - I am still not sure whether the user should be forced to reconfigure
>    debconf and locales

I think this is a bad idea.  It is hard to grasp what on earth the
configuration of locales is all about.

> (*) BFs can install additional packages when isntalling from CD or from
> net. There should still be one hook to disable wants_locale if we are
> installing from prepared basedebs.tar.

Any ideas on how to detect that?

Here is my current patch.  The termwrap changes are not complete.  I'm
not sure how to handle the fact that the given locale might be
invalid, and thus useless.  The would be detected in termwrap, but
would also need to be detected in base-config to avoid the perl
warnings and avoid using an unsupported charset.

diff -ruN ../empty/validlocale ./validlocale
--- ../empty/validlocale	Thu Jan  1 01:00:00 1970
+++ ./validlocale	Sat Feb 23 11:25:34 2002
@@ -0,0 +1,71 @@
+#!/usr/bin/perl -w
+#
+# Author: Petter Reinholdtsen <pere@hungry.com>
+# Date:   2002-02-23
+#
+# Test if the locale given as argument is a valid locale.  If it
+# isn't, print on stdout the string to add to /etc/locale.gen to make
+# locale-gen generate the locale (if it exists at all).
+
+use POSIX qw(setlocale LC_ALL);
+
+my $debug = 0;
+
+my $defaultcharset = $ENV{"DEFAULTCHARSET"} || "ISO-8859-1";
+
+my $supportedlist = "/usr/share/i18n/SUPPORTED";
+
+unless (defined $ARGV[0]) {
+    usage();
+    exit 1;
+}
+
+my $LANG = $ARGV[0];
+
+my $loc = setlocale(LC_ALL, $LANG);
+if ( ! $loc) {
+    print STDERR "locale '$LANG' not available\n";
+
+    my ($locale)   = $LANG =~ m/^([^.@]+)/;
+    my ($charset)  = $LANG =~ m/^[^.]+\.([^@]+)/;
+    my ($modifier) = $LANG =~ m/(@.+)$/;
+
+    $modifier = "" unless defined $modifier;
+
+    # Hm, if charset is missing, how to we pick the correct one to
+    # use?  Fetching the value from /usr/share/i18n/SUPPORTED should
+    # work on Debian.
+    $charset = get_default_charset("$locale$modifier")
+	unless (defined $charset);
+
+    # print "L: $locale C: $charset M: $modifier\n";
+    print "$locale$modifier $charset\n";
+
+    exit 1;
+} else {
+    print STDERR "locale '$LANG' valid and available\n";
+    exit 0;
+}
+
+sub usage {
+    print "Usage: $0 <locale>\n"
+}
+
+sub get_default_charset {
+    my ($locale) = @_;
+    my ($l, $c);
+    open(SUPPORTED, "< $supportedlist") || die "Unable to open $supportedlist";
+    while (<SUPPORTED>) {
+	chomp;
+	($l, $c) = split(/\s+/);
+	print "Checking '$l' '$c' != '$locale'\n" if $debug;
+	last if  ($l eq $locale);
+    }
+    close(SUPPORTED);
+
+    if ($l eq $locale) {
+	return $c;
+    } else {
+	return $defaultcharset;
+    }
+}
diff -ruN ../empty/validlocale.8 ./validlocale.8
--- ../empty/validlocale.8	Thu Jan  1 01:00:00 1970
+++ ./validlocale.8	Sat Feb 23 11:54:02 2002
@@ -0,0 +1,49 @@
+.TH "validlocale" "8" "0.1" "Petter Reinholdtsen" ""
+.SH "NAME"
+.LP 
+validlocale \- Test if a given locale is available
+.SH "SYNTAX"
+.LP 
+validlocale <\fIlocale\fP>
+.SH "DESCRIPTION"
+.LP 
+Test if the locale given as argument is a valid locale.  If it
+isn't, print on stdout the string to add to /etc/locale.gen to make
+locale\-gen generate the locale (if it exists at all).
+.SH "FILES"
+.LP 
+\fI/usr/sbin/validlocale\fP
+.br 
+\fI/usr/share/i18n/SUPPORTED\fP
+.SH "ENVIRONMENT VARIABLES"
+.LP 
+.TP 
+\fBDEFAULTCHARSET\fP
+Which charset to assume if the given locale is missing from the
+list of supported locales.
+.SH "EXAMPLES"
+.LP 
+If you give a valid locale as parameter, it outputs a string
+specifying this on stderr:
+.LP 
+.IP 
+% validlocale C
+.br 
+locale 'C' valid and available
+.LP 
+When given a invalid (not generated or just nonexistant), it
+outputs a string on stderr telling that this is an invalid locale, and a string to stdout with the string to add to /etc/locale.gen
+to have this locale generated:
+.LP 
+.IP 
+% validlocale de_AU@euro
+.br 
+locale 'de_AT@euro' not available
+.br 
+de_AT@euro ISO\-8859\-15
+.SH "AUTHORS"
+.LP 
+Petter Reinholdtsen <pere@hungry.com>
+.SH "SEE ALSO"
+.LP 
+locale\-gen(8), localedef(1), locale(1), base\-config(8)
Index: base-config
===================================================================
RCS file: /cvs/debian-boot/base-config/base-config,v
retrieving revision 1.8
diff -u -3 -p -u -r1.8 base-config
--- base-config	2001/11/19 19:32:52	1.8
+++ base-config	2002/03/06 21:10:22
@@ -12,6 +12,80 @@ fi
 SHELL=/bin/sh
 export SHELL
 
+# Source it here to set LANG and LANGUAGE, to let debconf uses the
+# installation language if possible.  Make sure LANG is a valid locale
+# and try to generate it if it is missing.  Make sure the locale is
+# using a charset supported by the console
+test -f /root/dbootstrap_settings && . /root/dbootstrap_settings
+test -f /etc/environment          && . /etc/environment
+
+# Set console charset if possible, returning true if it is, and false if
+# the supplied charset is unsupported.
+set_console_charset() {
+    case $TERM in 
+	console)
+	    case $1 in
+		ISO-8859-1)
+		    # Nothing to do, should be supported by default.
+		    return 0
+		    ;;
+		*)
+		    return 1
+		    ;;
+	    esac
+	    ;;
+	jfbterm)
+	    case $1 in
+		UTF-8|EUC-JP)
+		    return 0
+		    ;;
+		*)
+		    return 1
+		    ;;
+	    esac
+    esac
+}
+
+if [ ! -z "$LANG" ]; then
+    localegen=/usr/sbin/locale-gen
+    localeconf=/etc/locale.gen
+    tmpfile=`/bin/tempfile`
+
+    LANG=C validlocale $LANG 2> /dev/null > $tmpfile || true
+    read locale charset < $tmpfile || true
+    rm -f $tmpfile
+    unset tmpfile
+
+    if LANG=C validlocale $LANG > /dev/null 2>&1; then
+	# Valid locale, no need to generate it
+	true
+    else
+	# Hm, should we install the 'locales' package if it is missing?
+	if [ -x $localegen ]; then
+	    echo "$locale $charset" >> $localeconf
+	    $localegen || true
+	else
+	    echo "Package 'locales' not installed.  Unable to generate $LANG"
+	fi
+    fi
+
+    # Make sure the locale is valid and the charset is usable
+    if set_console_charset $charset && \
+       LANG=C validlocale $LANG > /dev/null 2>&1 ; then
+	if [ ! -z "$LANGUAGE" ]; then
+	    export LANGUAGE
+	fi
+	export LANG
+    else
+	unset LANG
+	unset LANGUAGE
+    fi
+    unset locale
+    unset charset
+    unset localeconf
+    unset localegen
+fi
+
 echo "Configuring the base system..."
 
 cleanup () {
Index: termwrap
===================================================================
RCS file: /cvs/debian-boot/base-config/termwrap,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 termwrap
--- termwrap	2001/05/30 03:40:37	1.2
+++ termwrap	2002/03/06 21:10:22
@@ -15,12 +15,19 @@
 ######################################################################
 ##	Set some environment variables.
 ######################################################################
-# reads /etc/environment.
+# reads /root/dbootstrap_settings (from the boot floppies), and allow
+# overrides in /etc/environment.
+test -f /root/dbootstrap_settings && . /root/dbootstrap_settings
 test -f /etc/environment && . /etc/environment
 
 # Set all locale related environment variables.
-LC_ALL=$LANG
-export LANG LC_ALL
+if [ ! -z "$LANG" ]; then
+    LC_ALL=$LANG
+    export LANG LC_ALL
+    if [ ! -z "$LANGUAGE" ]; then
+	export LANGUAGE
+    fi
+fi
 
 ######################################################################
 ##	Display usage if no argument.
@@ -32,6 +39,10 @@ if [ -z "$1" ]; then
 fi
 
 ######################################################################
+##	Generate the locale data files if missing
+######################################################################
+
+######################################################################
 ##	Recognize terminal type.
 ######################################################################
 case `/usr/bin/tty` in
@@ -70,9 +81,12 @@ esac
 ##	Select suitable terminal as wrapper.
 ######################################################################
 WRAPPER=""
+
+# For this to work, the current locale must be valid
+ENCODING=$(locale charmap)
 
-case $LANG in
-ja*)	
+case $ENCODING in
+eucJP|EUC-JP|ujis)
 	case $TERMINAL in
 	x)
 		#WRAPPER="/usr/X11R6/bin/kterm -e"
@@ -88,6 +102,9 @@ ja*)	
 	# On pseudo and serial, we can't tell
 	# if the terminal can display japanese fonts...
 	esac
+	;;
+ISO-8859-1)
+	# Supported by Linux console and xterm by default?
 	;;
 esac
 
Index: debian/changelog
===================================================================
RCS file: /cvs/debian-boot/base-config/debian/changelog,v
retrieving revision 1.117
diff -u -3 -p -u -r1.117 changelog
--- debian/changelog	2001/12/27 13:27:10	1.117
+++ debian/changelog	2002/03/06 21:10:23
@@ -1,3 +1,9 @@
+base-config (1.34.1.Skolelinux.1) unstable; urgency=low
+
+  * Added initial locale support.
+
+ -- Petter Reinholdtsen <pere@hungry.com>  Sun, 24 Feb 2002 17:40:33 +0100
+
 base-config (1.34) unstable; urgency=low
 
   * Added aptitude as an option, and reworked the package selection stage.
Index: debian/rules
===================================================================
RCS file: /cvs/debian-boot/base-config/debian/rules,v
retrieving revision 1.34
diff -u -3 -p -u -r1.34 rules
--- debian/rules	2001/10/09 19:24:51	1.34
+++ debian/rules	2002/03/06 21:10:23
@@ -29,7 +29,7 @@ install: build
 	dh_testroot
 	dh_clean -k
 	dh_installdirs usr/share/base-config usr/sbin usr/lib/base-config
-	install apt-setup tzsetup base-config termwrap debian/base-config/usr/sbin/
+	install apt-setup tzsetup base-config termwrap validlocale debian/base-config/usr/sbin/
 	install lib/[0-9]* debian/base-config/usr/lib/base-config/
 	cp Mirrors.masterlist debian/base-config/usr/share/base-config/
 



Reply to: