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

Bug#375829: locales-all: compress locales



On Wed, Jun 28, 2006 at 09:42:29PM +0200, Denis Barbier wrote:
> On Wed, Jun 28, 2006 at 09:17:52PM +0200, Javier Serrano Polo wrote:
> > En/na Denis Barbier ha escrit:
> > > Ok, that looks like a good idea, reopening this bug.  But please note
> > > that this is not trivial, one has to think about interferences between
> > > locales and locales-all.
> > 
> > Would it be enough to divert locale-gen? The debconf part could be the
> > same as in locales,
> 
> Another option is to have shared templates to specify locales to
> generate, and the package which generates those locales is chosen
> via another template.  This is similar to kdm/gdm/xdm, or to the
> various dictionaries.

To be more precise, I did not want to ship locales-all files under
/usr/lib/locale/ to prevent configuration problems when both locales
and locales-all are installed.  Setting LOCPATH is only a workaround,
setuid programs do not use $LOCPATH for security reasons.
I was going to run
   localedef --add-to-archive /usr/lib/locales-all/*
in locales-all.postinst, but your bug report has good points.
So now I consider adding a debconf template like:
  The following packages can configure the locales to use on your
  system.  Only one of these packages have to be configured.

  Please select the package which will configure your locales:
    1. locales  2. locales-all  3. belocs-locales-data
Of course, only the packages which are installed are displayed.

> > then follow the second method described in README.Debian. The
> > compressed file'd be in /usr/share/locales-all.
> 
> In order to save space, similar files are currently hardlinked (by
> localedef).  When the package is generated, one has to hardlink
> (or symlink) compressed files instead, this is quite tricky.

Here are 2 scripts:
 * locales-compress compress files under /usr/share/locales-all/
   and take care of hard links.  It can be run when building the
   locales-all package.
 * locales-uncompress runs 'localedef --add-to-archive' qfter
   uncompressing locale files, it can be easily customized to
   only add the requested locales in locales-all.postinst.
The ideal solution would be to patch localedef so that it can
read .gz files directly, but this should be done only in conjunction
with --add-to-archive (or in other words, this feature should be
implemented within localedef but not within libc itself).  No idea
yet whether this is feasible, so please let me know if above scripts
are useful for low resource machines. 

Denis
#! /bin/sh

set -e
dir=/usr/lib/locales-all
tmp=$(tempfile)
find $dir -type f > $tmp
for f in $(cat $tmp | awk '{printf "%s ", $1'})
do
    [ -e $f ] || continue
    links=$(ls -l $f | awk '{print $2}')
    if [ $links -eq 1 ]; then
	gzip -9 "$f"
    else
        inode=$(ls -i $f | awk '{print $1}')
	tmp2=$(tempfile)
        find $dir -inum $inode > $tmp2
	for g in $(cat $tmp2 | awk '{printf "%s ", $1'})
	do
		[ "$f" = "$g" ] || unlink $g
	done
	gzip -9 "$f"
	for g in $(cat $tmp2 | awk '{printf "%s ", $1'})
	do
		[ "$f" = "$g" ] || ln $f.gz $g.gz
	done
        rm -f $tmp2
    fi
done
rm -f $tmp
#! /bin/sh

set -e
dir=/usr/lib/locales-all
tmp=$(mktemp -d)
rm -f /usr/lib/locale/locale-archive
for f in /usr/lib/locales-all/*
do
    rm -rf "$tmp"/*
    cp -a "$f" "$tmp"/
    find "$tmp" -name \*.gz | xargs gunzip
    localedef --add-to-archive "$tmp"/*
done
rm -rf "$tmp"

Reply to: