You need to sign in or sign up before continuing.
check-pkg-list 2.68 KB
Newer Older
1 2 3 4 5 6 7 8
#!/bin/sh
# script based on initial implementation
# by Vitaly Gusach (http://gusach.org.ua)
#
# purpose: warn on those entries in given packagelists(s)
# which are definitely absent; the build might still bail out
# but at least 80% of failures can be predicted early now
#
9
# usage: check-pkg-list [-n pkgnames] [--aptbox $PATH/to/aptbox] pkglist ...
10 11 12
# (pkgnames file should contain `apt-cache pkgnames`)
# NB: -n pkgnames MUST go first, if given

13 14
RET_ERROR=

15 16 17 18
error() {
	echo `basename $0`: $* >&2
	exit 1
}
19 20 21 22

exit_handler() {
	local rc=$?
	trap - EXIT
23
	rm -f -- "$ftemp" "$fpkgnames" "$fpkgwildcards" "$favaillist" "$fpkgerrors"
24 25 26 27 28
	exit $rc
}

# figure out apt.conf from recent aptbox or fallback to system one
dump_pkgnames() {
29
	${APTBOX:+$APTBOX/}apt-cache pkgnames  | sort -u > "$favaillist"
30 31 32 33 34 35 36 37 38 39 40 41 42 43
}

check_pkglist() {
	fprofilelist="$1"
	[ -f "$fprofilelist" ] || error "invalid packagelist filename: $fprofilelist"
	# cleaning pkg list from comments, empty lines,
	# splitting several pkgnames on the same line
	sed -e '/^#/d' -e '/^[ 	]*$/d' -e 's/ \+$//' -e 's/[ 	]\+/\n/g' \
	< "$fprofilelist" \
	| sed 's/-$//' \
	| sort -u \
	> "$ftemp" # got list of pkgnames we need

	# split pkgnames without wildcards and with wildcards
44
	grep -F -v '*' "$ftemp" > "$fpkgnames"
45
	grep -F    '*' "$ftemp" > "$fpkgwildcards"
46 47

	# return unavailable packages
48
	comm -23 "$fpkgnames" "$favaillist" > "$fpkgerrors"
49 50 51 52 53

	# return unavailable wildcards
	while read i; do
		# replacing * with regexp's \.+
		pattern="^`echo ${i#^} | sed -e 's/\*/.\\\\+/'`$"
54
		grep -q "$pattern" "$favaillist" || echo "$i" >> "$fpkgerrors"
55
	done < "$fpkgwildcards"
56
	if [ -s "$fpkgerrors" ]; then
57
		echo "** error: Packages are not available in $fprofilelist:" >&2
58
		RET_ERROR=1
59 60
		cat $fpkgerrors >&2
	fi
61 62 63 64 65 66 67 68 69 70
}

[ "$#" -gt 0 ] || error "need at least one argument, a packagelist to check"

# reusable temporary files with self-cleanup at exit
TEMP="${TMP:-/tmp}"
trap exit_handler HUP INT QUIT TERM EXIT
favaillist="`mktemp $TEMP/pkgchecker.avail.XXXXX`"
fpkgnames="`mktemp $TEMP/pkgchecker.names.XXXXX`"
fpkgwildcards="`mktemp $TEMP/pkgchecker.wildcards.XXXXX`"
71
fpkgerrors="`mktemp $TEMP/pkgchecker.error.XXXXX`"
72 73
ftemp="`mktemp $TEMP/pkgchecker.XXXXX`"

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
# check args
while :; do
	case "$1" in
	# make sure pkgnames dump is handy
	"-n"|"--pkgnames")
		[ -f "$2" ] && {
			sort "$2" > "$favaillist"
			shift; shift
		} || error "-n needs valid pkgnames filename"
		;;
	# PATH to aptbox
	"--aptbox")
		[ -d "$2" ] && {
			APTBOX="$2"
			shift; shift
		} || error "--aptbox needs valid directory"
		;;
	*)
		break
		;;
	esac
done
96 97 98 99 100 101

[ -s "$favaillist" ] || dump_pkgnames

for list in "$@"; do
	check_pkglist "$list"
done
102 103

[ -z "$RET_ERROR" ] || error "Some lists contain unavailable packages"