#!/bin/sh
# $Id: cp_to_client.sh,v 1.31.4.4 2004/03/10 02:38:28 $

#***************************************************************************
# $VRTScprght: Copyright 1993 - 2004 VERITAS Software Corporation, All Rights Reserved $
#***************************************************************************

# The following variable is changed by the Makefile to a valid value.
MACHINE=Solaris

# INSERT fn.set_echo_var
#---------- set_echo_var -- $Revision: 1.2 $ ------------
#
#		This function is a case statement sets
#		the ECHO variable
#		with the appropriate path & flags.

#Define Echo to allow escape characters
case "`uname -s`" in
	Linux*)
		unset POSIXLY_CORRECT
		ECHO="/bin/echo -e"
		;;
	SunOS*)
		ECHO="/usr/bin/echo"
		;;
	*)
		ECHO="echo"
		;;
esac

# INSERT fn.prompt
#---------- Prompt () -- $Revision: 1.1 $ ------------
#	Prompt () - determines the flags to use to print
#			a line without a newline char
#
# 	*** This function uses the set_echo_var function -${ECHO} to 
#		define the Prompt function.
#
#	calling signature - Prompt "some string"
#	return value - none

case "`${ECHO} 'x\c'`" in
	'x\c')
		Prompt()
		{
			${ECHO} -n "$*"
		}
		;;
	x)
		Prompt()
		{
			${ECHO} "$*\c"
		}
		;;
	*)
		Prompt()
		{
			${ECHO} -n "$*"
		}
		;;
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}
}"
}

##
#	Add an entry to the client's /etc/services
#	$1 = service name
#	$2 = service port

add_2_services ()
{

	${ECHO} "Adding NetBackup service $1 with default port $2 to /etc/services"
	${ECHO} "$1	$2/tcp	$1" >>/etc/services
}

##
#	If a file exists in source cp it to the client
#	$1 = filename
#	$2 = fullpath on client
#	$3 = file mode

If_file_cp ()
{

	if [ -f ${SOURCE_DIR}/${1} ] ; then
		${ECHO} "+ /bin/cp ${SOURCE_DIR}/${1} ${2}"
		/bin/cp ${SOURCE_DIR}/${1} ${2}
		/bin/chmod ${3} ${2}
		chgrp bin ${2}
	fi
}

# Check the inetdfile for an entry and add it if not there.
#
ck_inetdfile () {

	entry=$1
	file2check=$2
	Saved=0
	TAB=`${ECHO} ' ' | $TR ' ' '\011'`
	SPACE=' '

	Prompt "Checking for a $entry entry in $file2check: "
	Found=`egrep "^${entry}[${SPACE}${TAB}]" $file2check`
	if [ X"${Found}" = X ] ; then
		if [ ! -f $file2check.${dt} ] ; then
			Saved=1
			cp $file2check $file2check.${dt}
		fi
		${ECHO} " Adding $entry entry."
		chmod 644 $file2check

		# Use nowait.300 ONLY for Linux servers/clients using inetd.
		# xinetd doesn't need it.
		if [ "${MACHINE}" = "Linux" ] ; then
			NOWAIT="nowait.300"
		else
			NOWAIT="nowait"
		fi
		case "${entry}" in
			bpcd)
				bpcd_i
				${ECHO} "${bpcd_i_entry}" >> ${file2check}
				;;
			bpjava-msvc)
				bpjava_msvc_i
				${ECHO} "${bpjava_msvc_i_entry}" >> ${file2check}
				;;
			vnetd)
				vnetd_i
				${ECHO} "${vnetd_i_entry}" >> ${file2check}
				;;
			vopied)
				vopied_i
				${ECHO} "${vopied_i_entry}" >> ${file2check}
				;;
		esac

		# inform inetd of a change
		/bin/cp /dev/null /usr/openv/netbackup/.services_updated
	else
		${ECHO} " Found."
	fi

	if [ $Saved = 1 ] ; then
		${ECHO} "Original $file2check saved as $file2check.${dt}."
	fi
}

