#!/bin/sh
# $Header: install_client.sh,v 1.31 2000/01/27 18:50:44 raa Stab $
#bcpyrght
#***************************************************************************
#* Copyright 1993 - 1999 VERITAS Software Corporation, All Rights Reserved *
#***************************************************************************
#ecpyrght

MACHINE=`dirname $0`
class_os=`basename $MACHINE`
MACHINE=`dirname $MACHINE`
DESTMACH=`basename $MACHINE`

case "${DESTMACH}" in
HP*)	DSO_SUFFIX=sl ;;
*)	DSO_SUFFIX=so ;;
esac

OPENV_DIR=/usr/openv
OPENV_BIN=${OPENV_DIR}/bin
OPENV_LIB=${OPENV_DIR}/lib
OPENV_VAR=${OPENV_DIR}/var
OPENV_AUTH=${OPENV_VAR}/auth
BP_DIR=/usr/openv/netbackup
BP_BIN=${BP_DIR}/bin
BP_HELP=${BP_DIR}/help
BP_HELP_XBP=${BP_DIR}/help/xbp
BP_HELP_BP=${BP_DIR}/help/bp
BP_CMD=${BP_BIN}/bp
XBP_CMD=${BP_BIN}/xbp
BPCD_CMD=${BP_BIN}/bpcd
BPBKAR_CMD=${BP_BIN}/bpbkar
BPJAVAMS_CMD=${BP_BIN}/bpjava-msvc
BPJAVAUS_CMD=${BP_BIN}/bpjava-usvc
BPBACKUP_CMD=${BP_BIN}/bpbackup
BPRESTORE_CMD=${BP_BIN}/bprestore
BPLIST_CMD=${BP_BIN}/bplist
BPCLIMAGELIST_CMD=${BP_BIN}/bpclimagelist
BPCLNTCMD_CMD=${BP_BIN}/bpclntcmd
BPMOUNT_CMD=${BP_BIN}/bpmount
TAR_CMD=${BP_BIN}/tar
RBAK_CMD=${BP_BIN}/rbak
BPHDB_CMD=${BP_BIN}/bphdb
VERSION=${BP_BIN}/version
BP_CONFIG=${BP_DIR}/bp.conf
SOURCE_DIR=`dirname ${0}`
VOPIED_CMD=${OPENV_BIN}/vopied
VAUTH_UTIL_CMD=${OPENV_BIN}/vauth_util
VOPIE_UTIL_CMD=${OPENV_BIN}/vopie_util
VNOAUTH_LIB=${OPENV_LIB}/libvnoauth.${DSO_SUFFIX}
VOPIE_LIB=${OPENV_LIB}/libvopie.${DSO_SUFFIX}
METHODS_TXT=${OPENV_AUTH}/methods.txt
METHODS_ALLOW_TXT=${OPENV_AUTH}/template.methods_allow.txt
METHODS_DENY_TXT=${OPENV_AUTH}/template.methods_deny.txt
NAMES_ALLOW_TXT=${OPENV_AUTH}/template.names_allow.txt
NAMES_DENY_TXT=${OPENV_AUTH}/template.names_deny.txt
MERGE_AUTH_TEMPLATES_CMD=${BP_BIN}/merge_auth_templates

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

# 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.

INETD_CONF=/etc/inetd.conf; export INETD_CONF
TR=/bin/tr

case "$HARDWARE" in
	RS6000 | SOLARIS | ALPHA | PYRAMID)
		;;
	SGI)
		if [ -f /usr/etc/inetd.conf ] ; then
			INETD_CONF=/usr/etc/inetd.conf
		fi
		;;
	NCR)
		if [ -f /etc/inet/inetd.conf ] ; then
			INETD_CONF=/etc/inet/inetd.conf
		else
			INETD_CONF=/usr/etc/inetd.conf
		fi
		TR=/usr/bin/tr
		;;
	SUN4)
		PATH=/usr/5bin:$PATH
		;;
	HP* | Linux | SCO | FreeBSD)
		TR=/usr/bin/tr
		;;
	MACINTOSH)
		;;
	SEQUENT*)
		TR=/usr/bin/tr
		;;
 	*) echo "Unknown hardware type: $HARDWARE"
		exit 1
		;;
esac

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

# check if a remote file exists.  return 0 if exists

remote_file_exists () {

	/bin/rm -rf /tmp/remote_file_exists
	/bin/echo "if [ -s $2 ]; then /bin/echo yes; else /bin/echo no; fi" >>/tmp/remote_file_exists

	$RCP /tmp/remote_file_exists ${CLIENT}:/tmp/remot_file_exi
	answer=`$RSH $1 'sh /tmp/remot_file_exi' </dev/null`

	/bin/rm -rf /tmp/remote_file_exists
	$RSH $1 /bin/rm -f /tmp/remot_file_exi

        if [ "$answer" = "yes" ] ; then
                return 0
        else
                return 1
        fi
}

