#!/bin/sh -
# http://www.berklix.com/~jhs/bin/.sh/distfiles_dups
# Author Julian H. Stacey <jhs_ERASE_@berklix.com> May 2015 

# Looks for identical named files in /pub/freebsd/dists/*
# These files occur for various reasons including:
#	a fetch aborts
#	a disk fills 100% 
#	different releases want & fetch for different checksums.

# See also:
#	/site/domain/this/etc/make.conf.fetch
#	~/bin/.sh/distfiles_cmpd
#	~/bin/.sh/distfiles_fetch
#	~/bin/.sh/distfiles_mount

# Normally run distfiles_cmpd before this distfiles_dups

echo "Consider instead using /home/jhs/bin/.sh/dups"
exit 1
# its incredibly slow so must be wildly inefficient

full="$HOME/tmp/distfiles_dups_full.tmp"
dups="$HOME/tmp/distfiles_dups_dups.tmp"
found="$HOME/tmp/distfiles_dups_found.tmp"
cp /dev/null $full
cp /dev/null $dups
cp /dev/null $found
dists=/pub/freebsd/dists
dirs=""
dirs="$dirs 4.11-RELEASE"
dirs="$dirs 6.4-RELEASE"
dirs="$dirs 7.4-RELEASE"
dirs="$dirs 8.4-RELEASE"
dirs="$dirs 9.2-RELEASE"
dirs="$dirs 9.3-RELEASE"
dirs="$dirs 12.3-RELEASE"
dirs="$dirs 12.4-RELEASE"
# dirs="$dirs current"
# dirs="$dirs current.old"
dirs="$dirs jhs"

for i in $dirs ; do
	cd $dists ; cd $i
	find . -type f >> $full
	done
cd $dists 
cat $full | sed -e s/..// | sort | uniq -d > $dups 

echo "JJLATER Below very slow & inefficient"
echo "Will look for these files: " ; cat $dups ; echo 
for i in `cat $dups` ; do
	find $dirs -name `basename $i` -exec ls -l {} \; >> $found
	# JJLATER better to:
	#	grep `basename $i` $full >> $found
	echo 
	done
# rm $full
# rm $dups
ls -l $found
