#!/bin/sh 

## Rcs_ID="$RCSfile: gen_excludes,v $"
## Rcs_ID="$Revision: 1.2 $ $Date: 2000/05/26 23:16:05 $"    

# Tue May 23 17:46:59 PDT 2000, Hal Skelly, Collective Technologies

PATH=/bin:/usr/bin:/usr/sbin:/sbin:/usr/openv/volmgr/bin:/usr/openv/netbackup/bin:/usr/openv/netbackup/bin/admincmd:/usr/openv/netbackup/bin/goodies:/usr/openv/volmgr/goodies:/usr/symmapps/bin:/usr/local/bin:/usr/openv/local/bin:/usr/EMCpower/bin:/etc

export PATH

X=$$

if [ $# -lt 0 ] ; then
        Usage
        exit 1
fi

#get list of active unix hosts
gethosts() {
        cd /usr/openv/netbackup/db/class
        for class in *
        do
        
                ACTIVE=`grep 'ACTIVE[   ][      ]*0' $class/info`
                UNIX=`grep 'CLIENT_TYPE[         ][      ]*0' $class/info`
                
                if [ -n "$ACTIVE" -a -n "$UNIX" ] ; then
                        awk '{print $1}' $class/clients|grep -v "VMD5_DIGEST="
                fi
        
        done >/tmp/$X.unixhosts.txt
        HOSTS=`sort -u /tmp/$X.unixhosts.txt`
	rm /tmp/$X.unixhosts.txt
}


SBASE=/usr/openv/local/etc/exclude_lists
DBASE=/usr/openv/netbackup

# set source  This is either the specified file or cmdline args. (TBD)
Xfiles=$SBASE/exclude_list.skel

if [ ! -f $Xfiles ]; then
	echo "exclude list file, $Xfiles, does not exist"
	exit 1
fi
# this version assumes that there will only be adds from the client
# exclude list to combine with the skeleton, Xfiles.

gethosts
for client in  $HOSTS
	do
	echo "Updating exclude lists on $client"
	bpgp to $client $Xfiles $DBASE/exclude_list
	if [ -f $SBASE/${client}* ] ; then
		for file in  $SBASE/${client}*
		do
			suffix=`echo $file | sed -e "s/.*\/$client//" `
			cat $file $Xfiles | sort -u > $Xfiles.$X
			echo "	Found special exclude list: `basename $file`"
			bpgp to $client $Xfiles.$X $DBASE/exclude_list$suffix
			rm $Xfiles.$X
		done
	fi
done

description() {
	echo "This program will modify and distribute an exclude file based"
	echo "on a skeleton file, /usr/openv/local/etc/exclude_list and the"
	echo "equivalent set of files on the destination host.  Those files"
	echo "are of the pattern: $client.del.suffix and $client.add.suffix "
	echo "where suffix is in the set={null  "
	echo " .[A-z0-9]* "
	echo " .[A-z0-9]*.[A-z0-9]*}"
}

Usage () { 
	echo " $0 [list of files] "
}
