#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos72V src/bos/usr/lib/nim/methods/c_mk_nimclient.sh 1.48.7.7 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1993,2020 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)03 1.48.7.7 src/bos/usr/lib/nim/methods/c_mk_nimclient.sh, cmdnim, bos72V, v2020_18B4 4/28/20 11:59:23

#   COMPONENT_NAME: CMDNIM
#
#   FUNCTIONS: ./usr/lib/nim/methods/c_mk_nimclient.sh
#
#
#   ORIGINS: 27
#
#
#   (C) COPYRIGHT International Business Machines Corp. 1993, 1995
#   All Rights Reserved
#   Licensed Materials - Property of IBM
#   US Government Users Restricted Rights - Use, duplication or
#   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

# include common NIM shell defines/functions
NIMPATH=${0%/*}
NIMPATH=${NIMPATH%/*}
[[ ${NIMPATH} = ${0} ]] && NIMPATH=/usr/lpp/bos.sysmgt/nim
NIM_METHODS="${NIMPATH}/methods"
. ${NIM_METHODS}/c_sh_lib

#---------------------------- local defines     --------------------------------
NIM_CLIENT_OPTIONS="\
	${NIM_CLIENT_PACKAGE} \
	bos.net.tcp.client \
	bos.net.nfs.client"
NIM_DEINSTALL_OPTIONS="\
	bos.sysmgt.nim.master \
	bos.sysmgt.nim.spot"

#---------------------------- module globals    --------------------------------
REQUIRED_ATTRS="hostname ip"
OPTIONAL_ATTRS="snm ring_speed cable_type installp_flags filesets connect"
lpp_source=""
hostname=""
ip=""
snm=""
installp_flags=""
filesets=""
ring_speed=""
cable_type=""
license_msg="Network Installed"
geninstall_cmd=""
connect=""

#---------------------------- change_rc_net     --------------------------------
#
# NAME: change_rc_net
#
# FUNCTION:
#		changes the /etc/rc.net file to configure the client's primary network 
#			interface
#		this function only gets called when MKTCPIP fails
#
# EXECUTION ENVIRONMENT:
#
# NOTES:
#		calls error on failure
#
# RECOVERY OPERATION:
#
# DATA STRUCTURES:
#		parameters:
#		global:
#
# RETURNS: (int)
#		0							= success
#		1							= failure
#
# OUTPUT:
#-------------------------------------------------------------------------------
function change_rc_net {

	typeset pif_name=""
	typeset seqno=""
	typeset rs=""
	typeset ct=""
	typeset i=""
	typeset addr=""
	typeset hname=""
	typeset dest=""
	typeset routing_snm=""
	typeset gateway=""
	[[ -n "${ring_speed}" ]] && rs="-r ${ring_speed}"
	[[ -n "${cable_type}" ]] && ct="-t ${cable_type}"

	# make sure all the NIM_HOSTS are in /etc/hosts
	for i in ${NIM_HOSTS}
	do

		# separate IP address from hostname
		addr=${i%%:*}
		hname=${i##*:}

		# add this hostname if not already in /etc/hosts
		${EGREP} "^${addr}.*${hname}" ${HOSTS} >/dev/null 2>/dev/null || \
			echo "${addr}\t${hname}" >> ${HOSTS}

	done

	# determine logical interface name by first getting the name of the
	#		adapter we booted off of
	pif_name=$( ${BOOTINFO} -b )

	# now, separate logical device name from sequence number
	seqno=${pif_name##*[a-zA-Z]}

	# now, map the logical device name to a logical interface name
	case ${pif_name} in
		tr+([0-9])|tok+([0-9]))	pif_name="tr${seqno}";;
		ent+([0-9]))		pif_name="en${seqno}";;
		hfi+([0-9]))		pif_name="hfi${seqno}";;
		*)			error ${ERR_SYS} "unknown adapter name \"${pif_name}\"";;
	esac

	# first, change the default ring_speed (if necessary)
	if [[ -n "${ring_speed}" ]]
	then

		if ${ODMGET} -qattribute=ring_speed PdAt | \
				${AWK} -v ring_speed=16 \
				'$1 == "deflt" {gsub(/".*"/,ring_speed)};{print}' \
				>${TMPDIR}/pdat 2>${ERR}
		then

			${ODMDELETE} -qattribute=ring_speed -oPdAt 2>${ERR}
			[[ $? -eq 0 ]] && ${ODMADD} ${TMPDIR}/pdat 2>${ERR}
		fi

		if [[ $? -eq 0 ]]
		then

			${SAVEBASE}

		else

			warning_from_cmd "changing default ring_speed"

		fi

	fi

	# change /etc/rc.net
	if ${AWK} -v hostname=${hostname} -v pif_name=${pif_name} -v ip=${ip} \
		-v snm=${snm} \
		'/^#\/bin\/hostname/ {print "/bin/hostname " hostname; next;}; \
		/^#\/usr\/sbin\/ifconfig/ \
			{	if ($2==pif_name) \
		{print "/usr/sbin/ifconfig " pif_name " inet " ip " netmask " snm; next;}\
			else if ($2=="lo0") {$1="/usr/sbin/ifconfig";print;next};}; \
		{ print;}' /etc/rc.net >${TMPDIR}/rc.net 2>${ERR}
	then

		${CAT} ${TMPDIR}/rc.net >/etc/rc.net

	else

		warning_from_cmd "updating /etc/rc.net"

	fi

} # end of change_rc_net

#---------------------------- config_tcpip      --------------------------------
#
# NAME: config_tcpip
#
# FUNCTION:
#		configures TCP/IP with the specified information
#
# EXECUTION ENVIRONMENT:
#
# NOTES:
#		calls error on failure
#
# RECOVERY OPERATION:
#
# DATA STRUCTURES:
#		parameters:
#		global:
#
# RETURNS: (int)
#		0							= success
#		1							= failure
#
# OUTPUT:
#-------------------------------------------------------------------------------
function config_tcpip {

	typeset pif_name=""
	typeset seqno=""
	typeset rs=""
	typeset i=""
	typeset addr=""
	typeset hname=""
	typeset dest=""
	typeset routing_snm=""
	typeset gateway=""
	typeset def_gateway=""
	typeset hcn_value=""
	typeset hcn_pif_name=""
	[[ -n "${ring_speed}" ]] && rs="-r ${ring_speed}"
	[[ -n "${cable_type}" ]] && ct="-t ${cable_type}"

	# make sure all the NIM_HOSTS are in /etc/hosts
	if [[ -n $NIM_IPV6_HOSTS ]]
	then
		for i in $NIM_IPV6_HOSTS
		do
			# separate IP address from hostname
			IFS='|' set -- $i
                        addr=$1
                        hname=$2

			# add this hostname if not already in /etc/hosts
			${EGREP} "^${addr}.*${hname}" ${HOSTS} >/dev/null 2>/dev/null || \
				echo "${addr}\t${hname}" >> ${HOSTS}
		done
	fi

	if [[ -n $NIM_HOSTS ]]
	then
		for i in ${NIM_HOSTS}
		do
			# separate IP address from hostname
			addr=${i%%:*}
			hname=${i##*:}

			# add this hostname if not already in /etc/hosts
			${EGREP} "^${addr}.*${hname}" ${HOSTS} >/dev/null 2>/dev/null || \
				echo "${addr}\t${hname}" >> ${HOSTS}

		done
	fi

	# determine logical interface name by first getting the name of the
	#		adapter we booted off of
	pif_name=$( ${BOOTINFO} -b )

	# HCN support for migratable SRIOV VFs.
	# - Determine if this device is an HCN device
	# - If so, then find the etherchannel w. same hcn_id attr
	# - MKTCPIP should be called on the subsequent interface
	hcn_value=$(${ODMGET} -q "name=$pif_name AND attribute=hcn_id" CuAt | ${AWK} -F\" '/value/{print $2}')

	if [[ -n "$hcn_value" ]]
	then
		hcn_pif_name=$(${ODMGET} -q "value=$hcn_value AND attribute=hcn_id AND generic=DU" CuAt | ${AWK} -F\" '/name/{print $2}')

		if [[ -n "$hcn_pif_name" ]]
		then
			# separate logical device name from sequence number
			seqno=${hcn_pif_name##*[a-zA-Z]}
			hcn_pif_name=en${seqno}
		fi
	fi

	if [[ -n "$hcn_pif_name" ]]
	then
		# replace logical (boot) interface w/ target (hcn) interface
		pif_name=$hcn_pif_name

	else
		# now, separate logical device name from sequence number
		seqno=${pif_name##*[a-zA-Z]}

		# now, map the logical device name to a logical interface name
		case ${pif_name} in
			tr+([0-9])|tok+([0-9]))	pif_name="tr${seqno}";;
			fd*+([0-9]))		pif_name="fi${seqno}";;
			at+([0-9])|atm+([0-9]))	pif_name="at${seqno}";;
			e[nt]*+([0-9]))		# determine whether to use "en" or "et"
								EN=$( /usr/bin/netstat -i | \
										${EGREP} "en${seqno}.*" )
								[[ -n "${EN}" ]] && 
									pif_name=en${seqno} ||
									pif_name=et${seqno}
								;;
			hfi+([0-9]))		pif_name="hfi${seqno}";;
			*)				error ${ERR_SYS} "unknown adapter name \"${pif_name}\"";;
		esac
	fi  # end of hcn condition

	if [[ ${pif_name} = at+([0-9]) ]] 
	then
		# if atm then no need to do a mktcpip, the data is already in the ODM.
		:
	elif [[ "${NIM_CONFIGURATION}" != standalone &&
	        "${NIM_CONFIGURATION}" != ivm        &&
	        "${NIM_CONFIGURATION}" != vios ]]
	then
		# diskless/dataless clients cannot detach network device; resources
		# are NFS mounted.  So lets manually change /etc/rc.net file.
		change_rc_net
	else
		# if the host is ipv6, then we need to modify rc.net
		if [[ -n $NIM_IPV6_HOSTS ]] 
		then
			if $AWK '/\/usr\/sbin\/autoconf6/ {sub(/(.*)start \/usr\/sbin\/autoconf6 (.*)/, \
								   "start /usr/sbin/autoconf6 \"\" \"-6 -i '${pif_name}'\"")} {print}' \
				 /etc/rc.tcpip >$TMPDIR/rc.tcpip
			then
				$CAT $TMPDIR/rc.tcpip >/etc/rc.tcpip || warning_from_cmd "$CAT"

				set_hostname

				typeset -u ucaseip=$ip
				if [[ $ucaseip != FE80::* ]]; then
					typeset -i prefixlen=`mask2plen $snm`
					/usr/sbin/ifconfig $pif_name inet6 $ip/$prefixlen firstalias
					${CHDEV} -l $pif_name -a netaddr6=$ip -a prefixlen=$prefixlen -a state=up
				fi
			else
				warning_from_cmd "updating /etc/rc.net"
			fi
		# configure the primary network interface using mktcpip
		elif ${MKTCPIP} -h ${hostname} -a ${ip} -i ${pif_name} -m ${snm} \
			${rs} ${ct} 2>${ERR}
		then

			# everything ok - proceed
			:

		else
			# Temporarily save the error info.  We'll report
			# it after we get the routes back since we may need
			# code from the SPOT to do so.
			/usr/bin/cp ${ERR} ${TMPDIR}/mktcpip.err.sv

			# change the /etc/rc.net file directly
			change_rc_net

		fi
	fi

	# if this is a standalone machine... and not an IPv6 client...
	if [[ "${NIM_CONFIGURATION}" = standalone ||
	      "${NIM_CONFIGURATION}" = ivm        ||
	      "${NIM_CONFIGURATION}" = vios       &&
	      -z $NIM_IPV6_HOSTS ]]
	then

		# flush the routes added during the network boot process so that we
		#		can add them back using chdev
		# NOTE that we don't want to do this for diskless or dataless machines
		#		because flushing the routes at this point might cause them to
		#		loose contact with their SPOT server (and hang forever)
		${ROUTE} -f 2>${ERR} || warning_from_cmd ${ROUTE}

		# add any routes specified in ROUTES
		# NOTE that we don't want to do this for diskless or dataless machines
		#		because the routes which are added during the network boot process
		#		are still present at this point, so chdev will fail
		for i in ${ROUTES}
		do

			# format of each stanza is:
			#     <dest net>|<dest net snm>|<gateway>
			# separate the fields
			dest=${i%%:*}
			gateway=${i##*:}
			routing_snm=${i#*:}
			routing_snm=${routing_snm%:*}

			# add the route... use different cmd for default route
			if [[ ${dest} = default ]]
			then

				# set default gateway address
				[[ -n ${gateway} ]] && def_gateway="${gateway}"
				#add route
				${CHDEV} -l inet0 \
				-a route="0,${gateway}" \
				2>${ERR} || warning_from_cmd ${CHDEV}
			else
				${CHDEV} -l inet0 \
				-a route="net,${dest},-netmask,${routing_snm},${gateway}" \
				2>${ERR} || warning_from_cmd ${CHDEV}
			fi

		done

	fi

	if [[ -s ${TMPDIR}/mktcpip.err.sv ]]
	then
		# Let the user know MKTCPIP failed above
		mv ${TMPDIR}/mktcpip.err.sv ${ERR}
		warning_from_cmd ${MKTCPIP}
	fi

	# for mksysb installs, modify /etc/firstboot to compensate for
	# some potential interference from rda processing which is added to 
	# /etc/firstboot by bi_main
	if [[ "$NIM_BOS_FORMAT" = "mksysb" ]]
	then
		# Prepend a call to the route command to flush the
		# table.  As a result, any chdev invoked for rda
		# processing to add routes will succeed (for valid routes). 
		${MV} /etc/firstboot /tmp/fb.$$

		# D966339, don't call route -f for iscsi boot
		print "${BOOTLIST} -m normal -o -v 2>/dev/null | ${GREP} \":iscsi\" >/dev/null 2>&1" >/etc/firstboot
		print "ISCSI_RC=\$?" >> /etc/firstboot
		print "[[ \$ISCSI_RC -ne 0 ]] && ${ROUTE} -f" >> /etc/firstboot

		if [[ -n $NIM_IPV6_HOSTS ]]; then
			set_hostname "firstboot"

			typeset -u ucaseip=$ip
			if [[ $ucaseip != FE80::* ]]; then
				typeset -i prefixlen=`mask2plen $snm`
				/usr/sbin/ifconfig $pif_name inet6 $ip/$prefixlen firstalias
				${CHDEV} -l $pif_name -a netaddr6=$ip -a prefixlen=$prefixlen -a state=up
			fi

		else
			# Append a call to mktcpip to ensure that the correct
			# host name is set (rda may try to change it to the orig).
			# D966339, don't call mktcpip which has route delete for iscsi boot

			print "pif_name=${pif_name}" >> /etc/firstboot
			if [[ -n "$hcn_value" ]]
			then
				print "hcn_pif_name=\$(${ODMGET} -q \"value=$hcn_value AND attribute=hcn_id AND generic=DU\" CuAt | ${AWK} -F\\\" '/name/{print \$2}')" >> /etc/firstboot
				print "[[ -n \"\$hcn_pif_name\" ]] && pif_name=en\${hcn_pif_name##*[a-zA-Z]}" >> /etc/firstboot
			fi
			print "if [[ \$ISCSI_RC -eq 0 ]]; then" >> /etc/firstboot
			print "     ${CHDEV} -l inet0 -a hostname=${hostname}" >> /etc/firstboot
			print "     ${UNAME} -S ${hostname}" >> /etc/firstboot
			print "else" >> /etc/firstboot
			print "     ${MKTCPIP} -h  ${hostname} -a ${ip} -i \$pif_name -m ${snm} \
			${def_gateway:+-g $def_gateway} ${rs} ${ct}" >> /etc/firstboot
			print "fi" >> /etc/firstboot
		fi

		# Append a call to cfgmgr to (re)establish any routes
		# flushed/added above.
		# cfgmgr was changed to not configure devices in the "AVAILABLE" state.
		# Therefore, to add routes flushed above, we must call cfgrcnet.
		print "/usr/lib/methods/cfgrcnet" >> /etc/firstboot
		print "/usr/sbin/cfgmgr" >> /etc/firstboot

		${CAT} /tmp/fb.$$ >> /etc/firstboot
		${RM} /tmp/fb.$$
	fi

	# special processing for hcn (non-mksysb)
	if [[ "$NIM_BOS_FORMAT" != "mksysb" ]] && [[ -n "$hcn_value" ]]
	then

		if [[ -z $NIM_IPV6_HOSTS ]]; then
			print "pif_name=${pif_name}" >> /etc/firstboot
			print "hcn_pif_name=\$(${ODMGET} -q \"value=$hcn_value AND attribute=hcn_id AND generic=DU\" CuAt | ${AWK} -F\\\" '/name/{print \$2}')" >> /etc/firstboot
			print "[[ -n \"\$hcn_pif_name\" ]] && pif_name=en\${hcn_pif_name##*[a-zA-Z]}" >> /etc/firstboot
			print "${MKTCPIP} -h  ${hostname} -a ${ip} -i \$pif_name -m ${snm} \
                        ${def_gateway:+-g $def_gateway} ${rs} ${ct}" >> /etc/firstboot
		fi
	fi

} # end of config_tpcip

#---------------------------- set_hostname      --------------------------------
#
# NAME: set_hostname
#
# FUNCTION:
#               Set hostname from the variable NIM_HOSTNAME from /etc/niminfo
#
# EXECUTION ENVIRONMENT:
#
# NOTES:
#
# RECOVERY OPERATION:
#
# DATA STRUCTURES:
#               parameters:
#               global:
#
# RETURNS: (int)
#
# OUTPUT:
#-------------------------------------------------------------------------------
function set_hostname {
	typeset settype=$1

	if [[ $settype = "firstboot" ]]; then
		# Set hostname in ODM
		print "${CHDEV} -l inet0 -a hostname=$NIM_HOSTNAME" >> /etc/firstboot

		# Set hostname for initial boot
		print "${HOSTNAME} $NIM_HOSTNAME" >> /etc/firstboot
		print "${UNAME} -S $NIM_HOSTNAME" >> /etc/firstboot
	else
		# Set hostname in ODM
		${CHDEV} -l inet0 -a hostname=$NIM_HOSTNAME

		# Set hostname for initial boot
		${HOSTNAME} $NIM_HOSTNAME
		${UNAME} -S $NIM_HOSTNAME
	fi

} # end of set_hostname

#---------------------------- mask2plen --------------------------------
#
# NAME: mask2plen
#
# FUNCTION:
#               Calculate the prefix length from the subnetmask for IPv6
#
# EXECUTION ENVIRONMENT:
#
# NOTES:
#
# RECOVERY OPERATION:
#
# DATA STRUCTURES:
#               parameters:
#               global:
#
# RETURNS: (int)
#
# OUTPUT:
#-------------------------------------------------------------------------------
function mask2plen {

	typeset subnetmask=$1
	typeset -i prefixlen=0

	for subnet in `IFS=":"; echo $subnetmask`; do
		typeset -i count=1
		while [[ $count -lt ${#subnet}+1 ]]; do
			typeset -u character=`echo $subnet | /usr/bin/cut -c ${count}`
			count=$(( count + 1))
			typeset -i value=`ibase=16; echo $character | /usr/bin/bc`

			if [[ $value -eq 15 ]]; then
				prefixlen=$(( prefixlen + 4 ))
			elif [[ $value -eq 14 ]]; then
				prefixlen=$(( prefixlen + 3 ))
			elif [[ $value -eq 12 ]] || [[ $value -gt 12 ]]; then
				prefixlen=$(( prefixlen + 2 ))
			elif [[ $value -eq 8 ]] || [[ $value -gt 8 ]]; then
				prefixlen=$(( prefixlen + 1 ))
			fi
		done
	done

	echo $prefixlen

} # end of mask2plen

#*---------------------------- c_mk_nimclient           ------------------------
#
# NAME: c_mk_nimclient
#
# FUNCTION:
#		performs NIM client customization in the BOS install environment
#		this customization includes:
#			- installing the NIM client package
#			- initializing a /.rhosts file
#			- adding an inittab entry for nimclient to change the Mstate
#
#		in the future, when TCPIP configuration changes, this function will also
#			propogate the RAM filesystem TCPIP configuration into the real env
#
# EXECUTION ENVIRONMENT:
#
# NOTES:
#
# RECOVERY OPERATION:
#
# DATA STRUCTURES:
#		parameters:
#		global:
#
# RETURNS: (int)
#		0							= no errors
#		>0							= failure
#
# OUTPUT:
#-----------------------------------------------------------------------------*/

# signal processing
trap cleanup 0
trap err_signal 1 2 11 15

# NIM initialization
nim_init

# initialize local variables
typeset c=""
just_config=""
install_method=""

# set parameters from command line
while getopts :a:qtv c
do
	case ${c} in

		a)    # validate the attr ass
				parse_attr_ass "${OPTARG}"

				# include the assignment for use in this environment
				eval ${variable}=\"${value}\"
		;;

		q)    # show attr info
				cmd_what
				exit 0
		;;

		t)		# just configure tcpip
				# The assumtion is that we're doing diskless/dataless
				# config.
				just_config=TRUE
		;;

		v)    # verbose mode (for debugging)
				set -x
				for i in $(typeset +f)
				do
					typeset -ft $i
				done
		;;

		\?)   # unknown option
				error ${ERR_BAD_OPT} ${OPTARG}
		;;

	esac
