#!/bin/sh
# $Id: install_bp.sh,v 1.47.4.2 2004/01/16 23:52:52 $
#***************************************************************************
# $VRTScprght: Copyright 1993 - 2004 VERITAS Software Corporation, All Rights Reserved $
#***************************************************************************
#
# installation script for NetBackup servers
# References to BusinesServer have changed to NetBackup Server.
# References to DataCenter have changed to NetBackup Enterprise Server.

RELEASE=5.0MP1

trap trapped 1 2

trapped () {

	${ECHO} "A ^C was detected!"
	if confirm n "Do you really wish to abort the install?"
	then
		${ECHO} "
WARNING:  You must rerun ${NB_BIN}/install_bp for NetBackup to
         function correctly.
"
		exit 1
	else
		${ECHO} "	continuing ..."
	fi
}

# 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.confirm
#---------- confirm () -- $Revision: 1.4 $ ------------
#
#	confirm () - Takes three parameters:
#		     1: "y" or "n" to be displayed as the default
#		     2:  a prompt string to be displayed to the user
#		     3:  help text string (optional)
#
#			It is expected that the Trace_File variable
#			has been set to a file or /dev/null.
#			
#			*** This function uses the Prompt function
#				which uses the set_echo_var function - ${ECHO}.
#
#	calling signature:	confirm y "some string" [ "help text" ] 
#					or
#				confirm n "some string" [ "help text" ]
#
#	returns:		0 for Yes, 1 for No		

confirm ()
{
	help=${3}
	Q=""
	if [ -n "${help}" ]; then 
		Q=",?"
	fi
	Prompt "${2} [y,n${Q}] (${1}) "
	valid=0
	until [ ${valid} -ne 0 ]
	do
		#read ans and if it is empty, initialize it with the default
		read ans
		: ${ans:=${1}}


		#write to the tracefile

		${ECHO} ${ans} >> ${Trace_File}


		case "${ans}" in
			Y*|y*)
				valid=1
				return 0 ;;
			N*|n*)
				valid=1
				return 1 ;;
			?*)
				${ECHO} ""
				${ECHO} ${help}
				${ECHO} ""
				Prompt "${2} [y,n${Q}] (${1}) "
				;;
			*)
				${ECHO} ""
				Prompt "${ans} is invalid input.  Enter [y,n${Q}] (${1}) " 
				;;
		esac
	done
}

# INSERT fn.continue_or_quit
#---------- continue_or_quit () -- $Revision: 1.1 $ ------------
#
#	continue_or_quit () - The user is prompted to press
#			"x" or "X" to exit or <RETURN> to continue.
#
#			It is expected that the Trace_File variable
#			has been set to a file or /dev/null.
#			*** This function is dependent on the 
#				set_echo_var function - ${ECHO} and
#				the Prompt function.
#			
#	calling signature:	continue_or_quit
#
#	returns:		1 for Exit, 0 for Continue

continue_or_quit ()
{
	Prompt "Enter <RETURN> to continue, \"x\" to exit. "
	read Quit

	#check to make sure a filename was passed in
	${ECHO} ${Quit} >> ${Trace_File}

	if [ "${Quit}" = "x" -o "${Quit}" = "X" ] ; then
		exit 1
	fi
}

# INSERT fn.get_number
#---------- get_number () -- $Revision: 1.2 $ ------------
#
#	get_number () - Takes four parameters, three are mandatory.
#			Parameter one:   string displayed to the user
#				  two:   minimum value
#				  three: maximum value
#				  four (optional):  default
#
#			The input must be a number inbetween the min and max.
#			The number is placed in the VALUE variable.
#			*** This function uses the Prompt function and the prompt
#				function uses the set_echo_var function - ${ECHO}.
#			*** It is expected that the Trace_File variable has been 
#				set to a file or /dev/null.
#
#	calling signature:
#			get_number "some string" min_value max_value -d default_value
#				or
#			get_number "some string" min_value max_value

get_number ()
{
	#grab the default param if given
	if [ $# -gt 4 ] ; then
		if [ "${4}" = "-d" ] ; then
			defaultNum=${5}
		else
			defaultNum="none"
		fi		
	else
		defaultNum="none"
	fi

	valid=0
	until [ ${valid} -ne 0 ]
	do
		if [ ${defaultNum} = "none" ] ; then
			Prompt "${1} [${2} - ${3}]: "
		else

			Prompt "${1} [${2} - ${3}] (default: ${defaultNum}): "
		fi

		read VALUE
		#read ans and if it is empty, initialize it with the default
		VALUE=${VALUE:=${defaultNum}}


		if [ ${VALUE} = "none" ] ; then
			${ECHO} "" >> ${Trace_File} #this way "none" won't be written
		else
			${ECHO} ${VALUE} >> ${Trace_File}
		fi


		#check to see if input is really a number
		echo ${VALUE} | egrep -e \(\^[0-9]\+\$\) > /dev/null

		#if a number & in range
		if [ $? -eq 0 ] ; then
			if [ ${VALUE} -ge ${2} -a ${VALUE} -le ${3} ] ; then
				return
			fi
		fi 

		if [ "${VALUE}" != "none" ] ; then #this handles so that "none" won't be printed to the screen	
			${ECHO} "ERROR: ${VALUE} is invalid input. Please try again."
			${ECHO} ""
		fi
	done
}

# 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}
}"
}

# -----------------------------------------------------------------------------
# Get the base NB type, "NetBackup Enterprise Server" or "NetBackup Server"

get_base_nb () {
	list=`${NB_BIN}/admincmd/bpminlicense -nb_ufid 20 2>/dev/null`
	if [ $? -ne 0 -o "${list}" = ""  ]; then
		${ECHO} 0
	else
		PRID=`${ECHO} ${list} | sed -e 's/.*PRID=//' -e 's/ .*//' `

		if [ ${PRID} = "6" ]; then
			${ECHO} 2
		elif  [ ${PRID} = "7" ]; then
			${ECHO} 1
		else
			${ECHO} 0
		fi
	fi
}
# -----------------------------------------------------------------------------
# Get the base NB key value