# do_netinfo_service - add a service entry for Mac OS X or Mac OS X Server
#
# These OSes use the NetInfo utilities to administrate services rather than
# the /etc/services file.
#
# do_netinfo_service <line>
#
#	<line>		line from services file.

do_netinfo_service () {
	service_line="${1}"
	service_name=`echo "${service_line}" | awk '{print $1}'`
	service_port=`echo "${service_line}" | awk '{print $2}' | \
	    awk -F/ '{print $1}'`
	current_protocol=`$RSH ${CLIENT} niutil -readprop . \
	    /services/"${service_name}" protocol 2> /dev/null < /dev/null`
	current_port=`$RSH ${CLIENT} niutil -readprop . \
	    /services/"${service_name}" port 2> /dev/null < /dev/null`
	if [ \( "${current_protocol}" != 'tcp' \) -o \
	     \( "${current_port}" = '' \) ] ; then
		$RSH ${CLIENT} niutil -create . /services/"${service_name}" \
		    > /dev/null 2>&1 < /dev/null
		$RSH ${CLIENT} niutil -createprop . \
		    /services/"${service_name}" protocol tcp \
		    > /dev/null 2>&1 < /dev/null
		$RSH ${CLIENT} niutil -createprop . \
		    /services/"${service_name}" port "${service_port}" \
		    > /dev/null 2>&1 < /dev/null
		current_protocol=`$RSH ${CLIENT} niutil -readprop . \
		    /services/"${service_name}" protocol 2> /dev/null \
		    < /dev/null`
		current_port=`$RSH ${CLIENT} niutil -readprop . \
		    /services/"${service_name}" port 2> /dev/null < /dev/null`
	fi
	if [ \( "${current_protocol}" != 'tcp' \) -o \
	     \( "${current_port}" = '' \) ] ; then
		return 1
	fi
	return 0
}

EL=""
if [ "$#" = 1 ] ; then
	CLIENT=$1
elif [ "$#" = 2 -a $1 = "-L" ] ; then
	EL="-L"
	CLIENT=$2
else
	/bin/echo "usage: ${0} [-L] <client>" >& 2
	exit 1
fi

if [ "${class_os}" = "DN3000" ] ; then
	if [ ! -f /usr/openv/netbackup/client/DN3000/DomainOS/rbak ] ; then
		echo "
You need to put a 10.4 version of rbak in
usr/openv/netbackup/client/DN3000/DomainOS/
before attempting to ftp the files to a client.
"
		exit 1
	fi
elif [ "${class_os}" = "DN10000" ] ; then
	if [ ! -f /usr/openv/netbackup/client/DN10000/DomainOS/rbak ] ; then
		echo "
You need to put a 10.4 version of rbak in
usr/openv/netbackup/client/DN10000/DomainOS/
before attempting to ftp the files to a client.
"
		exit 1
	fi
fi

# Find the rsh and rcp commands
if [ -x /usr/net/rsh ] ; then
	RSH=/usr/net/rsh
elif [ -x /usr/bin/remsh ] ; then
	RSH=/usr/bin/remsh
elif [ -x /usr/bin/resh ] ; then
	RSH=/usr/bin/resh
elif [ -x /usr/bin/rsh ] ; then
	RSH=/usr/bin/rsh
elif [ -x /usr/bsd/rsh ] ; then
	RSH=/usr/bsd/rsh
elif [ -x /usr/ucb/rsh ] ; then
	RSH=/usr/ucb/rsh
else
	/bin/echo Cannot find rsh command
	exit 1
fi

if [ -x /usr/ucb/rcp ] ; then
	RCP=/usr/ucb/rcp
elif [ -x /usr/bsd/rcp ] ; then
	RCP=/usr/bsd/rcp
elif [ -x /usr/bin/rcp ] ; then
	RCP=/usr/bin/rcp
else
	/bin/echo Cannot find rcp command
	exit 1
fi

alive=`$RSH ${CLIENT} "/bin/echo successful" </dev/null`
if [ "${alive}" != "successful" ] ; then
	echo Client ${CLIENT} is not responding
	exit 1
fi

# Make the necessary directories and set their permissions

