#!/bin/sh

# will convert specified files to lower names

if [ "$1" = "-r" ] ; then
	recurse=1; shift;
else
	recurse=0;
fi;

for x in $* ; do
	if [ -r "$x" ] ; then
		conv="`echo $x | tr '[A-Z]' '[a-z]'`";
		if [ "$x" != "$conv" ] ; then
			if [ -e "$conv" -a ! "$x" -ef "$conv" ] ; then
				echo "ERROR: $conv already exists (from $x)";
				echo "exiting..."
				exit 1;
			fi;
			#wish i could do this:
			# mv "$x" "$conv";
			#but cygwin doesn't like that...
			mv "$x" "$x"_tmp;
			mv "$x"_tmp "$conv";
		fi;
		if [ $recurse -gt 0 -a -d "$conv" ] ; then
			"$0" -r "$conv"/*;
		fi;
	fi;
done;
