# By BFGR
# Licensed under the terms of the GNU GPL, version 2
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
# BFGR WadTools v0.39a

#!/bin/bash
tree() {
local DIR=$1
local ACTUALDIR=$(pwd)
cd $DIR
local filelist=$(ls)
for file in $filelist; do
if [ -d $file ]; then
tree "$file" $2
if [ $? -eq 3 ]; then
	return 3;
fi
else
	var=`openssl dgst -sha1 $file | sed -r 's/(.*)=\s(.*)/\2/g'`
	if [ "$var" = "$2" ]; then
		echo "File hit:  `pwd`/$file"
		return 3;
	fi
#echo $var = $2
fi
done
cd $ACTUALDIR
}
echo ""
echo "----   File finder by SHA Hash   ----"
echo "- Usage: finder directory sha1_hash -"
echo "-             By BFGR               -"
echo "-------------------------------------"
echo ""
echo "Searching..."
echo ""
tree $1 $2
if [ $? -ne 3 ]; then
	echo "No matches found.";
fi