get_base_key () {
	list=`${NB_BIN}/admincmd/bpminlicense -nb_ufid 20 2>/dev/null`
	if [ $? -ne 0 -o "${list}" = ""  ]; then
		${ECHO} 0
	else
		${ECHO} ${list} | sed -e 's/.*UKEY=//'
	fi
}
# -----------------------------------------------------------------------------
# Check the directory /usr/lib/X11 for XKeysymDB
#
ck_usr_lib_X11 () {

	if [ -f ${NB_DIR}/client/${1}/xbp ] ; then
		if [ ! -f /usr/lib/X11/XKeysymDB ] ; then
			if [ ! -d /usr/lib ] ; then
				mkdir /usr/lib
			fi
			if [ ! -d /usr/lib/X11 ] ; then
				mkdir /usr/lib/X11
			fi
			cp ${NB_DIR}/client/${1}/XKeysymDB /usr/lib/X11/XKeysymDB
		fi
	fi
}
# -----------------------------------------------------------------------------
# Check the inetdfile for an entry and add it if not there.
#
ck_inetdfile () {

	entry=${1}
	file2check=${2}
	Saved=0

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

		if [ "${HARDWARE}" = "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

		# Tell update_service to inform inetd of a change
		/bin/cp /dev/null ${NB_DIR}/.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 [ -f /etc/xinetd.d/${entry} ] ; then
	/bin/cp /dev/null /tmp/bp_services_updated
else
	# Don't need MACINTOSH check (to set groups) since install_bp
	# is only executed on servers.
	GROUP_LINE=""
	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 ${NB_DIR}/.services_updated

fi
}
# -----------------------------------------------------------------------------
# Copy startup/shutdown scripts to appropriate destination and create links.
# startup/shutdown script can be optionally renamed from previous release if
# new_link_dir and new_link_name are supplied as positional
# parameters 4 and 5, respectively.
#
cp_and_ln_netbackup () {
		init_dir=${1}
		link_dir=${2}
		link_name=${3}
		new_link_dir=${4}
		new_link_name=${5}

		# If link name does not begin with S, it is a shutdown
		# script. This is a text variable used in user messages.
		suffix=`${ECHO} ${link_name} | sed -e 's/^S//'`
		if [ "${suffix}" = "${link_name}" ]; then
			script_type="shut down"
		else
			script_type="start up"
		fi

		# local status variable
		RESULT=0

		if [ -d ${init_dir} -a -d ${link_dir} ]; then

		# save original startup script in init_dir (init.d),
		# rather than link_dir
		# because all scripts in link_dir (rc[0-9].d)
		# are run at system startup/shutdown

		# If a startup script has been previously installed
		# and has not already been saved as
		# $init_dir/script_name.timestamp, then save the
		# one previously installed as $init_dir/script_name.timestamp
		# and remove the link to it.
		# If copy was successful then copy new scripts to init_dir
		# and create links to it from link_dir/link_name.
		# If a copy already is saved, just copy the new one
		# over and create links to it.

		# If 4,5th parameter is supplied then a link is being
		# renamed.  If a link is renamed, remove the old link
		# using $link_dir/$link_name (deletion purpose) and create
		# new link using $new_link_dir/$new_link_name (creation purpose).
		# In case this script is rerun after the name change,
		# $link_dir/$link_name (deletion purposes)
		# is set to the value of
		# $new_link_dir/$new_link_name (creation purposes).
		# When there is no name change, $new_link_dir/$new_link_name
		# (creation purpose) is set to the value of
		# $link_dir/$link_name (deletion purpose).

			if [ -n "${new_link_name}" ] && \
			   [ -n "${new_link_dir}" ] && \
			   [ -f ${new_link_dir}/${new_link_name} ] ; then
				link_name=${new_link_name}
				link_dir=${new_link_dir}
			elif [ -z "${new_link_dir}" ]; then
				new_link_name=${link_name}
				new_link_dir=${link_dir}
			fi
			if [ -f ${link_dir}/${link_name} ] && [ ! -f ${init_dir}/${link_name}.${dt} ] ; then
				${ECHO} "
Copying NetBackup ${link_name} script found in ${link_dir} directory
to ${init_dir}/${link_name}.${dt} for future reference.
Any local modifications to ${link_name} should be re-evaluated.
"
				cp ${link_dir}/${link_name} ${init_dir}/${link_name}.${dt}
				RESULT=$?
				if [ ${RESULT} != 0 ]; then
					${ECHO} "ERROR copying NetBackup ${link_dir}/${link_name} script to ${init_dir}/${link_name}.${dt}."
				else
					rm ${link_dir}/${link_name}
				fi
			fi
			if [ ${RESULT} = 0 ]; then
				cp -f ${NB_BIN}/goodies/netbackup ${init_dir}/netbackup
				RESULT=$?
				if [ ${RESULT} -eq 0 ]; then
					rm -f ${link_dir}/${link_name}
					ln -s ${init_dir}/netbackup ${new_link_dir}/${new_link_name}
					RESULT=$?
					if [ ${RESULT} -eq 0 ]; then
						${ECHO} "
To make NetBackup ${script_type} automatically when
the system is restarted, the netbackup script found in
${NB_BIN}/goodies has been placed in ${init_dir},
with links to it placed in the ${link_dir} directory.
"
					fi
				fi
			fi
			if [ ${RESULT} != 0 ] ; then
				${ECHO} "
ERROR copying ${NB_BIN}/goodies/netbackup to ${init_dir}
and/or linking to it from ${new_link_dir}/${new_link_name} !
"
			fi
		else
			${ECHO} "
ERROR: ${init_dir} or ${link_dir} not found.
Unable to copy ${NB_BIN}/goodies/netbackup to ${init_dir}
and/or link to it from ${new_link_dir}/${new_link_name} !
"
		fi
}
# -----------------------------------------------------------------------------
# Wait for a daemon to start.
#
wait_for_daemon ()
{
	daemon=${1}
	Waited=0
	while [ ${Waited} -lt 30 ]
	do
		sleep 2
		Waited=`expr ${Waited} + 2`
		${PS} | grep ${daemon} | grep -v grep > /dev/null
		if [ $? = 0 ] ; then
			break
		fi
	done
	if [ ${Waited} = 30 ] ; then
		${ECHO} "
The NetBackup daemon process (${daemon}) was not started.
Check the services configuration -- files, YP, NIS, or NIS+."
		continue_or_quit
	fi
}


# -----------------------------------------------------------------------------
# determines solaris platform
is_solaris_platform ()
{
	case `uname -s` in
		SunOS*)  return 0 ;;
	esac
	return 1
}
################################# MAIN ########################################


# Make sure this is being run from root.

ISROOT=`id | egrep "^uid=0\("`
if [ "${ISROOT}" = "" ] ; then
	${ECHO} "
This must be run while logged in as root.
"
	exit 1
fi

# This is kludgey but we need a tab to use in regular expressions
# and we want it to be obvious and not get broken accidentally.

TAB=`${ECHO} ' ' | tr ' ' '\011'`
SPACE=' '

# Attempt to keep information about architecture dependent commands
# and file locations here.

NB_DIR=/usr/openv/netbackup
NB_BIN=/usr/openv/netbackup/bin
VM_BIN=/usr/openv/volmgr/bin
inetdfile=/etc/inetd.conf; export inetdfile
PS='/bin/ps -ea'; export PS
TMPDIR=${TMPDIR:-/tmp}
dt=NBU_`/bin/date +"%m%d%y.%T"`
LC_ALL=C
export LC_ALL

