#!/bin/sh
#
# This script tells you which files were modified on the root and usr
# partitions after the last full install of OS/MP.
#
# Normal usage is to do a find -print of system-partition files newer
# than the file /etc/sys_conf/system-configured, which is touched at
# first-time boot.
#
# -l option causes long-form output (find -ls rather than find -print)
#
# -c cutoff permits you to specify cutoff date as mmddhhmm[yy] instead
# of relying on date of /etc/sys_conf/system-configured
#

USAGE="Usage: $0 [-l] [-c mmddhhmm[yy] ]"
FINDMODE=print

EPOCH=/etc/sys_conf/system-configured


# ckok: check that things look good before proceeding
ckok()	{
	if [ ! -f $EPOCH ]
	then
		echo Could not find the file $EPOCH
		echo that marks the completion of OS/MP 4.1B installation.
		echo Cannot continue!
		exit 1
	fi

	if [ `whoami` != "root" ]
	then
		echo Please become superuser to run this script
		exit 1
	fi
	}

# do_partition: look for changed files on given partition, excluding others
do_partition()	{
	part=$1
	shift

	# build up the list of exclusions to be used in the find command
	excls=""
	for i in $*
	do
		excls="-name $i -prune -o $excls"
	done

	find $part -xdev $excls -newer $EPOCH -$FINDMODE
}

# argv: parse the argument vector
argv()	{
	while getopts lc: c
	do
		case $c in
		l)	FINDMODE=ls;;
		c)	CUTOFF=$OPTARG
			EPOCH=/tmp/epoch$$
			/usr/5bin/touch $CUTOFF $EPOCH
			if [ $? -ne 0 ]
			then
				echo $USAGE
				exit 2
			fi;;
		\?)       echo $USAGE
			  exit 2;;
		esac
	done
	shift `expr $OPTIND - 1`
	if [ "X$*" != X ]
	then
		echo $USAGE
		exit 2
	fi
	}

# main: drive the subroutines
main()	{
	# parse arguments
	argv $*

	# make sure we want to be here
	ckok

	# Look for files modified since install on system partitions	
	# (do /var separately because it may be on a separate partition)
	#
	# look at:   	partition	excluding
	do_partition 	/		dev etc var tmp_mnt tmp usr
	do_partition	/etc		ld.so.cache mtab xtab sm state \
					psdatabase utmp ypbind.lock syslog.pid
	do_partition 	/var		sadm tmp
	do_partition 	/usr		OBJ

	# clean up tmp file if used -c cutoff
	if [ "X$CUTOFF" != X ]
	then
		rm -f $EPOCH
	fi
	}

# shell script body just invokes main
main $*
exit  0
