#!/bin/bash # Copyright (C) 2003 Eric Olinger, http://evvl.rustedhalo.net # Distributed under the terms of the GNU General Public License, v2 or later # Author : Eric Olinger animate_waiting () { case "${ANI}" in 0 ) echo -n "[|]" ;; 1 ) echo -n "[/]" ;; 2 ) echo -n "[-]" ;; 3 ) echo -n "[\]" ;; * ) ANI=0 ; return ;; esac let ANI=${ANI}+1 } list_files_to_keep () { echo -n "Genterating list of files to keep ... " for PKG_DIR in /var/db/pkg/*/* ; do if [ -e ${PKG_DIR}/CATEGORY ]; then DIGEST_LOCATION=`find /usr/portage/$(cat ${PKG_DIR}/CATEGORY)/ -name digest-$(cat ${PKG_DIR}/PF)*` if [ -n "${DIGEST_LOCATION}" ]; then cut -d \ -f 3 ${DIGEST_LOCATION}* >> /tmp/$$-distfiles-keep fi fi animate_waiting done echo "cvs-src" >> /tmp/$$-distfiles-keep # Hack to keep the cvs-src dir echo "done!" } list_files_to_remove () { echo -n "Genterating list of files to remove ... " for DISTFILE in $(ls -1 --color=none /usr/portage/distfiles/); do grep "${DISTFILE}" /tmp/$$-distfiles-keep &> /dev/null if [ $? != "0" ]; then echo "${DISTFILE}" >> /tmp/$$-distfiles-remove fi animate_waiting done echo "done!" if [ ! -e /tmp/$$-distfiles-remove ]; then exit 0 fi } process_files_to_remove () { if [ "${PRETEND}" = "NO" ]; then echo -n "Removing outdated files ... " fi for TARBALL in $(cat /tmp/$$-distfiles-remove); do if [ "${PRETEND}" = "NO" ]; then animate_waiting rm /usr/portage/distfiles/${TARBALL} else echo "${TARBALL}" fi done if [ "${PRETEND}" = "NO" ]; then echo "done!" fi } clean_up () { if [ -e /tmp/$$-distfiles-keep ]; then rm /tmp/$$-distfiles-keep fi if [ -e /tmp/$$-distfiles-remove ]; then rm /tmp/$$-distfiles-remove fi } ANI=0 PRETEND=NO while getopts "ph" OPTIONS; do case ${OPTIONS} in p ) PRETEND=YES echo -e "\nThese are the files I would remove:\n" ;; \? | h ) echo "Usage:" echo -e " distclean [ -hp ]\n" echo -e " -h Displays this help.\n" echo " -p Pretend. Instead of actually removing the outdated tarballs" echo " in the disfiles directory, simply display what tarballs *would*" echo " have been removed if -p weren't used." exit 1 ;; esac done if [ "${PRETEND}" = "NO" ]; then echo -e "\nCleaning the outdated files from the distfiles:\n" fi list_files_to_keep list_files_to_remove process_files_to_remove clean_up exit 0