# -----------------------------------------------------------------------------
# Add files to xinetd.d directory for NetBackup services if xinetd is used.
#
ck_xinetd () {

	entry=$1

	#  If using xinetd and the machine is a MACINTOSH, it must be the
	#  MacOSX10.2 client.  If there isn't a groups entry in the file,
	#  remove it and we'll create a new one from scratch.

	if [ -f /etc/xinetd.d/${entry} -a "${MACHINE}" = "MACINTOSH" ] ; then
		${TR} -d ' \011' < /etc/xinetd.d/${entry} | grep "^groups=yes" >/dev/null 2>&1
		if [ $? -eq 1 ] ; then
			rm -f /etc/xinetd.d/${entry}
		fi
	fi
	if [ ! -f /etc/xinetd.d/${entry} ] ; then
		if [ "${MACHINE}" = "MACINTOSH" ] ; then
			GROUP_LINE="groups                  = yes"
		else
			GROUP_LINE=""
		fi
		case "${entry}" in
			bpcd)
				bpcd_x
				${ECHO} "${bpcd_x_entry}" >> /etc/xinetd.d/${entry}
				;;
			bpjava-msvc)
				bpjava_msvc_x
				${ECHO} "${bpjava_msvc_x_entry}" >> /etc/xinetd.d/${entry}
				;;
			vnetd)
				vnetd_x
				${ECHO} "${vnetd_x_entry}" >> /etc/xinetd.d/${entry}
				;;
			vopied)
				vopied_x
				${ECHO} "${vopied_x_entry}" >> /etc/xinetd.d/${entry}
				;;
		esac

		# Tell update_service to inform inetd of a change
		/bin/cp /dev/null /usr/openv/netbackup/.services_updated
	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 <name> <port>
#
#	<name>		service name (e.g. "bpcd").
#	<port>		service port (e.g. 13782).

do_netinfo_service () {
	service_name="${1}"
	service_port="${2}"
	current_protocol=`niutil -readprop . /services/"${service_name}" \
	    protocol 2> /dev/null`
	current_port=`niutil -readprop . /services/"${service_name}" port 2> \
	    /dev/null`
	if [ \( "${current_protocol}" != 'tcp' \) -o \
	     \( "${current_port}" = '' \) ] ; then
		niutil -create . /services/"${service_name}" > /dev/null 2>&1
		niutil -createprop . /services/"${service_name}" protocol \
		    tcp > /dev/null 2>&1
		niutil -createprop . /services/"${service_name}" port \
		    "${service_port}" > /dev/null 2>&1
		current_protocol=`niutil -readprop . \
		    /services/"${service_name}" protocol 2> /dev/null`
		current_port=`niutil -readprop . /services/"${service_name}" \
		    port 2> /dev/null`
	fi
	if [ \( "${current_protocol}" != 'tcp' \) -o \
	     \( "${current_port}" = '' \) ] ; then
		return 1
	fi
	return 0
}
##################### MAIN #####################

dt=`/bin/date +"%m-%d-%y.%T"`

TR=/usr/bin/tr
class_os=`pwd`
class_os=`basename ${class_os}`
InstallJava=0
CopyOnly=0

DSO_SUFFIX='so'
case "${MACHINE}" in
	ALPHA)
		InstallJava=1;;
	HP*)
		DSO_SUFFIX='sl'
		InstallJava=1
		;;
	Linux)
		ECHO="${ECHO} -e"
		if [ "${class_os}" != "IBMzSeriesLinux2.4" ] ; then
			InstallJava=1
		fi
		;;
	RS6000)
		TR=/bin/tr
		Version=`uname -v`
		if [ ${Version} -ge 5 ] ; then
			InstallJava=1
		fi ;;
	Solaris*)
		TR=/bin/tr
		InstallJava=1
		;;
esac

OPENV_DIR=/usr/openv
OPENV_BIN=${OPENV_DIR}/bin
OPENV_LIB=${OPENV_DIR}/lib
OPENV_SHARE=${OPENV_DIR}/share
OPENV_VAR=${OPENV_DIR}/var
OPENV_AUTH=${OPENV_VAR}/auth
BP_DIR=${OPENV_DIR}/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
BPJAVAMS_CMD=${BP_BIN}/bpjava-msvc
BPJAVAUS_CMD=${BP_BIN}/bpjava-usvc
BPBKAR_CMD=${BP_BIN}/bpbkar
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
TAR_CMD=${BP_BIN}/tar
RBAK_CMD=${BP_BIN}/rbak
MTFRD_CMD=${BP_BIN}/mtfrd
BPFIS_CMD=${BP_BIN}/bpfis
BPHDB_CMD=${BP_BIN}/bphdb
BPMOUNT_CMD=${BP_BIN}/bpmount
BPNBAT_CMD=${BP_BIN}/bpnbat
BPNBAT_HELP_CMD=${BP_BIN}/bpnbat_helper
VXSS_DB_CMD=${BP_BIN}/vxss_db_paths
BPTPCINFO_CMD=${BP_BIN}/bptpcinfo
VERSION=${BP_BIN}/version
BP_CONFIG=${BP_DIR}/bp.conf
SOURCE_DIR=.

