#!/bin/sh

# take output of:
# apt-get ... --print-uris
# and from just the filename portions of those URIs/URLs,
# check if we appear to already have those files in our customary locations,
# and if so, report their pathnames.
# Also check for possible matches after unencoding %3a --> :

find \
	/var/cache/apt/archives \
	/media/cdrom*/ \
	/var/local/cache \
	\( \
		$(
			uris2f "$@" |
			perl -e '
				$^W=1;
				use strict;
				my %names=();
				while(<>){
					chomp;
					if(/%3a/){
						$names{"$_"}=undef;
						s/%3a/:/g;
					};
					$names{"$_"}=undef;
				};
				print(q(-name ),join(q( -o -name ),(keys %names)));
			'
		) \
	\) -type f -print 2>>/dev/null

