Bug#520255: gnome-user-guide: too big -- 50 MB is too much

Francesco Potorti` Potorti at isti.cnr.it
Fri Apr 10 06:06:04 UTC 2009


I added omf purging to the localepurge script.  It now deletes files
under

 /usr/share/locale
 /usr/share/man
 /usr/share/gnome/help
 /usr/share/omf

The script is vastly inefficient, and it would be easy to make it more
efficient using bash pattern matching rather than grep.  I can do that,
if there is nothing more important.

One thing to add is checking for Kde help, but I do not use Kde, so I do
not know what to look for.

One more thing: the script has always needed bash, so it should depend
on it.  I adjusted the #! line accordingly.  This is a bug even in the
current repository version.

===File /usr/sbin/localepurge===============================
#!/bin/bash

# Deleting all locale files and localized man pages installed 
# on system which are *not* listed in /etc/locale.nopurge

set -e

# Do nothing and report why if no valid configuration file exists:

if [ ! -f /etc/locale.nopurge ]
    then
	echo " No /etc/locale.nopurge file present, exiting ..."
	exit 0
    else
	if [ "$(grep -x ^NEEDSCONFIGFIRST /etc/locale.nopurge)" ]
	    then
		echo
		echo "	  You have to configure \"localepurge\" with the command"
		echo
		echo "	      dpkg-reconfigure localepurge"
		echo
		echo "	  to make $0 actually start to function."
		echo
		echo "	  Nothing to be done, exiting ..."
		echo
		exit 0
	fi
fi

# Make sure to exclude running under any locale other than C:
export LANG=C

# Initialise local variables
VERBOSE=
DONTBOTHERNEWLOCALE=disabled
SHOWFREEDSPACE=disabled
mantot=0
localetot=0
gnometot=0

if [ "$1" = "-debug" ] || [ "$1" = "-d" ] \
    || [ "$2" = "-debug" ] || [ "$2" = "-d" ]; then
    set -x
fi

if [ "$(grep -x ^SHOWFREEDSPACE /etc/locale.nopurge)" ]; then
    SHOWFREEDSPACE=enabled
fi

if [ "$(grep -x ^DONTBOTHERNEWLOCALE /etc/locale.nopurge)" ]; then
    DONTBOTHERNEWLOCALE=enabled
fi

if [ "$(grep -x ^VERBOSE /etc/locale.nopurge)" ] \
    || [ "$1" = "-verbose" ] || [ "$1" = "-v" ] \
    || [ "$2" = "-verbose" ] || [ "$2" = "-v" ]; then
    VERBOSE="-v"
fi

# Define a function for disk space calculation:

if [ $SHOWFREEDSPACE = disabled ]; then
    get_used_space() { echo 0; }
else
    if [ "$(grep -x ^QUICKNDIRTYCALC /etc/locale.nopurge)" ]; then
	get_used_space() # Usage: get_used_space <dirname>
	{
	    [ -d "$1" ] || return 1 # bail out if there's no such dir
	    set - $(df -P $1); shift $(($# - 6)); echo $3
	}
    else
	get_used_space() # Usage: get_used_space <dirname>
	{
	    [ -d "$1" ] || return 1 # bail out if there's no such dir
	    set - $(du -ks $1); echo $1
	}
    fi
fi

# first update $LOCALELIST with newly introduced locales if wanted

LOCALELIST=/var/cache/localepurge/localelist
NEWLOCALELIST="$LOCALELIST"-new

if [ "$VERBOSE" ]; then
    echo "localepurge: checking system for new locale ..."
fi

for NEWLOCALE in $(cd /usr/share/locale; ls .)
do 
 if [ -d /usr/share/locale/$NEWLOCALE/LC_MESSAGES ]; then
    if [ ! "$(grep -cx $NEWLOCALE $LOCALELIST)" = "1" ]; then
	echo "$NEWLOCALE" >> "$NEWLOCALELIST"
    fi
 fi
done

if [ -f $NEWLOCALELIST ]; then
  if [ $DONTBOTHERNEWLOCALE = enabled ]; then
    mv "$NEWLOCALELIST" "$NEWLOCALELIST".temp
    sort -u "$NEWLOCALELIST".temp "$LOCALELIST"> "$NEWLOCALELIST"
    mv "$NEWLOCALELIST" "$LOCALELIST"
    rm "$NEWLOCALELIST".temp
   else
    mv "$NEWLOCALELIST" "$NEWLOCALELIST".temp
    sort -u "$NEWLOCALELIST".temp > "$NEWLOCALELIST"
    rm "$NEWLOCALELIST".temp
  fi
fi

if [ -f "$NEWLOCALELIST" ] && [ ! $DONTBOTHERNEWLOCALE = enabled ]; then
    echo "Some new locales have appeared on your system:"
    echo
    tr '\n' ' ' < "$NEWLOCALELIST" 
    echo
    echo
    echo "They will not be touched until you reconfigure localepurge"
    echo "with the following command:"
    echo
    echo "    dpkg-reconfigure localepurge"
    echo
fi

# Getting rid of superfluous locale files in LOCALEDIR
LOCALEDIR=/usr/share/locale
if [ -d "$LOCALEDIR" ]; then
    localebefore=$(get_used_space "$LOCALEDIR")
    test "$VERBOSE" && echo "localepurge: processing locale files ..."
    for LOCALE in $(cd "$LOCALEDIR"; echo *); do
	if [ ! "$(grep -x ^$LOCALE /etc/locale.nopurge)" ] &&
	    [ "$(grep -x ^$LOCALE $LOCALELIST)" ] && 
	    [ -d "$LOCALEDIR/$LOCALE/LC_MESSAGES" ]; then
	    for file in "$LOCALEDIR/$LOCALE"/*/*  "$LOCALEDIR/$LOCALE"/*.po; do
		if [ -f "$file" ] || [ -h "$file" ]; then 
		    /bin/rm $VERBOSE "$file"
		fi done fi done
    if [ $SHOWFREEDSPACE = enabled ]; then
	localeafter=$(get_used_space "$LOCALEDIR")
	((localetot = localebefore - localeafter))
	echo "localepurge: Disk space freed in $LOCALEDIR: ${localetot}KB"
    fi
fi


# Getting rid of localized man pages in $MANPAGEDIR
MANPAGEDIR=/usr/share/man
if [ -d $MANPAGEDIR ] && [ "$(grep -x ^MANDELETE /etc/locale.nopurge)" ]; then
    manbefore=$(get_used_space $MANPAGEDIR)
    test "$VERBOSE" && echo "localepurge: processing man pages ..."
    for LOCALE in $(ls --ignore="man[1-9]*" $MANPAGEDIR); do
	if [ ! "$(grep -x ^$LOCALE /etc/locale.nopurge)" ] &&
	    [ "$(grep -x ^$LOCALE $LOCALELIST)" ] && 
	    [ -d $MANPAGEDIR/$LOCALE ]; then
	    for file in "$MANPAGEDIR/$LOCALE"/man[1-9]/*; do
		if [ -f "$file" ] || [ -h "$file" ]; then 
		    /bin/rm $VERBOSE "$file"
		fi done fi done
    if [ $SHOWFREEDSPACE = enabled ]; then
	manafter=$(get_used_space $MANPAGEDIR)
	((mantot = manbefore - manafter))
	echo "localepurge: Disk space freed in $MANPAGEDIR: ${mantot}KB"
    fi
fi

# Getting rid of superfluous locale files in Gnome
GNOMEDIR=/usr/share/gnome/help 
if [ -d "$GNOMEDIR" ]; then
    gnomebefore=$(get_used_space "$GNOMEDIR")
    test "$VERBOSE" && echo "localepurge: processing Gnome files ..."
    for LOCALEDIR in "$GNOMEDIR"/*/*; do
	LOCALE=${LOCALEDIR##*/}
	if [ $LOCALE != C ] &&
	    [ -d "$LOCALEDIR/../C" ] &&
	    [ ! "$(grep -x ^$LOCALE /etc/locale.nopurge)" ] &&
	    [ "$(grep -x ^$LOCALE $LOCALELIST)" ]; then
	    for file in "$LOCALEDIR"/*/* "$LOCALEDIR"/*.xml; do
		if [ -f "$file" ] || [ -h "$file" ]; then 
		    /bin/rm $VERBOSE "$file"
		fi done fi done
    if [ $SHOWFREEDSPACE = enabled ]; then
	gnomeafter=$(get_used_space "$GNOMEDIR")
	((gnometot = gnomebefore - gnomeafter))
	echo "localepurge: Disk space freed in $GNOMEDIR: ${gnometot}KB"
    fi
fi


# Getting rid of superfluous locale files in Omf
OMFDIR=/usr/share/omf
if [ -d "$OMFDIR" ]; then
    omfbefore=$(get_used_space "$OMFDIR")
    test "$VERBOSE" && echo "localepurge: processing Omf files ..."
    for file in "$OMFDIR"/*/*; do
	LOCALE=${file##*-}; LOCALE=${LOCALE%.omf}
	if [ $LOCALE != C ] &&
	    [ -f "${file/%-$LOCALE.omf/-C.omf}" ] &&
	    [ ! "$(grep -x ^$LOCALE /etc/locale.nopurge)" ] &&
	    [ "$(grep -x ^$LOCALE $LOCALELIST)" ]; then
	    if [ -f "$file" ] || [ -h "$file" ]; then 
		/bin/rm $VERBOSE "$file"
	    fi fi done
    if [ $SHOWFREEDSPACE = enabled ]; then
	omfafter=$(get_used_space "$OMFDIR")
	((omftot = omfbefore - omfafter))
	echo "localepurge: Disk space freed in $OMFDIR: ${omftot}KB"
    fi
fi


# Calculating and reporting total disk space freed:
if [ $SHOWFREEDSPACE = enabled ]; then
    echo
    echo "Total disk space freed by localepurge: $((localetot+mantot+gnometot+omftot))KB"
    echo
fi
============================================================






More information about the pkg-gnome-maintainers mailing list