SOURCE_HELP_DIR=../../../help
SOURCE_SHARE_DIR=../../../../share

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
VMANGLE_LIB=${OPENV_LIB}/libVmangle.${DSO_SUFFIX}
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
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
METHODS_TXT=${OPENV_AUTH}/template.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


if [ "$#" -ne 2 ] ; then
	if [ "$#" -eq 1 -a "$1" = "-CopyOnly" ] ; then
		CopyOnly=1
	else
		${ECHO} "usage: ${0} <server_hostname> <client_hostname>" >& 2
		exit 1
	fi
fi


if [ ! -f ${SOURCE_DIR}/bpcd -o ! -d ${SOURCE_HELP_DIR}/bp ] ; then
	${ECHO} "Your current working directory must be the client/<hardware>/<os> directory"
	${ECHO} "that contains the binaries that you want to copy."
	exit 1
fi

# This section does some tasks that only happen when option 2
# (a real client install) is chosen.

if [ $CopyOnly = 0 ] ; then

	SERVER=$1
	CLIENT=$2

	# Make the necessary directories and set their permissions
	make_dirs_755="/usr/openv \
		/usr/openv/netbackup \
		/usr/openv/netbackup/logs \
		/usr/openv/netbackup/bin \
		/usr/openv/lib \
		/usr/openv/share \
		/usr/openv/netbackup/help \
		/usr/openv/netbackup/dbext"
	if [ $InstallJava = 1 ] ; then
		make_dirs_755="$make_dirs_755 \
		/usr/openv/java"
	fi

	for dir in ${make_dirs_755}
	do
		if [ ! -d ${dir} ] ; then
			/bin/mkdir ${dir}
		fi
		/bin/chmod 755 ${dir}
		chgrp bin ${dir}
	done

	if [ ! -d /usr/openv/netbackup/logs/user_ops ]; then
		/bin/mkdir /usr/openv/netbackup/logs/user_ops
	fi
	/bin/chmod 777 /usr/openv/netbackup/logs/user_ops
	chgrp bin /usr/openv/netbackup/logs/user_ops

	if [ $InstallJava = 1 ] ; then
		if [ ! -d /usr/openv/java/logs ]; then
			/bin/mkdir /usr/openv/java/logs
		fi
		/bin/chmod 777 /usr/openv/java/logs
		chgrp bin /usr/openv/java/logs
	fi
fi

# This section does some tasks that have to happen when option 2
# (a real client install) is chosen and when option 1 (a server
# install followed by cp_to_client -CopyOnly) is chosen.

make_dirs_755="/usr/openv/bin \
		/usr/openv/var \
		/usr/openv/var/auth \
		/usr/openv/var/vxss \
		/usr/openv/var/vxss/credentials \
		/usr/openv/netbackup/help/bp"

for dir in ${make_dirs_755}
do
	if [ ! -d ${dir} ] ; then
		/bin/mkdir ${dir}
	fi
	/bin/chmod 755 ${dir}
	chgrp bin ${dir}
done

if [ -d ${SOURCE_DIR}/driver ]; then
	if [ ! -d /usr/openv/netbackup/bin/driver ]; then
		/bin/mkdir /usr/openv/netbackup/bin/driver
	fi
	/bin/chmod 755 /usr/openv/netbackup/bin/driver
	chgrp bin /usr/openv/netbackup/bin/driver
