Revision 15 (by dpavlin, 2005/10/06 09:09:53) check if there are files to delete
#!/bin/sh

from="rem.pliva.hr:/mirrors/debian/pub/debian"
mount | grep " /usb_drive " && to="/usb_drive/mirrors/debian"
test -z "$to" && mount | grep " /mnt " && to="/mnt/mirrors/debian"
test -z "$to" && echo "can't find destination directory!" && exit
dists="sid sarge"

echo "$from -> $to"

OPT="
--exclude "*-alpha" \
--exclude "*-arm" \
--exclude "*-hppa" \
--exclude "*-ia64" \
--exclude "*-m68k" \
--exclude "*-mips" \
--exclude "*-mipsel" \
--exclude "*-powerpc" \
--exclude "*-s390" \
--exclude "*-sparc" \
"

echo > /tmp/pool
echo > /tmp/pool-non-US

for dist in $dists ; do

	echo "working on $dist"

	test -d "$to/dists/$dist/" || mkdir -p "$to/dists/$dist/"
	test -d "$to-non-US/dists/$dist/" || mkdir -p "$to-non-US/dists/$dist/"

	rsync -raq --delete $OPT "$from/dists/$dist/" "$to/dists/$dist/"
	rsync -raq --delete $OPT "$from-non-US/dists/$dist/" "$to-non-US/dists/$dist/"

	grep ^Filename: $to/dists/$dist/*/binary-i386/Packages | sed 's#^.*Filename: *##' > /tmp/pool_$dist
	grep ^Filename: $to-non-US/dists/$dist/non-US/*/binary-i386/Packages | sed 's#^.*Filename: *##' > /tmp/pool-non-US_$dist

done

cat /tmp/pool_* | sort -u > /tmp/pool
cat /tmp/pool-non-US_* | sort -u > /tmp/pool-non-US

echo `wc -l /tmp/pool` " files in pool"
echo `wc -l /tmp/pool-non-US` " files in non-US pool"

cd $to || exit

echo -n "remove expired files "

e=/tmp/pool.existing

find pool -type f | sort -u > $e.old
cat /tmp/pool /tmp/pool-non-US | sort -u > $e.new
diff $e.old $e.new | grep '^<' | cut -c3- > $e.delete

wc -l $e.delete | cut -d" " -f1

test -s $e.delete && xargs rm < $e.delete

rsync -av --delete --files-from=/tmp/pool "$from/" "$to/"
rsync -av --delete --files-from=/tmp/pool-non-US "$from-non-US/" "$to-non-US/"