/bin/rm -rf /tmp/makebpdirs.${CLIENT}
/bin/echo "#!/bin/sh
	if [ ! -d /usr/openv/netbackup ]; then
	  if [ ! -d /usr/openv ]; then
	    /bin/mkdir /usr/openv
	    /bin/chmod 755 /usr/openv
	  fi
	  /bin/mkdir /usr/openv/netbackup
	  /bin/chmod 755 /usr/openv/netbackup
	fi
	if [ ! -d /usr/openv/netbackup/logs ]; then
	  /bin/mkdir /usr/openv/netbackup/logs
	  /bin/chmod 755 /usr/openv/netbackup/logs
	fi
	if [ ! -d /usr/openv/netbackup/logs/user_ops ]; then
	  /bin/mkdir /usr/openv/netbackup/logs/user_ops
	  /bin/chmod 1777 /usr/openv/netbackup/logs/user_ops
	fi
	if [ ! -d /usr/openv/netbackup/bin ]; then
	  /bin/mkdir /usr/openv/netbackup/bin
	  /bin/chmod 755 /usr/openv/netbackup/bin
	fi
	if [ ! -d /usr/openv/bin ]; then
	  /bin/mkdir /usr/openv/bin
	  /bin/chmod 755 /usr/openv/bin
	fi
	if [ ! -d /usr/openv/lib ]; then
	  /bin/mkdir /usr/openv/lib
	  /bin/chmod 755 /usr/openv/lib
	fi
	if [ ! -d /usr/openv/var ]; then
	  /bin/mkdir /usr/openv/var
	  /bin/chmod 755 /usr/openv/var
	fi
	if [ ! -d /usr/openv/var/auth ]; then
	  /bin/mkdir /usr/openv/var/auth
	  /bin/chmod 755 /usr/openv/var/auth
	fi
	if [ ! -d /usr/openv/netbackup/help ]; then
	  /bin/mkdir /usr/openv/netbackup/help
	  /bin/chmod 755 /usr/openv/netbackup/help
	fi
	if [ ! -d /usr/openv/netbackup/help/bp ]; then
	  /bin/mkdir /usr/openv/netbackup/help/bp
	  /bin/chmod 755 /usr/openv/netbackup/help/bp
	fi" >>/tmp/makebpdirs.${CLIENT}

if [ \( -f ${SOURCE_DIR}/xbp \) -a \( "${DESTMACH}" != 'MACINTOSH' \) ] ; then
	/bin/echo "
	if [ ! -d /usr/openv/netbackup/help/xbp ]; then
	  /bin/mkdir /usr/openv/netbackup/help/xbp
	  /bin/chmod 755 /usr/openv/netbackup/help/xbp
	fi
	if [ ! -d /usr/lib ]; then
	   /bin/mkdir /usr/lib
	   /bin/chmod 755 /usr/lib
	fi
	if [ ! -d /usr/lib/X11 ]; then
	   /bin/mkdir /usr/lib/X11
	   /bin/chmod 755 /usr/lib/X11
	fi" >>/tmp/makebpdirs.${CLIENT}
fi

/bin/echo "
	if [ ! -d /usr/openv/netbackup/dbext ]; then
	  /bin/mkdir /usr/openv/netbackup/dbext
	  /bin/chmod 755 /usr/openv/netbackup/dbext
	fi" >>/tmp/makebpdirs.${CLIENT}

# For some platform we also need to copy the java tools over and install them.
# and set up USE_APP_INITIALIZER in thier nbj.conf

InstallJava=0
USE_APP_INITIALIZER=""
if [ "$class_os" = "Solaris_x86_2.6" -o "$class_os" = "Solaris_x86_7" -o "$class_os" = "Solaris_x86_8" ] ; then
	InstallJava=1
	JRE_FILE=Solaris_X86_JRE_117B.tar.Z
elif [ "$class_os" = "Solaris2.5" -o "$class_os" = "Solaris2.6" -o "$class_os" = "Solaris7" -o "$class_os" = "Solaris8" ] ; then
	InstallJava=1
	JRE_FILE=Solaris_JRE_117B.tar.Z
elif [ "$class_os" = "HP-UX10.20" ] ; then
	InstallJava=1
	JRE_FILE=hp1020_jre116.tar.Z
elif [ "$class_os" = "HP-UX11.00" ] ; then 
	InstallJava=1
	JRE_FILE=hp110_jre116.tar.Z
	USE_APP_INITIALIZER="-Dvrts.nbu.admin.USE_APP_INITIALIZER=false"
fi

if [ $InstallJava = 1 ] ; then
	/bin/echo "
	if [ ! -d /usr/openv/java ] ; then
		/bin/mkdir /usr/openv/java
		/bin/chmod 755 /usr/openv/java
	fi
	if [ ! -d /usr/openv/java/logs ] ; then
		/bin/mkdir /usr/openv/java/logs
		/bin/chmod 777 /usr/openv/java/logs
	fi" >>/tmp/makebpdirs.${CLIENT}
fi

$RCP /tmp/makebpdirs.${CLIENT} ${CLIENT}:/tmp/makebpdirs
$RSH ${CLIENT} "sh /tmp/makebpdirs" </dev/null
$RSH ${CLIENT} "/bin/rm /tmp/makebpdirs" </dev/null
/bin/rm /tmp/makebpdirs.${CLIENT}

