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

Re: patch for termwrap



[Taketoshi Sano]
> When termwrap is invoked from a shell (maybe "use termwrap after
> installation" should be this case), then the required environment
> variables are provided by that invoking shell.
> 
> So termwrap just needs to check it, and use it as it is when
> already it is set.
> 
> On the first installation, termwarp is invoked from "init" (pid=1),
> and no environment variables are provided (because of absence of
> invoking shell) in this case.  The reason of configuration check
> in termwarp itself, is this "invoked by init" case.
> 
> Here is the updated patch.  What do you think ?

I understand your reasoning, but I'm not sure if it is ok during first
time boot to skip the reading of /etc/environment.  Anyone know?  Why
do you skip reading /etc/environment completely?  Do you assume the
content from the file already is part of the current environment?

Also, my patch tries very hard to make sure the locale is available,
if necessary by generating it in termwrap.  This is required during
first time install to get the translated texts to show up.  Your patch
is missing that part.

Also, your way of testing if the locale is valid will not work.  The
locale string (LANG) do not have to match a string in /etc/locale.gen.
I believe the only way to test this properly is to use setlocale() and
check the return value.  (If only the locale program gave error
messages when using invalid locales.  Then I could drop my program
validlocale from my patch)

The list of translations to use (LANGUAGE) do not have to match
anything in /etc/locale.gen either.  It can be a list of language
codes like 'no_NO:nb_NO:nb:no'.

Here is my current patch for termwrap.  The validlocale part is not
changed, so fetch it from a previous patch.

There are three parts:

 - load environment variables from relevant files

 - check if the requested LANG variable contains a valid locale, try
   to generate it if it is missing, and unset it if it is unavailable.

 - compare the requested locale's charset with the supported charsets,
   and choose terminal based on this information.

Index: termwrap
===================================================================
RCS file: /cvs/debian-boot/base-config/termwrap,v
retrieving revision 1.2.4.1
diff -u -3 -p -u -r1.2.4.1 termwrap
--- termwrap	2002/02/06 00:51:29	1.2.4.1
+++ termwrap	2002/03/20 09:06:55
@@ -15,12 +15,14 @@
 ######################################################################
 ##	Set some environment variables.
 ######################################################################
-# reads /etc/environment.
+# reads /etc/environment, and if the LANG varialbe already is set, ignore
+# /root/dbootstrap_settings (from the boot floppies).  This would make this
+# work when invoced manually with LANG set, even if /root/dbootstrap_settings
+# exists.
 test -f /etc/environment && . /etc/environment
-
-# Set all locale related environment variables.
-LC_ALL=$LANG
-export LANG LC_ALL
+if [ -z "$LANG" ]; then
+	test -f /root/dbootstrap_settings && . /root/dbootstrap_settings
+fi
 
 ######################################################################
 ##	Display usage if no argument.
@@ -32,6 +34,69 @@ if [ -z "$1" ]; then
 fi
 
 ######################################################################
+##	Generate the locale data files if missing
+######################################################################
+
+# Use LANG_INST and LANGUAGE_INST from /root/dbootstrap_settings if
+# set and allow override with LANG and LANGUAGE from /etc/environemnt.
+
+# Keep the locale info in the _INST variables until they are verified.
+if [ ! -z "$LANG" ]; then
+    LANG_INST=$LANG
+    unset LANG
+fi
+if [ ! -z "$LANGUAGE" ]; then
+    LANGUAGE_INST=$LANGUAGE
+    unset LANGUAGE
+fi
+
+if [ ! -z "$LANG_INST" ]; then
+    localeconf=/etc/locale.gen
+    tmpfile=`/bin/tempfile`
+
+    # Use this to detect if the 'locales' package is installed
+    localegen=`which locale-gen`
+
+    validlocale $LANG_INST 2> /dev/null > $tmpfile || true
+    read locale charset < $tmpfile || true
+    rm -f $tmpfile
+    unset tmpfile
+
+    if validlocale $LANG_INST > /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 [ "$localegen" && -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
+    if validlocale $LANG_INST > /dev/null 2>&1 ; then
+	if [ ! -z "$LANGUAGE_INST" ]; then
+	    LANGUAGE=$LANGUAGE_INST
+	    export LANGUAGE
+	    unset LANGUAGE_INST
+	fi
+	LANG=$LANG_INST
+	LC_ALL=$LANG_INST
+	export LANG LC_ALL
+	unset LANG_INST
+    else
+	unset LANG_INST
+	unset LANGUAGE_INST
+    fi
+    unset locale
+    unset charset
+    unset localeconf
+    unset localegen
+fi
+
+######################################################################
 ##	Recognize terminal type.
 ######################################################################
 case `/usr/bin/tty` in
@@ -70,9 +135,16 @@ esac
 ##	Select suitable terminal as wrapper.
 ######################################################################
 WRAPPER=""
+
+# For this to work, the current locale must be valid.  The block
+# generating the locale should have taken care of that.  If it isn't
+# valid, the output is 'ANSI_X3.4-1968' (at least on my test machine
+# 2002-02-09), and the case test below should unset both LANG and
+# LOCALE
+ENCODING=$(locale charmap)
 
-case $LANG in
-ja*)	
+case $ENCODING in
+eucJP|EUC-JP|ujis)
 	case $TERMINAL in
 	x)
 		#WRAPPER="/usr/X11R6/bin/kterm -e"
@@ -89,6 +161,17 @@ ja*)	
 	# if the terminal can display japanese fonts...
 	esac
 	;;
+ISO-8859-1)
+	# Supported by Linux console and xterm by default?
+	;;
+*)
+
+	# The requested charset is not supported.  Do not use the
+	# given locale.  If it was used, the translated texts might be
+	# completely unreadable in the current terminal
+	echo "Disabling unsupported locale '$LANG' and language list '$LANGUAGE'"
+	unset LANG
+	unset LANGUAGE
 esac
 
 if [ "$1" = "-nnt" ]; then



Reply to: