#!/bin/sh
# $Id: install_client.sh,v 1.31.4.2 2004/03/10 02:38:28 $
#***************************************************************************
# $VRTScprght: Copyright 1993 - 2004 VERITAS Software Corporation, All Rights Reserved $
#***************************************************************************

#	install_client.sh is called by install_client_files with the
#	rsh option. It installs the client binaries from the server.

# INSERT fn.set_tar_options
#---------- set_tar_options -- $Revision: 1.9 $ ------------
#
#		This function takes one parameter, a
#		string which is the MACHINE or platform type.
#		It sets two variables: TAR_C_OPTIONS and
#			TAR_X_OPTIONS
#
#		NOTE: The v flag is not handled in this function. If you want 
#		to add the v flag, you need to set it in your scripts.
#		For example, place the v before the variable like so, v${TAR_X_OPTIONS}.
#		The v must go before the variable because in the ALPHA|SGI
#		case statement you can't put the v after the 20 blocking factor.
#
#		calling signature:
#			set_tar_options "MachineType"

set_tar_options ()
{
	case "${1}" in
		ALPHA* | alpha* | OSF1* | SGI* | sgi6* | IRIX* )

			TAR_C_OPTIONS="cf" #same as default

			TAR_X_OPTIONS="xbpf 20"
			#x - extract
			#b - use blocking factor
			#p - use original tarred file protection properties
			#f - use given filename
			#20 - portable blocking factor
			;;
		HP* | hp* )

			TAR_C_OPTIONS="cOfA"
			#c - create new archive
			#O - write a pre-POSIX format archive
			#f - use given filename
			#A - suppress warning messages for ACL entries

			TAR_X_OPTIONS="xpfA"
			#x - extract
			#p - use original tarred file protection properties
			#f - use given filename
			#A - suppress warning messages for ACL entries	
			;;

		* )
			TAR_C_OPTIONS="cf"
			#c - create new archive
			#f - use given filename

			TAR_X_OPTIONS="xpf"
			#x - extract
			#p - use original tarred file protection propeties
			#f - use given filename
			;;
	esac
}

# INSERT fn.inetd_entries
#---------- inetd.entries -- $Revision: 1.1 $ ------------
#	Set up the entries needed for inetd or xinetd by
#	defining a bunch of mini-functions the calling
#	scripts can reference.
#
#	There are 2 major types (inetd or xinetd).
#	New entries need to be added to both sections.
#
#-------------------------------------------------------------------------------
# inetd entries - NOWAIT will be filled in based on machine type later
# when the appropriate function is called.  For most machines,
# NOWAIT will be "nowait" but for Linux, it will be "nowait.300".

bpcd_i ()
{
	bpcd_i_entry="bpcd	stream	tcp	${NOWAIT}	root	/usr/openv/netbackup/bin/bpcd bpcd"
}

bpjava_msvc_i ()
{
	bpjava_msvc_i_entry="bpjava-msvc	stream	tcp	${NOWAIT}	root	/usr/openv/netbackup/bin/bpjava-msvc bpjava-msvc -transient"
}

vnetd_i ()
{
	vnetd_i_entry="vnetd	stream	tcp	${NOWAIT}	root	/usr/openv/bin/vnetd vnetd"
}

vopied_i ()
{
	vopied_i_entry="vopied	stream	tcp	${NOWAIT}	root	/usr/openv/bin/vopied vopied"
}

#-------------------------------------------------------------------------------
# xinetd entries - GROUP_LINE will be filled in based on machine type
# later when the appropriate function is called.  For most machines,
# GROUP_LINE will be nothing, but for MACINTOSH, it will be replaced
# by "groups = yes"

bpcd_x ()
{
	bpcd_x_entry="# Service bpcd for NetBackup
service bpcd
{
        socket_type             = stream
        protocol                = tcp
        wait                    = no
        user                    = root
        server                  = /usr/openv/netbackup/bin/bpcd
        disable                 = no
        ${GROUP_LINE}
}"
}

bpjava_msvc_x ()
{
	bpjava_msvc_x_entry="# Service bpjava-msvc for NetBackup
service bpjava-msvc
{
        socket_type             = stream
        protocol                = tcp
        wait                    = no
        user                    = root
        server                  = /usr/openv/netbackup/bin/bpjava-msvc
        server_args             = -transient
        disable                 = no
        ${GROUP_LINE}
}"
}