# Copy over the client binaries and set their permissions
$RCP ${SOURCE_DIR}/bp ${CLIENT}:${BP_CMD}
$RCP ${SOURCE_DIR}/bpcd ${CLIENT}:${BPCD_CMD}
$RCP ${SOURCE_DIR}/bpbkar ${CLIENT}:${BPBKAR_CMD}
$RCP ${SOURCE_DIR}/bpjava-msvc ${CLIENT}:${BPJAVAMS_CMD}
$RCP ${SOURCE_DIR}/bpjava-usvc ${CLIENT}:${BPJAVAUS_CMD}
$RCP ${SOURCE_DIR}/bpbackup ${CLIENT}:${BPBACKUP_CMD}
$RCP ${SOURCE_DIR}/bprestore ${CLIENT}:${BPRESTORE_CMD}
$RCP ${SOURCE_DIR}/bplist ${CLIENT}:${BPLIST_CMD}
$RCP ${SOURCE_DIR}/bpclimagelist ${CLIENT}:${BPCLIMAGELIST_CMD}
$RCP ${SOURCE_DIR}/bpclntcmd ${CLIENT}:${BPCLNTCMD_CMD}
$RCP ${SOURCE_DIR}/version ${CLIENT}:${VERSION}
$RSH ${CLIENT} "/bin/chmod 500 ${BPCD_CMD}; /bin/chmod 644 ${VERSION}" </dev/null
RX_MODE="${BP_CMD} ${BPBKAR_CMD} ${BPBACKUP_CMD} ${BPRESTORE_CMD} ${BPLIST_CMD} ${BPCLIMAGELIST_CMD} ${BPCLNTCMD_CMD} ${BPJAVAMS_CMD} ${BPJAVAUS_CMD}"

# the following sleep was added because if inted on linux has
# more than 40 connections in a minute it assumes a loop and
# terminates the connection.
if [ "${DESTMACH}" = "Linux" ] ; then
        sleep 60
fi

$RSH ${CLIENT} "cd /usr/openv/netbackup/bin; /bin/rm -rf bparchive; ln -s bpbackup bparchive" </dev/null

if [ -f ${SOURCE_DIR}/tar ] ; then
	$RCP ${SOURCE_DIR}/tar ${CLIENT}:${TAR_CMD}
	RX_MODE="${RX_MODE} ${TAR_CMD}"
else
	$RCP ${SOURCE_DIR}/rbak ${CLIENT}:${RBAK_CMD}
	RX_MODE="${RX_MODE} ${RBAK_CMD}"
fi

if [ -f ${SOURCE_DIR}/bphdb ] ; then
	$RCP ${SOURCE_DIR}/bphdb ${CLIENT}:${BPHDB_CMD}
	RX_MODE="${RX_MODE} ${BPHDB_CMD}"
fi

if [ -f ${SOURCE_DIR}/bpmount ] ; then
	$RCP ${SOURCE_DIR}/bpmount ${CLIENT}:${BPMOUNT_CMD}
	RX_MODE="${RX_MODE} ${BPMOUNT_CMD}"
fi

if [ -f ${SOURCE_DIR}/vopied ] ; then
	$RCP ${SOURCE_DIR}/vopied ${CLIENT}:${VOPIED_CMD}
	RX_MODE="${RX_MODE} ${VOPIED_CMD}"
fi

if [ -f ${SOURCE_DIR}/vauth_util ] ; then
	$RCP ${SOURCE_DIR}/vauth_util ${CLIENT}:${VAUTH_UTIL_CMD}
	RX_MODE="${RX_MODE} ${VAUTH_UTIL_CMD}"
fi

if [ -f ${SOURCE_DIR}/vopie_util ] ; then
	$RCP ${SOURCE_DIR}/vopie_util ${CLIENT}:${VOPIE_UTIL_CMD}
	RX_MODE="${RX_MODE} ${VOPIE_UTIL_CMD}"
fi

if [ -f ${SOURCE_DIR}/libvnoauth.${DSO_SUFFIX} ] ; then
	$RCP ${SOURCE_DIR}/libvnoauth.${DSO_SUFFIX} ${CLIENT}:${VNOAUTH_LIB}
	RX_MODE="${RX_MODE} ${VNOAUTH_LIB}"
fi

if [ -f ${SOURCE_DIR}/libvopie.${DSO_SUFFIX} ] ; then
	$RCP ${SOURCE_DIR}/libvopie.${DSO_SUFFIX} ${CLIENT}:${VOPIE_LIB}
	RX_MODE="${RX_MODE} ${VOPIE_LIB}"
fi

if [ -f ${SOURCE_DIR}/merge_auth_templates ] ; then
	$RCP ${SOURCE_DIR}/merge_auth_templates ${CLIENT}:${MERGE_AUTH_TEMPLATES_CMD}
	RX_MODE="${RX_MODE} ${MERGE_AUTH_TEMPLATES_CMD}"
fi
if [ \( -f ${SOURCE_DIR}/xbp \) -a \( "${DESTMACH}" = 'MACINTOSH' \) ] ; then

	# MacOS X and MacOS X Server get a dummy xbp.
	# The real xbp for other platforms is handled elsewhere.

	$RCP ${SOURCE_DIR}/xbp ${CLIENT}:${XBP_CMD}
	RX_MODE="${RX_MODE} ${XBP_CMD}"
