#! /bin/sh
#
# @(#)shhdr.sh 6.1 95/12/15 Copyright (c) 1990-1995, Legato Systems, Inc.
#
# All rights reserved.
#
# Include this first in any generated installation removal shell script.
#
# @(#)pnsr_ize.sh 6.1 95/12/15 Copyright (c) 1990-1995, Legato Systems, Inc.
#
# Legato NetWorker Save and Recover (nsr) installation/deinstallation program
#
# Rules:
# 1) This file should be include first in the generated nsr_ize 
#    install remove shell script.
#
# nsr_ize [ -i | -r | -u ] [-c | -s ] [ -kmnqxv ]
#
# -i = do install
# -r = do remove
# -u = do an "upgrade" removal
# -c = do client side only w/o asking or checking
# -s = do server side w/o asking or checking
# -k = kill daemons if running w/o confirming
# -m = do not do any "man" stuff (neither remove or install)
# -n = don't actually change anything
# -q = quiet
# -x = debugging flag...
# -v = verbose
# -p = tells nsr_ize it was called by a package tool (pkgadd, custom,...)
#
# If none of -i, -r, or -u is specified, then nsr_ize will determine
# whether or not to run in install or remove mode by itself.
#

# The standard DEC sh doesn't handle functions, we need to make sure
# that we are using the sh5 shell.
if [ -r /usr/bin/sh5 -a "X${IZE_SHELL5}" != "X/usr/bin/sh5" ]; then
	IZE_SHELL5=/usr/bin/sh5
	export IZE_SHELL5
	exec sh5 $0 $*
fi
# @(#)arch.sh 6.1 95/12/15 Copyright (c) 1995, Legato Systems, Inc.
#
# Platform specific install remove shell functions.
#
# Rules:
# 1) There should not be any user input required by any functions
#    in this file.
#

# Do SCO specific SLS checking.
# Exits on error.
#
verifyscosls()
{

	if [ ${sco} = n -o X${server} != Xy -o X${op} != Xinstall ]; then
		return 0		# for SCO server installs only
	fi
	errquit=n
	exec="swconfig | grep \"Enhanced SCSI Tape Drivers\" 2>&1 >/dev/null"
	doexec
	errquit=y
	if [ ${execstatus} -eq 0 ]; then
		return 0		# we found what we are looking for
	fi

	ver=`uname -X | grep Release | cut -c15-17`
	if [ `expr "X${ver}" : 'X4.[012]'` -ne 4 ]; then
		return 0		# not an interesting version for us
	fi

	# Print an error message and exit
	cat << EOF

*** Warning: You must install SLS UDO376 "Enhanced SCSI Tape Drivers"
before installing NetWorker.  You can obtain SLS UDO376 from SCO
Technical Support.  See "Release Notes Legato NetWorker for UNIX
SCO Version" for details. ***

EOF
	exit 1
} # end verifyscosls

# Run arch dependant script to do things like build kernel on SCO
# install apps_default, set up icon on desktop...
myarchize()
{
if [ ${op} = install ]; then
	if [ -f ${myarch}/${myarch}_ize ]; then
		exec=". ${myarch}/${myarch}_ize"
# This is needed to tell myarch_ize if we are a server install
		export server
		doexec
# Added to support pkg installs
	elif [ -f /usr/sbin/${myarch}_ize ]; then
		exec=". /usr/sbin/${myarch}_ize"
		export server
		doexec
	elif [ -f /usr/bin/${myarch}_ize ]; then
		exec=". /usr/bin/${myarch}_ize"
		export server
		doexec
	fi
fi
} # end myarchize
# @(#)include.sh 6.1 95/12/15 Copyright (c) 1995, Legato Systems, Inc.
#
# General purpose installation removal shell functions
# Rules:
# 1) No user interaction can be requested, it should be driven by
#    sourcing the ${NSRREQUEST} file.
# 2) This file should be include in every install remove shell script.
# 3) This file should be included near the top of every install remove
#    shell script.

#
# Print a Legato Copyright notice.
#
copyright()
{
COPYRIGHT="Copyright (c) 1990-1996, Legato Systems, Inc."
echo "		${productname}(TM) - Release ${RELEASE}"
echo "${COPYRIGHT}  All rights reserved."
echo "This product includes software developed by the University of"
echo "California, Berkeley and its contributors."
echo ""
} # end copyright

#
# Call nsr_shutdown in the dir where we are executing from
#
do_shutdown()
{
	if [ -z "${mypath}" -o \! -f ${mypath}/nsr_shutdown ]; then
		# run in a subshell to hide error messages, such as
		# "nsr_shutdown: not found" if the command is not installed.
		(nsr_shutdown $*) 2> /dev/null
	else
		${mypath}/nsr_shutdown $*
	fi
}

#
# See if the any of the known ${productname} daemons are currently running.
#
# Outputs:
# 	Puts a list of running daemons into ${daemonsrunning}
#
find_daemons()
{
	# Call the nsr_shutdown script to return a list of daemons
	# that are running
	daemonsrunning="`do_shutdown -D -a -n | sort -u`"
}

# Try to set mypath from the PATH, looking for nsr_ize
setmypath()
{
	_p="$PATH"
	mypath=""
	while [ "X${_p}" != "X" ]
	do
		if [ `expr "X${_p}" : ".*:"` -gt 0 ]; then
			_i=`expr "${_p}" : '\([^:]*\):'`
			_q=`echo "X${_p}" | sed -e 's/[^:]*://'`
		else
			_i="${_p}"
			_q=""
		fi
		case "X${_i}" in
		X)	_i="."
			;;
		esac
		_p=${_q}
		if [ -f "${_i}/nsr_ize" ]; then
			mypath="${_i}"
			break
		fi
	done

	if [ "X${mypath}" = "X" -a -f ./nsr_ize ]; then
		mypath="."
	fi
}

installinit()
{
RELEASE=4.2

mypath="`expr X\"${0}\" : X'\(.*\)/.*' \| X\"${0}\" : X'\(/\)[^/]*$' \| 'X'`"
myname=`basename $0`

# if mypath isn't set, try to find the origin of this nsr_ize via PATH
case "X${mypath}" in
XX)	setmypath
	;;
esac

# NOTE: some systems put "Berkeley" utilities in /usr/ucb, others (e.g. SGI)
# put them in /usr/bsd.  Also, some systems use /usr/etc and other use
# /usr/sbin.  We include all variants in addition to the path to this
# program to be safe.
#
PATH=/usr/ucb:/usr/bsd:/bin:/usr/bin:/etc:/usr/etc:/usr/sbin:$mypath:$PATH
export PATH

# default values
productname=NetWorker
productized="nsr-ized"
deproductized="de nsr-ized"
productizing="nsr-izing"
deproductizing="de nsr-izing"

nsrhome=/nsr		# normally set up to be a symlink to a large partition
raphome=/var/rap
rapmom=/var
raplares=/etc/la.res
index_dir="${nsrhome}/index"
mm_dir="${nsrhome}/mm"
log_dir="${nsrhome}/logs"
cores_dir="${nsrhome}/cores"
default_bin=/usr/bin
exdir=${default_bin}
old_nsrres=/etc/nsr.res
nsrreshome=/nsr/res
jboxhome=${nsrreshome}
nsrres=${nsrreshome}/nsr.res
jboxres=${jboxhome}/nsrjb.res
nsrlares=${nsrreshome}/nsrla.res

server=UNKNOWN
qflag=n
nflag=n
xflag=n
kflag=n
mflag=y
Fflag=n
pflag=n
demo=n
errquitdefault=y
errquit=${errquitdefault}
op=
proc=
upgrade=false
local_only=
link_test_opt=-h
domanpage=n

daemons="ansrd nsrd nsrindexd nsrmmd nsrmmdbd nsrexecd"

start_message=\
"# Start of lines added by ${productname} - DO NOT DELETE OR CHANGE THIS LINE"
end_message=\
"# End of lines added by ${productname} - DO NOT DELETE OR CHANGE THIS LINE"

if [ -f /bin/hostname ]; then
	host=`/bin/hostname`
elif [ -f /usr/ucb/hostname ]; then
	host=`/usr/ucb/hostname`
elif [ -f /usr/bsd/hostname ]; then
	host=`/usr/bsd/hostname`
elif [ -f /usr/local/bin/hostname ]; then
	host=`/usr/local/bin/hostname`
else
	host=
fi
if [ -r /bin/uname -o -r /usr/bin/uname ]; then
	uname=`uname`
	proc=`uname -p 2>&1`
	if [ "X${host}" = X ]; then
		host=`uname -n`
	fi
fi
if [ X${host} = X ]; then
	echo "no host name set - assuming loopback"
	hostname loopback
fi

sun=n
dec=n
hpux=n
aix=n
sgi=n
sco=n
linux=n
# True if we have System V style /etc/rc*.d files
svrc=y
bsd_echo=true

df=df
id=id

man=/usr/man

# prefix to section directory where man pages go
sectiondir=man
# unformatted man pages sourcemandir=man, formated man pages sourcemandir=catman
sourcemandir=man
fmt="fmt"

# save the args
ARGS="$*"

# find the binary type of /bin/sh
set X `file /bin/sh`
shift
# for some shells, the above 'set' results in 'X' being $0 and '/bin/sh:'
# in $1 so check for that and shift if it is true
if [ X"$1" = X/bin/sh: ]; then
	shift
fi
if [ X"$1" = Xsymbolic ]; then
	set X `file -L /bin/sh`
	shift
fi
bin_type="$1"
set X $ARGS
shift
} # end installinit

setsolarisbins()
{
	case x$PKG in
		xSUNW*)
			default_bin=${BASEDIR}/sbin/nsr
			exdir=${BASEDIR}/sbin/nsr
			;;
		*)
			default_bin=${BASEDIR}/sbin
			exdir=${BASEDIR}/sbin
			;;
	esac
}

findarch()
{
#
# DEC's standard version of test doesn't know
# about -x option, so just use the -r option.
# note that we cannot use "elif", since this may be a BSD sh (news)!
#
if [ "X${proc}" = Xsparc ]; then
	# System V release 4 on SPARC, a.k.a. SunOS 5.0.x
	myarch=solaris
	sun=n
	setsolarisbins
	df="df -l"
	no_rewind_example=/dev/rmt/0mbn
	rewind_example=/dev/rmt/0mb
	if [ -f /usr/ucb/echo ]; then
		bsd_echo=true
	else
		bsd_echo=false
	fi
else if [ "X${uname}" = XSunOS -a "X${proc}" = Xppc ]; then
	# System V release 4 on PPC, a.k.a. SunOS 5.x
	myarch=solppc
	sun=n
	setsolarisbins
	df="df -l"
	no_rewind_example=/dev/rmt/0mbn
	rewind_example=/dev/rmt/0mb
	if [ -f /usr/ucb/echo ]; then
		bsd_echo=true
	else
		bsd_echo=false
	fi
else if [ "X${uname}" = XSunOS -a "X${proc}" = Xi386 ]; then
	# System V release 4 on i386, a.k.a. SunOS 5.0.x
	myarch=sol86
	sun=n
	setsolarisbins
	df="df -l"
	no_rewind_example=/dev/rmt/0mbn
	rewind_example=/dev/rmt/0mb
	if [ -f /usr/ucb/echo ]; then
		bsd_echo=true
	else
		bsd_echo=false
	fi
else if [ "X${uname}" = XLinux ]; then
	myarch=linux
	linux=y
	svrc=n
	fmt=cat
	default_bin=/usr/sbin
#ifdef DIGITAL_OSF
else if [ X${uname} = XOSF1 ]; then
	#
	# DEC OSF/1 is a little different from Ultrix
	#
	dec=y
	svrc=y
	myarch=decaxp
	bsd_echo=false
	no_rewind_example=/dev/nrmt0h
	rewind_example=/dev/rmt0h
	link_test_opt=-L
#endif /* DIGITAL_OSF */
else if [ -r /usr/bin/sh5 -o X"${bin_type}" = Xmipsel ]; then
	dec=y
	svrc=n
	if [ -r /bin/machine ]; then
		# Should be a DEC box running Ultrix
		myarch=dec`machine`
		if [ $myarch = "decmips" ]; then
			myarch=decsystem
		fi
	else
		if [ X"$bin_type" = Xmipsel ]; then
			myarch=decsystem
		else
			myarch=decvax
		fi
	fi
	bsd_echo=false
	no_rewind_example=/dev/nrmt0h
	rewind_example=/dev/rmt0h
	default_bin=/usr/etc
else if [ -f /hp-ux -o X"$bin_type" = Xs200 ]; then
	if [ X"$bin_type" = Xs200 ]; then
		myarch=hp-mc68k
	else
		myarch=hp-pa
	fi
	hpux=y
	svrc=n
	fmt="cat"
	no_rewind_example=/dev/rmt/0hn
	rewind_example=/dev/rmt/0h
	bsd_echo=false
	default_bin=/usr/local/bin
else if [ -f /bin/hinv ]; then
	myarch=sgi
	sgi=y
	fmt=/usr/sbin/fmt
	no_rewind_example=/dev/nrtape
	rewind_example=/dev/tape
	bsd_echo=false
	man=/usr/man/a_man
	sourcemandir=catman
else if [ "X${uname}" = XAIX ]; then
	myarch=aix6000
	aix=y
	svrc=n
	df="df -I"
	link_test_opt=-L
	no_rewind_example=/dev/rmt0.1
	rewind_example=/dev/rmt0
	bsd_echo=false
else if [ "X${uname}" = XUNIX_SV ]; then
	myarch=unixware
	no_rewind_example=/dev/rmt/ntape1
	rewind_example=/dev/rmt/ctape1
	if [ -f /usr/ucb/echo ]; then
		bsd_echo=true
	else
		bsd_echo=false
	fi
	man=/usr/flib/books/man
	sectiondir=cat
	sourcemandir=catman
else if [ -x /usr/bin/scosh ]; then
	sco=y
	myarch=sco
	no_rewind_example=/dev/nrStp0
	rewind_example=/dev/rStp0
	deffpy=/dev/rdsk/f03ht
	bsd_echo=false
	fmt=cat
	sectiondir=cat
	sourcemandir=catman
else if [ X${bin_type} = XiAPX ]; then
	# must go AFTER the other iAPX architectures like SCO
	myarch=sequent
	no_rewind_example=/dev/tx0n
	rewind_example=/dev/tx0
	bsd_echo=false
	fmt="/bin/cat"
else if [ -r /usr/bin/arch ]; then
	sun=y
	svrc=n
	myarch=`arch`
	default_bin=/usr/etc
	#
	# Since we explicitly set the PATH ourselves w/o the sys5 stuff,
	# we shouldn't get the sys5 echo behaviour from the shell.  We
	# don't use /bin/echo here because the sun386 /bin/echo will drop
	# lines after seeing a return within double quotes!
	#
	no_rewind_example=/dev/nrst8
	rewind_example=/dev/rst8
	df="df -t 4.2"
	id="whoami"
	sourcemandir=man
else
	echo "ERROR: Cannot determine base machine type for \`${host}'."
	exit 1
fi	# sequent
fi	# sco
#ifdef DIGITAL_OSF
fi      # dec OSF/1
#endif /* DIGITAL_OSF */
fi	# unixware
fi	# aix
fi	# sgi
fi	# hpux
fi	# dec
fi	# sun
fi	# linux
fi	# sol86
fi	# solppc
fi	# solaris

# This is to allow installing with a default file generated by a form
# before nsr_ize is run so that Compaq can use their front end to nsr_ize.
if [ -x /tmp/default.cfg ]; then
. /tmp/default.cfg
fi
} # end findarch