vnetd_x ()
{
	vnetd_x_entry="# Service vnetd for NetBackup
service vnetd
{
        socket_type             = stream
        protocol                = tcp
        wait                    = no
        user                    = root
        server                  = /usr/openv/bin/vnetd
        disable                 = no
        ${GROUP_LINE}
}"
}

vopied_x ()
{
	vopied_x_entry="# Service vopied for NetBackup
service vopied
{
        socket_type             = stream
        protocol                = tcp
        wait                    = no
        user                    = root
        server                  = /usr/openv/bin/vopied
        disable                 = no
        ${GROUP_LINE}
}"
}

# 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 MacOSX*
#
# 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
}

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

# Make sure we're really INTEL and not Linux in disguise.
# Important since we sleep and change inetd entries if Linux.
if [ "${DESTMACH}" = "INTEL" ] ; then
	echo ${class_os} | grep RedHat2.4 > /dev/null 2>&1
	if [ $? -eq 0 ] ; then
		DESTMACH="Linux"
	fi
fi

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
OPENV_SHARE=${OPENV_DIR}/share
BP_DIR=/usr/openv/netbackup
BP_BIN=${BP_DIR}/bin
BP_DRV=${BP_BIN}/driver
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_new
BPDYNAM_CMD=${BP_BIN}/bpdynamicclient
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
MTFRD_CMD=${BP_BIN}/mtfrd
BPFIS_CMD=${BP_BIN}/bpfis
BPHDB_CMD=${BP_BIN}/bphdb
BPMOUNT_CMD=${BP_BIN}/bpmount
BPTPCINFO_CMD=${BP_BIN}/bptpcinfo
BPNBAT_CMD=${BP_BIN}/bpnbat
BPNBAT_HELP_CMD=${BP_BIN}/bpnbat_helper
VXSS_DB_CMD=${BP_BIN}/vxss_db_paths
TAR_CMD=${BP_BIN}/tar
VERSION=${BP_BIN}/version
BP_CONFIG=${BP_DIR}/bp.conf
SOURCE_DIR=`dirname ${0}`
VNETD_CMD=${OPENV_BIN}/vnetd
VOPIED_CMD=${OPENV_BIN}/vopied
VAUTH_UTIL_CMD=${OPENV_BIN}/vauth_util
VAUTH_TEST_CMD=${OPENV_BIN}/vauth_test
VAUTH_TESTD_CMD=${OPENV_BIN}/vauth_testd
VOPIE_UTIL_CMD=${OPENV_BIN}/vopie_util
VNOAUTH_LIB=${OPENV_LIB}/libvnoauth.${DSO_SUFFIX}_new
VNOAUTH64_LIB=${OPENV_LIB}/libvnoauth64.${DSO_SUFFIX}_new
VOPIE_LIB=${OPENV_LIB}/libvopie.${DSO_SUFFIX}_new
VOPIE64_LIB=${OPENV_LIB}/libvopie64.${DSO_SUFFIX}_new
VMANGLE_LIB=${OPENV_LIB}/libVmangle.${DSO_SUFFIX}
VCVCOMB_LIB=${OPENV_LIB}/libVcvcomb.${DSO_SUFFIX}
VCVCOMB64_LIB=${OPENV_LIB}/libVcvcomb64.${DSO_SUFFIX}
VNBCONF_LIB=${OPENV_LIB}/libVnbconf.${DSO_SUFFIX}_new
VNBCONF64_LIB=${OPENV_LIB}/libVnbconf64.${DSO_SUFFIX}_new
VNBAT_LIB=${OPENV_LIB}/libVnbatST.${DSO_SUFFIX}_new
VNBAT64_LIB=${OPENV_LIB}/libVnbatST64.${DSO_SUFFIX}_new
MTVNBAT_LIB=${OPENV_LIB}/libVnbat.${DSO_SUFFIX}
MTVNBAT64_LIB=${OPENV_LIB}/libVnbat64.${DSO_SUFFIX}
VXSS_HELP_LIB=${OPENV_LIB}/libVxSS_helper.${DSO_SUFFIX}_new
VXSS_HELP64_LIB=${OPENV_LIB}/libVxSS_helper64.${DSO_SUFFIX}_new
XBSA_LIB=${OPENV_LIB}/libxbsa.${DSO_SUFFIX}
XBSA64_LIB=${OPENV_LIB}/libxbsa64.${DSO_SUFFIX}
UBS_LIB=${OPENV_LIB}/libubs.${DSO_SUFFIX}
BECLASS_LIB=${OPENV_LIB}/libnbbeclass.${DSO_SUFFIX}
BESTDUTIL_LIB=${OPENV_LIB}/libnbbestdutl.${DSO_SUFFIX}
BECOMMON_LIB=${OPENV_LIB}/libnbbedscomn.${DSO_SUFFIX}
DBSB_LIB=${OPENV_LIB}/libdbsb.${DSO_SUFFIX}
MERGE_AUTH_TEMPLATES_CMD=${BP_BIN}/merge_auth_templates
MOVELIBS_CMD=${BP_BIN}/move_libs

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

