From 4de875a68b4f83655465f7a1ff8310cd7e1457c4 Mon Sep 17 00:00:00 2001 From: José Alberto Suárez López Date: Sun, 2 Dec 2012 14:32:40 +0100 Subject: v0.5.2: import from current ebuild --- copyright | 7 ++ defaultlist | 320 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ locale.nopurge | 44 ++++++++ localepurge | 253 +++++++++++++++++++++++++++++++++++++++++++++ localepurge.8 | 95 +++++++++++++++++ 5 files changed, 719 insertions(+) create mode 100644 copyright create mode 100644 defaultlist create mode 100644 locale.nopurge create mode 100755 localepurge create mode 100644 localepurge.8 diff --git a/copyright b/copyright new file mode 100644 index 0000000..12175ef --- /dev/null +++ b/copyright @@ -0,0 +1,7 @@ +José Alberto Suárez López + +This script is based in the Debian script by +Paul Seelig + +This source code is copyright under the GNU Public License (GPL). + diff --git a/defaultlist b/defaultlist new file mode 100644 index 0000000..99ed1a5 --- /dev/null +++ b/defaultlist @@ -0,0 +1,320 @@ +aa +af +af_ZA +am +am_ET +ang +ar +ar_AE +ar_BH +ar_DZ +ar_EG +ar_IN +ar_IQ +ar_JO +ar_KW +ar_LB +ar_LY +ar_MA +ar_OM +ar_QA +ar_SA +ar_SD +ar_SY +ar_TN +ar_YE +as +az +az_AZ +az_IR +be +be_BY +bg +bg_BG +bn +bn_IN +br +br_FR +bs +bs_BA +byn +ca +ca_ES +ca_ES@euro +cs +cs_CZ +cy +cy_GB +da +da_DK +de +de_AT +de_AT@euro +de_BE +de_BE@euro +de_CH +de_DE +de_DE.UTF-8 +de_DE@euro +de_LU +de_LU@euro +dv +el +el_GR +el_GR.UTF-8 +el_GR@euro +en +en@IPA +en@boldquot +en@quot +en_AU +en_BW +en_CA +en_DK +en_GB +en_GB.UTF-8 +en_HK +en_IE +en_IE@euro +en_IN +en_NZ +en_PH +en_RN +en_SG +en_UK +en_US +en_US.UTF-8 +en_ZA +en_ZW +eo +eo_EO +es +es_AR +es_BO +es_CL +es_CO +es_CR +es_DO +es_EC +es_ES +es_ES@euro +es_ES.UTF-8 +es_GT +es_HN +es_MX +es_NI +es_PA +es_PE +es_PR +es_PY +es_SV +es_US +es_UY +es_VE +et +et_EE +eu +eu_ES +eu_ES@euro +fa +fa_IR +fa_IR.UTF-8 +fi +fi_FI +fi_FI@euro +fo +fo_FO +fr +fr_BE +fr_BE@euro +fr_CA +fr_CH +fr_FR +fr_FR.UTF-8 +fr_FR@euro +fr_LU +fr_LU@euro +ga +ga_IE +ga_IE@euro +gd +gd_GB +gez +gl +gl_ES +gl_ES@euro +gr +gu +gv +gv_GB +haw +he +he_IL +hi +hi_IN +hi_IN.UTF-8 +hr +hr_HR +hu +hu_HU +hy +hy_AM +ia +id +id_ID +is +is_IS +it +it_CH +it_IT +it_IT@euro +iu +iw +iw_IL +ja +ja_JP +ja_JP.EUC +ja_JP.EUC-JP +ja_JP.UTF-8 +ja_JP.eucJP +ka +ka_GE +kk +kl +kl_GL +kn +ko +ko_KR +ko_KR.EUC-KR +ko_KR.UTF-8 +kok +ku +kw +kw_GB +ky +li +lt +lt_LT +lv +lv_LV +mi +mi_NZ +mk +mk_MK +ml +mn +mr +mr_IN +mr_IN.UTF-8 +ms +ms_MY +mt +mt_MT +my_MM +nb +nb_NO +ne +nl +nl_BE +nl_BE@euro +nl_NL +nl_NL@euro +nn +nn_NO +no +no_NO +nso +nyc +oc +oc_FR +om +or +pa +pl +pl_PL +ps +pt +pt_BR +pt_PT +pt_PT@euro +rm +ro +ro_RO +ru +ru_RU +ru_RU.KOI8-R +ru_RU.UTF-8 +ru_UA +rw +sa +sid +sk +sk_SK +sl +sl_SI +so +sp +sq +sq_AL +sr +sr@Latn +sr@ije +sr_YU +sr_YU@cyrillic +sv +sv_FI +sv_FI@euro +sv_SE +sw +syr +ta +ta_IN +te +te_IN +tg +tg_TJ +th +th_TH +ti +ti_ER +ti_ET +tig +tk +tl +tl_PH +tr +tr_TR +tt +tt_RU +ug +uk +uk_UA +ur +ur_PK +uz +uz@Latn +uz_UZ +ve +vi +vi_VN +vi_VN.UTF-8 +wa +wal +wo +xh +yi +yi_US +zh +zh_CN +zh_CN.GB18030 +zh_CN.GB2312 +zh_CN.GBK +zh_CN.UTF-8 +zh_HK +zh_HK.UTF-8 +zh_SG +zh_TW +zh_TW.Big5 +zh_TW.EUC-TW +zh_TW.UTF-8 +zu diff --git a/locale.nopurge b/locale.nopurge new file mode 100644 index 0000000..159c1c0 --- /dev/null +++ b/locale.nopurge @@ -0,0 +1,44 @@ +#################################################### +# This is the configuration file for localepurge(8). +#################################################### +# Comment this to enable localepurge. +# NO COMMENT IT IF YOU ARE NOT SURE WHAT ARE YOU DOING +# THIS APP DO NOT ASK FOR CONFIRMATION + +NEEDSCONFIGFIRST + +#################################################### +# Uncommenting this string enables removal of localized +# man pages based on the configuration information for +# locale files defined below: + +MANDELETE + +#################################################### +# Uncommenting this string enables display of freed disk +# space if localepurge has purged any superfluous data: + +SHOWFREEDSPACE + +##################################################### +# Commenting out this string disables verbose output: + +VERBOSE + +##################################################### +# You like Colors? + +#NOCOLOR + +##################################################### +# You can use the -v -d -nc options in command linei. + +##################################################### +# Following locales won't be deleted from this system +# for example: +en +en_GB +es +es_ES +es_ES@euro +es_ES.UTF-8 diff --git a/localepurge b/localepurge new file mode 100755 index 0000000..71a0582 --- /dev/null +++ b/localepurge @@ -0,0 +1,253 @@ +#!/bin/bash + +# Deleting all locale files on system +# *not* listed in /etc/locale.nopurge + +set -e + +LOCALEDIRS="/usr/share/locale /usr/local/share/locale /usr/kde/?.?/share/locale /opt/sun-jdk-*/jre/lib/locale /opt/sun-jre-bin-*/lib/locale /usr/lib/locale" +MANPAGEDIRS="/usr/share/man /usr/man /usr/local/share/man /usr/kde/?.?/share/man /usr/kde/?.?/man /opt/sun-jdk-*/man /opt/sun-jre-bin-*/man" +LOCALELIST="/var/cache/localepurge/localelist" +CONFIGFILE="/etc/locale.nopurge" +VERSION="0.5.2" + +LOCALETOTAL=0 +MANTOTAL=0 + +GOOD=$'\e[32;01m' +WARN=$'\e[33;01m' +BAD=$'\e[31;01m' +NORMAL=$'\e[0m' +HILITE=$'\e[36;01m' +BRACKET=$'\e[34;01m' +BOLD=$'\e[1m' + +eerror () { + echo -e " ${BAD}*${NORMAL} $*" +} + +ewarn () { + echo -e " ${WARN}*${NORMAL} $*" +} + +einfo () { + echo -e " ${GOOD}*${NORMAL} $*" +} +etab () { + echo -e " ${GOOD}*${NORMAL} $*" +} + +ayuda () { + echo "${HILITE}localepurge${NORMAL} for ${BOLD}Gentoo Linux${NORMAL} ${BRACKET}[${NORMAL} ${GOOD}${VERSION}${NORMAL} ${BRACKET}]${NORMAL}" + echo -e " " "by bass@gentoo.org" + echo + einfo "Remember that you must edit ${CONFIGFILE}" + echo + einfo "Usage: `basename $0` [options]" + echo + etab "${BOLD}-help (-h) ${NORMAL} : show this help." + etab "${BOLD}-debug (-d) ${NORMAL} : debug mode." + etab "${BOLD}-verbose (-v) ${NORMAL} : verbose mode." + etab "${BOLD}-nocolor (-nc) ${NORMAL} : no color mode." + etab "${BOLD}-pretend (-p) ${NORMAL} : pretend mode." + etab "${BOLD}-version ${NORMAL} : show version." + echo +} + +version () { + einfo "${BRACKET}[${NORMAL} ${GOOD}${VERSION}${NORMAL} ${BRACKET}]${NORMAL}" +} + +# Check options in CONFIGFILE + +grep -xq SHOWFREEDSPACE ${CONFIGFILE} && SHOWFREEDSPACE=enabled +grep -xq VERBOSE ${CONFIGFILE} && VERBOSE=enabled +grep -xq NOCOLOR ${CONFIGFILE} && + unset GOOD WARN BAD NORMAL HILITE BRACKET BOLD + +# We need to loop through for no color first, otherwise options that exit +# will make us ignore nocolor, so we might as well loop for debug first as well + +for x in $@ +do + if [ "$x" = "-debug" ] || [ "$x" = "-d" ]; then + set -x + fi + + if [ "$x" = "-nocolor" ] || [ "$x" = "-nc" ]; then + unset GOOD WARN BAD NORMAL HILITE BRACKET BOLD + fi + +done + +# Loop through the rest of the options + +for x in $@ +do + + if [ "$x" = "-verbose" ] || [ "$x" = "-v" ]; then + VERBOSE=enabled + fi + + if [ "$x" = "-version" ] ; then + version + exit 0 + fi + + if [ "$x" = "-p" ] || [ "$x" = "-pretend" ]; then + PRETEND=enabled + fi + + if [ "$x" = "-help" ] || [ "$x" = "-h" ]; then + ayuda + exit 0 + fi + +done + +# Do nothing and report why if no valid configuration file exists: + +if [ ! -f ${CONFIGFILE} ] + then + eerror " No ${CONFIGFILE} file present, exiting ..." + exit 0 + else + if [ "`grep -x ^NEEDSCONFIGFIRST ${CONFIGFILE}`" ] + then + echo "" + einfo " You have to configure \"${CONFIGFILE}\" " + echo "" + einfo " to make $0 actually start to function." + echo "" + einfo " Nothing to be done, exiting ..." + echo "" + exit 0 + fi +fi + +# Prune the locale list using CONFIGFILE as a list of regex patterns: + +PURGELIST=`grep -xvf ${CONFIGFILE} "${LOCALELIST}"` + +# Getting rid of superfluous locale files in $LOCALEDIR: + +purgelocale () { + local LOCALEDIR="$1" +if [ -d $LOCALEDIR ]; then + + if [ "$SHOWFREEDSPACE" = "enabled" ]; then + LOCALEBEFORE=$(df -P $LOCALEDIR | awk '{if ( NR==2 ) { print $3 }}') + fi + + if [ "$VERBOSE" = "enabled" ]; then + einfo "localepurge: processing locale files in ${LOCALEDIR} ..." + for LOCALE in `/bin/ls ${LOCALEDIR}` + do + if echo "${PURGELIST}" | grep -xq ${LOCALE}; then + if [ -d ${LOCALEDIR}/${LOCALE}/LC_MESSAGES ]; then + if [ "${PRETEND}" = "enabled" ]; then + echo "${LOCALEDIR}/${LOCALE}" + else + /bin/rm -vf `find ${LOCALEDIR}/${LOCALE} -type f` + fi + fi + fi + done + else + for LOCALE in `/bin/ls ${LOCALEDIR}` + do + if echo "${PURGELIST}" | grep -xq ${LOCALE}; then + if [ -d ${LOCALEDIR}/${LOCALE}/LC_MESSAGES ]; then + if [ "${PRETEND}" = "enabled" ]; then + echo "${LOCALEDIR}/${LOCALE}" + else + /bin/rm -vf `find ${LOCALEDIR}/${LOCALE} -type f` + fi + fi + fi + done + fi + + if [ "$SHOWFREEDSPACE" = "enabled" ]; then + LOCALEAFTER=$(df -P $LOCALEDIR | awk '{if ( NR==2 ) { print $3 }}') + LOCALESUM=$(($LOCALEBEFORE - $LOCALEAFTER)) + LOCALETOTAL=$(($LOCALETOTAL + $LOCALESUM)) + if [ ! $LOCALEBEFORE = $LOCALEAFTER ]; then + einfo "localepurge: Disk space freed in $LOCALEDIR: ${BOLD}"$LOCALESUM"K${NORMAL}" + fi + fi +fi +} + +# Getting rid of localized man pages in $MANPAGEDIR + +purgeman () { + local MANPAGEDIR="$1" +if [ -d $MANPAGEDIR ] && [ "`grep -x ^MANDELETE ${CONFIGFILE}`" ]; then + + if [ "$SHOWFREEDSPACE" = "enabled" ]; then + MANBEFORE=$(df -P $MANPAGEDIR | awk '{if ( NR==2 ) { print $3 }}') + fi + + if [ "$VERBOSE" = "enabled" ]; then + einfo "localepurge: processing man pages in ${MANPAGEDIR} ..." + for LOCALE in `/bin/ls ${MANPAGEDIR} | grep -v ^man[1-9]` + do + if echo "${PURGELIST}" | grep -xq ${LOCALE}; then + if [ -d ${MANPAGEDIR}/${LOCALE} ]; then + if [ "${PRETEND}" = "enabled" ]; then + echo "${MANPAGEDIR}/${LOCALE}" + else + /bin/rm -f `find ${MANPAGEDIR}/${LOCALE} -type f` + fi + fi + fi + done + else + for LOCALE in `/bin/ls ${MANPAGEDIR} | grep -v ^man[1-9]` + do + if echo "${PURGELIST}" | grep -xq ${LOCALE}; then + if [ -d ${MANPAGEDIR}/${LOCALE} ]; then + if [ "${PRETEND}" = "enabled" ]; then + echo "${MANPAGEDIR}/${LOCALE}" + else + /bin/rm -f `find ${MANPAGEDIR}/${LOCALE} -type f` + fi + fi + fi + done + fi + + if [ "$SHOWFREEDSPACE" = "enabled" ]; then + MANAFTER=$(df -P $MANPAGEDIR | awk '{if ( NR==2 ) { print $3 }}') + MANSUM=$(($MANBEFORE - $MANAFTER)) + MANTOTAL=$(($MANTOTAL + $MANSUM)) + if [ ! $MANBEFORE = $MANAFTER ]; then + einfo "localepurge: Disk space freed in $MANPAGEDIR: ${BOLD}"$MANSUM"K${NORMAL}" + fi + fi +fi +} + +[ "${PRETEND}" = "enabled" ] && + ewarn "If not pretending, localepurge would clear the following directories:\n" + +for folder in ${LOCALEDIRS}; do + purgelocale "$folder" +done + +for folder in ${MANPAGEDIRS}; do + purgeman "$folder" +done + +# Calculating and reporting total disk space freed: + +if [ "$SHOWFREEDSPACE" = "enabled" ]; then + if [ $MANTOTAL ] && [ $LOCALETOTAL ]; then + if [ ! $MANBEFORE = $MANAFTER ] && [ ! $LOCALEBEFORE = $LOCALEAFTER ]; then + echo "" + einfo "Total disk space freed by localepurge: ${BOLD}"$(($LOCALETOTAL + $MANTOTAL))"K${NORMAL}" + echo "" + fi + fi +fi diff --git a/localepurge.8 b/localepurge.8 new file mode 100644 index 0000000..bfcf3ee --- /dev/null +++ b/localepurge.8 @@ -0,0 +1,95 @@ +.TH LOCALEPURGE 8 +.SH NAME +localepurge \- removing superfluous locale data +.SH SYNOPSIS +.B localepurge +.br +.SH "DESCRIPTION" +.BR localepurge +is a small script to recover disk space wasted for unneeded locale +files and localized man pages. It will be automagically invoked by +.BR emerge +some day... +You have to define the locale +directory names you want to keep from removal +in the +.BR /etc/locale.nopurge +configuration file. +.br +Any other directory (or file) in +.BR /usr/share/locale +not containing a subdirectory named +.BR LC_MESSAGES +will be discreetly ignored. +.SH OPTIONS +The configurable options consist of toggling verbose output, reporting a +summary of freed space, and deletion of localized manual pages in +addition to locale files. All actions are specified in the +.BR /etc/locale.nopurge +configuration file. +For detailed debugging the commandline switch +.BR -debug +or just a short +.BR -d +instead are available for usage. +For verbose output the commandline switch +.BR -verbose +or just a short +.BR -v +can be added. You can use too +.BR -help +to have help ;) or a short +.BR -h. +You can use too +.BR -version +and if you dont like colors you can use +.BR -nocolor +or the short form +.BR -nc +if you want a pretend mode you can use +.BR -pretend +or the short from +.BR -p +enjoy. + +.SH "A Word of CAUTION" +Please note, that +.BR this +.BR tool +.BR is +.BR a +.BR hack +.BR which +.BR is +.BR not +.BR integrated +.BR with +.BR Gentoo +.BR Portage +.BR system +and therefore is not meant for the faint of heart. Responsibility for its +usage and possible breakage of your system therefore lies in the sysadmin's +(your) hands. +.br +Please definitely do abstain from reporting any bugs blaming localepurge if +.BR you +break your system by using it. If you don't know what you are doing and +can't handle any resulting breakage on your own then please simply don't +use it. +.br +All locale directories containing a subdirectory named LC_MESSAGES +which are either commented out or not even listed at all in +.BR /etc/locale.nopurge +will be irreversibly deleted. The only way to +reinstall any lost locales is "remerging" +the ebuild. +.SH FILES +.BR /etc/locale.nopurge +.SH SEE ALSO +.SH AUTHOR +.BR localepurge +and its accompanying manual page was written for the +.BR Gentoo +.BR Linux +system by José Alberto Suárez López. Based in the grat job for Debian +GNU/Linux of Paul Seelig . -- cgit v1.2.3-65-gdbad