#!/bin/bash # # distclean v0.12 -- lists unneed files in the distfiles directory # (c) Christian Birchinger # # Version for portage <=2.0 cache format 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 files="${files} $([ -r "${DCROOT}/${o}/${i}" ] && head -n 4 ${DCROOT}/${o}/${i} | tail -n 1)" 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