# Based on the SERV_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.

TR=/bin/tr

case "$SERV_HARDWARE" in
	RS6000 | SOLARIS | ALPHA | SGI)
		;;
	HP* | LINUX*)
		TR=/usr/bin/tr
		;;
	*) echo "Unknown hardware type: $SERV_HARDWARE"
		exit 1
		;;
esac

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


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

# Make sure we're on an active node or a standalone machine
# before we allow the user to push to a client.

${BP_BIN}/cluster/cluster_active > /dev/null 2>&1
if [ $? -ne 0 ] ; then
	echo "
This machine appears to be an inactive member of a cluster.  Pushing
software to clients must occur on the active member of the cluster.
"
	exit 0
fi

# Check to see if the client is the master (the local machine).
# Use bpclntcmd so we aren't fooled by virtual names.
# Don't try to update the server with files from itself.

${BP_BIN}/bpclntcmd -is_local_host ${CLIENT} > /dev/null 2>&1
if [ $? -eq 0 ] ; then
	echo "
The client files are already on server ${CLIENT}.
"
	exit 0
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

# Look for 0 or more spaces and tabs followed by SERVER.  If the client
# is Java capable, it is used for the SERVER_HOST entry in nbj.conf.
# Note:  the master server name may be a virtual name if the machine has
# been clustered.
SRVR=`egrep "^[${SPACE}${TAB}]*SERVER[${SPACE}${TAB}]*=" ${BP_DIR}/bp.conf | head -1`
if [ "${SRVR}" = "" ] ; then
	/bin/echo "Missing SERVER in /usr/openv/netbackup/bp.conf"
	exit 1
else
	SRVR=`echo ${SRVR} | cut -d"=" -f2 | awk '{print $1}'`
fi

# Make the necessary directories and set their permissions

/bin/rm -rf /tmp/makebpdirs.${CLIENT}
/bin/echo "#!/bin/sh
	if [ ! -d /usr/openv ]; then
		/bin/mkdir /usr/openv
		/bin/chmod 755 /usr/openv
	fi
	if [ ! -d /usr/openv/netbackup ]; then
		/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 777 /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/share ]; then
		/bin/mkdir /usr/openv/share
		/bin/chmod 755 /usr/openv/share
	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/var/vxss ]; then
		/bin/mkdir /usr/openv/var/vxss
		/bin/chmod 755 /usr/openv/var/vxss
	fi
	if [ ! -d /usr/openv/var/vxss/credentials ]; then
		/bin/mkdir /usr/openv/var/vxss/credentials
		/bin/chmod 755 /usr/openv/var/vxss/credentials
	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 [ -d ${SOURCE_DIR}/driver ] ; then
	/bin/echo "
	if [ ! -d /usr/openv/netbackup/bin/driver ]; then
		/bin/mkdir /usr/openv/netbackup/bin/driver
		/bin/chmod 755 /usr/openv/netbackup/bin/driver
	fi" >>/tmp/makebpdirs.${CLIENT}
fi