if [ $# != 0 ] ; then
	Trace_File=${1}
else
	Trace_File=/dev/null
fi

# In case this was a solaris alternate root installation, create
# link now.
#
if is_solaris_platform; then
	if [ ! -h /usr/openv ] && [ ! -d /usr/openv ] ; then
		BASEDIR=`pkginfo -r VRTSnetbp`
		${ECHO} "
    Creating link from /usr/openv to ${BASEDIR}/openv.
"
		ln -s ${BASEDIR}/openv /usr/openv
		if [ $? != 0 ]; then
                	echo "
Unable to create link from /usr/openv to ${BASEDIR}/openv.
Rerun ${NB_BIN}/install_bp when the problem has been resolved."
		exit 1
		fi
	fi
fi


if [ -f ${NB_DIR}/version ] ; then
	HARDWARE=`head -1 ${NB_DIR}/version | cut -f2 -d" "`
else
	HARDWARE=NONE
fi

# Figure out MACHINE/PLATFORM for this server
# so that we can cd to the appropriate netbackup/client/$MACHINE/$PLATFORM
# subdirectory before calling cp_to_client -CopyOnly.
Install_sg=FALSE
Install_JAVA=TRUE
Make_SCSI_Dev=FALSE
PLATFORM=nosupport
Client_bins_copied=FALSE
case "${HARDWARE}" in
	ALPHA)
		MACHINE=ALPHA
		OS_f1=`uname -r | cut -f1 -d"."`
		if [ "${OS_f1}" = "V5" ] || [ "${OS_f1}" = "T5" ]  ; then
			PLATFORM=OSF1_V5
		fi
		;;
	HP*)
		MACHINE=HP9000-800
		OS_f1=`uname -r | cut -f2 -d"."`
		OS_f2=`uname -r | cut -f3 -d"."`
		if [ "${OS_f1}" = "11" -a "${OS_f2}" = "00" ] ; then
			PLATFORM=HP-UX11.00
		elif [ "${OS_f1}" = "11" -a "${OS_f2}" -ge "11" ] ; then
			PLATFORM=HP-UX11.11
		fi
		;;

	LINUX)
		MACHINE=Linux
		OS_f1=`uname -r | cut -f1 -d"."`
		OS_f2=`uname -r | cut -f2 -d"."`
		if [ "${OS_f1}" = "2" -a "${OS_f2}" -ge "4" ] ; then
			PLATFORM=RedHat2.4
		fi
		Make_SCSI_Dev=TRUE
		;;

	RS6000)
		MACHINE=RS6000
		OS=`oslevel | cut -f1-3 -d"." | sed -e 's/\.//g' `
		if [ "${OS}" -ge "433" -a "${OS}" -lt "510" ] ; then
			PLATFORM=AIX4.3.3
		elif [ "${OS}" -ge "510" ] ; then
			PLATFORM=AIX5
		fi
		;;
	SGI)
		MACHINE=SGI
		Install_JAVA=FALSE
		if [ -f /usr/etc/inetd.conf ] ; then
			inetdfile=/usr/etc/inetd.conf
		fi
		PATH="/usr/sbin:/usr/bsd:/bin:/usr/bin:${PATH}"
		OS_f1=`uname -r | cut -f1 -d"."`
		OS_f2=`uname -r | cut -f2 -d"."`
		if [ "${OS_f1}" = "6" -a "${OS_f2}" -ge "5" ] ; then
			PLATFORM=IRIX65
		fi
		;;
	SOLARIS)
		MACHINE=Solaris
		Install_sg=TRUE
		OS_f1=`uname -r | cut -f1 -d"."`
		OS_f2=`uname -r | cut -f2 -d"."`
		if [ "${OS_f1}" = "5" ]; then
			if [ "${OS_f2}" -ge "7" -a "${OS_f2}" -lt "9" ] ; then
				PLATFORM=Solaris7
				os_bits=`isainfo -nv`
				${ECHO} ${os_bits} | grep "386" > /dev/null 2>&1
				if [ $? -eq 0 ] ; then
					PLATFORM=Solaris_x86_7
				fi
			elif  [ "${OS_f2}" -ge "9" ]; then
				PLATFORM=Solaris9
			fi
		fi
		;;
	*)
		${ECHO} "
Unknown hardware type: \"${HARDWARE}\".
"
		exit 2
		;;
esac

if [ "${PLATFORM}" = "nosupport" ] ; then
	${ECHO} "
Unknown platform type: \"${PLATFORM}\".
"
	exit 2
fi

# Move client bins to install location.
if [ -d /usr/openv/netbackup/client/${MACHINE}/${PLATFORM} ]; then
	${ECHO} "
Copying ${PLATFORM} Client Binaries"
	(
	cd /usr/openv/netbackup/client/${MACHINE}/${PLATFORM}
	./cp_to_client -CopyOnly
	)
	if [ $? -ne 0 ] ; then
		${ECHO} "
A failure was detected running cp_to_client ${MACHINE} ${PLATFORM}.
Rerun ${NB_BIN}/install_bp when the problem has been resolved."
		exit 1
	else
		Client_bins_copied=TRUE
	fi
fi

# If we're upgrading, from what level?
if [ -f ${NB_DIR}/.upgrade.to.${RELEASE} ] ; then
	Old_BaseNB=`cat ${NB_DIR}/.upgrade.to.${RELEASE} | grep VERSION | awk '{print $3}' | cut -c1,3`
fi

default_key=""
if [ -f /usr/openv/var/license.txt ] ; then
	cp /usr/openv/var/license.txt /usr/openv/var/license.txt.pre.${RELEASE}
	Old_BaseNB=`get_base_nb`
	if [ "${Old_BaseNB}" = "0" ]; then
		${ECHO} "
ERROR: No valid license key for NetBackup Enterprise Server or NetBackup Server."
	else
		default_key=`get_base_key`
	fi
fi

BaseNB=0
while [ ${BaseNB} -ne 1 -a ${BaseNB} -ne 2 ] ; do
	${ECHO}
	${NB_BIN}/admincmd/get_license_key -I ${default_key}
	BaseNB=`get_base_nb`
done


${ECHO} "
All additional keys should be added at this time."
if confirm y "Do you want to add additional license keys now?"
then
	${NB_BIN}/admincmd/get_license_key
else
	${ECHO} "
Use ${NB_BIN}/admincmd/get_license_key
to add, delete or list license keys at a later time."
fi

Prompt "
Installing NetBackup "
if [ ${BaseNB} = 1 ] ; then
	NBUServer=Yes
	${ECHO} "Server version: ${RELEASE}"
	if [ -f ${NB_DIR}/.upgrade.to.${RELEASE} ] ; then
		# We still have a problem that will have to be resolved in a
		# future release.  There is the situation where the license
		# key has expired, in which case we do not know if the key
		# is a Enterprise key (DataCenter) or server (BusinesServer).
		# If the key is server we are ok, they are just upgrading
		# with a new server key, but if the old key is a Enterprise
		# (DataCenter) key we shouldn't allow this upgrade.
		if [ "${Old_BaseNB}" = 2 ] ; then
			rm -f /usr/openv/var/license.txt
			if [ -f /usr/openv/var/license.txt.pre.${RELEASE} ] ; then
				mv /usr/openv/var/license.txt.pre.${RELEASE} /usr/openv/var/license.txt
			fi
			${ECHO} "
