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

[locales] Solving the "debconf is not a registry" issue



Hi,

several threads recently came up on debian-devel about debconf issues.
One concern is that debconf must not be used to store configuration
items; another even more important is that user changes in configuration
files must be preserved.  A detailed example of writing config and
postinst files can be found in debconf-devel(7).
Here is a first try to have the locales package get it right.
It has been kindly reviewed (and improved) by Joey Hess (he also fixes
typos in the templates file).  Of course, remaining bugs are mine.

There is a problem with the current files: locales are always generated
when packages is reconfigured.  This is annoying, especially when
building all supported locales, but it does the right thing because
otherwise running locale-gen provides a different set of locales.
IMO this issue could be discussed later, we first need to fix current
ones.

Denis
Index: templates
===================================================================
RCS file: /cvs/glibc/glibc-package/debian/locales/DEBIAN/templates,v
retrieving revision 1.5
diff -u -r1.5 templates
--- templates	27 Feb 2003 13:16:16 -0000	1.5
+++ templates	22 Apr 2003 19:02:58 -0000
@@ -1,24 +1,25 @@
 Template: locales/locales_to_be_generated
 Type: multiselect
-_Choices: Leave alone, ${locales}
+_Choices: None, ${locales}
 _Description: Select locales to be generated.
  Locale is a framework to switch between multiple languages for users who can
  select to use their language, country, characters, collation order, etc.
  .
  You can choose locales to be generated by selecting locales you want.
- Selected locales will be saved to `/etc/locale.gen' file. You can also
- manually edit this file. You need to run `locale-gen' after edit the file.
+ Selected locales will be saved to the `/etc/locale.gen' file. You can also
+ manually edit this file. You need to run `locale-gen' after editing the
+ file.
 
 Template: locales/default_environment_locale
 Type: select
-_Choices: Leave alone, None, ${locales}
+_Choices: None, ${locales}
 Default: C
 _Description: Which locale should be the default in the system environment?
  Many packages in Debian use locales to display text in the correct
  language for users. The default is C but you can change this if you're not
  a native English speaker.
  .
- Note: This will reflect the language for your whole system. If you're
+ Note: This will select the language for your whole system. If you're
  running a multi-user system where not all of your users speak the language
  of your choice, then they will run into difficulties and you might want to
  leave "C" as the default locale.
#!/bin/bash
set -e

. /usr/share/debconf/confmodule
db_version 2.0
db_capb backup multiselect

#   Initializes debconf default values from the ones found in
#   configuration files
if [ -e /etc/locale.gen ]; then
  LG=/etc/locale.gen
  SELECTED_LOCALES=$(egrep -v "^#|^$" $LG | tr "\n" "," | sed -e "s/,/, /g" -e "s/, *$//")
  db_set locales/locales_to_be_generated "${SELECTED_LOCALES}"
else
  LG=/dev/null
fi
if [ -e /etc/environment ]; then
    db_set locales/default_environment_locale `awk 'BEGIN {lang="None"} /^LANG=/ {gsub("\"", ""); sub("LANG=", ""); lang=$0;} END {print lang}' /etc/environment`
else
    db_set locales/default_environment_locale None
fi

SUPPORTED_LOCALES="__SUPPORTED_LOCALES__"
SUPPORTED_LOCALES=$( (cat $LG && echo "$SUPPORTED_LOCALES") | egrep -hv "^#|^$" | sort -u | tr "\n" "," | sed -e "s/,/, /g" -e "s/, *$//")
db_subst locales/locales_to_be_generated locales "${SUPPORTED_LOCALES}"

STATE=1
while [ "$STATE" -ge 0 ]; do
    case "$STATE" in
    0)
        exit 1
        ;;
    1)
        db_input medium locales/locales_to_be_generated || true
        ;;
    2)
        db_get locales/locales_to_be_generated && DEFAULT_LOCALES=$(echo $RET | sed -e 's/None,*//g' -e 's/ [^ ]*,/,/g' -e 's/ [^ ]*$//')

        if test -z "$DEFAULT_LOCALES"; then
            DEFAULT_LOCALES=C
        else
            DEFAULT_LOCALES="C, $DEFAULT_LOCALES"
        fi
        db_subst locales/default_environment_locale locales $DEFAULT_LOCALES
        db_input medium locales/default_environment_locale || true
        ;;
    *)
        break
        ;;
    esac
    if db_go; then
        STATE=$(($STATE + 1))
    else
        STATE=$(($STATE - 1))
    fi
done
#! /bin/sh
set -e

LG="/etc/locale.gen"
EE="/etc/environment"

if [ "$1" = configure ]; then

    . /usr/share/debconf/confmodule
    db_version 2.0

    db_get locales/locales_to_be_generated && SELECTED_LOCALES=$RET
    db_get locales/default_environment_locale && SELECTED="$RET"

    if [ -n "$SELECTED_LOCALES" -a "$SELECTED_LOCALES" != "None" ]; then
        if [ -e $LG ]; then
            #   Comment previous defined locales
            sed -e 's/^[a-zA-Z]/#&/' $LG > $LG.tmp || true
            mv -f $LG.tmp $LG
        else
            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. Other
# combinations are possible, but may not be well tested. If you change
# this file, you need to rerun locale-gen.
#

EOF
        fi
        list=`echo $SELECTED_LOCALES | sed -e 's/, /,/g'`
        save_IFS=$IFS
        IFS=,
        for locale in $list; do
            if grep -q "^#$locale *\$" $LG; then
                #   Uncomment previous defined locales
                sed -e "s,#$locale *\$,$locale," $LG > $LG.tmp || true
                mv -f $LG.tmp $LG
            else
                #   Never wondered why Emacs sux?
                echo >> $LG
                #   Add a new locale
                echo $locale >> $LG
            fi
        done
        IFS=$save_IFS

        # Update requested locales.  Remove all old locale dir and 
        # locale-archive before generating new locale data.
        rm -rf /usr/lib/locale/* || true
        /usr/sbin/locale-gen
    fi

    # Set default LANG environment variable
    if [ -e $EE ]; then
        sed -e '/^ *LANG=/d' $EE > $EE.tmp || true
    else
        :> $EE.tmp
    fi
    if [ -n "$SELECTED" ] && [ "$SELECTED" != "None" ]; then
        echo "LANG=$SELECTED" >> $EE.tmp
        mv -f $EE.tmp $EE
    else
        rm -f $EE.tmp
    fi
fi

Reply to: