#!/bin/sh
# $Header: update_clients.sh,v 1.55 2002/02/01 21:03:06 fmr Stab $
#bcpyrght
#***************************************************************************
#* $VRTScprght: Copyright 1993 - 2002 VERITAS Software Corporation, All Rights Reserved $ *
#***************************************************************************
#ecpyrght
#
# update software on NetBackup clients

USAGE () {

	echo "usage: $0 [-ForceInstall -Install_Java -Install_Client_Bins] \

              [-ClientList filename | hardware_type operating_system]"
	quit 22
}

TMPDIR=${TMPDIR:-/tmp}
BP_DIR=/usr/openv/netbackup
BP_BIN=${BP_DIR}/bin
JAVA_DIR=/usr/openv/java
DRIVER_DIR=${BP_BIN}/driver
CLIENT_BIN_DIR=/usr/openv/netbackup/client
ClientList=""
Done=0

LC_MESSAGES="C"
export LC_MESSAGES

# Announce possible clients at the wrong level
#
# Input $1 = the "found" file
#	$2 = the hardware type for the message

announce_possibles () {

	Entries=`wc -l $1 | sed s/' '/''/g | cut -d '/' -f1`
	if [ $Entries -gt 4 ] ; then
		head -4 $1
		cat $1 >> $LOGFILE
		${ECHO} "  ...		There are $Entries $2 clients to check."
	else
		cat $1 | tee -a $LOGFILE
	fi

}

# Confirm an action with yes as the default
#
#	confirm prompt_string
#	Returns 0 for yes and 1 for no.

confirm () {
	Valid=1
	while [ $Valid = 1 ]
	do
		${ECHO} "$1 (y/n) [y]\c "
		read ans
		: ${ans:=y}
		case $ans in
			N*|n*)	return 1 ;;
			Y*|y*)	return 0 ;;
			*)	${ECHO} "You have entered an invalid option."
		esac
	done
}

# Get a numeric value from the user.
#
#	get_number prompt_string low_value high_value default
#
#	Entered value is returned in the VALUE variable

get_number() {

	${ECHO} "
$1
Must be in the range $2 - $3 (default: $4): \c"
	valid=0
	until [ $valid != 0 ]
	do
		read VALUE
		VALUE=${VALUE:=$4}
		expr $VALUE + 0 > /dev/null 2>/dev/null
		x=$?
		if [ $x -ne 2 -a $VALUE -ge $2 -a $VALUE -le $3 ] ; then
			valid=1
		else
			${ECHO} "Must be in the range $2 - $3, try again: \c"
		fi
	done
}

# Check for services and inetd entriespage

Check_Services () {

	Done=0
	# Read the bprd, bpjava-msvc, bpcd, and vopied entries from /etc/services.
	Services="bpcd bpjava bprd vopied"
	for service in $Services
	do
		grep $service /etc/services > /dev/null
		if [ $? != 0 ] ; then
			${ECHO} "You need an entry for $service in /etc/services" >& 2
			Done=1
		else
			grep $service /etc/services > ${TMPDIR}/${service}_service
		fi
	done

	# Read the entries from inetd.conf.
	Services="bpcd bpjava vopied"
	for service in $Services
	do
	# This check will create the tmp files is the server is using xinetd
		if [ -f /etc/xinetd.conf ] ; then
		${ECHO} "bpcd    stream  tcp     nowait.300      root    /usr/openv/netbackup/bin/bpcd bpcd" > ${TMPDIR}/bpcd_inetd.conf
		${ECHO} "bpjava-msvc     stream  tcp     nowait.300      root    /usr/openv/netbackup/bin/bpjava-msvc bpjava-msvc -transient" > ${TMPDIR}/bpjava_inetd.conf
		${ECHO} "vopied  stream  tcp     nowait.300      root    /usr/openv/bin/vopied vopied" > ${TMPDIR}/vopied_inetd.conf
		else
		grep $service ${INETD_CONF} > /dev/null
		if [ $? != 0 ] ; then
			${ECHO} "You need an entry for $service in ${INETD_CONF}" >& 2
			Done=1
		else
			/bin/rm -f ${TMPDIR}/${service}_inetd.conf
			grep $service ${INETD_CONF} > ${TMPDIR}/${service}_inetd.conf
		fi
		fi
	done
}

# Update a client in a given class
#

client_update() {

	ret=0
	Output=${TMPDIR}/client_update.$$.${JobIndex}
	exec > $Output 2>&1

	CLIENT=${3}

	DoingServer=0
	if [ "${CLIENT}" = "${MASTER}" -o "${CLIENT}" = "${MASTER}.${DOMAIN}" ] ; then
		# Don't try to update the server with files from itself.
		if [ $Install = TRUE ] ; then
			return
		fi
		DoingServer=1
	fi

	if [ $Install_Client_Bins = 1 ] ; then
		if [ ! -f ${CLIENT_BIN_DIR}/${1}/${2}/version ] ; then
			${ECHO} "
Cannot update client $CLIENT
	Invalid hardware type \"$1\" and/or operating system \"$2\"
	or binaries are not installed on the server.
"
			ret=2
		else

			${ECHO} "	$CLIENT $1/$2 ..."

			/bin/rm -f ${TMPDIR}/${CLIENT}
			${ECHO} "CLIENT_NAME = ${CLIENT}" > ${TMPDIR}/${CLIENT}

			${BP_BIN}/bpinst -NB ${ForceInstall} $EL -inst_dir ${CLIENT_BIN_DIR}/${1}/${2}/ -host ${CLIENT} -d </dev/null 2>>${Output}.stderr
			Status=$?
			if [ $Status != 0 ] ; then
				ret=2
			else
				Stat=`tail -2 ${Output}.stderr | grep "Version files match"`
				if [ $? = 0 ] ; then
					# if Version files match don't do any upgrade.
					ret=1
				fi
			fi

			cat ${Output}.stderr
			rm -f ${Output}.stderr ${TMPDIR}/${CLIENT}
		fi
	fi

	if [ $Install_Java = 1 -a $ret = 0 -a ${DoingServer} = 0 ] ; then
		# pick the correct JRE for Java client $1/$2
		# and set up USE_APP_INITIALIZER

		JRE_FILE=NONE
		JAVA_FILE=NB-Java.tar.Z
		USE_APP_INITIALIZER=""
		HP_Green=""
		case $1 in
		Linux)
			Tar_x_Options=xvpf
			JRE_FILE=Linux_JRE.tar.Z;;
		Solaris)
			Tar_x_Options=xvpf
			if [ `expr "$2" : '.*_x86'` != 0 ] ; then
				if [ -f /usr/openv/java/Solaris_x86_JRE.tar.Z ] ; then
					JRE_FILE=Solaris_x86_JRE.tar.Z
				elif [ -f /usr/openv/java/Solaris_X86_JRE_117B.tar.Z ] ; then
					JRE_FILE=Solaris_X86_JRE_117B.tar.Z
				fi
			elif [ $2 = "Solaris2.6" -o $2 = "Solaris7" -o $2 = "Solaris8" -o $2 = "Solaris9" ] ; then
				if [ -f /usr/openv/java/Solaris_Sparc_JRE.tar.Z ] ; then
					JRE_FILE=Solaris_Sparc_JRE.tar.Z
				elif [ -f /usr/openv/java/Solaris_JRE_117B.tar.Z ] ; then
					JRE_FILE=Solaris_JRE_117B.tar.Z
				fi
			fi ;;
		HP9000*)
			if [ $2 = "HP-UX11.00" ] ; then
				Tar_x_Options=xof
				USE_APP_INITIALIZER="-Dvrts.nbu.admin.USE_APP_INITIALIZER=false"
				HP_Green="-green"
				if [ -f /usr/openv/java/HPUX_JRE.tar.Z ] ; then
					JRE_FILE=HPUX_JRE.tar.Z
				elif [ -f /usr/openv/java/hp110_jre116.tar.Z ] ; then
					JRE_FILE=hp110_jre116.tar.Z
				fi
			elif [ $2 = "HP-UX10.20" ] ; then
				if [ -f /usr/openv/java/hp1020_jre116.tar.Z ] ; then
					JRE_FILE=hp1020_jre116.tar.Z
				fi
			fi ;;
		esac

		if [ $JRE_FILE != NONE ] ; then
			${ECHO} "	$CLIENT $1/$2 Java Update ..."

			if [ ! -d ${TMPDIR}/JAVA/$$.${JobIndex} ] ; then
				mkdir -p ${TMPDIR}/JAVA/$$.${JobIndex}
			fi

			${BP_BIN}/bpinst -MISC -Z ${JAVA_FILE} -src /usr/openv -dest /usr/openv -host ${CLIENT} -d 2>>${Output}
			if [ $? != 0 ] ; then
				ret=2
			fi

			${BP_BIN}/bpinst -MISC -Z ${JRE_FILE} -src /usr/openv/java -dest /usr/openv/java -host ${CLIENT} -d 2>>${Output}
			if [ $? != 0 ] ; then
				ret=2
			fi

			# modify the extract script and create a client specific one
			cat ${TMPDIR}/JAVA/extract.sh | sed s@X_JRE_FILE_X@${JRE_FILE}@ | sed s@X_TARXOPTION_X@${Tar_x_Options}@ >${TMPDIR}/JAVA/$$.${JobIndex}/extract.sh
			# If going to Linux make sure it is a new enough kernel
			if [ $1 = Linux ] ; then
				${ECHO} "
HardWare=\`uname -m | cut -c3-4\`
Version=\`uname -r | cut -f 1 -d- | awk -F. '{print (\$1*1000 + \$2*100 + \$3)}'\`
if [ \$HardWare = 86 -a \$Version -ge 2214 ] ; then
	: # All is well on an intel with a new enough kernel
else
	rm -rf /usr/openv/java
fi" >> ${TMPDIR}/JAVA/$$.${JobIndex}/extract.sh
			fi

			${BP_BIN}/bpinst -MISC -X -Z extract.sh -src ${TMPDIR}/JAVA/$$.${JobIndex} -dest /usr/openv/netbackup/bin -host ${CLIENT} -d 2>>${Output}
			if [ $? != 0 ] ; then
				ret=2
			fi

			# Create a client specific config file
			Cli_nbj_conf=${TMPDIR}/JAVA/$$.${JobIndex}/nbj.conf
			if [ -f ${Cli_nbj_conf} ] ; then
				rm -f ${Cli_nbj_conf}
			fi
			cp ${TMPDIR}/JAVA/nbj.conf $Cli_nbj_conf
			${ECHO} "USE_APP_INITIALIZER=${USE_APP_INITIALIZER}" >> $Cli_nbj_conf
			${ECHO} "HP_GREEN_THREADS=${HP_Green}" >> $Cli_nbj_conf
			${ECHO} "CLIENT_HOST=$CLIENT" >> $Cli_nbj_conf

			${BP_BIN}/bpinst -MISC -Z nbj.conf -src ${TMPDIR}/JAVA/$$.${JobIndex} -dest /usr/openv/java -host ${CLIENT} -d 2>>${Output}
			if [ $? != 0 ] ; then
				ret=2
			fi
			rm -rf ${TMPDIR}/JAVA/$$.${JobIndex}
		fi
	fi

	cat ${Output} >> ${LOGFILE}
	${ECHO} ${ret} > ${CLIENTS}.${JobIndex}
}

# Leave through here to clean up all files

quit () {

	/bin/rm -f ${TMPDIR}/client_update.$$.*
	if [ $1 = 0 -o $1 = 6 ] ; then
		rm -f ${CLIENTS}*
		${ECHO} "
The update trace can be found in ${LOGFILE}."
	elif [ $1 = 1 ] ; then	# the server is not setup properly
		rm -f ${CLIENTS}* ${LOGFILE}
	elif [ $1 = 2 ] ; then	# there are suspect clients
		${ECHO} "
The complete list of UNIX clients can be found in ${CLIENTS}."
		rm -f ${CLIENTS}.*
	elif [ $1 = 3 ] ; then	# No clients to upgrade
		rm -f ${CLIENTS}* ${LOGFILE}
	elif [ $1 = 4 ] ; then	# there are suspect clients
		${ECHO} "
The complete list of UNIX clients can be found in ${CLIENTS}."
		rm -f ${CLIENTS}.* ${LOGFILE}
	else
		/bin/rm -f ${CLIENTS}*
	fi

	# Only clean up these files if there are no other update_clients running

	OthersRunning=`$PS`
	OthersRunning=`echo "$OthersRunning" | grep update_clients | wc -l`
	if [ $OthersRunning = ${CMD_Count} ] ; then
		rm -f ${TMPDIR}/bpcd_inetd.conf ${TMPDIR}/bp?d_service ${TMPDIR}/etc_services ${TMPDIR}/bp_servers ${TMPDIR}/vopied_inetd.conf ${TMPDIR}/vopied_service
		rm -f ${TMPDIR}/bpjava_inetd.conf ${TMPDIR}/bpjava_service
		rm -rf /tmp/Flash /tmp/JAVA
	fi
	exit $1
}

######################
## MAIN Starts Here ##
######################

Install=FALSE
ForceInstall=""
Install_Flash=0
Install_Java=0
Install_Client_Bins=0

ClientList=""
PATH=/bin:$PATH
DATE_TIME=`/bin/date +%m-%d-%H%M`.$$
CLIENTS=${TMPDIR}/NB_CLIENT_LIST.${DATE_TIME}

# Based on the HARDWARE type, determine the location of the
# inetd.conf file and the tr command. Prepend /usr/5bin to
# PATH on Suns to get System V behaviour from echo.

if [ -f /usr/openv/netbackup/version ] ; then
	HARDWARE=`head -1 /usr/openv/netbackup/version | cut -f2 -d" "`
else
	HARDWARE=NONE
fi

INETD_CONF=/etc/inetd.conf; export INETD_CONF
TR=/bin/tr
PS="/bin/ps -ea"
HASYP=TRUE
ECHO=echo
CMD_Count=1
case "$HARDWARE" in
	ALPHA)
		;;
	HP*)
		TR=/usr/bin/tr ;;
	LINUX*)
		ECHO="echo -e"
		TR=/usr/bin/tr
		CMD_Count=2
		;;
	NCR)
		if [ -f /usr/etc/inetd.conf ] ; then
			INETD_CONF=/usr/etc/inetd.conf
		elif [ -f /etc/inet/inetd.conf ] ; then
			INETD_CONF=/etc/inet/inetd.conf
		fi
		TR=/usr/bin/tr
		PS="/bin/ps -ea -o pid,comm"
		;;
	PYRAMID)
		PS="/bin/ps -ea -o pid,comm"
		;;
	RS6000)
		PS="/bin/ps -ef -o pid,args";;
	SEQUENT*)
		PS="/bin/ps -ea -o pid,comm"
		TR=/usr/bin/tr
		HASYP=FALSE
		;;
	SGI)
		PS="/bin/ps -ea -o pid,args"
		if [ -f /usr/etc/inetd.conf ] ; then
			INETD_CONF=/usr/etc/inetd.conf
		fi ;;
	SOLARIS)
		PS="/bin/ps -ea -o pid,fname=XXXXXXXXXXXXXX" ;;
	SUN4)
		PS="/bin/ps -cax"
		PATH=/usr/5bin:$PATH ;;
	*)
		${ECHO} "
/usr/openv/netbackup/version not found or corrupted.
Unknown hardware type: \"$HARDWARE\"
"
		exit 1 ;;
esac

# Get Install flags
got_flag=`expr "$1" : '.*Instal'`
while [ $got_flag != 0 ]
do
	if [ $1 = "Install" ] ; then
		Install=TRUE
	elif [ $1 = "-ForceInstall" ] ; then
		ForceInstall='-force_install'
	elif [ $1 = "-Install_Flash" ] ; then
		Install_Flash=1
		USAGE
	elif [ $1 = "-Install_Java" ] ; then
		Install_Java=1
	elif [ $1 = "-Install_Client_Bins" ] ; then
		Install_Client_Bins=1
	fi
	shift
	if [ $# != 0 ] ; then
		got_flag=`expr "$1" : '.*Instal'`
	else
		got_flag=0
	fi
done

if [ $Install_Flash = 0 -a $Install_Java = 0 ] ; then
	Install_Client_Bins=1
fi

if [ $Install_Java = 1 ] ; then

	Message="
NetBackup Java is only installed and distributed to HP 11.00 and Solaris
NetBackup clients from an HP 11.00 or Solaris NetBackup master server.

You must install client software locally to install NetBackup Java on HP 11.00
and Solaris NetBackup clients."

	case "$HARDWARE" in
		LINUX | SOLARIS)
			;;
		HP*)
			OS=`uname -r | cut -f2 -d"."`
			if [ "${OS}" = "10" ] ; then
				${ECHO} "${Message}" >& 2
				Install_Java=0
			fi
			;;
		*)
			${ECHO} "${Message}" >& 2
			Install_Java=0
			;;
	esac
fi

# Verify that the right number of arguments were given
if [ $# = 0 ] ; then
	hardware="ALL"
	os_name="ALL"
elif [ $# = 2 ] ; then
	if [ $1 = "-ClientList" ] ; then
		ClientList=$2
		hardware="ALL"
	else
		hardware=$1
		os_name=$2
	fi
else
	USAGE
fi

if [ $Install_Java = 1 ] ; then
	if [ -d /usr/openv/java ] ; then
		if [ ! -d /tmp/JAVA ] ; then
			mkdir -p /tmp/JAVA
		fi
		${ECHO} "
Installing NetBackup-Java GUI applications to NetBackup-Java supported clients."

		# create the extract script
		cat <<eof >${TMPDIR}/JAVA/extract.sh
#!/bin/sh
cd /usr/openv
if [ -f /usr/openv/java/auth.conf ] ; then
	mv /usr/openv/java/auth.conf /usr/openv/java/auth.conf.bak
fi
# Clean out the vrts directory hierarchy
rm -rf /usr/openv/java/vrts
zcat NB-Java.tar.Z | /bin/tar X_TARXOPTION_X -
if [ ! -d /usr/openv/java/logs ] ; then
	mkdir /usr/openv/java/logs
	chmod 777 /usr/openv/java/logs
fi
rm -f /usr/openv/NB-Java.tar.Z
rm -f /usr/openv/java/auth.conf
if [ -f /usr/openv/java/auth.conf.bak ] ; then
	mv /usr/openv/java/auth.conf.bak /usr/openv/java/auth.conf
fi
cd /usr/openv/java
# Clean out the jre directory hierarchy
rm -rf jre
zcat X_JRE_FILE_X | /bin/tar X_TARXOPTION_X -
rm -f /usr/openv/java/X_JRE_FILE_X
rm -f ${BP_BIN}/jnbSA ${BP_BIN}/jbpSA
if [ \`uname -m\` != "i86pc" ] ; then
	ln -s ${JAVA_DIR}/jnbSA ${BP_BIN}/jnbSA
fi
ln -s ${JAVA_DIR}/jbpSA ${BP_BIN}/jbpSA

# Copy in our font.properties file.
mv ${JAVA_DIR}/jre/lib/font.properties ${JAVA_DIR}/jre/lib/font.properties.bak
mv ${JAVA_DIR}/font.properties ${JAVA_DIR}/jre/lib/
## Make the java/awt dir for class files to work around the finalizer hang ..
mkdir -p -m 755 ${JAVA_DIR}/java/awt
mv ${JAVA_DIR}/Finalize2.class ${JAVA_DIR}/java/awt/
mv ${JAVA_DIR}/Graphics*.class ${JAVA_DIR}/java/awt/
mv ${JAVA_DIR}/SecondaryFinalizer.class ${JAVA_DIR}/java/awt/
mv ${JAVA_DIR}/Component*.class ${JAVA_DIR}/java/awt/

# clean up old binaries from /usr/openv/java
rm -f GnuRe.jar jcchart400J.jar linux_blackdown_jre117B.tar.Z
rm -f hp110_jre130_beta.tar.Z j2re-1_3_0-beta_refresh-linux.tar.Z
rm -f j2re1_3_0beta_refresh-solsparc.bin j2re1_3_0rc-solsparc.bin
rm -f j2re1_3_0rc-solx86.bin jre130_aix.tar.Z Solaris_X86_JRE_117B.tar.Z
rm -f Solaris_JRE_117B.tar.Z hp1020_jre116.tar.Z hp110_jre116.tar.Z
rm -f X11FMFix.jar
eof

		# copy and modify nbj.conf for $CLIENT
		if [ -f /usr/openv/java/nbj.conf ] ; then
			grep -v CLIENT_HOST /usr/openv/java/nbj.conf | grep -v USE_APP_INITIALIZER > /tmp/JAVA.nbj.conf.$$
			if [ ! -f /tmp/JAVA/nbj.conf ] ; then
				mv /tmp/JAVA.nbj.conf.$$ /tmp/JAVA/nbj.conf
			else
				diff /tmp/JAVA.nbj.conf.$$ /tmp/JAVA/nbj.conf 2>/dev/null
				if [ $? != 0 ] ; then
					${ECHO} "
Modified /usr/openv/java/nbj.conf or old /tmp/JAVA/nbj.conf found.
Not doing JAVA client updates."
					Install_Java=0
				fi
			fi
		else
			${ECHO} "
Server is missing /usr/openv/java/nbj.conf.
You must create $CLIENT /usr/openv/java/nbj.conf manually"
		fi
	fi
fi

# Verify that if hardware/os were specified, they're valid
if [ ! "$hardware" = "ALL" -a ! -d "$CLIENT_BIN_DIR/$hardware/$os_name" ] ; then
	${ECHO} "
Invalid hardware type \"$hardware\" and/or operating system \"$os_name\"
"
	USAGE
fi

TAB=`/bin/echo ' ' | $TR ' ' '\011'`
SPACE=' '

# Determine the system's hostname.  Use hostname if available and strip
# away any domain information.
if type hostname | grep 'not found' >/dev/null
then
	MASTER=`uname -n | sed 's/\..*$//'`
else
	MASTER=`hostname | sed 's/\..*$//'`
fi

# Get the domainname into domain without a leading '.' (if there is one).
if [ $HASYP = TRUE ] ; then
	DOMAIN=`domainname | sed 's/^\.//'`
fi
if [ X"${DOMAIN}" = X ] ; then
	# No domain. Set it to something that will not be matched.
	DOMAIN=ZZZZZZZZ
fi

if [ $Install_Client_Bins = 1 ] ; then
	Check_Services
	if [ $Done = 1 ] ; then
		quit 1
	fi
fi

# Create a log file for output of update_client
LOGFILE=${TMPDIR}/update_clients.${DATE_TIME}
touch ${LOGFILE}

if [ "${ClientList}" = "" ] ; then
	/usr/openv/netbackup/bin/admincmd/bpclclients -allunique -noheader >${CLIENTS} 2>/dev/null
	if [ ! "$hardware" = "ALL" ] ; then
		grep $hardware ${CLIENTS} | grep $os_name > ${CLIENTS}.tmp
		mv ${CLIENTS}.tmp ${CLIENTS}
	fi

	ALPHA_FOUND=${TMPDIR}/ALPHA_FOUND.${DATE_TIME}
	AUSPEX_FOUND=${TMPDIR}/AUSPEX_FOUND.${DATE_TIME}
	HP_FOUND=${TMPDIR}/HP_FOUND.${DATE_TIME}
	LINUX_FOUND=${TMPDIR}/LINUX_FOUND.${DATE_TIME}
	RS6000_FOUND=${TMPDIR}/RS6000_FOUND.${DATE_TIME}
	SEQUENT_FOUND=${TMPDIR}/SEQUENT_FOUND.${DATE_TIME}
	SGI_FOUND=${TMPDIR}/SGI_FOUND.${DATE_TIME}
	SOLARIS_FOUND=${TMPDIR}/SOLARIS_FOUND.${DATE_TIME}
	NON_UNIX_FOUND=${TMPDIR}/non-UNIX_clients.${DATE_TIME}
	touch ${CLIENTS}.tmp
	/bin/cat ${CLIENTS} |
	while read class_hw class_os client
	do
		if [ "${client}" = "${MASTER}" -o "${client}" = "${MASTER}.${DOMAIN}" ] ; then
			if [ $Install = TRUE ] ; then
				continue
			fi
		fi
		if [ "$class_hw" = "Solaris" -o "$class_hw" = "Sun4" ] ; then
			if [ "$class_os" != "SunOS4" ] ; then
				${ECHO} "  $class_os   \t$client" >> ${SOLARIS_FOUND}
			fi
		elif [ "$class_hw" = "ALPHA" ] ; then
			if [ "$class_os" = "WindowsNT" ] ; then
				${ECHO} "  $class_os  \t$client" >> ${NON_UNIX_FOUND}
				continue
			fi
			${ECHO} "  $class_os   \t$client" >> ${ALPHA_FOUND}
		elif [ "$class_hw" = "Sequent" ] ; then
			${ECHO} "  $class_os   \t$client" >> ${SEQUENT_FOUND}
		elif [ "$class_hw" = "SGI" -o "$class_hw" = "C910_920" ] ; then
			${ECHO} "  $class_os  \t$client" >> ${SGI_FOUND}
		elif [ "$class_hw" = "RS6000" ] ; then
			${ECHO} "  $class_os   \t$client" >> ${RS6000_FOUND}
		elif [ "$class_hw" = "Linux" ] ; then
			${ECHO} "  $class_os   \t$client" >> ${LINUX_FOUND}
		elif [ "$class_hw" = "HP9000-700" -o "$class_hw" = "HP9000-800" ] ; then
			${ECHO} "  $class_os   \t$client" >> ${HP_FOUND}
		elif [ "$class_hw" = "Auspex" ] ; then
			${ECHO} "  $class_os     $client" >> ${AUSPEX_FOUND}
		elif [ "$class_hw" = "MACINTOSH" -a "$class_os" = "MacOS" ] ; then
			${ECHO} "  $class_os  \t$client" >> ${NON_UNIX_FOUND}
			continue
		elif [ "$class_hw" = "PC" -o "$class_hw" = "Novell" -o "$class_hw" = "NDMP" ] ; then
			${ECHO} "  $class_os  \t$client" >> ${NON_UNIX_FOUND}
			continue
		fi
		${ECHO} $class_hw $class_os $client >> ${CLIENTS}.tmp
	done

	mv ${CLIENTS}.tmp ${CLIENTS}
	if [ -s ${NON_UNIX_FOUND} ] ; then
		cat ${CLIENTS} | grep -v "^PC" | grep -v "^Novell" | grep -v "^NDMP" > ${CLIENTS}.tmp
		mv ${CLIENTS}.tmp ${CLIENTS}
		${ECHO} "
The following non-UNIX clients with the OS type listed
cannot be installed or upgraded from the server.
  OS Type       Client name"
		Entries=`wc -l $NON_UNIX_FOUND | sed s/' '/''/g | cut -d '/' -f1`
		if [ $Entries -gt 9 ] ; then
			head -9 $NON_UNIX_FOUND
			${ECHO} "  ...
There are $Entries clients in the list."
		else
			cat $NON_UNIX_FOUND
		fi
		${ECHO} "The complete list can be found in $NON_UNIX_FOUND ."
	fi

	if [ -f ${TMPDIR}/*_FOUND.${DATE_TIME} ] ; then
		${ECHO} "
The following clients with the OS type listed may need to be
changed in the NetBackup class configuration so the appropriate
NetBackup software for the OS type can be installed.
  OS Type       Client name"
		for File in ${TMPDIR}/*_FOUND.${DATE_TIME}
		do
			HW_Type=`head -1 ${File} | awk '{print $1}'`
			announce_possibles ${File} ${HW_Type}
		done
		/bin/rm -f ${TMPDIR}/*_FOUND.${DATE_TIME}
		sort $LOGFILE > $TMPDIR/update_clients.sort.$$
		mv $TMPDIR/update_clients.sort.$$ $LOGFILE
		${ECHO} "
The full list of suspect clients can be found in $LOGFILE."

		if confirm "\nDo you want to continue?"
		then
			${ECHO} "Continuing with the client update.  (Deleting $LOGFILE)"
			rm -f $LOGFILE
		else
			${ECHO} "
Aborting the client update.
"
			quit 2
		fi
	fi
else
	cp ${ClientList} ${CLIENTS}
fi

if [ ! -s ${CLIENTS} ] ; then
	${ECHO} "
There are no clients to upgrade."
	quit 3
else
	sort ${CLIENTS} > ${CLIENTS}.sorted
	mv ${CLIENTS}.sorted ${CLIENTS}
	NUM_CL=`wc -l ${CLIENTS} | sed s/' '/''/g | cut -d '/' -f1`
	if [ $NUM_CL -gt 15 ] ; then
		Default=15
	else
		Default=$NUM_CL
	fi
	if [ $NUM_CL -gt 30 ] ; then
		Max_Num=30
	else
		Max_Num=$NUM_CL
	fi

	${ECHO} "
There are $NUM_CL clients to upgrade."
	if [ $Install_Client_Bins = 1 ] ; then
		${ECHO} "
Do you want the bp.conf file on the clients updated"
		if confirm "to list this server as the master server?"
		then
			EL=""

			# Build up a list of valid servers on ${TMPDIR}/bp_servers_hostname.
			# Look for 0 or more spaces and tabs followed by SERVER.
			SRVR=`egrep "^[${SPACE}${TAB}]*SERVER" ${BP_DIR}/bp.conf`
			if [ "${SRVR}" = "" ] ; then
				${ECHO} "Missing SERVER in /usr/openv/netbackup/bp.conf"
				Done=1
			else
				egrep "^[${SPACE}${TAB}]*SERVER" ${BP_DIR}/bp.conf > ${TMPDIR}/bp_servers
			fi
		else
			EL="-L"
			touch ${TMPDIR}/bp_servers
		fi
	fi
	if [ $Done = 1 ] ; then
		quit 1
	fi
	if [ $NUM_CL != 1 ] ; then
		get_number "Enter the number of simultaneous updates you wish to take place" 1 $Max_Num $Default
	else
		VALUE=1
	fi
	MinTime=`expr \( $NUM_CL + 1 \) \/ \( ${VALUE} \* 2 \)`
	MaxTime=`expr \( \( 2 \* $NUM_CL \) + 1 \) \/ ${VALUE}`
	if [ $MinTime -lt 1 ] ; then
		MinTime=1
	fi
	if [ $MaxTime -le $MinTime ] ; then
		MaxTime=`expr $MinTime + 1`
	fi
	${ECHO} "
The upgrade will likely take $MinTime to $MaxTime minutes."
	if confirm "Do you want to upgrade clients now?"
	then
		${ECHO} "Please be patient."
	else
		${ECHO} "
You will need to upgrade clients later with install_client_files
or update_clients -ClientList filename
"
		quit 4
	fi
fi

${ECHO}
MostJobs=$VALUE
index=0
while [ $index -lt $MostJobs ]
do
	${ECHO} "Available" > ${CLIENTS}.${index}
	index=`expr $index + 1`
done

/bin/cat ${CLIENTS} |
while read class_hw class_os client
do
	index=0
	while [ $index -lt $MostJobs ]
	do
		Available=`cat ${CLIENTS}.${index}`
		if [ "$Available" = "Available" ] ; then
			${ECHO} "In Use" > ${CLIENTS}.${index}
			JobIndex=$index
			break
		fi
		index=`expr $index + 1`
		if [ $index -ge $MostJobs ] ; then
			sleep 1
			index=0
		fi
	done

	if [ "$hardware" = "ALL" -o \
	  \( "$hardware" = "$class_hw" -a "$os_name" = "$class_os" \) ] ; then
		(
		${ECHO} "Updating client ${client} -- ${class_hw} hardware running ${class_os}"
		client_update ${class_hw} ${class_os} ${client} ${JobIndex} & \
		PiD=$!
		wait $PiD
		Ustat=`cat ${CLIENTS}.${JobIndex}`
		if [ $Ustat = 1 ] ; then
			${ECHO} "	${client}: Version files match - no update needed"
		elif [ $Ustat = 2 ] ; then
			${ECHO} "	${client}: update failed, see ${LOGFILE}"
		else
			${ECHO} "	${client}: update complete"
		fi
		${ECHO} "Available" > ${CLIENTS}.${JobIndex}
		)&
	fi
done

# Wait for all jobs to be finished

index=0
while [ $index -lt $MostJobs ]
do
	if [ -f ${CLIENTS}.${index} ] ; then
		Available=`cat ${CLIENTS}.${index}`
		if [ "$Available" = "Available" ] ; then
			rm -f ${CLIENTS}.${index}
		else
			sleep 1
			continue  # wait for this one to be gone.
		fi
	fi
	index=`expr $index + 1`
done

# The xargs echo converts the wc -l output from "     x" to "x"
NumMatch=`grep "^Version files match" ${LOGFILE} | wc -l | xargs echo`
if [ $NumMatch != 0 ] ; then
	${ECHO} "
$NumMatch of the clients had up to date software according to the version file.
To force the install of the client software on these clients you need to do:

$0 -ForceInstall [-ClientList filename | hardware_type operating_system]"
	quit 6
fi

# Clean up the /tmp files.
quit 0

