#!/bin/sh5
########################################################################
#
#			Copyright (c) 1988, 1989, 1990 by
#		Digital Equipment Corporation, Maynard, MA
#			All rights reserved.
#
#	This software is furnished under a license and may be used and
#	copied  only  in accordance with the terms of such license and
#	with the  inclusion  of  the  above  copyright  notice.   This
#	software  or  any  other copies thereof may not be provided or
#	otherwise made available to any other person.  No title to and
#	ownership of the software is hereby transferred.		
#
#	The information in this software is subject to change  without
#	notice  and should not be construed as a commitment by Digital
#	Equipment Corporation.					
#
#	Digital assumes no responsibility for the use  or  reliability
#	of its software on equipment which is not supplied by Digital.
#
#	SCCSID = "@(#)genufi	7.1 (ULTRIX) 7/22/92"
#
#	001	16-oct-1990	ccb
#		bugfixes, integrate fsmount
#
#	000	Designed by ccb
#		Coded by jon		15-Aug-1990
#
########################################################################
#	genufi -
#		Takes the name of an inventory file as a command line
#		argument and generates a list of files resident on the
#		system which are not listed in this inventory.

CDPATH=
PATH=/install.tmp:/etc/stl:/etc:/bin:/usr/bin:/usr/adm/bin:/usr/ucb
export CDPATH PATH


Constants()
{
	TDIR=/usr/tmp
	TMP1=$TDIR/ufitmp1
	TMP2=$TDIR/ufitmp2
	SPLITS=/usr/tmp/ufisplits
	UFI=/usr/etc/subsets/UFI
	UPDATA=/usr/etc/subsets/DoNotUpdate.dat
}



Filter()
{
	# filter out components which are known to exist outside of
	#  any subset.
	EXPFILE=/tmp/ufiexp

	HOST=`hostname`
	KHOST=`Ucase $HOST`

	# Directories which are to be ignored
	egrep -v '^\./dev/|^\..*/sys/VAX/'$KHOST'|^\..*/sys/MIPS/'$KHOST |
	egrep -v '|^\./tmp|^\./usr/etc/subsets|^\..*/var/spool/rwho' |
	egrep -v '^\..*/var/tmp' |

	# individual files which are to be ignored
	egrep -v '^\..*/core$|^\..*/vmcore|^\..*/.dummy' |
	egrep -v '^\./\.profile$|^\./bin/STTY$|^\./bin/init$' |
	egrep -v '^./ultrixboot$|^\./bin/sh$|^\./etc/init$' |
	egrep -v '^\./etc/setldlog$|^\./etc/shutdown.msg$' |
	egrep -v '^\./etc/snmpd.pid$|^\./etc/state$|^\..*/var/adm/X0msgs$' |
	egrep -v '^\..*/var/adm/elcsdlog$|^\..*/var/adm/eventlock$' |
	egrep -v '^\..*/var/adm/fverifylog$|^\..*/var/adm/install.DEV.log$' |
	egrep -v '^\..*/var/adm/install.FS.log|^\..*/var/adm/install.log$' |
	egrep -v '^\..*/var/adm/sulog|^\..*/var/adm/syserr/syserr.'$HOST'$' |

	# fuzzy matches
	egrep -v '^\..*/var/spool/mqueue/syslog|^\./.*vmunix.*'
}


Main()
{
	cd /
	INFILE=/usr/etc/subsets/MSI
	
	echo "Working.\c"

	# Place list of all files in TMP1
	find ./ -mount ! -type d ! -type s -print > $TMP1
	for MOUNT in `fsmount < $INFILE | awk '{print $3}'`
	{
		find .$MOUNT -mount ! -type d ! -type s -print >> $TMP1
	}
	echo ".\c"

	# Filter out unwanted components
	Filter < $TMP1 > $TMP2
	# sort the list
	sort -o $TMP1 $TMP2
	echo ".\c"

	# put marks in list every 5000 characters, list now in TMP2
	awk  'BEGIN {
			nchars=0
			NCARGS=5000
		}
		{
			if( (nchars += length + 1) >= NCARGS )
			{
				nchars = 0
				printf "\n"
			}
			print $0
		}' < $TMP1 > $TMP2

	# split list of all files into 10000 byte chunks
	mkdir $SPLITS 2> /dev/null
	2>&1 csplit -k -f $SPLITS/ $TMP2 '/^$/' '{1000}'  > /dev/null
	echo ".\c"

	# ils the files listed in each chunk, concatenate results in TMP1
	> $TMP1
	for SPLIT in $SPLITS/*
	{
		ils `cat $SPLIT` >> $TMP1
		echo ".\c"


	}
	# clean up the split directory
	rm -rf $SPLITS

	# Filter installed files from list of all files
	udelta $TMP1 $INFILE > $TMP2
	echo ".\c"

	# Filter files which need not be trasferred from list
	[ -f $UPDATA ] || > $UPDATA
	sort -o $UPDATA +9 -10 $UPDATA
	echo ".\c"
	udelta $TMP2 $UPDATA > $UFI 
	echo done.
}


Ucase()
{
	echo $*| dd conv=ucase 2> /dev/null
}


ARGS=$*


Constants
[ "$GENUFI_DEBUG" ] || Main $ARGS