fi
$RSH ${CLIENT} "/bin/chmod 555 ${RX_MODE}" </dev/null

RD_MODE=""

if [ -f ${SOURCE_DIR}/methods.txt ] ; then
	$RCP ${SOURCE_DIR}/methods.txt ${CLIENT}:${METHODS_TXT}
	RD_MODE="${RD_MODE} ${METHODS_TXT}"
fi

if [ -f ${SOURCE_DIR}/template.methods_allow.txt ] ; then
	$RCP ${SOURCE_DIR}/template.methods_allow.txt \
	    ${CLIENT}:${METHODS_ALLOW_TXT}
	RD_MODE="${RD_MODE} ${METHODS_ALLOW_TXT}"
fi

if [ -f ${SOURCE_DIR}/template.methods_deny.txt ] ; then
	$RCP ${SOURCE_DIR}/template.methods_deny.txt \
	    ${CLIENT}:${METHODS_DENY_TXT}
	RD_MODE="${RD_MODE} ${METHODS_DENY_TXT}"
fi

if [ -f ${SOURCE_DIR}/template.names_allow.txt ] ; then
	$RCP ${SOURCE_DIR}/template.names_allow.txt ${CLIENT}:${NAMES_ALLOW_TXT}
	RD_MODE="${RD_MODE} ${NAMES_ALLOW_TXT}"
fi

if [ -f ${SOURCE_DIR}/template.names_deny.txt ] ; then
	$RCP ${SOURCE_DIR}/template.names_deny.txt ${CLIENT}:${NAMES_DENY_TXT}
	RD_MODE="${RD_MODE} ${NAMES_DENY_TXT}"
fi
if [ "$RD_MODE" != '' ] ; then
	$RSH ${CLIENT} "/bin/chmod 444 ${RD_MODE}" </dev/null
fi
if remote_file_exists $CLIENT "${MERGE_AUTH_TEMPLATES_CMD}" ; then
	$RSH ${CLIENT} "${MERGE_AUTH_TEMPLATES_CMD}"
fi