# For pkgadd systems, check if the prerequisite is installed.
# exits with a failure message if the prerequisite is not installed.
#
# INPUT:
#	prereq=	the name of the predicate package
checkpred()
{
	_ans=`pkginfo | grep ${prereq}`

	if [ -z "${_ans}" ]; then
		echo "
FATAL ERROR: This package cannot be installed until after the ${prereq}
package has been installed." | ${fmt}
		exit 1
	fi
}

setecho()
{
umask 22


if [ $bsd_echo = true ]; then
	echo_n()
	{

		echo -n "$*"
	}
else
	echo_n()
	{

		echo "$*\c"
	}
fi
} # end setecho

#
# explain function
#
# Print out a message explaining this program
#
explain()
{
	echo "
The ${myname} program will install or remove ${productname}
software.  The \`-i' flag to ${myname} will install ${productname},
the \`-r' flag to ${myname} will remove ${productname} from the system,
and the \`-u' flag will do an \"upgrade\" removal leaving the
${productname} configuration files and databases files.
If none of the \`-i', \`-r' or \`-u' flags are specified,
${myname} will automatically select the mode of operation.
By default, all commands that modify the file system will be shown.
The \`-q' flag to ${myname} will suppress this information.
The \`-n' flag will make ${myname} skip operations that modify the file
system and can be used to determine what the ${productname}
installation or removal process would entail.
The \`-s' flag selects ${productname} server side
installation or removal while the \`-c' flag selects
${productname} client side installation or removal.
The ${myname} program will provide interactive prompts with
normal defaults.  Unless you have any special installation requirements,
you can simply hit [Return] at each prompt.  The ${myname} program
is reentrant and can be interrupted and restarted.  Consult the
${productname} documentation for further details." | ${fmt}

}

#
# usage function - prints out a usage message and exits
#
usage()
{
	explain
	echo ""
	echo "usage: ${myname} [ -i | -r | -u ] [ -c | -s ] [ -kmnqxv ]"
	exit 1
}

#
# dirname function
#
# prints a non-NULL directory name for the given file
# Normally this is a system command, but it is optional on many systems.
#
dirname()
{
	expr X"${1}" : X'\(.*\)/.*' \| X"${1}" : X'\(/\)[^/]*$' \| '.'
}

#
# qecho
#	quite echo: if the qflag is no, then echo all arguments,
#	otherwise don't.
#
qecho()
{
	if [ ${qflag} = n ]; then
		echo "$*" | ${fmt}
	fi
}

#
# doexec function
#
# inputs:
#	exec=		string to execute
#	errquit=	if !"n", then take error exit on bad return value
#	nflag=		if "y", then don't really do it
#
# outputs:
#	execstatus=	return value from the eval'ing ${exec}
#	errquit=	${errquitdefault}
#
# Execute the "exec" string, echo'ing the string if qflag
# is not set and not really doing it if nflag is set.
#
doexec()
{
	# protect ourselves from keyboard interrupts if requested
	if [ ${nflag} != y ]; then
		eval "${exec}"
		execstatus=$?
		if [ ${execstatus} -ne 0 -a X${errquit} != Xn ]; then
			echo_n \
"${myname}: unexpected return code ${execstatus}"
			if [ ${qflag} = y ]; then
				echo " trying to execute:"
				echo "${exec}"
			else
				echo ""
			fi
			kill -2 $$
		fi
	else
		execstatus=0		# assume it would have worked...
	fi
	errquit=${errquitdefault}
}

#
# mmkdir function
#
# Function to recursively make directories, all the way back to /,
# if necessary.  Some systems provide a mkdir that does this, but
# it is not a standard feature.
#
# inputs:
#	$1	directory to create
#
mmkdir()
{
	case X"${1}" in
	X | X/ )
		;;
	* )
		if [ ! -d "${1}" ]; then
			mmkdir "`dirname ${1}`"
			exec="mkdir ${1}"
			doexec
		fi
		;;
	esac
}

#
# local_dir function:
#
# Generic function to test if (potential) directory is local
# inputs:
#	$1 directory to test for localhood
# outputs:
# 	result=		true or false; true if directory appears to be local
#
local_dir()
{
	_d="$1"
	while [ ! -d "${_d}" ]; do
		_d=`dirname "${_d}"`
	done
	if [ ${sco} = y ]; then
		mntfsname="`df "${_d}" 2>/dev/null \
			| sed -e 's/(/( /' \
			| awk '{ print $3 }'`"
	else
		mntfsname="`df "${_d}" 2>/dev/null \
			| grep '^[^ 	]' \
			| grep -v '^Filesystem' \
			| awk '{ print $1 }'`"
	fi
	if expr "$mntfsname" : '^[^/].*:/'> /dev/null 2>&1; then
		result=false
	else
		result=true
	fi
}
# @(#)prpoinrm.sh 6.1 95/12/15 Copyright (c) 1995, Legato Systems, Inc.
#
# All NetWorker install and remove shell functions that are
# independent of NetWorker binaries should go here.
# (e.g. configuring the /nsr directory, editing the rc scripts,
#  editing /etc/rpc, ...)
#
# Rules:
# 1) No user interaction can be requested, it should be driven by
#    sourcing the ${NSRREQUEST} file.
# 2) There should be no dependence on NetWorker binaries.
#    (e.g. uasm, nsr_shutdown) 
#

#
# add_device function
#
#       Append a resource descriptor for a device to a file
#
# inputs:
#
#	op = "install" or "remove"
#       DEVLIST = array of device name device type pairs
#	source ${NSRREQUEST} to define DEVLIST 
#
add_device()
{
	if [ ${op} = install ]; then
		file=${nsrres}
		if [ ! -f "${file}" ]; then
			# Avoid a null set command. Prepend X and shift it off.
			# A null set command prints the current environment.
			set X `echo ${DEVLIST}` 
			shift
			while [ ! -z "$1" ]; do
				device="$1"
				type="$2"
				# fix up device type strings with spaces
				if [ "$3" = "5GB" ]; then
					type="${type} $3"
					shift
				fi
				shift
				shift
				echo "type: NSR device;" >> ${file}
				echo "media type: ${type};" >> ${file}
				echo "name: ${device};" >> ${file}
				echo "" >> ${file}
			done
		fi
	fi
} # end add_device

#
# Like rmdir_if_empty but don't ask first.
#
# Inputs:
#	$1 	-- the directory to remove (if empty)
#
rmdir_if_empty()
{
	rda_dir=$1
	if [ "X`ls ${rda_dir}`" = X ]; then
		# Directory is empty, remove it
		# check if directory to be removed is a symlink
		rie_ls_output="`ls -ld ${rda_dir}`"
		case "$rie_ls_output" in
		l* )
			# remove what it points to
			exec="rmdir `cd ${rda_dir}; /bin/pwd`"
			errquit=n
			doexec
			;;
		esac

		exec="rm -rf ${rda_dir}"
		doexec
	fi
}

#
# backoutfile function
#
# Backout nsr changes to a given file
#
# inputs:
#	file	= file to egrep thru
#	tfile	= tmp file created by stripping out nsr-izations of ${file}
#
# outputs:
#	filechange=	y if file changed
#			n if file is not changed
#
backoutfile()
{
	filechange=n
	if [ -f ${file}.prensr ]; then
		cmp -s ${tfile} ${file}.prensr
		cmpstatus=$?
		if [ ${cmpstatus} -eq 2 ]; then
			qecho "${myexecname}: error cmp'ing ${file} and ${tfile}"
			kill -2 $$
		elif [ ${cmpstatus} -eq 0 ]; then
			# the same, just use ${file}.prensr
			exec="mv -f ${file}.prensr ${file}"
			doexec
			filechange=y
			return		# all done
		else
			# files are different, warn the user
			qecho \
"${file} has changed since ${productname} was originally installed."
		fi
		qecho \
"	Removing ${productname} modifications from ${file}"
		exec="mv -f ${tfile} ${file}"
		doexec
		if [ -f ${file}.prensr ]; then
			exec="rm -f ${file}.prensr"
			doexec
		fi
		filechange=y
	else
		exec="mv -f ${tfile} ${file}"
		doexec
		filechange=y
	fi
}

# modfile function
#
# Scan $file for $searchstr.
#	If installing, and no match is found this function's behavior
#	depends upon the setting of ${insertmode}:
#		If ${insertmode} = "y", then ${insertcmd} is used to change
#		${file}.
#		If insertmode != y then contents of ${appendstr} are appended
#		to ${file}.
#
#	If removing, and a match is found,
#	use $sedcmd to strip out lines of a given type or range.
#
# inputs
#	op=		"install" or "remove"
#	file=		file to egrep thru and modify
#	searchstr=	string to egrep for to determine if already nsr-ized
#
# inputs when in install mode:
#	appendstr=	string to append to ${file} if ${searchstr} not found
#	insertcmd=	sed command to stick lines in file if in insert mode
#	insertmode=	y if lines are to be inserted in ${file}.
#
# inputs when in remove mode:
#	sedcmd=		sed command to use to remove changes if searchstr found
#
# outputs when in install mode:
#	filechange=	y if file changed
#			n if file is not changed
#
modfile()
{
	egrep "${searchstr}" ${file}	>/dev/null 2>&1
	grepstatus=$?
	filechange=n
	if [ ${grepstatus} -eq 2 ]; then
		echo "${myname}: could not read ${file}"
		kill -2 $$
	elif [ ${grepstatus} -eq 0 ]; then
		# ${searchstr} was found
		if [ ${op} = install ]; then
			qecho "	${file} already ${productized}"
			return
		fi
		# remove the lines in ${file} using ${sedcmd}
		tfile=/tmp/file.$$
		# copy so the new file has to correct permissions
		if [ "X${file}" != "X${_lastmod}" ]; then
			qecho "	Modifying ${file}"
			_lastmod="${file}"
		fi
		cp ${file} ${tfile}
		sed -e "${sedcmd}" ${file} > ${tfile}
		backoutfile
	else
		# ${searchstr} not found
		if [ ${op} = remove ]; then
			qecho "	${file} already ${deproductized}"
			return
		fi
		if [ "X${file}" != "X${_lastmod}" ]; then
			qecho "	Modifying ${file}"
			_lastmod="${file}"
		fi
		# For now, only keep a .prensr copy if debugging...
		if [ ${xflag} = y -a ! -f ${file}.prensr ]; then
			exec="cp ${file} ${file}.prensr"
			doexec
		fi
		if [ "${insertmode}" = "y" ]; then
			# apply ${insertcmd} to ${file}
			tfile=/tmp/file.$$
			# copy so the new file has the correct permissions
			cp ${file} ${tfile}
			sed -e "${insertcmd}" ${file} > ${tfile}
			backoutfile
			filechange=y
		else
			# Append the new data
			exec="cat >> ${file} << EOF
${appendstr}
EOF"
			doexec
			filechange=y
		fi
	fi
}

#
# nsr_done
#	Finish the install or removal process, updating or removing ${flagfile}
#
# inputs:
#	exdir=		directory where executables for this machine go
#	flagfile=	single file to be installed/removed
#	banner=		first part of a generic "everything ok" message
#	skip_execs=	don't install/remove anything if this is true
#
nsr_done()
{
if [ "${myarch}" != "solaris" ]; then
	file="${exdir}/${flagfile}"
	qecho ""
	if [ -f "${file}" -a X${skip_execs} = Xfalse ]; then
		if [ ${op} = install ]; then
			if [ ${nflag} = y ]; then
				qecho "	${file} already exists, overwriting (not really)..."
			else
				qecho "	${file} already exists, overwriting..."
			fi
			exec="rm -f ${file}"
			doexec
			exec="cp ${flagfile} ${file}"
			doexec
		else
			exec="rm -f ${file}"
			doexec
			rmdir_if_empty ${exdir}
			rmdir_if_empty "${nsrhome}"
		fi
	elif [ X${skip_execs} = Xfalse ]; then
		if [ ${op} = install ]; then
			exec="cp ${flagfile} ${file}"
			doexec
		else
			qecho "${file} does not exist"
		fi
	elif [ X${skip_execs} = Xtrue -a "${op}" = "remove" ]; then
		if [ ${myarch} = sco -o ${myarch} = solaris -o \
		     ${myarch} = sol86 -o ${myarch} = solppc ]; then
			if [ X${server} = Xy ]; then
				rmdir_if_empty "${nsrhome}"
			fi
		fi
	fi
fi
	if [ ${op} = install ]; then
		qecho \
"${banner} successfully installed on \`${host}'!"
	elif [ ${upgrade} = true ]; then
		qecho \
"${banner} successfully removed for upgrade from \`${host}'."
	else
		qecho \
"${banner} successfully removed from \`${host}'."
	fi
} # nsr_done

#
# check_setuid
#	Verify that the setuid files in the given directory look correct.
#	If not, issue a warning and give the operator a chance to bail out.
#
# inputs:
#	dir		directory with the binaries to check over
#	server		y or n
#	arch		the arch we're checking
#	myarch		the arch of the system we're running.
#
check_setuid()
{
	if [ $server = y -a ${arch} = ${myarch} ]; then
		_list="${setuid_client} ${setuid_server}"
	else
		_list="${setuid_client}"
	fi
	_tfile=/tmp/ls.$$
	for _file in ${_list}
	do
		ls -l ${dir}/${_file} > ${_tfile}
		egrep "${setuid_mode}" ${_tfile} > /dev/null
		if [ $? -ne 0 ]; then
			qecho \
"ERROR: ${dir}/${_file} does not have the right permissions.
Expected mode bits of \`${setuid_mode}', but found this:" | ${fmt}
			cat ${_tfile}
			exit 1
		fi

		egrep " ${setuid_owner} " ${_tfile} > /dev/null
		if [ $? -eq 0 ]; then
			continue
		fi

		qecho \
"ERROR: ${dir}/${_file} does not have the right owner.
Expected the owner to be \`${setuid_owner}', but found this:" | ${fmt}
		cat ${_tfile}
		egrep "nobody" ${_tfile} > /dev/null
		if [ $? -eq 0 ]; then
			echo "
This looks like a potential problem with \`${setuid_owner}'
being mapped to \`nobody' via an NFS mounted file system.
You should rerun ${myname} using a different filesystem
other than the one ${dir} is contained within." | ${fmt}
		fi
		exit 1
	done
	exec="rm -f ${_tfile}"
	doexec
}

#
# If remove server files that  might be present.
#
removeserverfiles()
{
if [ ${op} = remove -a ${upgrade} = false ]; then
	isupgrade
fi
if [ ${op} = remove -a ${upgrade} = false ]; then
	if [ -f ${old_nsrres} ]; then
		qecho \
"	Removing ${old_nsrres} (${productname} server configuration) file"
		exec="rm -f ${old_nsrres}"
		doexec
	fi

	if [ -f ${nsrres} ]; then
		qecho \
"	Removing ${nsrres} (${productname} server configuration) file"
		exec="rm -f ${nsrres}"
		doexec
	fi

	if [ -f ${jboxres} ]; then
		qecho \
"	Removing ${jboxres} (${productname} jukebox configuration) file"
		exec="rm -f ${jboxres}"
		doexec
	fi

	if [ -f ${nsrlares} ]; then
		qecho \
"	Removing ${nsrlares} (${productname} nsrexecd configuration) file"
		exec="rm -f ${nsrlares}"
		doexec
	fi

	if [ -d "${nsrreshome}" ]; then
		rmdir_if_empty "${nsrreshome}"
	fi

	file=/.nsr
	if [ -f ${file} ]; then
		qecho "	Removing ${file} file"
		exec="rm -f ${file}"
		doexec
	fi
fi
} # end removecommonfiles

#
# Start up the master nsrd daemon at reboot time.
# The daemon handles index file checking
# and starting all the other daemons.
#
# exdir should be initialized above
# when installing local server binaries.
#
restart_mod()
{
	if [ $hpux = y ]; then
		# we really should modify the localrc() subroutine in /etc/rc,
		# but that requires a set of support functions.
		file=/etc/rc
	elif [ $aix = y ]; then
		file=/etc/rc.nsr
	elif [ $linux = y ]; then
		file=/etc/rc.d/rc.local
	elif [ $svrc = y ]; then
		file=/etc/init.d/networker
	else
		file=/etc/rc.local
	fi
	searchstr="${start_message}"
	sedcmd="/${start_message}/,/${end_message}/d"

	# construct the kind of echo which should be used in the ${file} shell.
	if [ ${bsd_echo} = false -a ${dec} = n ]; then
		nf=
		nt="\c"
	else
		nf=-n
		nt=
	fi

	if [ $aix = y -o $svrc = y ]; then
		# We create a new startup file for these architectures.
		if [ $op = remove ]; then
			qecho "	Removing ${file}"
			rm -f "${file}"
			if [ $svrc = y ]; then
				qecho "	Removing /etc/rc2.d/S95networker"
				qecho "	Removing /etc/rc2.d/K05networker"
				rm -f /etc/rc2.d/S95networker
				rm -f /etc/rc0.d/K05networker
			fi
		else
			# remove in case it is something other than a file...
			rm -f ${file}
			if [ $svrc = y ]; then
				rm -f  /etc/rc2.d/S95networker
				rm -f  /etc/rc0.d/K05networker
			fi
			qecho "	Creating ${file}"
			cat > "${file}" << EOF
${appendstr}
EOF
			chmod 744 "${file}"
			if [ $svrc = y ]; then
				qecho "	Creating /etc/rc2.d/S95networker"
				qecho "	Creating /etc/rc2.d/K05networker"
				ln "${file}" /etc/rc2.d/S95networker
				ln "${file}" /etc/rc0.d/K05networker
			fi
		fi
	else
		modfile
	fi
	if [ $aix = y ]; then
		# Deal with inittab.  The idea is to add a line in
		# the appropriate place, after rctcpip, or rcnfs,
		# or rcpnd, whichever occurs last in inittab
		file=/etc/inittab
		rctcpip="`grep -n '^rctcpip' ${file} | awk -F: '{print $1}'`"
		rcnfs="`grep -n '^rcnfs' ${file} | awk -F: '{print $1}'`"
		rcpnd="`grep -n '^rcpnd' ${file} | awk -F: '{print $1}'`"
		if [ "${rcnfs}" -gt "${rctcpip}" ]; then
			linebefore="rcnfs"
		else
			linebefore="rctcpip"
		fi
		if [ -n "${rcpnd}" ]; then
			linebefore="rcpnd"
		fi
		# The AIX inittab uses colons to quote lines.
		# not specifying the quote character in $sedcmd allows for
		# backward compatiblity
		aix_start_message=\
"Start of lines added by ${productname} - DO NOT DELETE OR CHANGE THIS LINE"
		aix_end_message=\
"End of lines added by ${productname} - DO NOT DELETE OR CHANGE THIS LINE"
		searchstr="${aix_start_message}"
		sedcmd="/${aix_start_message}/,/${aix_end_message}/d"
		if [ -n "${rcnfs}" -o -n "${rctcpip}" ]; then
			# we had better just append to the end in this case
			insertmode=y
			insertcmd="/${linebefore}/a\\
: ${aix_start_message}\\
: installed by ${myname} on `date`\\
rcnsr:2:wait:sh /etc/rc.nsr\\
: ${aix_end_message}"
		fi
		modfile
		insertmode=""
	fi
}

#
# Test if rpc is running. If not, don't edit rc file to startup nsrexecd
# Will exit on a client side install.
#
modifyclientfiles()
{

if [ ${op} = "install" ]; then
#
# install daemons in the rc file, and start them
#
	qecho \
"	${productizing} system files"
	
	if [ -f /tmp/nsrrequest ]; then
		. /tmp/nsrrequest
	fi
	nsrexeccmd="${exdir}/nsrexecd${NSREXECD}"

	if [ ${dec} = y ]; then
		appendstr=\
"${start_message}
# installed by ${myname} on `date`
	(echo ${nf} 'Starting ${productname} daemons...${nt}') > /dev/console
[ -f ${exdir}/nsrexecd ] && {
	(${nsrexeccmd}) > /dev/console 2>&1
	(echo '') > /dev/console
}
[ -f ${exdir}/nsrd ] && {
	(nsrd) > /dev/console 2>&1
	(echo '') > /dev/console
}
${end_message}"

	else
	if [ ${svrc} = y ]; then
appendstr=\
"#! /bin/sh
# installed by ${myname} on `date`
case \$1 in
'start')
(echo ${nf} 'starting ${productname} daemons:${nt}') > /dev/console
if [ -f ${exdir}/nsrexecd ]; then
	(${nsrexeccmd})	> /dev/console 2>&1
	(echo ${nf} ' nsrexecd${nt}') > /dev/console
	(echo '') > /dev/console
fi
if [ -f ${exdir}/nsrd ]; then
	(${exdir}/nsrd) > /dev/console 2>&1
	(echo ${nf} ' nsrd${nt}') > /dev/console
        (echo '') > /dev/console
fi
	;;
'stop')
(echo ${nf} 'stopping ${productname} daemons:${nt}') > /dev/console
if [ -f ${exdir}/nsr_shutdown ]; then
	(${exdir}/nsr_shutdown -a -q&) > /dev/console 2>&1
	(echo ${nf} ' nsr_shutdown -a -q${nt}')	> /dev/console
	(echo '') > /dev/console
fi
	;;
*)
echo \"usage: \`basename \$0\` {start|stop}\"
	;;
esac"

	else
appendstr=\
"${start_message}
# installed by ${myname} on `date`
(echo ${nf} 'starting ${productname} daemons:${nt}') > /dev/console
if [ -f ${exdir}/nsrexecd ]; then
	(${nsrexeccmd})	> /dev/console 2>&1
	(echo ${nf} ' nsrexecd${nt}') > /dev/console
	(echo '') > /dev/console
fi
if [ -f ${exdir}/nsrd ]; then
	(${exdir}/nsrd)	> /dev/console 2>&1
	(echo ${nf} ' nsrd${nt}') > /dev/console
	(echo '') > /dev/console
fi
${end_message}"

	fi
	fi
fi
	restart_mod
	# nothing more to do
	banner="${productname}"
if [ X${myarch} = Xsolaris -o X${myarch} = Xsol86 -o \
     X${myarch} = Xsolppc ]; then
	#
	# "man.cf" is a man page configuration file. When the user does NOT
	# request a specific section on the "man" command line, this file
	# is used to determine the order manual sections in this directory
	# tree are searched. If the file exists only those sections listed
	# in the file are searched. If the file does NOT exist all
	# sub-directories are searched.
	#
	# If the file does not exist it should not be created, because only
	# the sections added by this script would be searched.
	#
	# So if the file exists make sure section 8 is on the list of
	# sections to be serached, else don't do anything.
	#
	if [ -f /usr/man/man.cf -a -w /usr/man/man.cf -a "${domanpage}" = "y" ]
	then
		file=/usr/man/man.cf
		insertmode=y
		searchstr=",8"
		insertcmd="s/MAN.*/&\,8/"
		sedcmd="s/\,8//"
		modfile
		insertmode=""
	fi
	f=/lib/X11/app-defaults/Networker
	if [ "${BASEDIR}" != /usr -a -f "${BASEDIR}${f}" -a "${pflag}" = y ]; then
		exec="rm -f /usr${f}"
		doexec
		if [ "${op}" = "install" ]; then
			exec="cp ${BASEDIR}${f} /usr${f}"
			doexec
		fi
	fi
fi
} # end modifyclientfiles

#
# Server installation: make sure that we have ${nsrhome} set up.
#

#
# XXX - later add code to check for available disk space using
# df and give some useful information about what can be supported
# based on the current amount of free space in ${nsrhome}.
#
buildindexdirs()
{
test_objects="indexes"
if [ ${op} = install ]; then
	if [ ! -d "${NSRHOME}" ]; then
		qecho "	Directory ${NSRHOME}, does not exist."
		qecho "	Creating directory ${NSRHOME}."
		mmkdir "${NSRHOME}"
	fi	
	#
	# If the user supplied nsr home directory NSRHOME is not the default
	# nsr home directory nsrhome then create a symbolic link.
	#
	if [ ! "${NSRHOME}" = "${nsrhome}" ]; then
		if [ -d ${nsrhome} -a "${pflag}" = y ]; then
			# probably pkgadd after LGTOclnt created ${nsrhome}
			# if there's something useful in it, rename the
			# existing /nsr, else blow it away and start again
			if [ -f ${nsrres} -o -d ${index_dir}/${host} ]; then
			    exec="mv -f ${nsrhome} ${nsrhome}.pre-${RELEASE}"
			    doexec
			else
			    exec="rm -rf ${nsrhome}"
			    doexec
			fi
			if [ -d ${nsrhome} ]; then
				echo "
FATAL ERROR: cannot create symbolic link ${nsrhome} to ${NSRHOME}
because ${nsrhome} already exists. " | ${fmt}
				exit 1
			fi
		fi
		qecho "	Installing ${productname} home directory in ${NSRHOME}"
		exec="ln -s "${NSRHOME}" ${nsrhome}"
		doexec
	fi
	if [ ! -d "${nsrreshome}" ]; then
		exec="mkdir ${nsrreshome}"
		doexec
	fi
	if [ ! -d "${rapmom}" ]; then
		# probably an RS/6000 or SCO, or SGI
		exec="mkdir ${rapmom}"
		doexec
	fi
	if [ ! -d ${index_dir} ]; then
		exec="mkdir ${index_dir}"
		doexec
	fi
	if [ ! -d ${mm_dir} ]; then
		exec="mkdir ${mm_dir}"
		doexec
	fi
	if [ ! -d ${nsrhome}/tmp ]; then
		exec="mkdir ${nsrhome}/tmp"
		doexec
	fi
	chmod 777 ${nsrhome}/tmp
	if [ ! -d ${log_dir} ]; then
		exec="rm -f ${log_dir}"
		doexec
		exec="mkdir ${log_dir}"
		doexec
		exec="touch ${log_dir}/messages ${log_dir}/summary"
		doexec
		exec="chown daemon ${log_dir}/messages ${log_dir}/summary"
		doexec
	fi
	if [ ! -d "${raphome}" ]; then
		exec="rm -f ${raphome}"
		doexec
		if [ ! -d "${nsrhome}/rap" ]; then
			exec="mkdir ${nsrhome}/rap"
			doexec
		fi
		exec="ln -s ${nsrhome}/rap ${raphome}"
		doexec
	fi
fi

if [ ${op} = install ]; then
	qecho \
"	${productizing} system files"
else
	qecho \
"	${deproductizing} system files"
fi
} # end buildindexdirs

#
# Handle each of the system files that we need to modify.
#
# /etc/rpc
# /etc/rc.local
# /etc/syslog.conf
#

#
# Add name to number mapping to /etc/rpc
#
modifyserverfiles()
{
file=/etc/rpc
searchstr='^nsr'
sedcmd="/${searchstr}/d"
appendstr=\
"nsrd		390103	nsr
nsrmmd		390104	nsrmm
nsrindexd	390105	nsrindex
nsrmmdbd	390107	nsrmmdb
nsrstat		390109
nsrjb		390110	nsrjbd
nsrexec		390113	nsrexecd"

if [ $server = y ]; then
	modfile
fi

#
# Add RAP name to number mapping to /etc/rpc too
#
file=/etc/rpc
searchstr='39010[1-2]'
sedcmd="/${searchstr}/d"
appendstr=\
"rap		390101	rapla
rapserv		390102	raprd"

if [ $server = y ]; then
	modfile
fi

#
# Make the default syslog changes
#
file=/etc/syslog.conf
#
# Different syslogs have different configuration formats
#
if [ ${sun} = y -o ${hpux} = y -o ${aix} = y -o ${sco} = y -o \
     ${myarch} = solaris -o ${myarch} = sol86 -o ${myarch} = solppc ]; then
	searchstr="${start_message}"
	sedcmd="/${start_message}/,/${end_message}/d"
	appendstr=\
"${start_message}
# installed by ${myname} on `date`
daemon.notice			/dev/console
daemon.notice			${log_dir}/messages
daemon.notice			operator
local0.notice			${log_dir}/summary
local0.alert			root, operator
${end_message}"

	if [ $server = y ]; then
		modfile
	fi
else
	# We don't bother using the DEC syslog facility by default.
	filechange=n
fi

if [ X${filechange} = Xy ]; then
	file=/etc/syslog.pid
	if [ -f ${file} ]; then
		echo \
"	Restarting syslog daemon"
		exec="kill -1 `cat ${file}`"
		errquit=n
		doexec
		errquit=y
	fi
	if [ ! -f ${file} -o ${execstatus} -ne 0 ]; then
		echo "
I'm having trouble figuring out how to (re)start syslog daemon
on \`${host}'.  Restart the syslog daemon by hand, if necessary.
" | ${fmt}
	fi
fi
} # end modifyserverfiles

installepilog()
{
if [ ${op} = install ]; then
	#
	# Now do the real work...
	#

	qecho \
"	Completing Installation"
	exec="(mkdir /nsr/res) > /dev/null 2>&1"
	errquit=n
	doexec
	# Copy NSR resource file to new location.
	if [ $server = y -a -f ${old_nsrres} ]; then
		errquit=y
		exec="cp ${old_nsrres} ${nsrres}"
		doexec
		# Before removing old placement of nsr.res, make sure new one
		# is actually there.
		if [ -f ${nsrres} ]; then
			exec="rm ${old_nsrres}"
			doexec
		fi
	fi

	if [ $server = y -a "${pflag}" != "y" ]; then
		add_rmv_drivers	# install any drivers for this architecture
	fi

	if [ "${DODAEMONS}" = y ]; then
		qecho \
"	Starting ${productname} daemons"
		exec="(cd /; ${exdir}/nsrexecd${NSREXECD})"
		doexec
		if [ $server = y ]; then
			exec="(cd /; ${exdir}/nsrd)"
			doexec
		fi
	fi
else
	if [ ${upgrade} = false -a -d "${nsrhome}" -a "${pflag}" != y ]; then
		qecho \
"	Removing ${productname} directories"
		if [ $server = y ]; then
			add_rmv_drivers	# possibly deinstall any added drivers
		fi
		exec="rm -rf ${cores_dir}"
		doexec

		# XXX
		# Need question in request
		#
		if [ -d "${raphome}" ]; then
			qecho \
"	Removing RAP resource directory ${raphome}"
			exec="rm -rf ${raphome} ${nsrhome}/rap"
			doexec
		fi
		# XXX
		# Need question in request
		#
		if [ -d ${log_dir} ]; then
			qecho \
"	Removing ${productname} logging directory ${log_dir}"
			exec="rm -rf ${log_dir}"
			doexec
		fi

		# XXX
		# Need a way to delay this action for 5 or 10 min.
		# Warn customer that this will occur, and how to stop
		# it.
		if [ -d ${mm_dir} ]; then
			qecho \
"	Removing all on-line index and volume information"
			exec="rm -rf ${mm_dir} ${index_dir} ${nsrhome}/tmp"
			doexec
		fi

	elif [ $server = y -a "${pflag}" != y ]; then
		add_rmv_drivers # possibly deinstall any added drivers
		exec="rm -f ${index_dir}/*/.nsr"
		doexec
	else
		qecho ""
		qecho "To completely remove ${productname} from the system"
		qecho "you must remove the ${nsrhome} directory. ${nsrhome}"
		qecho "may be a symbolic link, if so you will also need to"
		qecho "remove the directory that it points to."
		qecho ""
		qecho "Warning: the ${nsrhome} directory contains the online"
		qecho "client file index files and the server media index file."
		qecho "You should only remove it if you want to completely"
		qecho "remove ${productname} from the system."
	fi
fi
} # end installepilog
# @(#)addrm.sh 6.3 96/04/14 Copyright (c) 1995, Legato Systems, Inc.
#
# The shell functions in this file do the process of installing
# and removing NetWorker binaries. 
#
# Rules:
# 1) No user interaction should happen in this file all interaction
#    should be driven by shell environment variables sourced from
#    the ${NSRREQUEST} file. (note: rule "1" is currently violated
#    however since only nsr_ize includes these shell functions it
#    is acceptable. When this file is converted we will able to 
#    drive a nsr_ize install by a UI front end.)
# 2) This file should not be included in any package installation scripts.
#    (e.g. don't include it in pkgadd's postinstall or postremove scripts.)

#
# install/remove the nsr_man shell script.
#
handle_nsr_man()
{
	file="${dir}/nsr_man"
	if [ ${op} = install ]; then
		if [ -f "${file}" ]; then
			if [ ${nflag} = y ]; then
				qecho "${file} already exists, overwriting (not really)..."
				return
			fi
			qecho "${file} already exists, overwriting..."
			exec="rm -f ${file}"
			doexec
		fi

		qecho \
"	Creating ${file}"
		if [ ${nflag} = n ]; then
			cat > "${file}" << EOF
#! /bin/sh
#
# print out a list of the NetWorker man pages
#
# This is intended to be used to list the file arguments to troff,
# as in the shell command:
# 		% troff -man \`nsr_man -l\`

myname="\$0"
# the line below is automaticaly modified, so it must match '^man_dir=".*"$'
man_dir="$man"
man_list="$man_list"

if [ -r /usr/bin/sh5 ]; then
	#
	# The standard DEC sh doesn't handle functions, we
	# need to make sure that we are using the sh5 shell.
	#
	if [ "X\${MAN_SHELL5}" != "X/usr/bin/sh5" ]; then
		MAN_SHELL5=/usr/bin/sh5
		export MAN_SHELL5
		exec sh5 \$0 \$*
	fi
fi

#
# usage function - prints out a usage message and exits
#
usage()
{
	echo "usage: \${myname} [-l]

 <no options>	  Print out this usage message.
 -l		  List the full path names to all the ${productname} man pages.

		  This can be used to print the ${productname} man pages with the
		  shell command below:
				troff -man \\\`\${myname} -l\\\`
"
}

if [ \$# -le 0 ]; then
	usage
elif [ \$# -gt 1 -o X"\$1" != X"-l" ]; then
	usage
	exit 2
else
	for file in \$man_list
	do
		echo "\$man_dir/man\${file}"
	done
fi

exit 0
EOF
			chmod a+x "${file}"
		fi
	else
		if [ -f "${file}" ]; then
			exec="rm -f ${file}"
			doexec
		else
			qecho "${file} does not exist"
		fi
	fi
}

#
# handlefiles function
# 	Install/Remove files, preserving modes and dates
#
#	cp -p on each file does the job, but Ultrix doesn't support this option
#	tar could be used, but you would have to run 2 tar processes
#	  per file or you have to give up the ability to not overwrite
#	  any existing installed binaries
#	so we use uasm to do the work for us, telling it not to overwrite
#	  any existing binaries by default.
#
# input:
#	dir	= destination where the files should be installed/removed
#	list	= list of files to installed/removed there
#
# output:
#	none
#
handlefiles()
{
	if [ -z "${list}" ]; then
		return 0;
	fi
	if [ ${op} = install ]; then
		test_objects="binaries"
		testdir ${dir}
		testfiles ${dir}
		errquit=n
		exec="uasm -si `echo ${list}` | (cd ${dir}; uasm -riY)"
		doexec
	else
		for file in ${list}
		do
			if [ -f ${dir}/${file} ]; then
				exec="rm -f ${dir}/${file}"
				doexec
			else
				qecho "${dir}/${file} does not exist"
			fi
		done
	fi
}

installmanpages()
{
if [ ${mflag} = y -a ${op} = install -a ! -d man ]; then
	#
	# skip installing the man pages, it appears
	# that they weren't extracted from the tape
	#
	mflag=n
fi

if [ ${mflag} = y ]; then
	# Optionally Install/Remove the man pages
	if [ -d ${man} ]; then
		if [ -w ${man} -a "X`ls ${man}`" != X ]; then
			# a writable, non-empty directory - use it
			default="yes"
		else
			if [ ! -w ${man} -a "X`ls ${man}`" != X ]; then
				qecho \
"	${myname}: ${man} exists, but is not writable"
			fi
			default="no"
		fi
	else
		default="no"
	fi
fi

man_list="`prepend_manpaths $NSR_MAN_LIST`"

if [ ${mflag} = n ]; then
	result=n
elif [ ${op} = install ]; then
	action="installed"
	preposition="into"
	prompt="Install the ${productname} man pages"
	yesno
else
	action="removed"
	preposition="from"
	# If removing, ask the user whether there are man pages installed
	prompt="Remove the ${productname} man pages"
	yesno
fi

if [ "${result}" = y ]; then
	domanpage=y
prompt="Directory ${preposition} which the ${productname} man pages
should be ${action}"
	default=${man}
	verifydir
	man="${result}"
	if [ ${op} = install ]; then
		qecho \
"	Installing ${productname} man pages into ${man}"
	else
		qecho \
"	Removing ${productname} man pages from ${man}"
	fi
	for file in ${man_list}; do
		if [ `expr "${file}" : '.*nsr_ize'` -ne 0 ]; then
			break
		fi
	done
	if [ ! -z ${file} -a -f ${man}/${sectiondir}${file} ]; then
		grep "${productname} ${RELEASE}" ${man}/${sectiondir}${file} > /dev/null 2>&1
		case $? in
		0)	;;
		*)	qecho \
"
	Man pages are not for ${productname} ${RELEASE}!
	You must de-install ${productname} using the same
	version of ${myname} as was used for installation.

${myname}: exiting..."
			exit 1
			;;
		esac
	fi
	catmanlist=
	fmtmanlist=
	test_objects="manual pages"
	lastdir=
	didi=

	# make sure the tree exists before attempting to create subdirectories
	if [ ! -d ${man} ]; then
		qecho "	Directory ${man}, does not exist."
		qecho "	Creating directory ${man}."
		mmkdir "${man}"
	fi

	for file in ${man_list}; do
		sfile="$file"
		if [ $hpux = y ]; then
			# truncate the man page name portion of the path
			file="`trunc_manpaths $file`"
		fi
		dir="`dirname "${man}/${sectiondir}${file}"`"
		if [ ${op} = remove -a -f "${man}/${sectiondir}${file}" ]; then
			exec="rm -f ${man}/${sectiondir}${file}"
			doexec
			rmdir_if_empty_ask ${dir}
			if [ -f ${man}/cat${file} ]; then
				exec="rm -f ${man}/cat${file}"
				doexec
				dir="`dirname "${man}/cat${file}"`"
				rmdir_if_empty_ask ${dir}
			fi
			if [ -f ${man}/fmt${file} ]; then
				exec="rm -f ${man}/fmt${file}"
				doexec
				dir="`dirname "${man}/fmt${file}"`"
				rmdir_if_empty_ask ${dir}
			fi
			rmdir_if_empty_ask ${man}
		else
			if [ ${op} = install ]; then
				if [ ! -d ${dir} ]; then
					testdir "`dirname "${dir}"`"
					exec="mkdir ${dir}"
					doexec
				fi

				i="`dirname "${file}"`"
				dir="${man}/${sectiondir}${i}"
				if [ X"${lastdir}" != X"${dir}" ]; then
					testdir "${dir}"
				fi

				# remove any old version left around
				exec="rm -f ${man}/${sectiondir}${file}"
				doexec

				sfile=${sourcemandir}/"`basename "${sfile}"`"
				exec="cp ${sfile} ${man}/${sectiondir}${file}"
				doexec

				didmaninstall=y
				if [ `expr X${didi} : ".*${i}"` -ne 0 ]; then
					# already checked this directory out
					continue
				fi
				didi=${didi}${i}
				#
				# Now see if we have to add
				# anything for cat? directories.
				#
				dir="${man}/cat${i}"
				[ -d ${dir} ] && [ "X`ls ${dir}`" != X ] && \
					catmanlist="${catmanlist}${i}"
				#
				# Now see if we have to add
				# anything for fmt? directories.
				#
				dir="${man}/fmt${i}"
				[ -d ${dir} ] && [ "X`ls ${dir}`" != X ] && \
					fmtmanlist="${fmtmanlist}${i}"
			else
				qecho \
"	${man}/${sectiondir}${file} does not exist"
			fi
		fi
	done
	if [ X${didmaninstall} != X -a X${sourcemandir} != Xcatman ]; then
		if [ X${catmanlist} != X ]; then
			prompt="Format new nroff copies of man pages"
			prompt="${prompt}"' (NOTE - this takes a while)'
			default="yes"
			yesno
			if [ ${result} = y ]; then
				exec="catman -M ${man} ${catmanlist}"
				errquit=n
				doexec
			fi
		fi
		if [ X${fmtmanlist} != X ]; then
			prompt="Format new troff copies of man pages"
			prompt="${prompt}"'(NOTE - this takes a while)'
			default="yes"
			yesno
			if [ ${result} = y ]; then
				exec="catman -t -M ${man} ${fmtmanlist}"
				errquit=n
				doexec
			fi
		fi
		if [ X${catmanlist} = X -a X${fmtmanlist} = X -a \
		    -f ${man}/whatis ]; then
			# just redo the whatis database
			prompt="Update the man page directory"
			prompt="${prompt}"' (NOTE - this takes a while)'
			default="yes"
			yesno
			if [ ${result} = y ]; then
				exec="catman -w -M ${man}"
				errquit=n
				doexec
			fi
		fi
	fi
fi
} # end installmanpages

installexecutables()
{
# Current policy is to only support installing one architecture at a time.
arch=${myarch}

# Install/Remove all the executables for each architecture
skip_execs=false
if [ ${op} = install ]; then
	if [ X${arch} = X${myarch} -o -d /export/exec/${arch}/etc ]; then
		default=yes
	else
		default=no
	fi

	prompt=\
"Install the ${arch} ${productname} programs"
	yesno
	if [ $result = n ]; then
		# need to confirm the directory name
		# for the executables to make sure we
		# do the right thing for starting daemons
		# and/or installing this script near the end
		prompt=\
"Directory where the ${arch} ${productname} programs
are already installed"
		default=${default_bin}
		verifydir
		exdir=${result}
		skip_execs=true
	else
		if [ ! -d ${arch} ]; then
			# no ${arch} directory to get executables from
			qecho \
"${myname}: cannot find ${arch} programs for this architecture!
If necessary, extract the ${arch} programs from the ${productname}
distribution tape.

$myname: exiting..."
			 exit 1
		fi

		# Verify that the files came off the tape ok
		dir=`pwd`/${arch}
		if [ ${nflag} = n ]; then
			check_setuid
		fi

	fi
else
	default=yes
	prompt=\
"Remove the ${productname} programs"
	yesno
	if [ $result = n ]; then
		# need to confirm the directory name
		# for the executables to make sure we
		# do the right thing for removing rc file entries, etc.
		prompt=\
"Directory where the ${productname} programs
are installed"
		default=${default_bin}
		verifydir
		exdir=${result}
		skip_execs=true
	fi
fi

# Skip installing or removing executables
if [ $skip_execs = "false" ]; then

	# Set default bin directory
	if [ X${arch} = X${myarch} ]; then
		dir=${default_bin}
	elif [ -d /export/exec/${arch}/etc ]; then
		dir=/export/exec/${arch}/etc
	else
		dir=
	fi

	#
	# The sun386 comes with /usr mounted read-only and over 100% full.
	# For now, we verify that the install directory is writable and
	# if not, we just don't have a reasonable default directory.
	#
	if [ X${dir} != X ]; then
		if [ ! -w ${dir} ]; then
			# sigh, no default directory
			qecho \
"	Cannot write ${dir}, no default installation directory"
			dir=
		fi
	fi

	if [ ${op} = install ]; then
		prompt=\
"Directory where ${arch} ${productname} programs
should be installed"
	else
		prompt=\
"Directory from which the ${arch} ${productname} programs
should be removed"
	fi

	default=${dir}
	verifydir
	dir=${result}

	# make sure that ${dir} uses an absolute pathname
	if [ `expr X${dir} : X/` -eq 0 ]; then
		dir=`pwd`/${dir}
	fi

	# remember the install dir for later uses
	exdir=${dir}

	# if de-installing, make sure nsr_ize is the right version
	if [ ${op} != install -a -f ${exdir}/nsr_ize ]; then
		grep "RELEASE=${RELEASE}" ${exdir}/nsr_ize > /dev/null 2>&1
		case $? in
		0)	;;
		*)	qecho \
"
	Executables are not for ${productname} version ${RELEASE}!
	You must de-install ${productname} using the same
	version of ${myname} as was used for installation.

${myname}: exiting..."
			exit 1
			;;
		esac
	fi

	if [ $server = y ]; then
		list="${client_files} ${server_only_files} `arch_specific_files`"
	else
		list="${client_files} `arch_specific_files`"
	fi

	if [ $server = n ]; then
		if [ ${op} = install ]; then
			qecho \
"	Installing ${arch} ${productname} client programs into ${dir}"
		else
			qecho \
"	Removing ${arch} ${productname} client programs from ${dir}"
		fi
	else if [ ${op} = install ]; then
			qecho \
"	Installing ${arch} ${productname} programs into ${dir}"
		else
			qecho \
"	Removing ${arch} ${productname} programs from ${dir}"
		fi
	fi

	if [ ${op} = install ]; then
		cd ${arch}
		bindir="${dir}"
		handlefiles		# install all the needed binaries
		handle_nsr_man
		cd ..
		list="${client_common_files}"
		handlefiles

		# Verify that the files made if over to ${dir} ok
		if [ ${nflag} = n ]; then
			check_setuid
		fi
		if [ -f Networker -a -d /usr/lib/X11/app-defaults ]; then
			# Don't abort on errors, in case the cp fails such as
			# if /usr/lib is a remote mounted R/O directory.
			# Failure is not fatal.  nwadmin has built-in defaults.
			exec="cp Networker /usr/lib/X11/app-defaults"
			errquit=n
			doexec
		fi
		if [ ${arch} = sun4 ]; then
			olddir=${dir}
			list="nls"
			dir="/usr/lib/X11"
			# Make /usr/lib/X11 if it does not
			# exist.
			if [ ! -d ${dir} ]; then
				exec="mkdir ${dir}"
				doexec
			fi
			# Do nothing on ${op}=remove because there is
			# no way to tell if we installed these files
			# or they were already there. Assume that if
			# ${dir} does not exist they don't have X
			# and won't run nwadmin....
			if [ ! -d ${dir}/${list} ]; then
				errquit=n
				exec=\
"( cd ${arch}; uasm -si `echo ${list}` ) | (cd ${dir}; uasm -r)"
				doexec
			fi
			dir=${olddir}
		fi
	else
		list="${list} ${client_common_files}"
		handlefiles		# remove the ${productname} files
		handle_nsr_man
		if [ -f /usr/lib/X11/app-defaults/Networker ]; then
			exec="rm -f /usr/lib/X11/app-defaults/Networker"
			doexec
		fi
	fi
	#
	# Atimeasm was undocumented external program created by using
	# a link to mailasm prior to 4.1 that nsr_ize never knew about
	# so it never was cleaned up by older versions of nsr_ize.
	# Now that atimeasm it is built in, just blow away if we see one.
	#
	if [ ${link_test_opt} "${dir}/atimeasm" -o -f "${dir}/atimeasm" ]; then
		exec="rm -f ${dir}/atimeasm"
		doexec
	fi
fi
} # end installexecutables

#
# If a package tool is used to install selectively do this section (e.g. pkgadd,
# custom, installp). Check pflag to determine if package tool is being
# used.
#
installfiles()
{

	if [ X${pflag} = Xy ]; then
		# ${server} and ${op} variables should already be set up...
		skip_execs=true
	else
		# steps to verify things and set up some variables
		findoperation
		verifysupport
		verifyoperationmode	# terminates on error
		installprolog		# terminates on error
	fi
	#
	# Do some checks now that ${op} and ${servers} variables are set.
	#
	verifyscosls
	stopdaemons

	if [ X${pflag} = Xn ]; then
		installmanpages
		installexecutables
	fi
	requestmain
} # end installfiles

# actually *install* the driver (if any)
add_rmv_drivers()
{
	#
	# Patch up for pre-xenia:
	#
	# unconditionally remove any old
	# sjidriver or uscsidrv directories
	#
	for obslist in sjidriver uscsidrv
	do
		if [ -d ${nsrhome}/${oblist} ]; then
			exec="rm -rf ${nsrhome}/${obslist}"
			doexec
		fi
	done
	#
	mandir=$man
	# export condition of man page installation
	export domanpage mandir
	# export execution bin directory (for pscinfo)
	export exdir
	#
	if [ ${op} = install -a -f ${myarch}/drivers/install ]; then
		default="yes"
		prompt="Install the NetWorker device drivers"
		yesno
		if [ $result = y ]; then
			exec="rm -rf ${nsrhome}/drivers"
			doexec
			if [ ! -d ${nsrhome}/drivers ]; then
				exec="mkdir ${nsrhome}/drivers"
				doexec
			fi
			exec="cp -r ${myarch}/drivers/* ${nsrhome}/drivers/"
			doexec
			exec="chmod 555 ${nsrhome}/drivers/*"
			doexec
			exec="(cd ${nsrhome}/drivers; ./install)"
			doexec
		fi
	fi
	if [ ${op} = remove -a -f ${nsrhome}/drivers/deinstall ]; then
		default="yes"
		prompt="Remove the NetWorker device drivers"
		yesno
		if [ $result = y ]; then
			exec="(cd ${nsrhome}/drivers; ./deinstall)"
			doexec
			exec="rm -rf ${nsrhome}/drivers"
			doexec
		fi
	fi
}

buildlists()
{
#
# List of the standard files that need to be installed/removed.
#

#
# flagfile is used as a boolean to determine if the product is installed
#
flagfile="nsr_ize"

client_files="\
mminfo
mmlocate
mmpool
nsradmin
nsrarchive
nsrclone
nsrexecd
nsrinfo
nsrmm
nsrretrieve
nsrwatch
recover
save
savefs
uasm
"

server_only_files="\
ansrd
asavegrp
jbexercise
jb_config
nsralist
nsrcap
nsrck
nsrd
nsrim
nsrindexasm
nsrindexd
nsrjb
nsrls
nsrmmd
nsrmmdbasm
nsrmmdbd
mmrecov
savegrp
scanner
tapeexercise
"

#
# To include product.res in the installation add it
# to the list below
#
#product.res
#

client_common_files="\
nsr.help
nsr_shutdown
nsr_support
"

# What the nsr setuid programs should have for their mode and owner
setuid_mode="rwsr-xr-x"
setuid_owner="root"

# Setuid client programs
setuid_client="\
recover
save
"

# Setuid server-only programs
setuid_server="\
savegrp
"

#
# server only nsr snmp man pages
#
if [ "${myarch}" = "sun4" -o "${myarch}" = "solaris" -o \
	"${myarch}" = "sol86" -o "${mayarch}" = "solppc" -o \
	"${myarch}" = "aix6000" ]; then
		SNMP_MAN_LIST="nsrtrap.8"
fi

#
# List of man page files to be installed/removed relative to ${man}/man
#
NSR_MAN_LIST="\
getdate.3 mm_data.5 nsr.5 nsr_archive_request.5 nsr_client.5 nsr_data.5 nsr_device.5 nsr_directive.5 nsr_group.5 nsr_jukebox.5 nsr_label.5 nsr_layout.5 nsr_license.5 nsr_migration.5 nsr_notification.5 nsr_policy.5 nsr_pool.5 nsr_resource.5 nsr_schedule.5 nsr_service.5 ansrd.8 asavegrp.8 changers.8 erase.8 hpflip.8 ielem.8 inquire.8 jb_config.8 jbexercise.8 ldunld.8 libscsi.8 libsji.8 lrescan.8 lreset.8 lusbinfo.8 lusdebug.8 lusmode.8 mminfo.8 mmlocate.8 mmpool.8 mmrecov.8 msense.8 networker.8 nsr.8 nsr_crash.8 nsr_ize.8 nsr_shutdown.8 nsradmin.8 nsralist.8 nsrarchive.8 nsrcap.8 nsrck.8 nsrclone.8 nsrd.8 nsrexecd.8 nsrhsmck.8 nsrib.8 nsriba.8 nsrim.8 nsrindexasm.8 nsrindexd.8 nsrinfo.8 nsrjb.8 nsrls.8 nsrmig.8 nsrmm.8 nsrmmd.8 nsrmmdbasm.8 nsrmmdbd.8 nsrpmig.8 nsrretrieve.8 nsrwatch.8 nwadmin.8 nwarchive.8 nwbackup.8 nwrecover.8 nwretrieve.8 pmode.8 recover.8 relem.8 save.8 savefs.8 savegrp.8 scanner.8 sjidopen.8 sjiielm.8 sjiinq.8 sjirdp.8 sjirdtag.8 sjirelem.8 sjirjc.8 tapeexercise.8 tur.8 uasm.8 writebuf.8
resource.5
${SNMP_MAN_LIST}
"

#
# server only nsr snmp binaries.
#
snmp_server_files="\
nsrtrap
"

#
# client only nsr hsm binaries.
#
hsm_client_files="\
nsrhsmck
nsrib
nsriba
nsrpmig
nsrmig
"
} # end buildlists

#
# prepend the section number as a directory in front of the manpage name
# eg: nsrd.8 -> 8/nsrd.8
#
prepend_manpaths()
{
	OIFS="${IFS}"
	IFS=".${OIFS}"
	set -- $*
	while [ $# -gt 1 ]
	do
		manpage="$1"
		section="$2"
if [ "${sco}" = "y" ]; then
		echo ".${section}/${manpage}.${section}"
else
		echo "${section}/${manpage}.${section}"
fi
		shift; shift
	done
}

#
# truncate the man page path arguments to 11 characters (for sysV filesystems)
#
trunc_manpaths()
{
	for path in $*
	do
		OIFS="${IFS}"
		IFS="./${IFS}"
		set X $path
		IFS="${OIFS}"
		dir="$2"
		manpage="$3"
		section="$4"
		echo "${dir}/`expr "$manpage" : '\(...........\)' \| "$manpage" : '\(.*\)'`.${section}"
	done
}

#
# arch_specific_files function
#
# list the archecture specific files for needed for this architecture
#
# inputs:
#	arch=	arch value to use
#	server= "y" or "n"
#
arch_specific_files()
{
	tmp="networker nwadmin nwarchive nwbackup nwrecover nwretrieve"
	case ${arch} in
	    linux)
		if [ -f ./Networker ]; then
			tmp="networker nwadmin nwbackup nwrecover"
		else
			tmp=
		fi
		;;
	    sun386 | sun3)
		# no specific executables
		tmp=
		;;
	    sun4 | solaris | sol86 | solppc | aix6000)
		# Motif and maybe SNMP
		if [ ${arch} != "aix6000" ]; then
			tmp="${tmp} ${hsm_client_files}"
		fi
		if [ ${server} = "y" ]; then
			tmp="${tmp} ${snmp_server_files}"
		fi
		;;
	    * )
		# Motif specific executables
		;;
	esac

	case "X{$tmp}" in
	    X)	# nothing to do
		;;
	    *)	echo "${tmp}"
		;;
	esac
} # end arch_specific_files

#
# Check if product supported on this architecture
#
verifysupport()
{
if [ ${op} = install -a X${Fflag} != Xy ]; then
	if [ ! -d ${myarch} ]; then
		if [ ${myarch} = solaris -a -d sun4 ]; then
			echo "
Error: You have attempted to install Sun 4.1.x binaries on a ${myarch} system."
			exit 1
		fi
		if [ -f mminfo -o ! -f ${flagfile} ]; then
			echo "
Error: You are in the wrong directory for installation.
Change to the directory into which you extracted the
distribution media and retry the installation."
			exit 1
		fi
		echo "
$productname is not supported on ${myarch} machines."
		exit 1
	fi

	if [ ! -f ${myarch}/nsrd ]; then
		if [ ${server} = y ]; then
			if [ ${myarch} = solaris -a -d sun4 ]; then
				echo "
Error: You attempted to install Sun 4.1.x binaries on a ${myarch} machine."
				exit 1
			else
				echo "
$productname is not supported for server configurations on ${myarch} machines."
			fi
		fi
		server=n
	fi
fi
} # end verifysupport
# @(#)askio.sh 6.1 95/12/15 Copyright (c) 1995, Legato Systems, Inc.
#
# All NetWorker install and remove user input will come from shell functions
# in this file.
#
# Rules:
# 1) Store user responses in ${NSRREQUEST} file for use by other scripts.
# 2) Other scripts must source the ${NSRREQUEST} for their input.
# 3) The flow of the questions must be as deterministic as possible so
#    that automated installs can be done with response files generated
#    by pkgask.

#
# Return the name of a local directory with the most space
# that is writable by root
#
# outputs:
#	bigdir= directory path
#	bigdirs= the 4 mount points with the most free space...
#
find_bigdir()
{
	x4=
	bigdirs=
	bigdir=
	OIFS="$IFS"
	if [ ${sco} = y ]; then
		output="`${df} 2>/dev/null | sort -nr -t: +1 \
				| awk '/\(\/dev\// { if ( $1 != "/tmp" ) print sprintf("%-30s:%8.8s", $1, $4) }'`"
	else
		output="`${df} 2>/dev/null | sort -nr +3 -5 \
				| awk '/^\/dev/ { if ( $6 != "/tmp" ) print sprintf("%-30s:%8.8s", $6, $4) }'`"
	fi
	# don't loose the white space -- remove space from the internal field
	# separator list (only tab and ret)
	IFS='
	'
	# use tabs, not spaces, in the following line...
	for	i	in	$output
	do
		# trim the spaces and :
		IFS=":${OIFS}"
		set -- $i
		# go back to the original
		IFS="${OIFS}"
		if [ -w "${1}" ]; then
			x4="${x4}x"	# cheap way of counting to 4.
			if [ -z "${bigdir}" ]; then
				bigdir="${1}"
			fi
			bigdirs="${bigdirs}
${i}";
			if [ ${x4} = "xxxx" ]; then
				return	# we've got four now...
			fi
		fi
	done
}

#
# verify that we can write in ${1}
#
testdir()
{
	_dir="${1}"
	while [ ! -w "${_dir}" ];
	do

		echo "
${myname}: ERROR, the permissions on ${_dir} do not allow root to write in it"
		prompt="Should I change the permissions on ${_dir} to allow root write access?"
		default="yes"
		yesno
		if [ $result = y ]; then
			chmod u+w "${_dir}" > /dev/null 2>&1
		else
			echo "
${myname}: ERROR, this process cannot complete.  Please rerun ${myname} when you
have either fixed the problem, or decided to use another directory for
the ${productname} ${test_objects}." | ${fmt}
			echo "
${myname}: aborting..."
			exit 2
		fi

	done
	touch "${_dir}/nsr$$" > /dev/null 2>&1
	if [ $? -ne 0 ]; then
		echo "
${myname}: ERROR, ${_dir} is not writable by root!

This may be caused by ${_dir} being a remote filesystem where this
machine doesn't have write permission privledges for root. See the
${productname} 'Read This First' document for further instructions on how
to use a remote filesystem for the ${productname} ${test_objects}.

After correcting this problem please run ${myname} again.

${myname}: aborting..."
		rm -f "${_dir}/nsr$$"
		exit 1
	fi
	set X `ls -l ${_dir}/nsr$$`
	if [ "$4" != "root" ]; then
		echo "
${myname}: FATAL ERROR, files created in ${_dir} by root do not end up being owned by root!

This can be caused by ${_dir} being a remote filesystem where the
root user id from this machine is being mapped to user \`$4' on the
remote machine.

After correcting this problem please run ${myname} again.

${myname}: aborting..."
		rm -f "${_dir}/nsr$$"
		exit 1
	fi
	rm -f "${_dir}/nsr$$"
}

#
# rmdir_if_empty
#
# remove the specified directory, if it is empty.  If it really is a symlink
# to a empty directory, remove both.
#
#	$1 	-- the directory to remove (if empty)
#
rmdir_if_empty_ask()
{
	rie_dir="$1"
	rie_ls_output="`ls ${rie_dir} 2>&1`"

	if [ -z "${rie_ls_output}" ]; then
		# directory is now empty, nuke it
		prompt="${rie_dir} is empty, remove it"
		default="yes"
		yesno
		if [ ${result} = n ]; then
			qecho "	Skipping removal of ${rie_dir} directory"
		else
			# check if directory to be removed is a symlink
			rie_ls_output="`ls -ld ${rie_dir}`"
			case "$rie_ls_output" in
			l* )
				# remove what it points to
				exec="rmdir `cd ${rie_dir}; /bin/pwd`"
				errquit=n
				doexec
				;;
			esac

			exec="rm -rf ${rie_dir}"
			doexec
		fi
	fi
}

#
# isupgrade function - determine whether this will be an upgrade
# removal or a complete removal.
#
isupgrade()
{
qecho ""
qecho "WARNING: if you answer [yes] to the following question the entire"
qecho "contents of the ${nsrhome} directory will be removed. This"
qecho "includes the online client index files and server media index"
qecho "file. You should only answer [yes] if you want to completely"
qecho "remove ${productname} from the system."

prompt="Do you want to remove ${productname} configuration and database files"
	default="no"
	yesno
	if [ X${result} = Xn ]; then
		upgrade=true
	fi
}

#
# Process arguments
#
processargs()
{
while [ $# -gt 0 ]; do
	case "$1" in
	-i)
		if [ ! -z "${op}" ]; then
			usage
		fi
		op=install
		shift
		;;
	-r)
		if [ ! -z "${op}" ]; then
			usage
		fi
		op=remove
		shift
		;;
	-u)
		if [ ! -z "${op}" -a "${op}" != remove ]; then
			usage
		fi
		op=remove
		upgrade=true
		shift
		;;
	-c)
		if [ ${server} != UNKNOWN ]; then
			usage
		fi
		server=n
		shift
		;;
	-s)
		if [ ${server} != UNKNOWN ]; then
			usage
		fi
		server=y
		shift
		;;
	-k)
		kflag=y
		shift
		;;
	-m)
		mflag=n
		shift
		;;
	-x)
		xflag=y
		shift
		;;
	-v)
		set -x
		shift
		;;
	-n)
		nflag=y
		shift
		;;
	-q)
		qflag=y
		shift
		;;
	-F)
		# allow *unsupported* install of server software
		Fflag=y
		shift
		;;
	-p)
		pflag=y
		shift
		;;
	-??*)
		# rip apart the concatenated argument, reset 'em, and reloop.
		first_opt="`expr substr "$1" 2 1`"
		rest_opts="`expr substr "$1" 3 255`"
		shift
		set -- "-$first_opt" "-$rest_opts" $*
		;;
	*)
		usage
		;;
	esac
done

#
# If not running in "do nothing mode" (or not debugging),
# insist on being run by the Super user.
#
whoiam=`${id} | grep root`
if [ ${nflag} != y -a ${xflag} != y -a -z "$whoiam" ]; then
	echo ""
	echo "FATAL ERROR: ${myname} must be run by the Super user!"
	exit 1
fi
} # end processargs

# yesno function
#
# Generic function to get yes/no answer
#
# inputs:
#	prompt=		string to prompt with (excluding default value)
#	default=	name of default value if no response
#
# outputs:
#	result=		'y' or 'n'
#
yesno()
{
	qecho ""
	if [ $nflag = y ]; then
		notreally="(not really) "
	else
		notreally=
	fi
	while true
	do
		if [ -z "${default}" ]; then
			echo_n "${prompt}${notreally}? "
			read ans
		elif [ ${qflag} = n ]; then
			echo_n "${prompt} ${notreally}[${default}]? "
			read ans
		else
			ans=y
		fi
		if [ "X${ans}" = X ]; then
			result="${default}"
		else
			result="${ans}"
		fi

		if [ `expr "X${result}" : 'X[yY]'` -ne 0 ]; then
			result=y
			break
		elif [ `expr "X${result}" : 'X[nN]'` -ne 0 ]; then
			result=n
			break
		else
			echo "Please respond \`yes' or \`no'"
		fi
	done
}

#
# verifycontinue
#
# Verify whether or not this program should continue
#
# inputs:
#	continuestr=	string to prompt with
#	default=	name of default value if no response
#
verifycontinue()
{
	echo "${continuestr}"
	prompt="Do you wish to continue with ${myname}"
	yesno
	if [ ${result} = n ]; then
		kill -2 $$
	fi
}

#
# verifydir function
#
# Generic function to verify or create a directory
#
# inputs:
#	prompt=		string to prompt with (excluding default value)
#	default=	name of default value
#	op=		"install" to create dir if it doesn't exist
#	local_only=	if "yes" filesystem must be local
# outputs:
#	result=		resultant confirmed value
#
verifydir()
{
	qecho ""
	while true
	do
		if [ -z "${default}" ]; then
			echo_n "${prompt}? "
			read ans
		elif [ ${qflag} = n ]; then
			echo_n "${prompt} [${default}]? "
			read ans
		else
			ans=
		fi
		if [ ! -z "${ans}" ]; then
			_res="${ans}"
		else
			if [ -z "${default}" ]; then
				continue
			fi
			_res="${default}"
		fi

		# verify that the file exists of the given type
		while true; do
			# it might be SingleServer; force local
			if [ "X${local_only}" = "Xyes" ]; then
				local_dir ${_res}
				if [ ${result} = false ]; then
					qecho "
Directory \`${_res}' is within a remote filesystem.
The directory must be within a local filesystem!"
					break
				fi
			fi
			if [ -d "${_res}" ]; then
				if [ -w "${_res}" ]; then
					result=${_res}
					return
				fi
				echo "\`${_res}' is not writable"
				break
			fi
			if [ ${op} = install ]; then
				result=${_res}
				return
			else
				echo "\`${_res}' does not exist"
				break
			fi
		done
	done
}

#
# testfiles function
#	Check if any files on ${list} exist in ${1}, if so
#	ask if they can be overwritten, exit if user says "no".
#
# input:
#	$1:	the directory to test
#	$list:	the files to check for in that directory
#
testfiles()
{
	_dir="${1}"
	_list=""

	for file in ${list}
	do
		if [ -f ${_dir}/${file} ]; then
			_list="${_list} ${file}"
		fi
	done

	case "X${_list}" in
	X)	;;
	*)	echo ""
		echo "The following files in ${_dir} will be overwritten:"
		echo ${_list} | ${fmt}
		continuestr=
		default="no"
		verifycontinue
		;;
	esac
}

#
# select_one_of function
#
# Let the user select from a set of values.
#
# inputs:
#	prompt=		string to prompt with (excluding default value)
#	default=	name of default value
#	selections=	space separated set of values
#	gb=		separate string for "8mm 5GB" hack
#
# outputs:
#	result=		selected value
#
select_one_of()
{
	result=""
	while true
	do
		# in quiet mode we just take the default if there is one
		if [ ${qflag} = n -o "X${default}" = X ]; then
			if [ "X${default}" = X ]; then
				qecho ${prompt}
				echo_n \
`echo "(one of \"${selections} ${gb}\")?" | ${fmt}`" "
			else
				qecho ${prompt}
				echo_n \
`echo "(one of \"${selections} ${gb}\") [${default}]?" | ${fmt}`" "
			fi
			read _ans
		else
			_ans=
		fi
		if [ -z "$_ans" ]; then
			_ans="${default}"
		fi
		for value in ${selections}
		do
			case "$_ans" in
				"$value" )
					result="${value}"
					break
				;;
			esac
		done
		if [ ! -z "${result}" ]; then
			break
		fi
		if [ "X${gb}" = "X${_ans}" ]; then
			result="${gb}"
			break
		fi
		echo "\`${_ans}' is not one of \"${selections} ${gb}\"; please try again"
	done
}

#
# getdevices function
#
# outputs:
#	none
#
getdevices()
{
	qecho ""
	if [ ${aix} = y ]; then
		echo "
The following is a list of the tape devices available on your system:" | ${fmt}
		device_count=`lsdev -C -c tape | wc -l`
		lsdev -C -c tape
		if [ ${device_count} = 1 ]; then
			dev=/dev/`lsdev -C -c tape -r name`.1
			type=`lsdev -C -c tape -r type`
			case ${type} in
			    9trk )
				type=himt
				;;
			    150mb )
				type=qic
				;;
			    ost|8mm5gb )
				type="8mm 5GB"
				;;
			    * )
				# hope it is correct
				;;
			esac
			echo "
The only tape device on your system is ${dev} of type ${type}."
			prompt=\
"Do you wish to use this as your ${productname} device"
			default="yes"
			yesno
			if [ ${result} = y ]; then
				if [ "${type}" = "8mm" ]; then
					chdev -l `lsdev -C -c tape -r name` -a extfm='yes'
				fi
				DEVLIST="$DEVLIST ${dev} ${type}"
				return
			fi
		fi
		qecho "
The name needed by ${productname} is usually \`/dev/' plus the name
of the device as given the first column of the above table, followed by
\`.1' to indicate a no-rewind device name."
	fi
	if [ ${sgi} = y ]; then
		echo "
The following is a list of the tape devices available on your system:" | ${fmt}
		hinv -c tape
	fi
	if [ ${demo} = y ]; then
		echo "
Enter the tape or disk device that is going to be used by the
${productname} server.  Use the no-rewind name for the tape device
(i.e., use ${no_rewind_example} instead of ${rewind_example})." | ${fmt}

		_prompt="
Enter device name:"

	else
		echo "
Enter the tape or disk device(s) that are going to be used by the
${productname} server. Use the no-rewind name for each tape device
If you do not choose a device a default device will be created for you.
(i.e., use ${no_rewind_example} instead of ${rewind_example}).
" | ${fmt}

		_prompt="
Enter device name ([Return] if no more):"
	fi

	gotadev=true
	while true
	do
		echo_n "${_prompt} "
		read dev
		if [ "X${dev}" = "X" -o "X${dev}" = "X." ]; then
			type="8mm 5GB"
			if [ ${dec} = y ]; then
				type="tk50"
			fi
			dev=${no_rewind_example}
			if [ ${gotadev} = false ]; then
				echo "
No backup devices have been specified.
${myname} needs to know which tape device(s) to set up for use
by the ${productname} server when files are being saved.
If no devices are specified here,
${productname} will be set up to use the default
tape device \`${dev}' with type \`${type}'.
" | ${fmt}
				prompt=\
"Use the default tape device configuration"
				default="yes"
				yesno
				if [ ${result} = n ]; then
					continue
				fi
				if [ ${aix} = y ]; then
					chdev -l rmt0 -a extfm='yes'
				fi
				DEVLIST="$DEVLIST ${dev} ${type}"
			fi
			# all done
			echo "DEVLIST=\"${DEVLIST}\"" >> ${NSRREQUEST}
			return
		fi
		_verify=n

		if [ ${aix} = y ]; then
			device_prefix=/dev/
			device_preflength=6
		else
			device_prefix=/dev/n
			device_preflength=7
			if [ ${myarch} = "solaris" -o ${myarch} = "sol86" -o \
				${myarch} = "solppc" ]
			then
				device_prefix=/dev/rmt
				device_preflength=9
			fi
		fi
		echo ${dev} | egrep '[:;]' > /dev/null
		if [ $? -ne 1 -o `echo "X${dev}" | wc -w` -ne 1 -o \
		    `expr "X${dev}" : X${device_prefix}` \
			-lt ${device_preflength} ]; then
			echo \
"\`${dev}' does not look like a typical tape device name
(it does not start with \`${device_prefix}' or is more than one word)" | ${fmt}
			_verify=y
		elif [ ! -c "${dev}" -a ! ${link_test_opt} "${dev}" ]; then
			echo \
"\`${dev}' is not a character special device on \`${host}'"
			_verify=y
		fi

		if [ $_verify = y ]; then
			prompt="Is this the device name you really wanted"
			default="no"
			yesno
			if [ $result = n ]; then
				continue
			fi
		fi

		prompt="Select device type for ${dev}:"
		if [ ${aix} = y ]; then
			default="8mm"
			basedev=`echo "${dev}" | awk '($2 ~ "dev") {print $3}' FS="[\.\/]" -`
			type=`lsdev -C -l ${basedev} -r type`
			case ${type} in
			    9trk )
				type=himt
				;;
			    150mb )
				type=qic
				;;
			    ost|8mm5gb )
				type="8mm 5GB"
				;;
			    8mm )
				chdev -l ${basedev} -a extfm='yes'
				;;
			    * )
				# hope it is correct already?
				;;
			esac
			echo "Device ${basedev} is of ${productname} type: ${type}"
		else
			if [ ${demo} = y ]; then
				default=""
			else
				default="8mm 5GB"
			fi
			selections="8mm 4mm himt 3480 qic optical dlt"
			gb="8mm 5GB"
			echo "Select the device type for \"${dev}\"."
			echo "The possible types are:"
			echo "	8mm 5GB	- 8mm double density tape."
			echo "	8mm 	- 8mm tape."
			echo "	4mm	- 4mm DAT tape."
			echo "	himt	- 1/2 inch magnetic tape."
			echo "	3480	- 1/2 inch cartridge tape."
			echo "	qic	- 1/4 inch data cartridge."
			echo "	optical	- Optical Disk."
			echo "	dlt	- Digital Linear Tape."
			echo "	vhs	- VHS Format Tape."
			echo ""
			select_one_of
			type=${result}
		fi
		echo ""

		# add device to the ${file} file
		DEVLIST="$DEVLIST ${dev} ${type}"
		if [ ${demo} = y ]; then
			break
		fi
	done
	echo "DEVLIST=\"${DEVLIST}\"" >> ${NSRREQUEST}
}

#
# See if a mode of operation was specified.
# If not, try to figure it out ourselves.
# If argv[0] has install or remove it in, we
# do that operation, otherwise we use the existence
# of ${flagfile} to determine mode of operation.
#
findoperation()
{
verifymode=n
if [ X${op} = X ]; then
	if [ `expr X${myname} : '.*install'` -ne 0 ]; then
		op=install
	elif [ `expr X${myname} : '.*remove'` -ne 0 ]; then
		op=remove
	elif [ ! -f ${default_bin}/${flagfile} ]; then
		op=install
		verifymode=y
	else
		op=remove
		verifymode=y
	fi
fi
} # end findoperation

#
# Verify the mode of operation
#
verifyoperationmode()
{
while true; do
	if [ ${op} = install ]; then
		preposition="on"
	elif [ ${upgrade} = true ]; then
		preposition="for upgrade from"
	else
		preposition="from"
	fi
	prompt="${op} ${productname}"
	if [ ${server} = UNKNOWN ]; then
		qecho "
${myname} is about to ${prompt} ${preposition} machine \`${host}'."
	else
		if [ ${server} = y ]; then
			qecho "
${myname} is about to ${prompt} server software
${preposition} machine \`${host}'."
		else
			qecho "
${myname} is about to ${prompt} client software
${preposition} client machine \`${host}'."
		fi
	fi
	if [ ${verifymode} = n ]; then
		break
	fi

	default="yes"
	prompt="Ready to ${prompt}"
	yesno
	if [ ${result} = y ]; then
		break
	fi

	if [ ${op} = install ]; then
		op=remove
		preposition="for"
	else
		op=install
		preposition="on"
	fi
	prompt=\
"Do you wish to ${op} ${productname} ${preposition} machine \`${host}' instead"
	default="yes"
	yesno
	if [ ${result} = n ]; then
		echo "${myname}: ERROR, cannot continue with this operation"
		echo "${myname}: aborting..."
		exit 1
	fi
done
} # end verifyoperationmode

installprolog()
{
if [ ${op} = install ]; then
	#
	# Installing NSR - make sure that we are
	# in the directory that this executable is in.
	#
	dir="`dirname "$0"`"
	cd ${dir}

	#
	# Set our path to include the binaries for this architecture
	# so that we can use uasm to install the binaries for various
	# versions of Unix and maintain all modes, owners, and times.
	#
	PATH="`pwd`/${myarch}:${PATH}"
	export PATH

	if [ ${sun} = y ]; then
		#
		# Verify that the machine is running 4.1.x.                #
		if [ "X${uname}" != X ]; then
			osrel=`uname -r`
		fi
		if [ "X${osrel}" = X ]; then
			osrel=`dmesg - | egrep 'SunOS.*Release' | tail -1 | \
			sed -e 's/.*Release \([0-9\.]*\).*/\1'/`
		fi
		if [ "X${osrel}" = X -a -f /etc/motd ]; then
			osrel=`egrep 'SunOS.*Release' /etc/motd | \
			tail -1 | sed -e 's/.*Release \([0-9\.]*\).*/\1'/`
			if [ "X${osrel}" = X -a -f /etc/motd ]; then
				osrel=`egrep 'SunOS 5' /etc/motd | \
				tail -1 | sed -e 's/.*SunOS \([0-9\.]*\).*/\1'/`
			fi
		fi
		if [ "X${osrel}" = X ]; then
			osrel=`egrep 'SunOS.*Release' /usr/adm/messages | \
			tail -1 | sed -e 's/.*Release \([0-9\.]*\).*/\1'/`
		fi

		if [ "X${osrel}" = X ]; then
			echo "WARNING: unable to determine OS release level."
		elif [ `expr "X${osrel}" : "X5."` -eq 3 ]; then
			echo "Running SunOS binaries on Solaris 2.x"
		elif [ `expr "X${osrel}" : "X4.1"` -lt 4 ]; then
			echo \
"ERROR: Machine \`${host}' is running SunOS Release ${osrel},
${productname} ${RELEASE} requires a 4.1.x SunOS Release."
			exit 1
		fi
	else
		#
		# XXX - should add tests for other OS installs here.
		# For now, assume all is ok...
		#
		true
	fi

	if [ ! -z "${daemonsrunning}" ]; then
		if [ ${server} = n ]; then
			echo "
It appears that ${productname} daemons were previously running on \`${host}',
making it look like a ${productname} server, not a ${productname} client.

${daemonsrunning}

${productname} will still be installed as a client.
"
		else
			server="y"
		fi
	elif [ ${server} = UNKNOWN ]; then
		qecho "
A ${productname} server is a machine that will provide the
${productname} service.  It will allow other machines on the network to
back up to it or recover from it.  The server is the machine
with the backup devices and available disk space for on-line indexing.
A ${productname} client is a machine that has data (disks) that
it needs to protect."
		prompt="Will \`${host}' be a ${productname} server"
		default="yes"
		yesno
		if [ ${result} = y ]; then
			server="y"
		else
			server="n"
		fi
	fi
else
	# remove - assume "server mode" if ${nsrhome} exists
	# and nsrd exists in the same directory as nsr_ize
	if [ ${server} = UNKNOWN ]; then
		if [ -d ${nsrhome} -a -f "${mypath}/nsrd" ]; then
			server="y"
		else
			server="n"
		fi
	else
		if [ ${server} = n -a -d ${nsrhome} -a \
		    -f "${mypath}/nsrd" ]; then
			qecho "
Aborting....
You must ${op} the ${productname} server software before you
can ${op} the ${productname} client software."
			exit 1
		fi
	fi
fi
} # end installprolog

#
# Determine which servers can talk to nsrexecd
#
# outputs:
#	result=		list of servers for nsrexecd, with appropriate "-s"s
#
ask_servernames()
{
	if [ $server = y ]; then
		servermsg=\
"  By default, only this server will be allowed access.  Enter the
value 'all' to allow all servers to back up this computer."
		result=" -s localhost"
	else
		servermsg=""
		result=""
	fi

	qecho "
The nsrexecd program restricts access to a select set of
${productname} servers.  Please enter the names of each computer running
a ${productname} server that will back up this computer, one name at a time.
If a computer has more than one network interface, please enter each
interface's name (one at a time).${servermsg}
"
	_next="first"
	while true; do
		echo_n "Enter the ${_next} ${productname} server's name [no more]: "
		read _ans
		if [ X"${_ans}" = X ]; then
			break
		fi
		if [ `expr X"${_ans}" : ".* "` -ne 0 ]; then
			echo "Please enter one name at a time."
		elif [ X"${_ans}" = Xall ]; then
			result=""
			break
		else
			result="${result} -s ${_ans}"
			_next="next"
		fi
	done

	if [ X"${result}" = X ]; then
		if [ $server = n -o X"${_ans}" = Xall ]; then
			qecho "Allowing access to all ${productname} servers."
		fi
	fi

	echo "NSREXECD=\"${result}\"" >> ${NSRREQUEST}
}

#
# Stop the currently running ${productname} daemons (if really needed).
# If we got a -k flag or are running in demo mode, don't bother asking
# if the daemons are running, just shut 'em down without asking.
#
stopdaemons()
{
	find_daemons

	#
	# If there are no running daemons, just return
	#
	if [ -z "${daemonsrunning}" ]; then
		return 0
	fi

	#
	# Prompt if we are not running in demo mode.
	#
	if [ ${kflag} = n -a ${demo} = n ]; then
                qecho "
The following ${productname} programs are currently
running and must be shutdown before continuing:"
		if [ ${qflag} = n ]; then
			echo "${daemonsrunning}"
		fi
		prompt=\
"Shutdown currently running ${productname} programs"
		default="yes"
		yesno
		if [ ${result} = n ]; then
			echo "ERROR: cannot continue while daemons are running..."
			exit 1
		fi
	fi

	if [ ${nflag} = y ]; then
		# assume it would have worked
		execstatus=0
	else
		do_shutdown -a -q
		execstatus=$?
	fi
	if [ ${execstatus} -ne 0 ]; then
		echo \
"ERROR: Can't kill ${productname} daemons, giving up"
		exit 1
	fi
} # end stopdaemons

#
# askbuildindexdirs - ask where the indexdirs should be
#
askbuildindexdirs()
{
test_objects="indexes"
if [ ${op} = install ]; then
	qecho "
To set up a ${productname} server, you need to supply a
directory with enough free space to maintain all the on-line
save file indexing and media management information."
	qecho "
To set up a ${productname} client, you need to supply a
directory for the nsrexecd state file."
	result=
	while true; do
		find_bigdir
		if [ -d ${nsrhome} ]; then
			qecho \
"
Directory ${nsrhome} exists, it will be used as the default."
		fi
		if [ ! -z "${bigdirs}" ]; then
			prompt="
Below is a list of some of the filesystems, with their free space, which you
might consider:

$bigdirs

Directory to use for client and server information"
		fi
		if [ "X${bigdir}" = "X/" ]; then
			bigdir=""
		fi
		if [ -d ${nsrhome} ]; then
			default=${nsrhome}
		else
			default="${bigdir}/nsr"
		fi
		# Ensure default is local.  Only test if default
		# already exists, cuz local_dir is slow on sco.
		if [ -d ${default} ]; then
			local_dir ${default}
			if [ ${result} = false ]; then
				default="${bigdir}/nsrdir"
			fi
		fi
		local_only=yes
		verifydir
		local_only=

		dir=${result}
		if [ `expr X${dir} : X/` -lt 2 ]; then
			echo \
"ERROR: \"${dir}\" needs to be specified as an absolute path"
			exit 2
		fi

		if [ ! -d ${dir} -a -r ${dir} ]; then
			echo "ERROR: \"${dir}\" is not a directory"
			exit 2
		fi
		echo "NSRHOME=${dir}" >> ${NSRREQUEST}
		break;
	done
fi
} # askbuildindexdirs

#
# requestmisc - Ask the misc install questions and cache the answers
# in shell variables.
# 
askmisc()
{
if [ ! -f ${nsrres} -a "${op}" = "install" -a "${server}" = y ]; then
	getdevices
fi

if [ "${op}" = install ]; then
	if [ "${server}" = n -o "${pflag}" != y ]; then
		ask_servernames
	fi
fi

if [ "${op}" = install ]; then
	prompt="Start ${productname} daemons at end of install"
	default="yes"
	yesno
	echo "DODAEMONS=${result}" >> ${NSRREQUEST}
fi
}

#
# requestmain - Driver function to ask all questions, and set environment.
#
requestmain()
{
if [ "${server}" != y -o "${pflag}" != y ]; then
	askbuildindexdirs
fi
askmisc
}
# @(#)nsr_ize.sh 6.1 95/12/15 Copyright (c) 1995, Legato Systems, Inc.
#
# This file will drive a nsr_ize installation or removal.
#
# Rules:
# 1) There should be mostly calls to shell functions that exist in 
#    other install remove shell function files.
# 2) No explicit user interaction is allowed from within this file.
#    Input comes from sourcing ${NSRREQUEST}.
#
NSRREQUEST=${NSRREQUEST-/tmp/nsrrequest}
if [ -f "${NSRREQUEST}" ]; then
	rm -f ${NSRREQUEST}
fi

installinit $*
copyright
findarch
setecho
buildlists
processargs $*

# Set traps to their program specific defaults
# must be done at the top level (not in a function) or the
# trap "..." 0 will cause the script to exit on AIX 4.1.3
if [ ! "${pflag}" = "y" ]; then
	if [ ${xflag} = n ]; then
		trap "exit 2" 2
		trap "rm -f /tmp/*.$$; exit" 0
	else
		trap "exit 2" 2
		trap "echo leaving files /tmp/*.$$; exit" 0
	fi
fi

installfiles
if [ -f "${NSRREQUEST}" ]; then
	. ${NSRREQUEST}
fi
if [ "$server" = "y" ]; then
	removeserverfiles
	buildindexdirs
	modifyserverfiles
	add_device
else
	buildindexdirs
fi
modifyclientfiles		# terminates if client install
installepilog
myarchize

banner=${productname}
nsr_done
if [ -f "${NSRREQUEST}" ]; then
	rm -f ${NSRREQUEST}
fi
exit 0