fi

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

	#  Make sure to populate servers so they can push to all
	#  clients regardless if the local xbp is a binary or not.
	#  For clients, only do if xbp is a binary and therefore
	#  supports X Windows.

	if [ $? -eq 1 -o ${CopyOnly} -eq 1 ] ; then
		for dir in /usr/lib /usr/lib/X11 \
			/usr/openv/netbackup/help/xbp
		do
			if [ ! -d ${dir} ]; then
				/bin/mkdir ${dir}
			fi
			/bin/chmod 755 ${dir}
		done
		chgrp bin /usr/openv/netbackup/help/xbp
	fi
fi

# 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 [ "${MACHINE}" = "RS6000" ] ; then
	/usr/sbin/slibclean
fi

# Copy over the client binaries and set their permissions
ls -R > /dev/null 2>&1	#HP access
set -x
/bin/cp ${SOURCE_DIR}/bp ${BP_CMD}
/bin/cp ${SOURCE_DIR}/bpcd ${BPCD_CMD}
/bin/cp ${SOURCE_DIR}/bpdynamicclient ${BPDYNAM_CMD}
/bin/cp ${SOURCE_DIR}/bpjava-msvc ${BPJAVAMS_CMD}
/bin/cp ${SOURCE_DIR}/bpjava-usvc ${BPJAVAUS_CMD}
/bin/cp ${SOURCE_DIR}/bpbkar ${BPBKAR_CMD}
/bin/cp ${SOURCE_DIR}/bpbackup ${BPBACKUP_CMD}
/bin/cp ${SOURCE_DIR}/bprestore ${BPRESTORE_CMD}
/bin/cp ${SOURCE_DIR}/bplist ${BPLIST_CMD}
/bin/cp ${SOURCE_DIR}/bpclimagelist ${BPCLIMAGELIST_CMD}
/bin/cp ${SOURCE_DIR}/bpclntcmd ${BPCLNTCMD_CMD}
/bin/cp ${SOURCE_DIR}/tar ${TAR_CMD}
/bin/cp ${SOURCE_DIR}/version ${VERSION}
set +x
/bin/cp ${SOURCE_DIR}/vxss_db_paths ${VXSS_DB_CMD}
/bin/chmod 555 ${BP_CMD}
/bin/chmod 500 ${BPCD_CMD}
/bin/chmod 500 ${BPDYNAM_CMD}
/bin/chmod 555 ${BPJAVAMS_CMD}
/bin/chmod 555 ${BPJAVAUS_CMD}
/bin/chmod 555 ${BPBKAR_CMD}
/bin/chmod 555 ${BPBACKUP_CMD}
/bin/chmod 555 ${BPRESTORE_CMD}
/bin/chmod 555 ${BPLIST_CMD}
/bin/chmod 555 ${BPCLIMAGELIST_CMD}
/bin/chmod 555 ${BPCLNTCMD_CMD}
/bin/chmod 555 ${TAR_CMD}
/bin/chmod 444 ${VERSION}
/bin/chmod 500 ${VXSS_DB_CMD}
chgrp bin ${BP_CMD} ${BPCD_CMD} ${BPDYNAM_CMD} ${BPJAVAMS_CMD} ${BPJAVAUS_CMD}
chgrp bin ${BPBKAR_CMD} ${BPBACKUP_CMD} ${BPRESTORE_CMD} ${BPLIST_CMD}
chgrp bin ${BPCLIMAGELIST_CMD} ${BPCLNTCMD_CMD} ${TAR_CMD} ${VERSION}
chgrp bin ${VXSS_DB_CMD}