if [ \( -f ${SOURCE_DIR}/xbp \) ] ; then
	head -1 ${SOURCE_DIR}/xbp | grep '\#!\/bin\/sh' >/dev/null	#is xbp a shell script?

	if [ $? -eq 1 ] ; then #yes it's a binary & therefore supports x windows
		/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
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 platforms, we also need to copy the java tools over, install them,
# and set up their nbj.conf.

InstallJava=0

set_tar_options ${class_os} # note no v

case "${class_os}" in
	AIX*)		JRE_FILE=AIX_JRE.tar.Z
			JNI_FILE=${OPENV_LIB}/server/rs6000/libSigScheduleJNI.so
			OSTYPE=AIX
			InstallJava=1 ;;
	Solaris_x*)	JRE_FILE=Solaris_x86_JRE.tar.Z
			JNI_FILE=${OPENV_LIB}/server/Solaris_x86/libSigScheduleJNI.so
			OSTYPE=Solaris_X86
			InstallJava=1 ;;
	Solaris*)	JRE_FILE=Solaris_Sparc_JRE.tar.Z
			JNI_FILE=${OPENV_LIB}/server/Solaris/libSigScheduleJNI.so
			OSTYPE=Solaris
			InstallJava=1 ;;
	OSF1_V*)	JRE_FILE=Tru64_JRE.tar.Z
			JNI_FILE=${OPENV_LIB}/server/alpha_5/libSigScheduleJNI.so
			OSTYPE="${class_os}"
			InstallJava=1 ;;
	HP-UX11*)	JRE_FILE=HPUX_JRE.tar.Z
			JNI_FILE=${OPENV_LIB}/server/hp_ux/libSigScheduleJNI.sl
			OSTYPE=HP_UX
			InstallJava=1 ;;
	RedHat2.4)	JRE_FILE=Linux_JRE.tar.Z
			JNI_FILE=${OPENV_LIB}/server/linux/libSigScheduleJNI.so
			OSTYPE=Linux
			InstallJava=1 ;;
esac

if [ ${InstallJava} = 1 ] ; then
	Message="
NetBackup Java is not installed and distributed to $SERV_HARDWARE servers.

You must install client software locally, from the CD-ROM, to install
NetBackup Java components on a ${OSTYPE} NetBackup client."

	case "$SERV_HARDWARE" in
		SGI )
			echo "${Message}" >& 2
			InstallJava=0 ;;
	esac
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" >>/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
RX_MODE="${BP_CMD} ${BPBKAR_CMD} ${BPBACKUP_CMD} ${BPRESTORE_CMD} ${BPLIST_CMD} \
	${BPCLIMAGELIST_CMD} ${BPCLNTCMD_CMD} ${BPJAVAMS_CMD} ${BPJAVAUS_CMD} ${TAR_CMD}"

# On an rs6000 machine, free unused shared objects from kernel and library
# memory, so we don't bomb replacing libraries in /usr/openv/lib.

if [ "${DESTMACH}" = "RS6000" ] ; then
	$RSH ${CLIENT} "/usr/sbin/slibclean" </dev/null
fi
$RCP ${SOURCE_DIR}/bp ${CLIENT}:${BP_CMD}
$RCP ${SOURCE_DIR}/bpcd ${CLIENT}:${BPCD_CMD}
$RCP ${SOURCE_DIR}/bpdynamicclient ${CLIENT}:${BPDYNAM_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}/tar ${CLIENT}:${TAR_CMD}
$RCP ${SOURCE_DIR}/version ${CLIENT}:${VERSION}
$RCP ${SOURCE_DIR}/move_libs ${CLIENT}:${MOVELIBS_CMD}
$RSH ${CLIENT} "/bin/chmod 500 ${BPCD_CMD} ${BPDYNAM_CMD} ${MOVELIBS_CMD}; /bin/chmod 444 ${VERSION}" </dev/null

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

# the following sleep was added because if inetd 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

RX_MODE="${RX_MODE} ${MTFRD_CMD} ${BPMOUNT_CMD} ${BPNBAT_CMD} ${VAUTH_TEST_CMD} ${VNOAUTH_LIB} \
	${VCVCOMB_LIB} ${VNBCONF_LIB} ${VNBAT_LIB} ${MTVNBAT_LIB} ${VXSS_HELP_LIB} ${VOPIE_LIB}"
