:
#	%Z% %M% %I% %E% %Q%
#
#	Copyright (C) The Santa Cruz Operation, 1988, 1989, 1990.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, and should be treated as Confidential.
#

#	LINKS
#	mitrecordperm
#		will read list of files in PERMLISTINPUT
#		will create a permlist, PERMLISTOUTPUT based on PERMLISTINPUT
#	mitfixperm
#		will inact a permlist, PERMLISTOUTPUT on a system
#	required to be run in the current directory
#
#	PERMLISTINPUT by default has the following files for the
#	following reasons:
#	./usr/mmdf		mmdfupdate corrupts permissions
#	./etc/conf/cf.d		kernel relink corrupts permissions
#	./unix			""	""	""	""	""
#	./inittab		""	""	""	""	""
#

# set the environment variables
PATH=/etc:/bin:/usr/bin:.

# set the standard exit values
: ${OK=0} ${FAIL=1} ${STOP=10}

PWD=`pwd`
PERMLISTINPUT=fixpermdata
PERMLISTOUTPUT=mitpermdata

TRAPMSG="<Del> key pressed or program killed.  Exiting."

# Prompt for yes or no answer - returns non-zero for no
getyn() {
	while	echo "\n$* (y/n) \c">&2
	do	read yn rest
		case $yn in
		[yY])	return $OK 			;;
		[nN])	return $FAIL			;;
		*)	echo "Please answer y or n" >&2	;;
		esac
	done
}

# Prompt with mesg, return non-zero on q
prompt() {
	while	echo "\n${1}\c" >&2
	do	read cmd
		case $cmd in
		+x|-x)	set $cmd					;;
		Q|q)	return $FAIL;					;;
		!*)	eval `expr "$cmd" : "!\(.*\)"`			;;
		"")	cmd="return"
			return $OK
			;;
		*)	return $OK					;;
		esac
	done
}

record() {

	echo "Getting permissions for specified files..."
	cd /

	#check that PERMLISTOUTPUT exists
	[ -r ${PWD}/${PERMLISTOUTPUT} ] || {
		echo "ERROR:	$PERMLISTOUTPUT does not exist"
		echo "		Cannot access file that is"
		echo "		needed to build perm file."
	}

	#make the perms list
	${PWD}/setperm -rf ${PWD}/${PERMLISTOUTPUT} > ${PWD}/${PERMLISTINPUT}
	[ "$?" ] || {
		echo "FATAL ERROR: unable to make permissions list"
		exit $FAIL
	}

	cd $PWD
	return $OK
}

fix() {
	echo "Fixing permissions for specified files..."
	cd /
	fixperm -cv ${PWD}/${PERMLISTINPUT} 
	cd $PWD
	return $OK

}

#main

case `basename $0` in
	mitrecordperm) record || {
		echo "ERROR: $0 failed"
		exit $FAIL
		}
		;;
	mitfixperm) fix || {
		echo "ERROR: $0 failed"
		exit $FAIL
		}
		;;
	*) echo "Unknown option $0 exiting"
		exit $FAIL
		;;
esac

exit $OK