If_file_cp mtfrd ${MTFRD_CMD} 555
If_file_cp bpfis ${BPFIS_CMD} 555
If_file_cp bphdb ${BPHDB_CMD} 555
If_file_cp bpmount ${BPMOUNT_CMD} 555
If_file_cp bpnbat ${BPNBAT_CMD} 555
If_file_cp bpnbat_helper ${BPNBAT_HELP_CMD} 555
If_file_cp bptpcinfo ${BPTPCINFO_CMD} 555
If_file_cp vnetd ${VNETD_CMD} 500
If_file_cp vopied ${VOPIED_CMD} 500
If_file_cp vauth_util ${VAUTH_UTIL_CMD} 500
If_file_cp vauth_test ${VAUTH_TEST_CMD} 555
If_file_cp vauth_testd ${VAUTH_TESTD_CMD} 500
If_file_cp vopie_util ${VOPIE_UTIL_CMD} 500
If_file_cp libVmangle.${DSO_SUFFIX} ${VMANGLE_LIB} 555
If_file_cp libvnoauth.${DSO_SUFFIX} ${VNOAUTH_LIB} 555
If_file_cp libvnoauth64.${DSO_SUFFIX} ${VNOAUTH64_LIB} 555
If_file_cp libvopie.${DSO_SUFFIX} ${VOPIE_LIB} 555
If_file_cp libvopie64.${DSO_SUFFIX} ${VOPIE64_LIB} 555
If_file_cp libVcvcomb.${DSO_SUFFIX} ${VCVCOMB_LIB} 555
If_file_cp libVcvcomb64.${DSO_SUFFIX} ${VCVCOMB64_LIB} 555
If_file_cp libVnbconf.${DSO_SUFFIX} ${VNBCONF_LIB} 555
If_file_cp libVnbconf64.${DSO_SUFFIX} ${VNBCONF64_LIB} 555
If_file_cp libVnbatST.${DSO_SUFFIX} ${VNBAT_LIB} 555
If_file_cp libVnbatST64.${DSO_SUFFIX} ${VNBAT64_LIB} 555
If_file_cp libVnbat.${DSO_SUFFIX} ${MTVNBAT_LIB} 555
If_file_cp libVnbat64.${DSO_SUFFIX} ${MTVNBAT64_LIB} 555
If_file_cp libVxSS_helper.${DSO_SUFFIX} ${VXSS_HELP_LIB} 555
If_file_cp libVxSS_helper64.${DSO_SUFFIX} ${VXSS_HELP64_LIB} 555
If_file_cp libxbsa.${DSO_SUFFIX} ${XBSA_LIB} 555
If_file_cp libxbsa64.${DSO_SUFFIX} ${XBSA64_LIB} 555
If_file_cp libubs.${DSO_SUFFIX} ${UBS_LIB} 555
If_file_cp libnbbeclass.${DSO_SUFFIX} ${BECLASS_LIB} 555
If_file_cp libnbbestdutl.${DSO_SUFFIX} ${BESTDUTIL_LIB} 555
If_file_cp libnbbedscomn.${DSO_SUFFIX} ${BECOMMON_LIB} 555
If_file_cp libdbsb.${DSO_SUFFIX} ${DBSB_LIB} 555
If_file_cp merge_auth_templates ${MERGE_AUTH_TEMPLATES_CMD} 500
If_file_cp template.methods.txt ${METHODS_TXT} 444
If_file_cp template.methods_allow.txt ${METHODS_ALLOW_TXT} 444
If_file_cp template.methods_deny.txt ${METHODS_DENY_TXT} 444
If_file_cp template.names_allow.txt ${NAMES_ALLOW_TXT} 444
If_file_cp template.names_deny.txt ${NAMES_DENY_TXT} 444
if [ -x ${MERGE_AUTH_TEMPLATES_CMD} ] ; then
	${MERGE_AUTH_TEMPLATES_CMD}
fi

# Move the *_new files to their real locations.

${SOURCE_DIR}/move_libs

(cd /usr/openv/netbackup/bin; /bin/rm -rf bparchive; ln -s bpbackup bparchive)

# Copy over the help files.