ERROR:	Proceeding with this upgrade would result in the loss of some current
	capabilities, configuration options and the loss of some metadata.

	To install NetBackup Server, the current installation of
	NetBackup Enterprise (DataCenter) must first be removed.

	You may also rerun $0 and enter a NetBackup Enterprise key when asked.
"
			exit 48
		fi
	fi
elif [ ${BaseNB} = 2 ] ; then
	NBUServer=No
	${ECHO} "Enterprise Server version: ${RELEASE}"
else
	# error in get license, we can't continue
	${ECHO} "Cannot continue without a valid license."
	rm -f /usr/openv/var/default.txt
	exit 3
fi
rm -f /usr/openv/var/license.txt.pre.${RELEASE}

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

# hostnm is going to stay the real hostname of the machine.
# my_host is going to float with whatever the name of this
# machine is.  Could be hostname, could be a virtual name,
# could be something entered in by the user.  host starts
# out the hostname but could change depending on the install.

hostnm=${host}
my_host=${hostnm}

# Get the domainname without a leading '.' (if there is one).
domain=`domainname | sed 's/^\.//'`

server_type=""
virtual_name=0
master_name=""
cluster_name=""
req_int_name=""
server_found=""

# Now that virtual names are possible, a machine can only be a
# master if:  a) there is a CLUSTER_NAME entry and its value
# matches the 1st valid SERVER entry, b) there is a REQUIRED_INTERFACE
# entry and its value matches the 1st valid SERVER entry or
# c) no CLUSTER_NAME or REQUIRED_INTERFACE entry and the 1st valid
# SERVER entry value is equal to hostname.  Media servers can also
# be clustered.
#
# When checking for a SERVER entry, make sure I'm looking for the
# right name (i.e. account for virtual names).
#
# When making comparisons between bp.conf entries and host names, use
# all lower case as hostnames are supposed to be case insensitive.
# However, use the real values for everything else.

if [ -f ${NB_DIR}/bp.conf ] ; then
	lc_host=`${ECHO} ${host} | tr "[:upper:]" "[:lower:]"`

	cluster_name=`tr -d ' \011' < ${NB_DIR}/bp.conf | \
		grep "^CLUSTER_NAME" | tail -1 | cut -f2 -d"=" | cut -f1 -d"."`

	lc_cluster_name=`${ECHO} ${cluster_name} | tr "[:upper:]" "[:lower:]"`

	req_int_name=`tr -d ' \011' < ${NB_DIR}/bp.conf | \
		grep "^REQUIRED_INTERFACE" | tail -1 | cut -f2 -d"=" | cut -f1 -d"."`

	lc_req_int_name=`${ECHO} ${req_int_name} | tr "[:upper:]" "[:lower:]"`

	server_1=`tr -d ' \011' < ${NB_DIR}/bp.conf | \
		grep "^SERVER=" | head -1 | cut -f2 -d"=" | cut -f1 -d"."`

	lc_server_1=`${ECHO} ${server_1} | tr "[:upper:]" "[:lower:]"`

	if [ "${lc_cluster_name}" != "" -a "${lc_req_int_name}" != "" ] ; then
		${ECHO} "
/usr/openv/netbackup/bp.conf cannot contain CLUSTER_NAME and
REQUIRED_INTERFACE entries.  REQUIRED_INTERFACE entries are used to
select a different network interface than the default.  CLUSTER_NAME
entries are used to specify the virtual name of a cluster.  Please
refer to the NetBackup System Administrator's Guide, Volume 2 and
the NetBackup High Availability Guide for more information.  Rerun
/usr/openv/netbackup/bin/install_bp after the problem has been resolved.
"
		exit 1
	elif [ "${lc_cluster_name}" != "" -a  "${NBUServer}" = "Yes" ] ; then
		${ECHO} "
/usr/openv/netbackup/bp.conf contains a CLUSTER_NAME entry.  Clustering
is not supported for machines running NetBackup Server.  Rerun
/usr/openv/netbackup/bin/install_bp after the problem has been resolved.
"
		exit 1
	fi

	if [ "${lc_server_1}" = "${lc_host}" -o \
	     \( "${lc_cluster_name}" != "" -a "${lc_server_1}" = "${lc_cluster_name}" \) -o \
	     \( "${lc_req_int_name}" != "" -a "${lc_server_1}" = "${lc_req_int_name}" \) ] ; then
		server_type="master"
		if [ "${lc_server_1}" != "${lc_host}" ] ; then
			virtual_name=1
			my_host=${server_1}
		fi
	else
		server_type="media"
		if [ "${lc_cluster_name}" != "" -a "${lc_cluster_name}" != "${lc_host}" ] ; then
			virtual_name=1
			my_host=${cluster_name}
		elif [ "${lc_req_int_name}" != "" -a "${lc_req_int_name}" != "${lc_host}" ] ; then
			virtual_name=1
			my_host=${req_int_name}
		fi
	fi
	master_name="${server_1}"
	server_found=`egrep "^[${SPACE}${TAB}]*SERVER[${SPACE}${TAB}]*=[${SPACE}${TAB}]*${my_host}" ${NB_DIR}/bp.conf`
fi

# not a master or there was no bp.conf
if [ "${server_type}" != "master" ] ; then

	if [ "${server_found}" = "" ] ; then
		# If we have a domainname and the server name was not in the
		# bp.conf file, suggest the fully qualified host name. If the
		# default name is not desired, they can enter in a name.
		# Note the name they enter could be a virtual hostname.
		${ECHO} "


If this machine will be using a different network interface than the
default (${hostnm}), the name of the preferred interface should be used
as the configured server name.  If this machine will be part of a
cluster, the virtual name should be used as the configured server name."
		if [ "${domain}" != "" ] ; then
			${ECHO} "
The domainname of your server appears to be \"${domain}\".
You may choose to use this domainname in your configured NetBackup server
name, or simply use \"${host}\" as the configured NetBackup server name.

Would you like to use \"${host}.${domain}\" as the configured"
		else
			${ECHO} "
Would you like to use \"${host}\" as the configured"
		fi
		if confirm y "name of the NetBackup server?"
		then
			if [ "${domain}" != "" ] ; then
				host=${host}.${domain}
			fi
		else
			Prompt "