$RCP ${SOURCE_DIR}/mtfrd ${CLIENT}:${MTFRD_CMD}
$RCP ${SOURCE_DIR}/bpmount ${CLIENT}:${BPMOUNT_CMD}
$RCP ${SOURCE_DIR}/bpnbat ${CLIENT}:${BPNBAT_CMD}
$RCP ${SOURCE_DIR}/vauth_test ${CLIENT}:${VAUTH_TEST_CMD}
$RCP ${SOURCE_DIR}/libvopie.${DSO_SUFFIX} ${CLIENT}:${VOPIE_LIB}
$RCP ${SOURCE_DIR}/libvnoauth.${DSO_SUFFIX} ${CLIENT}:${VNOAUTH_LIB}
$RCP ${SOURCE_DIR}/libVcvcomb.${DSO_SUFFIX} ${CLIENT}:${VCVCOMB_LIB}
$RCP ${SOURCE_DIR}/libVnbconf.${DSO_SUFFIX} ${CLIENT}:${VNBCONF_LIB}
$RCP ${SOURCE_DIR}/libVnbatST.${DSO_SUFFIX} ${CLIENT}:${VNBAT_LIB}
$RCP ${SOURCE_DIR}/libVnbat.${DSO_SUFFIX} ${CLIENT}:${MTVNBAT_LIB}
$RCP ${SOURCE_DIR}/libVxSS_helper.${DSO_SUFFIX} ${CLIENT}:${VXSS_HELP_LIB}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

$RSH ${CLIENT} "/bin/chmod 555 ${RX_MODE}" </dev/null

# Move the *_new files to their real locations.

$RSH ${CLIENT} "${MOVELIBS_CMD}" </dev/null
$RSH ${CLIENT} "rm -f ${MOVELIBS_CMD}" </dev/null

RX_OWNER_MODE="${VNETD_CMD} ${VOPIED_CMD} ${VAUTH_UTIL_CMD} ${VAUTH_TESTD_CMD} \
	${VOPIE_UTIL_CMD} ${MERGE_AUTH_TEMPLATES_CMD} ${VXSS_DB_CMD}"
$RCP ${SOURCE_DIR}/vxss_db_paths ${CLIENT}:${VXSS_DB_CMD}
$RCP ${SOURCE_DIR}/vnetd ${CLIENT}:${VNETD_CMD}
$RCP ${SOURCE_DIR}/vopied ${CLIENT}:${VOPIED_CMD}
$RCP ${SOURCE_DIR}/vauth_util ${CLIENT}:${VAUTH_UTIL_CMD}
$RCP ${SOURCE_DIR}/vauth_testd ${CLIENT}:${VAUTH_TESTD_CMD}
$RCP ${SOURCE_DIR}/vopie_util ${CLIENT}:${VOPIE_UTIL_CMD}
$RCP ${SOURCE_DIR}/merge_auth_templates ${CLIENT}:${MERGE_AUTH_TEMPLATES_CMD}

$RSH ${CLIENT} "/bin/chmod 500 ${RX_OWNER_MODE}" </dev/null

$RCP ${SOURCE_DIR}/template.*.txt ${CLIENT}:${OPENV_AUTH}
$RCP /usr/openv/share/tpc_Client.txt ${CLIENT}:${OPENV_SHARE}
$RCP /usr/openv/share/tpc_Console.txt ${CLIENT}:${OPENV_SHARE}

