#!/bin/sh

DATESTR=`date +%Y%m%d`

if [ "$#" -ne 1 ]; then
	echo Usage: $0 DIRECTORY
	echo "       where DIRECTORY is the place to start a recursive find"
	echo
	exit 1
fi

found=0

for conf in `find $1 -type f \( -name .htaccess -or -name \*.conf \) -print`
do
	grep -q "MTUISOAuthenticateURI https://www.login.mtu.edu:11443/tools/public/login/index.cgi" $conf
	if [ $? -eq 0 ]; then
		echo Found a conf file or htaccess file containing:
		echo MTUISOAuthenticateURI https://www.login.mtu.edu:11443/tools/public/login/index.cgi
		echo  at $conf.  Changing the line to:
		echo MTUISOAuthenticateURI https://www.login.mtu.edu/tools/public/login/index.cgi
		echo "The original will be copied to $conf.$DATESTR"
		echo
		sed -i.$DATESTR -e 's@MTUISOAuthenticateURI https://www.login.mtu.edu:11443/tools/public/login/index.cgi@MTUISOAuthenticateURI https://www.login.mtu.edu/tools/public/login/index.cgi@' $conf
		found=1
	fi
done

if [ $found -eq 1 ]; then
	echo
	echo At least one configuration change was found. 
	echo You should restart any web server uses the config files.
	echo
fi