Enter the name of the NetBackup server: "
			read host
			${ECHO} ${host} >> ${Trace_File}
		fi
		# A media or master name can be virtual (the name for
		# this machine does not match the hostname output).
		# Be case insensitive on the compare of hostnames.
		short_name=`${ECHO} ${host} | sed 's/\..*$//' | tr "[:upper:]" "[:lower:]"`
		lc_host=`${ECHO} ${hostnm} | tr "[:upper:]" "[:lower:]"`
		if [ "${short_name}" != "${lc_host}" ] ; then
			virtual_name=1
		fi

		my_host=${host}

		# Set up the bp.conf file.
		/bin/rm -rf ${TMPDIR}/bp.conf.new

		if [ ${NBUServer} = Yes ] ; then
			server_type="master"
			master_name="${host}"
			if [ ! -f ${NB_DIR}/bp.conf ] ; then
				${ECHO} "SERVER = ${host}" >${NB_DIR}/bp.conf
				${ECHO} "CLIENT_NAME = ${hostnm}" >>${NB_DIR}/bp.conf
			else
				server_found=`egrep "^[${SPACE}${TAB}]*SERVER[${SPACE}${TAB}]*=[${SPACE}${TAB}]*${host}" ${NB_DIR}/bp.conf`

				if [ "${server_found}" = "" ] ; then
					# Fully qualified server is not in bp.conf - add it.
					${ECHO} "SERVER = ${host}" >${TMPDIR}/bp.conf.new
					/bin/cat ${NB_DIR}/bp.conf >>${TMPDIR}/bp.conf.new
					/bin/cp ${TMPDIR}/bp.conf.new ${NB_DIR}/bp.conf
				fi
			fi
		else
			# SGI is no longer supported as a master server in NB 5.0
			# If the machine is SGI, it must be a media server install.

			${ECHO} ""
			master_prompt=no
			if [ "${MACHINE}" != "SGI" ] ; then
				if confirm y "Is ${host} the master server?"
				then
					master_prompt=yes
				fi
			fi
			if [ "${master_prompt}" = "yes" ] ; then
				server_type="master"
				master_name="${host}"
				if [ ! -f ${NB_DIR}/bp.conf ] ; then
					${ECHO} "SERVER = ${host}" >${NB_DIR}/bp.conf
					if confirm n "Do you have any media servers?"
					then
						${ECHO} " "
						finished=0
						while [ ${finished} != 1 ]
						do
							Prompt "Enter the fully qualified name of a media server (q to quit): "
							read mediaserver
							${ECHO} ${mediaserver} >> ${Trace_File}
							if [ "${mediaserver}" = "q" ] ; then
								finished=1
							else
								${ECHO} "SERVER = ${mediaserver}" >>${NB_DIR}/bp.conf
							fi
						done
					fi

					${ECHO} "CLIENT_NAME = ${hostnm}" >>${NB_DIR}/bp.conf
				else
					server_found=`egrep "^[${SPACE}${TAB}]*SERVER[${SPACE}${TAB}]*=[${SPACE}${TAB}]*${host}" ${NB_DIR}/bp.conf`

					if [ "${server_found}" = "" ] ; then
						# Fully qualified server is not in bp.conf - add it.
						${ECHO} "SERVER = ${host}" >${TMPDIR}/bp.conf.new
						/bin/cat ${NB_DIR}/bp.conf >>${TMPDIR}/bp.conf.new
						/bin/cp ${TMPDIR}/bp.conf.new ${NB_DIR}/bp.conf
					fi
				fi
			else
				server_type="media"
				Prompt "
What is the fully qualified name of the master server? "
				read master_name
				${ECHO} ${master_name} >> ${Trace_File}

				if [ ! -f ${NB_DIR}/bp.conf ] ; then
					${ECHO} "SERVER = ${master_name}" >${NB_DIR}/bp.conf
					${ECHO} "SERVER = ${host}" >>${NB_DIR}/bp.conf
				else
					master_found=`egrep "^[${SPACE}${TAB}]*SERVER[${SPACE}${TAB}]*=[${SPACE}${TAB}]*${master_name}" ${NB_DIR}/bp.conf`
					server_found=`egrep "^[${SPACE}${TAB}]*SERVER[${SPACE}${TAB}]*=[${SPACE}${TAB}]*${host}" ${NB_DIR}/bp.conf`

					if [ "${master_found}" = "" ] ; then
						# No master in the bp.conf file. Add master first.
						${ECHO} "SERVER = ${master_name}" >${TMPDIR}/bp.conf.new
						if [ "${server_found}" = "" ] ; then
							${ECHO} "SERVER = ${host}" >>${TMPDIR}/bp.conf.new
						fi

						/bin/cat ${NB_DIR}/bp.conf >>${TMPDIR}/bp.conf.new
						/bin/cp ${TMPDIR}/bp.conf.new ${NB_DIR}/bp.conf
					else
						/bin/rm -rf ${TMPDIR}/bp.conf.new

						# Copy existing SERVERs into ${TMPDIR}/bp.conf.new
						egrep "^[${SPACE}${TAB}]*SERVER[${SPACE}${TAB}]*=" ${NB_DIR}/bp.conf >${TMPDIR}/bp.conf.new

						if [ "${server_found}" = "" ] ; then
							# Add media server to ${TMPDIR}/bp.conf.new
							${ECHO} "SERVER = ${host}" >>${TMPDIR}/bp.conf.new
						fi

						# Append non SERVER lines to ${TMPDIR}/bp.conf.new
						/bin/cat ${NB_DIR}/bp.conf |
						while read FILE
						do
							# If $FILE is not blank.
							if [ "${FILE}" != "" ] ; then
								# Get values of $FILE into $1, $2, $3.
								set ${FILE}
								ID=$1

								if [ "${ID}" != "SERVER" ] ; then
									${ECHO} "${FILE}" >>${TMPDIR}/bp.conf.new
								fi
							else
								${ECHO} "${FILE}" >>${TMPDIR}/bp.conf.new
							fi
						done

						# Replace old bp.conf with ${TMPDIR}/bp.conf.new
						/bin/cp ${TMPDIR}/bp.conf.new ${NB_DIR}/bp.conf
					fi
				fi # bp.conf
			fi # master server
		fi # NBUServer
	fi # server_found
fi # master_name

# Find out if we're on an active node.  A standalone machine is
# considered active; however, on an initial install if the name
# is a virtual one, reset to inactive.  Also check cluster_name and
# req_int_name as they would potentially have a value on a re-install
# but should not on an initial install.  The daemons will not
# come up anyway and it saves some heartache.  Clustering does
# not apply to NetBackup Server (previously known as BusinesServer).

inactive=0
if [ "${NBUServer}" != "Yes" ] ; then
	${NB_BIN}/cluster/cluster_active > /dev/null 2>&1
	inactive=$?
	if [ ${inactive} -eq 0 -a ! -f ${NB_DIR}/.upgrade.to.${RELEASE} -a \
	     ${virtual_name} -eq 1 -a "${cluster_name}" = "" -a \
	     "${req_int_name}" = "" ] ; then
		inactive=1
	fi
fi

# Remove client directory if NetBackup Media server installation.
# If this is a NetBackup Master Server and Client Bins were not copied,
# report error.  This case should never happen unless the NB_DIR/client
# directory was deleted manually. 

