#!/bin/bash # # distclean v0.20 -- lists unneed files in the distfiles directory # (c) Christian Birchinger option=$1 if [ "$option" = '-h' -o "$option" = '--help' ]; then echo echo "Usage: `basename $0` [options]" echo echo " -h | --help Display this help" echo " -r | --remove Remove unneeded files" echo exit fi DCROOT='/var/cache/edb/dep' # Ugly but faster than multiple portageq commands eval `emerge --verbose --info | egrep "^(DISTDIR|PORTDIR|PORTDIR_OVERLAY)"` echo >&2 echo -n ">>> Scanning all portages for used distfiles... " >&2 spin() { case "$SPIN" in '' ) SPIN='|'; echo -n " ";; '|') SPIN='/';; '/') SPIN='-';; '-') SPIN='\';; '\') SPIN='|';; esac echo -e -n "\e[1D$SPIN" } for x in $( ( for i in $(find /var/db/pkg -mindepth 2 -maxdepth 2 -printf "%P\n") do files="" for o in ${PORTDIR} ${PORTDIR_OVERLAY}; do if [ -r "${DCROOT}/${o}/${i}" ]; then files="${files} $(sed -n "s/^SRC_URI=//p" "${DCROOT}/${o}/${i}")" elif [ -r "${o}/metadata/cache/${i}" ]; then files="${files} $(sed '4q;d' "${o}/metadata/cache/${i}")" fi done for j in ${files} do if [ "${j/\:\/\/}" != "${j}" ] then echo "`basename ${j}`" spin >&2 fi done done | sort -u ; ls -1 ${DISTDIR} ) | sort | uniq -u echo -e "\e[1D " >&2 echo >&2 ) do if [ -f "${DISTDIR}/${x}" ] then if [ "$option" = '-r' -o "$option" = '--remove' ] then rm -fv ${DISTDIR}/${x} else echo "${x}" fi fi done echo >&2