done

# check for missing attrs
ck_attrs

if [[ -z "${just_config}" ]]
then

	# set defaults
	installp_flags=$( ck_installp_flags "${installp_flags}" )
	filesets=${filesets:-${NIM_CLIENT_OPTIONS}}

	# set geninstall_cmd (if needed)
	set_geninst ${installp_flags}

	# set the NIM_BOOT_ENV variable so that the bos.sysmgt.nim.master
	#		unconfig scripts know not to do bad things
	export NIM_BOOT_ENV=yes

	# make sure that the bos.sysmgt.nim.master & spot pieces are not present
	# this is important because the source for the BOS image could be a /usr
	#		SPOT, which will at least contain the bos.sysmgt.nim.spot package
	#   We need to get rid of any /etc/niminfo.prev files if they exist since the
	#   unconfigure scripts for bos.sysmgt.nim.master will copy them over the
	#   /etc/niminfo file.....That would be bad.
	[[ -f /etc/niminfo.prev ]] && ${RM} /etc/niminfo.prev
	${geninstall_cmd:-$INSTALLP -e $INSTALLP_LOG -b} \
		${geninstall_cmd:+-I "-e $INSTALLP_LOG -b"} \
		-u ${NIM_DEINSTALL_OPTIONS} 2>${ERR} || \
		warning_from_cmd ${INSTALLP}

	# unset the NIM_BOOT_ENV variable so we don't mess anything else up
	unset NIM_BOOT_ENV

	# get rid of the NIM_BOSINST_ENV variable from /etc/niminfo
	# so it doesn't look like we are still in that environment 
	# when running NIM commands after reboot.
	echo "grep -v -e \"^export NIM_BOSINST_ENV\" -e \"^export NIM_CREDENTIAL\" /etc/niminfo > /etc/__niminfo.post_bi" >> /etc/firstboot
	echo "mv /etc/__niminfo.post_bi /etc/niminfo" >> /etc/firstboot

	# Check to see if nfsmnthelp file is currently installed on the system
	# if it is, then check if the INSTALL_DEVICES_AND_UPDATES flag permits us to update it.
	${LSLPP} -l bos.net.nfs.client >/dev/null 2>&1
	if [ $? -ne 0 ] || [ "$INSTALL_DEVICES_AND_UPDATES" = yes ]
	then
		# install the NIM client package
		# since this script should only be run during a BOS install, we know that
		#		simages is already mounted and accessable, so that's what our source is
		${geninstall_cmd:-$INSTALLP -e $INSTALLP_LOG -agXb} \
				${geninstall_cmd:+-I "-e $INSTALLP_LOG -agXb"} \
				-d/SPOT/usr/sys/inst.images bos.net.tcp.client bos.net.nfs.client \
				2>${ERR} 1>&2 || warning_from_cmd ${INSTALLP}
	fi

	# Check to see if bos.sysmgt.nim.client is currently installed on the system
	${LSLPP} -l bos.sysmgt.nim.client >/dev/null 2>&1
	if [ $? -ne 0 ] || [ "$INSTALL_DEVICES_AND_UPDATES" = yes ]
	then
		# install the NIM client package
		# since this script should only be run during a BOS install, we know that
		#               simages is already mounted and accessable, so that's what our source is
		${geninstall_cmd:-$INSTALLP -e $INSTALLP_LOG -agXb} \
				${geninstall_cmd:+-I "-e $INSTALLP_LOG -agXb"} \
				-d/SPOT/usr/sys/inst.images bos.sysmgt.nim.client \
				2>${ERR} 1>&2 || warning_from_cmd ${INSTALLP}
	fi

	# Remove any nim entries that may currently be in the inittab file.
	# Old entries may be there if this machine was installed from a
	# mksysb, for example.
	${RMITAB} nim >/dev/null 2>&1
	${RMITAB} nimc >/dev/null 2>&1
	${RMITAB} nimclient >/dev/null 2>&1
	${RMITAB} nimsh >/dev/null 2>&1

	# add entry in inittab for nimclient
	# 1st NOTE: we want the entry to come late enough for ensure that the
	#	network interface has been configured by the time it is executed
	# 2nd NOTE: for vios management configurations
	#	nimclient state info must be sent AFTER vio_daemon has started
	if [[ "${NIM_CONFIGURATION}" = vios ]]; then
		${MKITAB} -i vio_daemon nimclient:2:once:"${NIMCLIENT} -S ${STATE_RUNNING} > /dev/console 2>&1 #   inform nim we're running" \
		2>${ERR} 1>&2 || warning_from_cmd ${MKITAB}
	else
		${MKITAB} -i cron nimclient:2:once:"${NIMCLIENT} -S ${STATE_RUNNING} > /dev/console 2>&1 #   inform nim we're running" \
		2>${ERR} 1>&2 || warning_from_cmd ${MKITAB}
	fi

	# configure client for nimsh if connect sez to
	if [[ ${connect} = "nimsh" ]]; then
		echo "${NIMCLIENT} -C" >> /etc/firstboot
		${MKITAB} -i cron nimsh:2:wait:"/usr/bin/startsrc -g nimclient >/dev/console 2>&1" \
			2>${ERR} 1>&2 || warning_from_cmd ${MKITAB}
	elif [[ ${connect} = "nimsh (secure)" ]]; then
		echo "${NIMCLIENT} -c" >> /etc/firstboot
		${MKITAB} -i cron nimsh:2:wait:"/usr/bin/startsrc -a \"-c\" -g nimclient >/dev/console 2>&1" \
			2>${ERR} 1>&2 || warning_from_cmd ${MKITAB}
	else
		# initialize the /.rhosts file
		if [[ -n ${NIM_MASTER_HOSTNAME_LIST} ]]
		then
			for i in ${NIM_MASTER_HOSTNAME_LIST}
			do
				echo "${i} ${NIM_MASTER_UID:-root}" >>/.rhosts
			done
		else
			echo "${NIM_MASTER_HOSTNAME} ${NIM_MASTER_UID:-root}" >>/.rhosts
		fi
	fi

	#
	# Check to see if we have a license signature file.
	#  if so, sign it with network install.
	#
	echo "[[ -f ${LICENSE_SIG} ]] && echo ${license_msg} >> ${LICENSE_SIG}" >> /etc/firstboot

	#
	# If performing a vios ios_mksysb restore and NIM_LICENSE_ACCEPT=yes
	# then add the swma.response file (required for vios migration)
	#
	if [[ "${NIM_CONFIGURATION}" = vios &&
	      "${NIM_BOS_FORMAT}" = mksysb  &&
	      "${NIM_LICENSE_ACCEPT}" = yes ]]; then
		echo "/usr/ios/cli/ioscli license -accept" >> /etc/firstboot
		timestamp=`${DATE} +"%b %d %Y, %H:%M:%S"`
		echo "echo \"$timestamp response:a\" >/var/adm/ras/swma.response" >> /etc/firstboot
	fi
fi

# configure TCPIP
config_tcpip

# configure NFS
${MKNFS} -I 2>${ERR} 1>&2 || warning_from_cmd ${MKNFS}
#
# Set the date/time and time zone for non migration installs.
#
[[ -e /var/adm/ras/bosinst.data ]] &&
install_method=`awk '
			BEGIN {
			while (getline )
			if ($1 == "INSTALL_METHOD")
				print $3 ;
			} ' /var/adm/ras/bosinst.data`

if [[ ${install_method} != "migrate" ]]; then
	echo "${NIMCLIENT} -d" >> /etc/firstboot
fi
# success
exit 0

