#!/bin/sh

case $USER in 
	"katalyz")
	report="/home/katalyz/backup/report-htaccess.txt"
	report_pass="/home/katalyz/backup/report-pass.txt"
;;
	"gilles")
	start="/Users/katalyz"
	cd $start
	report="backup/report-htaccess_0.txt"
	report_pass="backup/report-pass_0.txt"
;;
	*) exit ;;
esac
pass_list=""
#date > $report
list=$(find . -name .htaccess | sort)

check_pass_list () {
	for pass in $pass_list; do
		if [ "$pass" = "$1" ]; then return 1; fi
	done
	pass_list="$pass_list $1"
	return 0
}

for HTAC in $list; do
	echo "[$HTAC]" >> $report
	#old_file=$(cat $HTAC)
	if line=$(cat $HTAC | grep 'AuthUserFile') ; then
		echo "[$HTAC] -> $pass_file" 
		pass_file=$(echo $line | cut -d' ' -f2)
		pass_file=$(echo $pass_file | sed s/home\.10\.[0-9]*/home/ )
		cat $HTAC | sed s/home\.10\.[0-9]*/home/ > $HTAC
		if check_pass_list $pass_file ; then
			echo "adding $pass_file to pass_list"
		fi
	fi
	cat $HTAC >> $report
done
echo cat $pass_list | wc -w
echo $pass_list
date > $report_pass
for pass_file in $pass_list ; do
	echo "[$pass_file]" >> $report_pass
	cat $pass_file >> $report_pass
done