if [ $CopyOnly = 0 ] ; then
	/bin/cp ${SOURCE_HELP_DIR}/bp/* ${BP_HELP_BP}/
	/bin/chmod 444 ${BP_HELP_BP}/*
	chgrp bin ${BP_HELP_BP}/*
fi

# Copy over the Third Party Copyright files.

if [ $CopyOnly = 0 ] ; then
	/bin/cp ${SOURCE_SHARE_DIR}/tpc_Client.txt ${OPENV_SHARE}/
	/bin/cp ${SOURCE_SHARE_DIR}/tpc_Console.txt ${OPENV_SHARE}/
	/bin/chmod 444 ${OPENV_SHARE}/tpc_*
	chgrp bin ${OPENV_SHARE}/tpc_*
fi

if [ -f ${SOURCE_DIR}/xbp ] ; then
	/bin/cp ${SOURCE_DIR}/xbp ${XBP_CMD}	#always copy over xbp
	/bin/chmod 555 ${XBP_CMD}
	chgrp bin ${XBP_CMD}

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

	#  Make sure to populate servers so they can push to all
	#  clients regardless if the local xbp is a binary or not.
	#  For clients, only do if xbp is a binary and therefore
	#  supports X Windows.

	if [ $? -eq 1 -o ${CopyOnly} -eq 1 ] ; then

		# xbp help files are already installed on servers
		# where xbp is supported. Must install help 
		# files for client install ( $CopyOnly = 0 ).

		if [ $CopyOnly = 0 ] ; then
			/bin/cp ${SOURCE_HELP_DIR}/xbp/* ${BP_HELP_XBP}/
			/bin/chmod 444 ${BP_HELP_XBP}/*
			chgrp bin ${BP_HELP_XBP}/*
		fi

		# Don't overwrite an existing XKeysymDB on the client.
		if [ ! -f /usr/lib/X11/XKeysymDB ] ; then
			/bin/cp ${SOURCE_DIR}/XKeysymDB /usr/lib/X11/XKeysymDB
			/bin/chmod 444 /usr/lib/X11/XKeysymDB
		fi

		for file in XNB XNB.dt
		do
			loc=${SOURCE_DIR}/../../..
			if [ -f ${loc}/${file} -a ! -f ${BP_BIN}/${file} ] ; then
				/bin/cp ${loc}/${file} ${BP_BIN}/${file}
				/bin/chmod 444 ${BP_BIN}/${file}
				chgrp bin ${BP_BIN}/${file}
			fi
		done
	fi
fi

if [ -d ${SOURCE_DIR}/driver ] ; then
	If_file_cp driver/snapcachelist ${BP_DRV}/snapcachelist 544
	If_file_cp driver/snapctl ${BP_DRV}/snapctl 544
	If_file_cp driver/snapctl.conf ${BP_DRV}/snapctl.conf 444
	If_file_cp driver/snapctl_x ${BP_DRV}/snapctl_x 544
	If_file_cp driver/snaplist ${BP_DRV}/snaplist 544
	If_file_cp driver/snapoff ${BP_DRV}/snapoff 544
	If_file_cp driver/snapon ${BP_DRV}/snapon 544
	If_file_cp driver/snapstat ${BP_DRV}/snapstat 544
fi

if [ $CopyOnly = 0 ] ; then

	if [ ! -f ${BP_CONFIG} ] ; then
		${ECHO} "SERVER = ${SERVER}" >${BP_CONFIG}
		${ECHO} "CLIENT_NAME = ${CLIENT}" >>${BP_CONFIG}
		/bin/chmod 444 ${BP_CONFIG}
	fi

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

	bprd=`grep bprd /etc/services`
	bpcd=`grep bpcd /etc/services`
	vnetd=`grep vnetd /etc/services`
	vopied=`grep vopied /etc/services`
	bpjava=`grep bpjava-msvc /etc/services`

	if [ X"${bprd}" != X -o X"${bpjava}" != X -o X"${bpcd}" != X -o X"${vopied}" != X -o X"${vnetd}" != X ]
	then
		# Add bprd to the /etc/services file if necessary.
		if [ X"${bprd}" = X ] ; then
			add_2_services bprd 13720
		fi

		# Add bpjava-msvc to the /etc/services file if necessary.
		if [ X"${bpjava}" = X ] ; then
			add_2_services bpjava-msvc 13722
		fi

		# Add bpcd to the /etc/services file if necessary.
		if [ X"${bpcd}" = X ] ; then
			add_2_services bpcd 13782
		fi

		# Add vnetd to the /etc/services file if necessary.
		if [ X"${vnetd}" = X ] ; then
			add_2_services vnetd 13724
		fi

		# Add vopied to the /etc/services file if necessary.
		if [ X"${vopied}" = X ] ; then
			add_2_services vopied 13783
		fi
	else
		# We need to add all the services. So add our header.
		${ECHO} "Editing /etc/services to update NetBackup services."
		${ECHO} "Copying original /etc/services file to /etc/services.${dt}"
		/bin/cp /etc/services /etc/services.${dt}

		${ECHO} "#" >>/etc/services
		${ECHO} "# NetBackup services" >>/etc/services
		${ECHO} "#" >>/etc/services
		add_2_services bprd 13720
		add_2_services bpjava-msvc 13722
		add_2_services bpcd 13782
		add_2_services vnetd 13724
		add_2_services vopied 13783
	fi

	else # "${MACHINE}" = 'MACINTOSH'

		# MacOSX* uses the NetInfo utilities
		# rather than /etc/services to configure network interfaces.

		do_netinfo_service bprd 13720
		do_netinfo_service bpjava-msvc 13722
		do_netinfo_service bpcd 13782
		do_netinfo_service vnetd 13724
		do_netinfo_service vopied 13783

	fi

	# Determine location of the clients inetd.conf file.

	inetdfile=/etc/inetd.conf
	if [ "${MACHINE}" = "SGI" ] ; then
		if [ -f /usr/etc/inetd.conf ] ; then
			inetdfile=/usr/etc/inetd.conf
		fi
	fi
	# Add our daemons to the /etc/xinetd.d directory if necessary.
	if [ -d /etc/xinetd.d -a -f /etc/xinetd.conf ] ; then
		ck_xinetd bpcd
		ck_xinetd vnetd
		ck_xinetd vopied
		ck_xinetd bpjava-msvc
	else

		# Add our daemons to the /usr/etc/inetd.conf file if necessary.
		ck_inetdfile bpcd $inetdfile
		ck_inetdfile vnetd $inetdfile
		ck_inetdfile vopied $inetdfile
		ck_inetdfile bpjava-msvc $inetdfile

	fi

	if [ -f /usr/openv/netbackup/.services_updated ] ; then
		rm -f /usr/openv/netbackup/.services_updated

		# We need to find the process number for inetd to
		${ECHO} "Send a SIGHUP to inetd or xinetd so the (x)inetd.conf file will be reread."
		if [ "${MACHINE}" = "Linux" -o "${MACHINE}" = "INTEL" ] ; then
			inetd=`/bin/ps aux|grep inetd|grep -v grep|grep -v osinetd|awk '{print $2}'`
		elif [ "${MACHINE}" = "MACINTOSH" ] ; then
			inetd=`/bin/ps -aux|grep inetd|grep -v grep|grep -v osinetd|awk '{print $2}'`
		elif [ "${MACHINE}" = "RS6000" ] ; then
			# We need to execute the inetimp command on AIX
			oslevel=`oslevel | cut -c1-3 | sed -e 's/\.//'`
			if [ ${oslevel} -lt 51 -a -f /usr/bin/inetimp ] ; then
				/usr/bin/inetimp
			fi
			inetd=`/bin/ps -ef|grep inetd|grep -v grep|grep -v osinetd|awk '{print $2}'`
		else
			inetd=`/bin/ps -ef|grep inetd|grep -v grep|grep -v osinetd|awk '{print $2}'`
		fi

		#  MacOSX10.2 has xinetd but doesn't have the reload option.
		#  Use SIGHUP for it instead.
		if [ -d /etc/xinetd.d -a -f /etc/xinetd.conf -a \
		     "${MACHINE}" != "MACINTOSH" ] ; then
			/etc/rc.d/init.d/xinetd reload
			#equivalent to kill -USR2 xinetd_pid or kill -s 12 xinetd_pid

		elif [ "${MACHINE}" = "MACINTOSH" ] ; then
			/bin/kill -s HUP $inetd
		else
			kill -1 $inetd
		fi
	fi

	if [ $InstallJava = 1 ] ; then
		NBClient=`pwd`
		while [ `basename ${NBClient}` != NBClients ] ; do
			NBClient=`dirname ${NBClient}`
			if [ `basename ${NBClient}` = "solaris" ] ; then
				NBClient=`dirname ${NBClient}`/NBClients
			elif [ ${NBClient} = '/' ] ; then
				${ECHO} "	Clients directory not found to install java
		Aborting .
	"
			fi
		done
		${NBClient}/catalog/anb/Java.inst /tmp/cp_to_client.$$ -Install_Client
		if [ $? -eq 1 ] ; then
			${ECHO} "	A problem was encountered installing Java pieces.
		Aborting.
	"
			exit 2
		fi
		rm -f /tmp/cp_to_client.$$
	fi
else
	#  Put fsanalyze in netbackup/bin for server installs only.
	#  Do not add fsanalyze to the other usual client pushing executables.
	If_file_cp fsanalyze ${BP_BIN}/fsanalyze 544
fi