if [ "${server_type}" = "media" ] ; then
	/bin/rm -rf ${NB_DIR}/client
elif [ "${server_type}" = "master" ] ; then
	if [ ${Client_bins_copied} = FALSE ]; then 
		 $ECHO "
Error in client binary installation.   
/usr/openv/netbackup/client/${MACHINE}/${PLATFORM} does not exist.  Aborting ...
Rerun ${NB_BIN}/install_bp when the problem has been resolved."
		exit 1
	fi
fi

/bin/rm -f ${TMPDIR}/bp.conf.new
chgrp bin ${NB_DIR}/bp.conf
chmod 644 ${NB_DIR}/bp.conf

if [ -d ${NB_DIR} ] ; then
	mkdir -p ${NB_DIR}/db/jobs 2> /dev/null
	mkdir -p ${NB_DIR}/db/media 2> /dev/null
	mkdir -p ${NB_DIR}/db/images 2> /dev/null
fi

# Add /usr/openv/var to file that lists directories for NetBackup DB backups
SYNC=${NB_DIR}/db/config/sync
if [ -f ${SYNC} ] ; then
	grep \/openv/\var ${SYNC} > /dev/null 2>&1
	if [ $? != 0 ] ; then
		# /usr/openv/var not found in sync file, add it before volmgr
		sed -e 's/ \/usr\/openv\/volmgr/ \/usr\/openv\/var \/usr\/openv\/volmgr/' < ${SYNC} > ${SYNC}.new
		if [ $? = 0 ] ; then
			${ECHO} "
Adding /usr/openv/var to NetBackup DB backups."
			mv ${SYNC}.new ${SYNC}
		else
			rm -f ${SYNC}.new
		fi
	fi
fi

# Create links for X application resource files.
# As of NB R3.1, all x apps use the same resource file.
if [ -d /.dt -o -d /.vue ] ; then
	XRESOURCE_EXT=.dt
else
	XRESOURCE_EXT=""
fi
${ECHO} " "
XNB_BP_XRES=${NB_BIN}/XNB${XRESOURCE_EXT}
if [ -d /usr/lib/X11/app-defaults ] ; then
	if [ ! -f /usr/lib/X11/app-defaults/XNB -a -f ${XNB_BP_XRES} ] ; then
		${ECHO} "Linking /usr/lib/X11/app-defaults/XNB --> ${XNB_BP_XRES}
"
                rm -f /usr/lib/X11/app-defaults/XNB
		ln -s ${XNB_BP_XRES} /usr/lib/X11/app-defaults/XNB
	fi
elif [ -d /usr/openwin/lib/app-defaults ] ; then
	if [ ! -f /usr/openwin/lib/app-defaults/XNB -a -f ${XNB_BP_XRES} ] ; then
		${ECHO} "Linking /usr/openwin/lib/app-defaults/XNB --> ${XNB_BP_XRES}
"
                rm -f /usr/openwin/lib/app-defaults/XNB
		ln -s ${XNB_BP_XRES} /usr/openwin/lib/app-defaults/XNB
	fi
fi

# If the sysadm hasn't removed the xbp binary, install it on the server.
case "${HARDWARE}" in
	ALPHA)	ck_usr_lib_X11 "ALPHA/OSF1_V5"
		;;
	HP*)	ck_usr_lib_X11 "HP9000-700/HP-UX11.00"
		;;
	LINUX*) ck_usr_lib_X11 "Linux/RedHat2.4"
		;;
	SGI)	ck_usr_lib_X11 "SGI/IRIX65"
		;;
	SOLARIS)	ck_usr_lib_X11 "Solaris/Solaris7"
		;;
esac

# Add our daemons to the /etc/xinetd.d directory if necessary.
# Linux servers are currently the only ones using xinetd.
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
	if [ -f ${inetdfile} ] ; then

		# 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}
	else
		${ECHO} "
ERROR:	/etc/xinetd.d or /etc/xinetd.conf and ${inetdfile} do not exist.
	inetd/xinetd does not appear to be installed.
	NetBackup requires inetd/xinetd for communication between daemons."
		continue_or_quit
	fi
fi

${ECHO} ""
${NB_BIN}/update_services
${NB_BIN}/merge_auth_templates

# Copy the Startup and Shutdown scripts.

case "${HARDWARE}" in
	ALPHA)
		cp_and_ln_netbackup /sbin/init.d /sbin/rc3.d S77netbackup
		cp_and_ln_netbackup /sbin/init.d /sbin/rc0.d K77netbackup /sbin/rc0.d K01netbackup
		;;
	HP*)
		cp_and_ln_netbackup /sbin/init.d /sbin/rc2.d S777netbackup
		cp_and_ln_netbackup /sbin/init.d /sbin/rc0.d K777netbackup /sbin/rc1.d K001netbackup
		;;
	LINUX*)
		cp_and_ln_netbackup /etc/rc.d/init.d /etc/rc.d/rc2.d S77netbackup
		cp_and_ln_netbackup /etc/rc.d/init.d /etc/rc.d/rc3.d S77netbackup
		cp_and_ln_netbackup /etc/rc.d/init.d /etc/rc.d/rc5.d S77netbackup
		cp_and_ln_netbackup /etc/rc.d/init.d /etc/rc.d/rc0.d K77netbackup /etc/rc.d/rc0.d K01netbackup
		cp_and_ln_netbackup /etc/rc.d/init.d /etc/rc.d/rc6.d K77netbackup /etc/rc.d/rc6.d K01netbackup
		;;
	RS6000)
		if [ -f /etc/rc.veritas.aix ] ; then
			cp /etc/rc.veritas.aix /etc/rc.veritas.aix.${dt}
			${ECHO} "
Copying NetBackup startup script rc.veritas.aix found in /etc directory
to /etc/rc.veritas.aix.${dt} for future reference.  Any local
modifications to rc.veritas.aix should be re-evaluated.
"
		fi
		${ECHO} "
To make NetBackup start up automatically when the system is restarted,
the netbackup script found in ${NB_BIN}/goodies has been copied
to /etc/rc.veritas.aix.  You must modify /etc/inittab to include it.
"
		cp ${NB_BIN}/goodies/netbackup /etc/rc.veritas.aix
		;;
	SGI)
		cp_and_ln_netbackup /etc/init.d /etc/rc2.d S91netbackup
		cp_and_ln_netbackup /etc/init.d /etc/rc0.d K91netbackup /etc/rc0.d K01netbackup
		;;
	*)
		cp_and_ln_netbackup /etc/init.d /etc/rc2.d S77netbackup
		cp_and_ln_netbackup /etc/init.d /etc/rc0.d K77netbackup /etc/rc0.d K01netbackup
		;;
esac

# Install/configure NB-Java
if [ ${Install_JAVA} = TRUE ] ; then
	/usr/openv/NB-Java.install /usr/openv/NB-Java.tar.Z
	if [ $? -ne 0 ] ; then
		${ECHO} "
