#!/usr/bin/env bash
DISTDIR=/usr/portage/distfiles
PORTDIR=/usr/portage
export PATH="/usr/lib/portage/bin:${PATH}"
echo -n "Source archive pruning started "
date
#will only prune files not touched for 60 days
touch ${DISTDIR}/.cleaned -d "60 days ago"
sleep 2
cd ${PORTDIR}
for x in `find ${PORTDIR}/ -iname '*.ebuild'` 
do
	ebuild ${x} touch
done
if [ ! -d ${DISTDIR}-old ]
then
	mkdir ${DISTDIR}-old
fi
cd ${DISTDIR}
for x in `find ! -newer .cleaned | grep ./` 
do
	mv $x ${DISTDIR}-old
done
echo -n "Source archive pruning completed "
date
