:
# an attempt to get the permissions write after the cleanup process
#

USAGE="*** USAGE *** $0 [-chk] RDBMSPATH"
CHK=false

case $# in
	1)
		case $1 in
			-chk) echo "$USAGE"; exit;;
			-*) echo "$USAGE"; exit;;
			*) RDBMSPATH=$1;;
		esac
		;;
	2)
		case $1 in
			-chk) CHK=true; RDBMSPATH=$2;;
			*) echo "$USAGE"; exit;;
		esac
		;;
	*)	echo "$USAGE"; exit;;
esac

for I in `find $RDBMSPATH ! \( -perm 755 -o -perm 644 \) -print`
do
	if test -d $I
	then
		chmod 755 $I
	else
		J=`ls -l $I`
		case $CHK in
			true)
				case $J in
					-rwxr-xr-x*);;
					-rw-r--r--*);;
					drwxr-xr-x*);;
					*) echo "Wrong permission: $J";;
				esac
				;;
			
			false)
				J=`expr "$J" : '.\(...\).*'`
				if test "$J" = "rwx"
				then
					chmod 755 $I
				else
					chmod 644 $I
				fi
				;;
		esac
	fi
done

# check that the following directories should only have 644 permission code

for I in `find $RDBMSPATH/man -type f -print`
do
	case $I in
	   *mkwhatis) 	
			if test ! -x $I
			then
				echo "Wrong permission: $I"
			fi
			;;
	   *)
			if test -x $I
			then
				echo "Wrong permission: $I"
			fi
			;;
	esac
done

# check backup files

echo "Checking for backup files..."

cd $RDBMSPATH

for I in *
do
	case $I in
		testdbs|testwork|testsrc*|test|bin_pro)
			;;

		local | src_h)
			find $I -type f \( -name core -o -name "*.o" -o \
				-name "?" -o \
				-name "?.c" \) -print
			;;

		src|bin|src_lib|dist)
			find $I -type f \( -name core -o -name "*.o" -o \
				-name "?" -o -name "??" -o \
				-name "*.v[0-9]" -o \
				-name "?.c" \) -print | \
			sed -e '/f77main.o$/d'
			;;
				
		man)
			find $I -type f \( -name core -o -name "*.or*" -o \
				-name "*.old*" -o \
				-name "?" -o -name "??" -o \
				-name "?.c" -o \
				-name "*[02-9]" -o \
				-name "*.o" -o -name "?" \) -print
				;;
		*)
			find $I -type f \( -name core -o -name "*.orig" -o \
				-name "*.old*" -o \
				-name "?" -o \
				-name "*.v[0-9]" -o -name "*..[0-9]" -o \
				-name "*.org" -o -name "?.c" -o \
				-name "*.o" -o -name "?" \) -print | \
			sed -e '/lib\/f77main.o$/d'
				;;
	esac
done