# Copy over the help files.
$RCP ${BP_HELP_BP}/*	${CLIENT}:${BP_HELP_BP}
$RSH ${CLIENT} "/bin/chmod 444 ${BP_HELP_BP}/*" </dev/null

# the following sleep was added because if inted on linux has
# more than 40 connections in a minute it assumes a loop and
# terminates the connection.
if [ "${DESTMACH}" = "Linux" ] ; then
        sleep 60
fi

if [ \( -f ${SOURCE_DIR}/xbp \) -a \( "${DESTMACH}" != 'MACINTOSH' \) ] ; then
	$RCP ${SOURCE_DIR}/xbp	${CLIENT}:${XBP_CMD}
	$RCP ${BP_HELP_XBP}/*	${CLIENT}:${BP_HELP_XBP}

	# Don't overwrite an existing XKeysymDB on the client.
	if remote_file_exists $CLIENT /usr/lib/X11/XKeysymDB
	then
		echo "/usr/lib/X11/XKeysymDB exists on the client - not copied."
	else
		$RCP ${SOURCE_DIR}/XKeysymDB ${CLIENT}:/usr/lib/X11/XKeysymDB
	fi

	# Don't overwrite an existing XNB or XNB.dt file
	if remote_file_exists $CLIENT ${BP_BIN}/XNB
	then
		echo "${BP_BIN}/XNB already exists on the client - not copied."
	else
		$RCP ${BP_BIN}/XNB ${CLIENT}:${BP_BIN}/XNB
	fi

	if remote_file_exists $CLIENT ${BP_BIN}/XNB.dt
	then
		echo "${BP_BIN}/XNB.dt already exists on the client - not copied."
	else
		$RCP ${BP_BIN}/XNB.dt ${CLIENT}:${BP_BIN}/XNB.dt
	fi

	$RSH ${CLIENT} "/bin/chmod 555 ${XBP_CMD}; \
		/bin/chmod 444 ${BP_HELP_XBP}/*" </dev/null
fi

# the following sleep was added because if inted on linux has
# more than 40 connections in a minute it assumes a loop and
# terminates the connection.
if [ "${DESTMACH}" = "Linux" ] ; then
        sleep 60
fi

if [ "${EL}eave_bp.conf" != "-Leave_bp.conf" ] ; then
	# Look for 0 or more spaces and tabs followed by SERVER.
	SRVR=`egrep "^[${SPACE}${TAB}]*SERVER" ${BP_DIR}/bp.conf`
	if [ "${SRVR}" = "" ] ; then
		/bin/echo "Missing SERVER in /usr/openv/netbackup/bp.conf"
		exit 1
	fi

	# Build up a list of valid servers on /tmp/bp_servers_hostname.
	/bin/rm -f /tmp/bp_servers_${CLIENT}
	# Look for 0 or more spaces and tabs followed by SERVER.
	egrep "^[${SPACE}${TAB}]*SERVER" ${BP_DIR}/bp.conf >/tmp/bp_servers_${CLIENT}

	# Get a copy of the bp.conf file from the client (if it exists).
	if remote_file_exists $CLIENT ${BP_CONFIG}
	then
		$RCP ${CLIENT}:${BP_CONFIG} /tmp/bp.conf_${CLIENT}_old
	fi
	# Merge in the new servers into bp.conf if told to.
	if [ -f /tmp/bp.conf_${CLIENT}_old ] ; then
		/bin/cat /tmp/bp.conf_${CLIENT}_old |
		while read FILE1
		do
			# If $FILE1 is not blank.
			if [ X"${FILE1}" != X ] ; then
				# Get the fields of $FILE1 into $1, $2, and $3.
				set -- $FILE1
				ID1=$1
				if [ "${ID1}" = "SERVER" ] ; then
					SERVER1=$3
					# Go through the /tmp/bp_servers_${CLIENT} file and
					# check to see if we have an entry to add.
					/bin/rm -f /tmp/bp_servers_${CLIENT}_found
					/bin/cat /tmp/bp_servers_${CLIENT} |
					while read FILE2
					do
						# Get the fields of $FILE1 into $1, $2, and $3.
						set -- $FILE2
						SERVER2=$3
						if [ "${SERVER1}" = "${SERVER2}" ] ; then
							/bin/touch /tmp/bp_servers_${CLIENT}_found
						fi
					done

					# Add the server to a tmp file.
					if [ ! -f /tmp/bp_servers_${CLIENT}_found ] ; then
						/bin/echo "${FILE1}" >>/tmp/bp.conf_${CLIENT}_add
					fi
				elif [ "${ID1}" = "CLIENT_NAME" ] ; then
					/bin/touch /tmp/bp_client_name_${CLIENT}_found
					/bin/echo "${FILE1}" >>/tmp/bp.conf_${CLIENT}_add
				else
					# Not a SERVERS entry, add to bp.conf_hostname_add.
					/bin/echo "${FILE1}" >>/tmp/bp.conf_${CLIENT}_add
				fi
			else
				/bin/echo "${FILE1}" >>/tmp/bp.conf_${CLIENT}_add
			fi
		done

		# If there is anything in /tmp/bp.conf_hostname_add, add to
		# /tmp/bp_servers_hostname.
		if [ -f /tmp/bp.conf_${CLIENT}_add ] ; then
			/bin/cat /tmp/bp.conf_${CLIENT}_add >>/tmp/bp_servers_${CLIENT}
		fi

		# If we didn't find a CLIENT_NAME, add one.
		if [ ! -f /tmp/bp_client_name_${CLIENT}_found ] ; then
			/bin/echo "CLIENT_NAME = ${CLIENT}" >>/tmp/bp_servers_${CLIENT}
		fi

		# Copy the /tmp/bp_servers_${CLIENT} file to the client.
		$RCP /tmp/bp_servers_${CLIENT} ${CLIENT}:${BP_CONFIG}
	else
		# Copy /tmp/bp_servers_${CLIENT} to the client.

		/bin/echo "CLIENT_NAME = ${CLIENT}" >>/tmp/bp_servers_${CLIENT}
		$RCP /tmp/bp_servers_${CLIENT} ${CLIENT}:${BP_CONFIG}
	fi
	$RSH ${CLIENT} "/bin/chmod 444 ${BP_CONFIG}" </dev/null
fi


/bin/rm -rf /tmp/bp.conf_${CLIENT}* /tmp/bp_servers_${CLIENT}* /tmp/bp_client_name_*

if [ "${DESTMACH}" != 'MACINTOSH' ] ; then

bprd=`$RSH ${CLIENT} grep bprd /etc/services </dev/null`
bpcd=`$RSH ${CLIENT} grep bpcd /etc/services </dev/null`
vopied=`$RSH ${CLIENT} grep vopied /etc/services </dev/null`
bpjava=`$RSH ${CLIENT} grep bpjava-msvc /etc/services </dev/null`

bpcd_entry=`grep bpcd /etc/services`
vopied_entry=`grep vopied /etc/services`
bpjava_entry=`grep bpjava-msvc /etc/services`
bprd_entry=`grep bprd /etc/services`

if [ X"${bprd}" != X -o X"${bpcd}" != X -o X"${vopied}" != X -o X"${bpjava}" != X ] ; then
	# Add bprd to the /etc/services file if necessary.
	if [ X"${bprd}" = X ] ; then
		$RSH ${CLIENT} "/bin/echo \"${bprd_entry}\" >>/etc/services" </dev/null
	fi

	# Add bpcd to the /etc/services file if necessary.
	if [ X"${bpcd}" = X ] ; then
		$RSH ${CLIENT} "/bin/echo \"${bpcd_entry}\" >>/etc/services" </dev/null
	fi

	# Add vopied to the /etc/services file if necessary.
	if [ X"${vopied}" = X ] ; then
		$RSH ${CLIENT} "/bin/echo \"${vopied_entry}\" >>/etc/services" </dev/null
	fi
	# Add bpjava-msvc to the /etc/services file if necessary.
	if [ X"${bpjava}" = X ] ; then
		$RSH ${CLIENT} "/bin/echo \"${bpjava_entry}\" >>/etc/services" </dev/null
	fi
else
	# We need to add all the services.
	$RSH ${CLIENT} "/bin/echo \" #\" >>/etc/services" </dev/null
	$RSH ${CLIENT} "/bin/echo \" # OpenV*NetBackup services\" >>/etc/services" </dev/null
	$RSH ${CLIENT} "/bin/echo \" #\" >>/etc/services" </dev/null
	$RSH ${CLIENT} "/bin/echo \"${bpcd_entry}\" >>/etc/services" </dev/null
	$RSH ${CLIENT} "/bin/echo \"${vopied_entry}\" >>/etc/services" </dev/null
	$RSH ${CLIENT} "/bin/echo \"${bpjava_entry}\" >>/etc/services" </dev/null
	$RSH ${CLIENT} "/bin/echo \"${bprd_entry}\" >>/etc/services" </dev/null
fi

else # [ "${DESTMACH}" = 'MACINTOSH' ]

	# MacOS X and MacOS X Server use the NetInfo utilities
	# rather than /etc/services to configure network interfaces.

	do_netinfo_service "`grep bprd /etc/services`"
	do_netinfo_service "`grep bpcd /etc/services`"
	do_netinfo_service "`grep vopied /etc/services`"
	do_netinfo_service "`grep bpjava-msvc /etc/services`"

fi

# Add bpcd to the inetd.conf file if necessary.

bpcd_inetd_entry=`grep bpcd ${INETD_CONF}`

# Add vopied to the inetd.conf file if necessary.

vopied_inetd_entry=`grep vopied ${INETD_CONF}`

# Add bpjava-msvc to the inetd.conf file if necessary.

bpjava_inetd_entry=`grep bpjava-msvc ${INETD_CONF}`

# Determine location of the clients inetd.conf file.

R_INETD_CONF=/etc/inetd.conf

if [ "${DESTMACH}" = "SGI" -o "${DESTMACH}" = "NCR" ] ; then
	if remote_file_exists $CLIENT /usr/etc/inetd.conf
	then
		R_INETD_CONF=/usr/etc/inetd.conf
	fi
        if [ "${DESTMACH}" = "NCR" ] ; then
        	if remote_file_exists $CLIENT /etc/inet/inetd.conf
        	then
        		R_INETD_CONF=/etc/inet/inetd.conf
         	fi
        fi
fi

bpcd_inetd=`$RSH ${CLIENT} grep bpcd $R_INETD_CONF </dev/null`

if [ X"${bpcd_inetd}" = X ] ; then
	$RSH ${CLIENT} "/bin/echo \"${bpcd_inetd_entry}\" >>$R_INETD_CONF" </dev/null
fi

vopied_inetd=`$RSH ${CLIENT} grep vopied $R_INETD_CONF </dev/null`

if [ X"${vopied_inetd}" = X ] ; then
	$RSH ${CLIENT} "/bin/echo \"${vopied_inetd_entry}\" >>$R_INETD_CONF" </dev/null
fi

bpjava_inetd=`$RSH ${CLIENT} grep bpjava-msvc $R_INETD_CONF </dev/null`

if [ X"${bpjava_inetd}" = X ] ; then
	$RSH ${CLIENT} "/bin/echo \"${bpjava_inetd_entry}\" >>$R_INETD_CONF" </dev/null
fi

# NCR--Add bpcd or vopied to the /etc/inet/inetd.local file if necessary.
if [ "$HARDWARE" = "NCR" ] ; then
    if [ "$R_INETD_CONF" = "/etc/inet/inetd.conf" ] ; then     # NCR 3.0
       R_INETD_CONF_LOCAL=/etc/inet/inetd.local
       if remote_file_exists $CLIENT $R_INETD_CONF_LOCAL
       then
          bpcd_inetd=`$RSH ${CLIENT} egrep "'^bpcd'" $R_INETD_CONF_LOCAL </dev/null`
          vopied_inetd=`$RSH ${CLIENT} egrep "'^vopied'" $R_INETD_CONF_LOCAL </dev/null`
          bpjava_inetd=`$RSH ${CLIENT} egrep "'^bpjava-msvc'" $R_INETD_CONF_LOCAL </dev/null`
       else
          bpcd_inetd=""
          vopied_inetd=""
          bpjava_inetd=""
       fi
       if [ X"${bpcd_inetd}" = X ] ; then
            $RSH ${CLIENT} "/bin/echo \"${bpcd_inetd_entry}\" >>$R_INETD_CONF_LOCAL" </dev/null
       fi
       if [ X"${vopied_inetd}" = X ] ; then
            $RSH ${CLIENT} "/bin/echo \"${vopied_inetd_entry}\" >>$R_INETD_CONF_LOCAL" </dev/null
       fi
       if [ X"${bpjava_inetd}" = X ] ; then
            $RSH ${CLIENT} "/bin/echo \"${bpjava_inetd_entry}\" >>$R_INETD_CONF_LOCAL" </dev/null
       fi
    fi
fi

if [ $InstallJava = 1 ] ; then
	JAVA_FILE=NB-Java.tar.Z
	$RCP /usr/openv/${JAVA_FILE} ${CLIENT}:/usr/openv/
	$RCP /usr/openv/java/${JRE_FILE} ${CLIENT}:/usr/openv/java
	echo "#!/bin/sh
cd /usr/openv
zcat NB-Java.tar.Z | /bin/tar xvf - >/dev/null
rm -f /usr/openv/NB-Java.tar.Z
rm -f /usr/openv/java/auth.conf
cd /usr/openv/java
zcat ${JRE_FILE} | /bin/tar xvf - >/dev/null
rm -f ${BP_BIN}/jnbSA ${BP_BIN}/jbpSA
if [ `expr "$class_os" : '.*_x86'` = 0 ] ; then
	ln -s /usr/openv/java/jnbSA ${BP_BIN}/jnbSA
fi
ln -s /usr/openv/java/jbpSA ${BP_BIN}/jbpSA
rm -f /usr/openv/java/${JRE_FILE}

# Copy in our font.properties file.
mv /usr/openv/java/jre/lib/font.properties /usr/openv/java/jre/lib/font.properties.bak
mv /usr/openv/java/font.properties /usr/openv/java/jre/lib/
## Make the java/awt dir for class files to work around the finalizer hang ...
mkdir -p -m 755 /usr/openv/java/java/awt
mv /usr/openv/java/Finalize2.class /usr/openv/java/java/awt/
### Yes, dollar sign 1 in the file name below ...
mv /usr/openv/java/Graphics*.class /usr/openv/java/java/awt/
mv /usr/openv/java/SecondaryFinalizer.class /usr/openv/java/java/awt/
### Yes, dollar sign in this file name as well ...
mv /usr/openv/java/Component*.class /usr/openv/java/java/awt/" > /tmp/JAVA.${CLIENT}
	$RCP /tmp/JAVA.${CLIENT} ${CLIENT}:/tmp
	RX_MODE="${RX_MODE} /tmp/JAVA.${CLIENT}"
	$RSH ${CLIENT} "/bin/chmod 555 ${RX_MODE}" </dev/null
	$RSH ${CLIENT} "/tmp/JAVA.${CLIENT}" </dev/null
	# 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/JAVAnbj.conf.${CLIENT}
		echo "USE_APP_INITIALIZER=${USE_APP_INITIALIZER}" >> /tmp/JAVAnbj.conf.${CLIENT}
		echo "CLIENT_HOST=$CLIENT" >> /tmp/JAVAnbj.conf.${CLIENT}
		$RCP /tmp/JAVAnbj.conf.${CLIENT}  ${CLIENT}:/usr/openv/java/nbj.conf
	fi
	$RSH ${CLIENT} "rm -f /tmp/JAVA.${CLIENT}" </dev/null
	rm -f /tmp/JAVA.${CLIENT} /tmp/JAVAnbj.conf.${CLIENT}
fi

# We need to find the process number for inetd so that we can
# send a SIGHUP so that it will reread its inetd.conf file.

if [ "${DESTMACH}" = "Sun3" -o "${DESTMACH}" = "Sun4" ] ; then

	inetd=`$RSH ${CLIENT} /bin/ps -aux </dev/null|grep inetd|grep -v grep|awk '{print $2}'`

elif [ "${DESTMACH}" = "DGUX" ] ; then
	inetd=`$RSH ${CLIENT} /bin/ps -e </dev/null|grep inetd|grep -v grep|awk '{print $1}'`
 
elif [ "${DESTMACH}" = "Linux" ] ; then
	inetd=`$RSH ${CLIENT} /bin/ps aux </dev/null|grep inetd|grep -v grep|awk '{print $2}'`

elif [ "${DESTMACH}" = "MACINTOSH" ] ; then
	inetd=`$RSH ${CLIENT} /bin/ps -aux < /dev/null | grep inetd | \
	    grep -v grep | awk '{print $2}'`

elif [ "${DESTMACH}" = "RS6000" ] ; then

	# We need to execute the inetimp command on AIX
	if remote_file_exists $CLIENT /usr/bin/inetimp
	then
		$RSH ${CLIENT} /usr/bin/inetimp </dev/null
	fi
	inetd=`$RSH ${CLIENT} /bin/ps -ef </dev/null|grep inetd|grep -v grep|awk '{print $2}'`

else
	inetd=`$RSH ${CLIENT} /bin/ps -ef </dev/null|grep inetd|grep -v grep|awk '{print $2}'`
fi
$RSH ${CLIENT} kill -1 $inetd </dev/null
