:
#!/bin/sh
# @(#) generic/sybconfig/setperm/setperm_all 63.1 10/8/92
# Set Sybase File and Directory Permissions

if [ "%${SYBASE}%" = "%%" ]
then
	SYBASE=`grep '^sybase:' /etc/passwd | awk -F: '{ print $6 }'`
fi

if [ ! -d "${SYBASE}" ]
then
	echo "$0:" 'Cannot find $SYBASE='"${SYBASE}" 'directory.'
	exit 1
fi

echo 'Setting file permissions.  (This may take a while.  Please wait.)'

cd ${SYBASE}

# set permissions on base Sybase directories
for bdname in	bin charsets diag formdefs doc help include install \
		lib locales msgs sample scripts termdef upgrade init \
		devlib sygcforms
do
	if [ -d "${bdname}" ]
	then
		find ${bdname} -type d -print | while read dname
		do
			chmod 755 ${dname}
		done
	fi
done

# set permissions on user accessible directories
for bdname in	custom log
do
	if [ -d "${bdname}" ]
	then
		find ${bdname} -type d -print | while read dname
		do
			chmod 777 ${dname}
		done
	fi
done

# set file permissions in "bin" directories - assume all files are executable
for dname in bin diag/bin 
do
	if [ -d "${dname}" ]
	then
		# all files are executable
		find "${dname}" -type f -print | while read fname
		do
			chmod 755 ${fname}
		done
	fi
done

# set text and data file permissions
for dname in	charsets  doc formdefs \
		help include install lib locales msgs sample termdef \
		upgrade  scripts init  devlib  diag/custom \
		diag/formdefs diag/locales diag/termdef\
		diag/locales/us_english sygcforms
do
	if [ -d "${dname}" ]
	then
		# all files are readable
		find "${dname}" -type f -print | while read fname
		do
			chmod 644 ${fname}
		done
	fi
done

# special case: install directory
# all files were changed to 644. now go back and change individual files
if [ -d install ]
then
	for fname in	install/loadschema install/setperm* \
			install/showserver install/startserver \
			install/syb* install/ins_* install/RUN*\
			install/*install* install/*setup* install/rs_init\
			install/auditinit* install/omnicfg*
	do
		if [ -f "${fname}" ]
		then
			chmod 755 ${fname}
		fi
	done
fi



# special case: upgrade directory
# all files were changed to 644. now go back and change individual files
if [ -d upgrade ]
then
	for fname in	upgrade/*upgrade* upgrade/betaup \
			upgrade/fixtables
	do
		if [ -f "${fname}" ]
		then
			chmod 744 ${fname}
		fi
	done
fi

# special case: devlib directory
# all files were changed to 644. now go back and change individual files
if [ -d devlib  ]
then
	for fname in	devlib/*.s*
	do
		if [ -f "${fname}" ]
		then
			chmod 755 ${fname}
		fi
	done
fi

# special case: lib directory
# all files were changed to 644. now go back and change individual files
if [ -d lib  ]
then
	for fname in	lib/*.s*
	do
		if [ -f "${fname}" ]
		then
			chmod 755 ${fname}
		fi
	done
fi

# special case: sample directory
# all files were changed to 644. now go back and change individual files
# note: all makefiles are to be changed.
if [ -d sample ]
then
	find sample -name '[Mm]akefile' -print | while read fname
	do
		chmod 755 ${fname}
	done
fi
# some replication server sample files need to be executable
if [ -d sample/repserver ]
then
       for fname in    sample/repserver/cr_* sample/repserver/prim_* \
                       sample/repserver/rep_* sample/repserver/upd_*
       do
               if [ -f "${fname}" ]
               then
                       chmod 755 ${fname}
               fi
       done
fi

if [ -d "${SYBASE}/tli_sybinit" ]
then
	cd ${SYBASE}/tli_sybinit

# set permissions on base Sybase directories
	for bdname in	charsets install \
		locales init 
	do
		if [ -d "${bdname}" ]
		then
			find ${bdname} -type d -print | while read dname
			do
				chmod 755 ${dname}
			done
		fi
	done

# set text and data file permissions
	for dname in	charsets init \
		install locales 
	do
		if [ -d "${dname}" ]
		then
		# all files are readable
			find "${dname}" -type f -print | while read fname
			do
				chmod 644 ${fname}
			done
		fi
	done

# special case: install directory
# all files were changed to 644. now go back and change individual files
	if [ -d install ]
	then
		for fname in  install/syb*
		do
			if [ -f "${fname}" ]
			then
				chmod 755 ${fname}
			fi
		done
	fi
fi

echo "done..."
echo " "
