aboutsummaryrefslogtreecommitdiff
blob: 23af32be2b108882f64158bf7f35bea7fa8c8bf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
#
# distfiles-clean
#
# Cleans unused files from Portage's distfiles directory.
#
# Jos´┐Ż Fonseca <j_r_fonseca@yahoo.co.uk>

PROGRAM=`basename "$0"`

while [ ${#} -gt 0 ]
do
	case "$1" in
		-h|--help)
			USAGE=y
			break
			;;
		-i|--ignore)
			IGNORE="$IGNORE $2"
			shift 2
			;;
		-I|--ignore-file)
			IGNORE="$IGNORE `cat "$2"`"
			shift 2
			;;
		-p|--pretend)
			PRETEND=y
			shift
			;;
		*)
			echo "$PROGRAM: Invalid option \'$1\'" 1>&2
			USAGE=y
			break
			;;
	esac
done

# For PORTDIR and DISTDIR
. /etc/make.globals
. /etc/make.conf

if [ "$USAGE" ]
then
	echo "Usage:	$PROGRAM [-h|--help] [-i|--ignore <glob>] [-I|--ignore-file <globfile>] [-p|--pretend]"
	echo "Cleans unused files from $DISTDIR directory."
	exit
fi

DBDIR=/var/db/pkg
CACHEDIR=/var/cache/edb/dep

for DIR in "$PORTDIR" "$DISTDIR" "$DBDIR" "$CACHEDIR"
do
	if [ ! -d "$DIR" ]
	then
		echo "$PROGRAM: \'$DIR\' not found."
		exit
	fi
done

TMPFILE=`mktemp /tmp/$PROGRAM.XXXXXX`

cd "$DISTDIR"

{
	echo "cvs-src"
	[ "$IGNORE" ] && ls -1d $IGNORE
	find "$DBDIR" -name '*.ebuild' | sed -n -e "s:^$DBDIR/\([^/]*\)/\([^/]*\)/\([^/]*\)\.ebuild$:$CACHEDIR/\1/\3:p" | xargs sed -s -e '4!d;/^$/d;s/[[:alnum:]]\+?\|(\|)//g;s/\<[^[:space:]]\+\/\<//g;s/^[[:space:]]\+//g;s/[[:space:]]\+$//g;s/[[:space:]]\+/\n/g'
} | sort -u > "$TMPFILE" && ls -1 | comm -23 - "$TMPFILE" | {
	if [ "$PRETEND" ]
	then
		cat
	else
		xargs rm -f
	fi
}

rm "$TMPFILE"