Bug#520255: gnome-user-guide: too big -- 50 MB is too much
Francesco Potorti`
Potorti at isti.cnr.it
Wed Apr 22 07:37:21 UTC 2009
This is a partly rewritten version of localepurge. It is more modular
and thus much more readable. Still needs modularisation and
optimisation, but it is better than the previous version I sent.
Still does not purge Kde files. I see that multilingual help files are
under /usr/share/doc/kde/HTML, but I guess there are others.
===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 fgrep --quiet --line-regexp 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
MANDELETE=disabled
globaltot=0
if [ "$1" = "-debug" ] || [ "$1" = "-d" ] \
|| [ "$2" = "-debug" ] || [ "$2" = "-d" ]; then
set -x
fi
if fgrep --quiet --line-regexp SHOWFREEDSPACE /etc/locale.nopurge; then
SHOWFREEDSPACE=enabled
fi
if fgrep --quiet --line-regexp DONTBOTHERNEWLOCALE /etc/locale.nopurge; then
DONTBOTHERNEWLOCALE=enabled
fi
if fgrep --quiet --line-regexp MANDELETE /etc/locale.nopurge; then
MANDELETE=enabled
fi
if fgrep --quiet --line-regexp VERBOSE /etc/locale.nopurge \
|| [ "$1" = "-verbose" ] || [ "$1" = "-v" ] \
|| [ "$2" = "-verbose" ] || [ "$2" = "-v" ]; then
VERBOSE="-v"
fi
# Define a function for disk space calculation
# Usage: get_used_space <dirname>
if [ $SHOWFREEDSPACE = disabled ]; then
function get_used_space () { echo 0; }
else
if fgrep --quiet --line-regexp QUICKNDIRTYCALC /etc/locale.nopurge; then
function get_used_space ()
{
[ -d "$1" ] || return 1 # bail out if there's no such dir
set - $(df -P $1); shift $(($# - 6)); echo $3
}
else
function get_used_space ()
{
[ -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
# Return value tells if the argument is a locale to be deleted
# Needs optimisation
function superfluous ()
{
local locale="$1"
[ "$locale" != C ] &&
! fgrep --quiet --line-regexp "$locale" /etc/locale.nopurge &&
fgrep --quiet --line-regexp "$locale" $LOCALELIST
}
# Removes files given as arguments, after checking them
# Needs optimisation
function remove_files ()
{
for file; do
if [ -f "$file" ] || [ -h "$file" ]; then
rm $VERBOSE "$file"
fi
done
}
# Removes files under dirs given as arguments, after checking them
# Currently unused
function remove_files_under ()
{
find "$@" -mindepth 1 -type f -o -type l | xargs echo rm $VERBOSE
}
# Compute space before removing files
function spacebefore ()
{
if [ $SHOWFREEDSPACE = enabled ]; then
local dir="$1"
before=$(get_used_space "$dir")
fi
}
# Compute space freed after removing files and updates global total
function spaceafter ()
{
if [ $SHOWFREEDSPACE = enabled ]; then
local dir="$1"
after=$(get_used_space "$dir")
((tot = before - after)); ((globaltot += tot))
echo "localepurge: Disk space freed in $dir: ${tot}KiB"
fi
}
# Getting rid of superfluous locale files in LOCALEDIR
LOCALEDIR=/usr/share/locale
if [ -d "$LOCALEDIR" ]; then
test "$VERBOSE" && echo "localepurge: processing locale files ..."
spacebefore "$LOCALEDIR"
for LOCALE in $(cd "$LOCALEDIR"; echo *); do
if superfluous "$LOCALE"; then
remove_files "$LOCALEDIR/$LOCALE"/*/* "$LOCALEDIR/$LOCALE"/*.po
fi done
spaceafter "$LOCALEDIR"
fi
# Getting rid of localized man pages in $MANPAGEDIR
MANPAGEDIR=/usr/share/man
if [ -d $MANPAGEDIR ] && [ $MANDELETE = enabled ]; then
test "$VERBOSE" && echo "localepurge: processing man pages ..."
spacebefore "$MANPAGEDIR"
for LOCALE in $(ls --ignore="man[1-9]*" $MANPAGEDIR); do
if superfluous "$LOCALE"; then
remove_files "$MANPAGEDIR/$LOCALE"/man[1-9]/*
fi done
spaceafter "$MANPAGEDIR"
fi
# Getting rid of superfluous locale files in Gnome
GNOMEDIR=/usr/share/gnome/help
if [ -d "$GNOMEDIR" ]; then
test "$VERBOSE" && echo "localepurge: processing Gnome files ..."
spacebefore "$GNOMEDIR"
for LOCALEDIR in "$GNOMEDIR"/*/*; do
LOCALE=${LOCALEDIR##*/}
if superfluous "$LOCALE" && [ -d "$LOCALEDIR/../C" ]; then
remove_files "$LOCALEDIR"/*/* "$LOCALEDIR"/*.xml
fi done
spaceafter "$GNOMEDIR"
fi
# Getting rid of superfluous locale files in Omf
OMFDIR=/usr/share/omf
if [ -d "$OMFDIR" ]; then
test "$VERBOSE" && echo "localepurge: processing Omf files ..."
spacebefore "$OMFDIR"
for file in "$OMFDIR"/*/*; do
LOCALE=${file##*-}; LOCALE=${LOCALE%.omf}
if superfluous "$LOCALE" && [ -f "${file/%-$LOCALE.omf/-C.omf}" ]; then
remove_files "$file"
fi done
spaceafter "$OMFDIR"
fi
# Calculating and reporting total disk space freed:
if [ $SHOWFREEDSPACE = enabled ]; then
echo
echo "Total disk space freed by localepurge: ${globaltot}KiB"
echo
fi
============================================================
--
Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR Fax: +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa Email: Potorti at isti.cnr.it
(entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it/
More information about the pkg-gnome-maintainers
mailing list