$RSH ${CLIENT} "/bin/chmod 444 ${OPENV_AUTH}/template.*.txt" </dev/null
$RSH ${CLIENT} "/bin/chmod 444 ${OPENV_SHARE}/tpc_*" </dev/null

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 inetd 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 \) ] ; then

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

	head -1 ${SOURCE_DIR}/xbp | grep '\#!\/bin\/sh' >/dev/null	#is xbp a shell script?

	if [ $? -eq 1 ] ; then #yes it's a binary & therefore supports x windows

		$RCP ${BP_HELP_XBP}/* ${CLIENT}:${BP_HELP_XBP}
		$RSH ${CLIENT} "/bin/chmod 444 ${BP_HELP_XBP}/*" </dev/null

		# 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
			$RSH ${CLIENT} "/bin/chmod 444 /usr/lib/X11/XKeysymDB" </dev/null
		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
			$RSH ${CLIENT} "/bin/chmod 444 ${BP_BIN}/XNB" </dev/null
		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
			$RSH ${CLIENT} "/bin/chmod 444 ${BP_BIN}/XNB.dt" </dev/null
		fi
	fi
fi


if [ -d ${SOURCE_DIR}/driver ] ; then
	for file in snapcachelist snapctl snapctl_x snaplist snapoff \
		snapon snapstat
	do
		if [ -f ${SOURCE_DIR}/driver/${file} ] ; then
			${RCP} ${SOURCE_DIR}/driver/${file}	${CLIENT}:${BP_DRV}/${file}
		fi
	done
	${RSH} ${CLIENT} "/bin/chmod 544 ${BP_DRV}/snap*" </dev/null
	if [ -f ${SOURCE_DIR}/driver/snapctl.conf ] ; then
		${RCP} ${SOURCE_DIR}/driver/snapctl.conf	${CLIENT}:${BP_DRV}/snapctl.conf
		${RSH} ${CLIENT} "/bin/chmod 444 ${BP_DRV}/snapctl.conf" </dev/null
	fi
fi

# the following sleep was added because if inetd 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

	# 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[${SPACE}${TAB}]*=" ${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`
vnetd=`$RSH ${CLIENT} "grep '^vnetd' /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`
vnetd_entry=`grep '^vnetd' /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 -o X"${vnetd}" != 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 vnetd to the /etc/services file if necessary.
	if [ X"${vnetd}" = X ] ; then
		$RSH ${CLIENT} "/bin/echo \"${vnetd_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 \"${vnetd_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' ]

	# MacOSX* uses 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 '^vnetd' /etc/services`"
	do_netinfo_service "`grep '^vopied' /etc/services`"
	do_netinfo_service "`grep '^bpjava-msvc' /etc/services`"

fi

# inetd entries are coming from the functions in the fn.inetd_entries file.
# Use nowait.300 ONLY for Linux clients using inetd.

if [ "${DESTMACH}" = "Linux" ] ; then
	NOWAIT="nowait.300"
else
	NOWAIT="nowait"
fi
bpcd_i
vopied_i
bpjava_msvc_i
vnetd_i


# Determine location of the clients inetd.conf file.

R_INETD_CONF=/etc/inetd.conf

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

# Add our daemons to the /etc/xinetd.d directory if necessary.
if remote_file_exists $CLIENT /etc/xinetd.d ] ; then
	is_dir=yes
else
	is_dir=no
fi
if remote_file_exists $CLIENT /etc/xinetd.conf ] ; then
	is_file=yes
else
	is_file=no
fi
if [ "${is_dir}" = "yes" -a "${is_file}" = "yes" ] ; then
	R_INETD_CONF=/etc/xinetd.conf
	if [ "${DESTMACH}" = "MACINTOSH" ] ; then
		GROUP_LINE="groups                  = yes"
	else
		GROUP_LINE=""
	fi
	bpcd_x
	echo "${bpcd_x_entry}" > /tmp/xinetd_bpcd
	chmod 644 /tmp/xinetd_bpcd
	$RCP /tmp/xinetd_bpcd ${CLIENT}:/etc/xinetd.d/bpcd
	rm /tmp/xinetd_bpcd
	vnetd_x
	echo "${vnetd_x_entry}" > /tmp/xinetd_vnetd
	chmod 644 /tmp/xinetd_vnetd
	$RCP /tmp/xinetd_vnetd ${CLIENT}:/etc/xinetd.d/vnetd
	rm /tmp/xinetd_vnetd
	vopied_x
	echo "${vopied_x_entry}" > /tmp/xinetd_vopied
	chmod 644 /tmp/xinetd_vopied
	$RCP /tmp/xinetd_vopied ${CLIENT}:/etc/xinetd.d/vopied
	rm /tmp/xinetd_vopied
	bpjava_msvc_x
	echo "${bpjava_msvc_x_entry}" > /tmp/xinetd_bpjava-msvc
	chmod 644 /tmp/xinetd_bpjava-msvc
	$RCP /tmp/xinetd_bpjava-msvc ${CLIENT}:/etc/xinetd.d/bpjava-msvc
	rm /tmp/xinetd_bpjava-msvc
	#SIGHUP is sent to xinetd_pid further down in the code
	#look for the xinetd reload function
else

	#  Only update client's inetd.conf file if entries are not already there.
	bpcd_inetd=`$RSH ${CLIENT} "grep '^bpcd' $R_INETD_CONF" </dev/null`
	if [ X"${bpcd_inetd}" = X ] ; then
		$RSH ${CLIENT} "/bin/echo \"${bpcd_i_entry}\" >>$R_INETD_CONF" </dev/null
	fi

	vnetd_inetd=`$RSH ${CLIENT} "grep '^vnetd' $R_INETD_CONF" </dev/null`
	if [ X"${vnetd_inetd}" = X ] ; then
		$RSH ${CLIENT} "/bin/echo \"${vnetd_i_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_i_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_msvc_i_entry}\" >>$R_INETD_CONF" </dev/null
	fi
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}" = "Linux" -o "${DESTMACH}" = "INTEL" ] ; then
	inetd=`$RSH ${CLIENT} /bin/ps aux </dev/null|grep inetd|grep -v grep|grep -v osinetd|awk '{print $2}'`

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

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

	# We need to execute the inetimp command on AIX
	oslevel=`${RSH} ${CLIENT} oslevel | cut -c1-3 | sed -e 's/\.//'`
	if [ ${oslevel} -lt 51 ] ; then
		if remote_file_exists $CLIENT /usr/bin/inetimp
		then
			$RSH ${CLIENT} /usr/bin/inetimp </dev/null
		fi
	fi
	inetd=`$RSH ${CLIENT} /bin/ps -ef </dev/null|grep inetd|grep -v grep|grep -v osinetd|awk '{print $2}'`

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

#  Send the SIGHUP to either inetd_pid or to xinetd_pid.
#  MacOSX10.2 has xinetd but doesn't have the reload option.
#  Use SIGHUP for it instead.
if [ "${R_INETD_CONF}" = "/etc/xinetd.conf" -a "${DESTMACH}" != "MACINTOSH" ] ; then
	$RSH ${CLIENT} "/etc/rc.d/init.d/xinetd reload" </dev/null
	#equivalent to kill -USR2 xinetd_pid or kill -s 12 xinetd_pid
elif [ "${DESTMACH}" = "MACINTOSH" ] ; then
	$RSH ${CLIENT} /bin/kill -s HUP $inetd </dev/null
else
	$RSH ${CLIENT} kill -1 $inetd </dev/null
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
	$RCP ${JNI_FILE} ${CLIENT}:/usr/openv/lib
	echo "#!/bin/sh
DoJava=Yes
if [ "${DESTMACH}" = "RS6000" ] ; then
	Version=\`uname -v\`
	if [ \${Version} -lt 5 ] ; then
		DoJava=No
	fi
fi
if [ \$DoJava = Yes ] ; then
	cd /usr/openv
	#  Clean up the java directory.  There are a couple of things to keep
	#  so create a temp directory to save those in.
	java_tmp_dir=/usr/openv/NB_java_tmp.\$\$
	if [ ! -d \${java_tmp_dir} ] ; then
		mkdir \${java_tmp_dir}
	else
		rm -rf \${java_tmp_dir}/*
	fi
	for conf in auth.conf nbj.conf
	do
		if [ -f /usr/openv/java/\${conf} ] ; then
			mv /usr/openv/java/\${conf} \${java_tmp_dir}/\${conf}.bak
		fi
	done
	# already have the new JRE so save it off before we clobber the java dir
	if [ -f /usr/openv/java/${JRE_FILE} ] ; then
		mv /usr/openv/java/${JRE_FILE} \${java_tmp_dir}
	fi

	#  The next section of code tries to figure out if VSM, GDM
	#  or a locale package has been installed.  If so, save off
	#  the pieces installed by those packages.
	for file in HSMApplet.properties allHSM.jar migfb migsa \
		.gdmConf archiver.jar crimson-1.1.jar gdm.conf \
		gdmDashboard.jar gdmSA idl.jar jacorb.jar jaxp-1.1.jar \
		SchedUI_ja_JP.jar VxHelp_ja_JP.jar \
		SchedUI_zh_CN.jar VxHelp_zh_CN.jar
	do
		if [ -f /usr/openv/java/\${file} ] ; then
			mv /usr/openv/java/\${file} \${java_tmp_dir}
		fi
	done
	for loc in ja zh
	do
		if [ -f /usr/openv/java/vrts/i18n_\${loc}.properties ] ; then
			if [ ! -d \${java_tmp_dir}/vrts ] ; then
				mkdir \${java_tmp_dir}/vrts
			fi
			mv /usr/openv/java/vrts/i18n_\${loc}.properties \${java_tmp_dir}/vrts
		fi
		for dir in help helpDC ; do
			if [ -d /usr/openv/java/vrts/nbu/\${dir}/\${loc} ] ; then
				if [ ! -d \${java_tmp_dir}/vrts/nbu/\${dir} ] ; then
					mkdir -p \${java_tmp_dir}/vrts/nbu/\${dir}
				fi
				mv /usr/openv/java/vrts/nbu/\${dir}/\${loc} \${java_tmp_dir}/vrts/nbu/\${dir}
			fi
		done
	done
	for dir in hsm gdm ; do
		if [ -d /usr/openv/java/vrts/\${dir} ] ; then
			if [ ! -d \${java_tmp_dir}/vrts ] ; then
				mkdir \${java_tmp_dir}/vrts
			fi
			mv /usr/openv/java/vrts/\${dir} \${java_tmp_dir}/vrts
		fi
	done

	#  Now remove the existing java directory and if anything actually
	#  got saved, move the temp directory back to /usr/openv/java.
	if [ -d /usr/openv/java ] ; then
		rm -rf /usr/openv/java 2>/dev/null
	fi
	rmdir \${java_tmp_dir} 2>/dev/null
	if [ \$? != 0 ] ; then
		mv \${java_tmp_dir} /usr/openv/java
		chgrp -R bin /usr/openv/java
	fi

	zcat NB-Java.tar.Z | /bin/tar ${TAR_X_OPTIONS} - >/dev/null
	rm -f /usr/openv/NB-Java.tar.Z
	if [ ! -d /usr/openv/java/logs ] ; then
		/bin/mkdir /usr/openv/java/logs
		/bin/chmod 777 /usr/openv/java/logs
	fi

	#  note only the backup copy of auth.conf gets copied back
	#  not nbj.conf
	if [ -f /usr/openv/java/auth.conf.bak ] ; then
		rm -f /usr/openv/java/auth.conf
		mv /usr/openv/java/auth.conf.bak /usr/openv/java/auth.conf
	fi

	cd /usr/openv/java
	zcat ${JRE_FILE} | /bin/tar ${TAR_X_OPTIONS} - >/dev/null
	rm -f /usr/openv/java/${JRE_FILE}
	rm -f ${BP_BIN}/jnbSA ${BP_BIN}/jbpSA
	ln -s /usr/openv/java/jbpSA ${BP_BIN}/jbpSA
	ln -s /usr/openv/java/jnbSA ${BP_BIN}/jnbSA
	chmod 555 /usr/openv/lib/libSigScheduleJNI.s?
else	# We don't support Java on this platform
	rm -rf /usr/openv/java /usr/openv/NB-Java.tar.Z
	rm -f /usr/openv/java/${JRE_FILE} /usr/openv/lib/libSigScheduleJNI.s?
fi" > /tmp/JAVA.${CLIENT}

	$RCP /tmp/JAVA.${CLIENT} ${CLIENT}:/tmp
	$RSH ${CLIENT} "/bin/chmod 555 /tmp/JAVA.${CLIENT}" </dev/null
	$RSH ${CLIENT} "/tmp/JAVA.${CLIENT}" </dev/null
	# copy and modify nbj.conf for $CLIENT
	if [ -f /usr/openv/java/nbj.conf -a "${class_os}" != "AIX4.3.3" ] ; then
		Java_Server="${SRVR}"
		grep -v CLIENT_HOST /usr/openv/java/nbj.conf | grep -v SERVER_HOST > /tmp/JAVAnbj.conf.${CLIENT}
		echo "CLIENT_HOST=${CLIENT}
SERVER_HOST=${Java_Server}" >> /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