Installing Java failed.  Aborting ...
Rerun ${NB_BIN}/install_bp when the problem has been resolved."
		exit 4
	fi
fi

if [ $Install_sg = TRUE ]; then
	if [ -x ${VM_BIN}/driver/sg.install ] ; then

		#  Cannot abort if sg.install fails since there legitimately
		#  may be no SCSI devices on the machine.

		${VM_BIN}/driver/sg.install
	else
		$ECHO "
Problem with installation of NetBackup binaries.
${VM_BIN}/driver/sg.install is missing or not executable.
Rerun ${NB_BIN}/install_bp when the problem has been resolved."
		exit 4
	fi
fi
if [ ${Make_SCSI_Dev} = TRUE ] ; then
	${VM_BIN}/make_scsi_dev
fi

$ECHO

IS_NETBACKUP_DAEMON=YES
export IS_NETBACKUP_DAEMON

${VM_BIN}/vmd >/dev/null 2>&1

start_bpdbm=0
# Set up the global database.  Use real hostname for -h not a virtual one.
${VM_BIN}/vmoprcmd -h ${hostnm} -autoconfig "-get_gdbhost" > /dev/null 2>&1
vm_stat=$?
if [ "${server_type}" = "master" ] ; then
	if [ ${vm_stat} != 0 ] ; then
		if [ ${NBUServer} = Yes ] ; then
			gdbhost=${master_name}
		else
			Prompt "
In order for device discovery and auto-configuration to work properly in a
NetBackup Enterprise environment, particularly where peripherals are
connected to multiple servers, one host must serve as the repository for
global device database information.

Enter which host will store the global device database.
(default: ${master_name}): "
			read gdbhost
			${ECHO} ${gdbhost} >> ${Trace_File}
			if [ "${gdbhost}" = "" ] ; then
				gdbhost=${master_name}
			fi
		fi
		${VM_BIN}/vmoprcmd -h ${hostnm} -autoconfig "-set_gdbhost ${gdbhost}" > /dev/null 2>&1
		if [ $? != 0 ] ; then
			${ECHO} "
Set global device database host failed.
"
		fi
	fi

	# For initial NetBackup Server (previously known as BusinesServer)
	# master server installs or a master server upgrade on an active
	# node, start up bpdbm.  For initial Enterprise (previously known
	# as DataCenter) master server installs, only offer to start bpdbm
	# if on an active node.  And if it appears this is an initial
	# Enterprise install using a virtual name, use bpclntcmd to see
	# if the name is a local one (as in a REQUIRED_INTERFACE) versus
	# one expected to be used in a cluster.  Need to do the templates
	# if REQ_INT but cluster_config will do it in the cluster case.

	if [ ${NBUServer} = Yes ] ; then
		start_bpdbm=1
	elif [ ${inactive} -eq 0 -a -f ${NB_DIR}/.upgrade.to.${RELEASE} ] ; then
		start_bpdbm=1
	elif [ ${inactive} -eq 0 ] ; then
		${ECHO} "
To be able to install the client software the NetBackup
processes need to be started. Do you want to start the"
		if confirm y "NetBackup processes so client software can be installed?"
		then
			start_bpdbm=1
		fi
	else
		${NB_BIN}/bpclntcmd -is_local_host ${my_host} > /dev/null 2>&1
		if [ $? -eq 0 -a ! -f ${NB_DIR}/.upgrade.to.${RELEASE} -a \
		     ${inactive} -eq 1 ] ; then
			start_bpdbm=1
		fi
	fi

	#  Clean up possible file left over from a previous install.
	rm -f ${NB_BIN}/cluster/.do_templates

	if [ ${start_bpdbm} = 1 ] ; then
		${ECHO} "
Starting the NetBackup database manager process (bpdbm).
"
		${NB_BIN}/initbpdbm
		wait_for_daemon bpdbm

		if [ ! -f ${NB_DIR}/.upgrade.to.${RELEASE} ] ; then
			if [ ${NBUServer} = Yes ] ; then
				${ECHO} "Creating policy and schedule examples that you can view or use
when you are configuring your own policies and schedules."
				${NB_BIN}/goodies/pltemplates netbackup
			else
				${ECHO} "Do you want to create policy and schedule examples that you can view or use"
				if confirm y "when you are configuring your own policies and schedules?"
				then
					${NB_BIN}/goodies/pltemplates netbackup
				fi
			fi
			${NB_BIN}/goodies/pltemplates lotus_notes ms_exchange windows2000 ms_sharepoint oracle db2
			${ECHO}
		else
			# Typically directive sets are only created during a new install.
			# However, ms_sharepoint and ms_exchange have been changed or are
			# new for 45FP1 and need to be replaced on upgrade installations.
			# oracle and db2 are new in 5.0.

			${NB_BIN}/goodies/pltemplates ms_exchange ms_sharepoint oracle db2
			${ECHO}

			# Make sure we're on an active node or a standalone machine
			# before we allow the user to push to the clients.
			if [ "${NBUServer}" = "Yes" -o ${inactive} -eq 0 ] ; then
				# NOTE update_clients should be run before bprd
				# is started so no backups can start.
				if confirm y "Do you want to update the NetBackup software on the clients?"
				then
					${ECHO} "Starting update_clients script."
					${NB_BIN}/update_clients Install -Install_Client_Bins -Install_Java ALL ALL
					${ECHO} "
Finished update_clients script.
"
				else
					${ECHO} "
You will have to run the ${NB_BIN}/update_clients
script yourself to update the NetBackup software on the clients.
"
				fi
			fi
		fi

		# Do possible conversion of policies dealing with Advanced
		# Client features.

		${NB_BIN}/goodies/bpplconvert -allpolicies
		${ECHO}
	else
		if [ ${inactive} -eq 0 ] ; then
			${ECHO} "
NetBackup bpdbm process not started. You will have to start it
yourself using ${NB_BIN}/initbpdbm before you can
configure your policies and schedules and install the client software.
"
		else
			# bpdbm needs to be up in order to run pltemplates but
			# it won't come up on an inactive node.  Create a
			# script for cluster scripts to run later.
			${ECHO} "#!/bin/sh" > ${NB_BIN}/cluster/.do_templates
			if [ ! -f ${NB_DIR}/.upgrade.to.${RELEASE} ] ; then
				${ECHO} "${NB_BIN}/goodies/pltemplates netbackup lotus_notes windows2000" >> ${NB_BIN}/cluster/.do_templates
			fi
			${ECHO} "${NB_BIN}/goodies/pltemplates ms_exchange ms_sharepoint oracle db2" >> ${NB_BIN}/cluster/.do_templates
			${ECHO} "${NB_BIN}/goodies/bpplconvert -allpolicies" >> ${NB_BIN}/cluster/.do_templates
			chmod +x ${NB_BIN}/cluster/.do_templates
		fi
	fi
else
	if [ ${vm_stat} != 0 ] ; then
		master_name=`tr -d ' \011' < ${NB_DIR}/bp.conf | \
			grep "^SERVER=" | head -1 | cut -f2 -d"="`

		# Find out from the master who has the global db.  If there is one,
		# use that as the default, otherwise use the master name as the
		# default.
		default_gdbhost=`${VM_BIN}/vmoprcmd -h ${master_name} -autoconfig "-get_gdbhost" 2>/dev/null`
		if [ $? -ne 0 ] ; then
			default_gdbhost="${master_name}"
		fi
		Prompt "
Enter global device database host (default: ${default_gdbhost}): "
		read gdbhost
		${ECHO} ${gdbhost} >> ${Trace_File}
		if [ "${gdbhost}" = "" ] ; then
			gdbhost=${default_gdbhost}
		fi
		${VM_BIN}/vmoprcmd -h ${hostnm} -autoconfig "-set_gdbhost ${gdbhost}"
		if [ $? != 0 ] ; then
			${ECHO} "
Set global device database host failed.
"
		fi
	fi
fi

if [ ! -f ${NB_DIR}/.upgrade.to.${RELEASE} ] ; then
	${VM_BIN}/tpautoconf -ready_devices
else
	${VM_BIN}/tpautoconf -upgrade
fi
${ECHO}
${PS} | grep ltid | grep -v grep > /dev/null
if [ $? = 0 ] ; then
	ltid_is_running=1
else
	ltid_is_running=0
fi

# For NetBackup Server master server installs, start up ltid.  For
# Enterprise  master or media servers, don't offer to start ltid
# for initial installs if on an inactive node.
start_ltid=0
if [ ${NBUServer} = Yes ] ; then
	if [ ${ltid_is_running} = 0 ] ; then
		start_ltid=1
	fi
else
	${VM_BIN}/tpconfig -dbconvert 2> /dev/null
	if [ ${ltid_is_running} = 0 ] ; then
		if [ ${inactive} -eq 0 ] ; then
			if confirm y "Do you want to start the Media Manager device daemon processes?"
			then
				start_ltid=1
			fi
		fi
	fi
fi
if [ ${start_ltid} = 1 ] ; then
	${ECHO} "Starting the Media Manager device daemon processes."
	ltidparams=""
	if [ -f ${TMPDIR}/active_nb_processes ] ; then
		ltidparams=`cat ${TMPDIR}/active_nb_processes`
	fi
	${VM_BIN}/ltid ${ltidparams} >/dev/null 2>&1
fi
rm -f ${TMPDIR}/active_nb_processes

${ECHO}
# For NetBackup Server (previously known as BusinesServer)
# master server installs, start up bprd.
# For Enterprise master server installs (DataCenter), only
# offer to start bprd if on an active node.  We do not
# start bprd on media servers.
start_bprd=0
if [ ${NBUServer} = Yes ] ; then
	start_bprd=1
elif [ "${server_type}" = "master" -a ${inactive} -eq 0 ] ; then
	${ECHO} "Do you want to start the NetBackup bprd process so"
	if confirm y "backups and restores can be initiated?"
	then
		start_bprd=1
	fi
fi
if [ ${start_bprd} = 1 ] ; then
	${ECHO} "Starting the NetBackup request daemon process (bprd)."
	${NB_BIN}/initbprd >/dev/null 2>&1
	wait_for_daemon bprd
elif [ "${server_type}" = "master" -a ${inactive} -eq 0 ] ; then
	${ECHO} "
You will have to start bprd using ${NB_BIN}/initbprd
before attempting to do scheduled or manual backups.
"
fi

# Do some cluster related activities.  Clustering is not applicable
# for NetBackup Server (BusinesServer).  Check against cluster_name
# and req_int_name too in order to handle re-installs properly.

if [ ${NBUServer} != Yes ] ; then
	if [ ${inactive} -eq 1 -a ${virtual_name} -eq 1 ] ; then
		if [ ! -f ${NB_DIR}/.upgrade.to.${RELEASE} -a \
		     "${cluster_name}" = "" -a "${req_int_name}" = "" ] ; then
			${ECHO} "
**********************************************************************
********************* ALERT - ACTION REQUIRED ************************
**********************************************************************

This installation could fit one of two scenarios.
Follow the instructions that fit your situation.


**********************************************************************

1.  It appears NetBackup is being installed with the intention of
    using a different network interface than the default (${hostnm}).
    NetBackup daemons will be shut down.  Additional entries must
    be added to /usr/openv/netbackup/bp.conf and
    /usr/openv/volmgr/vm.conf.  The entry and the file affected
    are as follows:

REQUIRED_INTERFACE=${my_host}         (bp.conf)
REQUIRED_INTERFACE=${my_host}         (vm.conf)
DEVICE_HOST=${my_host}                (vm.conf)

    After these entries have been added, the NetBackup and Media
    Manager daemons need to be started.

**********************************************************************

                               OR

**********************************************************************

2.  This machine appears to be a member of a cluster.  NetBackup
    daemons will be shut down.  Do not install any NetBackup add-on
    or database agent products on this machine until after the
    NetBackup server has been configured to run in a cluster.  After
    NetBackup server installation activities have occurred on all
    members of the cluster, execute the following command on the
    primary node:

    /usr/openv/netbackup/bin/cluster/cluster_config

**********************************************************************
"
		else
			${ECHO} "
This machine appears to be a member of a cluster.  NetBackup daemons
will be shut down.  Update any NetBackup add-on or database agent
products that are installed locally on this machine at this time.
When finished, proceed to the next NetBackup node in the cluster.
"
		fi
		${NB_BIN}/goodies/bp.kill_all FORCEKILL > /dev/null 2>&1
	fi
	if [ ${virtual_name} -eq 1 -a "${req_int_name}" = "" -a \
	     \( -f ${NB_DIR}/.upgrade.to.${RELEASE} -o "${cluster_name}" != "" \) ] ; then
		${NB_BIN}/cluster/cluster_upgrade
	fi
else
	if [ ! -f ${NB_DIR}/.upgrade.to.${RELEASE} -a ${virtual_name} -eq 1 -a \
	     "${req_int_name}" = "" ] ; then
		${ECHO} "
**********************************************************************

    It appears NetBackup is being installed with the intention of
    using a different network interface than the default (${hostnm}).
    NetBackup daemons will be shut down.  Additional entries must
    be added to /usr/openv/netbackup/bp.conf and
    /usr/openv/volmgr/vm.conf.  The entry and the file affected
    are as follows:

REQUIRED_INTERFACE=${my_host}         (bp.conf)
REQUIRED_INTERFACE=${my_host}         (vm.conf)
DEVICE_HOST=${my_host}                (vm.conf)

    After these entries have been added, the NetBackup and Media
    Manager daemons need to be started.

**********************************************************************
"
		${NB_BIN}/goodies/bp.kill_all FORCEKILL > /dev/null 2>&1
	fi
fi

${ECHO}
exit 0
