#!/sbin/sh
#
#	@(#)suninstall.sh 1.117 01/08/29 
#
# 	Copyright (c) 1992-1996 Sun Microsystems, Inc.  All Rights Reserved.
#

# This script is executed via the path
#  sbin/init < etc/inittab -> etc/rcS
#  sbin/init < etc/inittab -> sbin/startup -> sbin/sysconfig -> sbin/suninstall
#
# 

# Local Variables
#
LOCKFILE=/tmp/.suninstall
JSLOCKFILE=/tmp/.jumpstart
LOGDIR=/a/var/sadm/system/logs
RBLOGDIR=/var/sadm/system/logs
OLDLOGDIR=/a/var/sadm
RELLOGDIR=system/logs
INSTALLBOOT=/tmp/.install_boot
PREINSTALL=/tmp/.preinstall
CD_CONFIG_DIR=/cdrom/.bbi
SMI_INSTALL=/tmp/.smi_boot
SUPPRESS_SOLSTART_FINISH=/tmp/.suppress_solstart_finish
BEGIN=begin
FINISH=finish
BEGINLOG=begin.log
FINISHLOG=finish.log

MY_VERSION=2	# used to match version in JumpStart rules file
ESTATUS=0	# exit status

# Global Variables
#
SI_CONFIG_DIR=/tmp/install_config
SI_CONFIG_PROG=rules.ok
SI_CONFIG_FILE=${SI_CONFIG_DIR}/${SI_CONFIG_PROG}
SI_SYS_STATE=/a/etc/.sysIDtool.state
SI_INSTALL_APP=interactive
export SI_CONFIG_DIR SI_CONFIG_PROG SI_SYS_STATE SI_CONFIG_FILE SI_INSTALL_APP

# create a lock file if one does not already exist; this is to prevent
# the suninstall script from being invoked more than once
#
si_single_lock() {
	if [ ! -f ${LOCKFILE} ]; then
		touch ${LOCKFILE}
	fi
}

# remove the suninstall lock if it exists.
#
si_single_unlock() {
	rm -f ${LOCKFILE}
}

# remove the suninstall lock and execute the /sbin/sh
# NOTE:	If the program being executed is not the shell, but is
#	instead one of the install applications should we really
#	be removing this lock at this point?
#
become_shell() {
	si_single_unlock
	exec /sbin/sh
}


# This shell function and the function templates_date_time() found
# in .../src/common/lib/libspmisvc/svc_templates.c are the same.  If a change
# is made to one, the same change has to be made to the other.
#
# $1 ::= filename to use to determine date/time string
# $2 ::= the directory and filename to check while
#        establishing a unique dated file name
#
#	Returns a date string of the form YYYY_MM_DD[_n]
#
suninstall_date_time()
{
	old_name=$1 
	mon=`ls -l $old_name | awk ' { printf("%s", $6) } ' `
	day=`ls -l $old_name | awk ' { printf("%2.2d", $7) } ' `
	year=`ls -l $old_name | awk ' { printf("%s", $8) } ' `
	case $mon in
		Jan) mon_ndx=01 ;;
		Feb) mon_ndx=02 ;;
		Mar) mon_ndx=03 ;;
		Apr) mon_ndx=04 ;;
		May) mon_ndx=05 ;;
		Jun) mon_ndx=06 ;;
		Jul) mon_ndx=07 ;;
		Aug) mon_ndx=08 ;;
		Sep) mon_ndx=09 ;;
		Oct) mon_ndx=10 ;;
		Nov) mon_ndx=11 ;;
		Dec) mon_ndx=12 ;;
	esac
	mon_day="${mon_ndx}_${day}"

	if echo $year | grep ':' >/dev/null 2>&1
	then
		current_mon_ndx=`date "+%m"`
		year=`date "+%Y"`
		if [ "$mon_ndx" -gt "$current_mon_ndx" ] ; then
			year=`expr $year - 1`
		fi
	fi

	new_name="${2}_${year}_${mon_day}"
	ndx="0"
	ndx_str=
	while [ -f ${new_name}${ndx_str} ] ; do
		ndx=`expr $ndx + 1`
		ndx_str="_$ndx"
	done
	echo "${year}_${mon_day}${ndx_str}"
}

# Move the given log (either begin.log or finish.log) into the system 
# log directory.
move_log()
{
    LogName=$1
    #
    # remove any, and all, symbolic links from $LogName
    #
    if [ -h ${OLDLOGDIR}/${LogName} ]
    then
        rm -f ${OLDLOGDIR}/${LogName}
    fi

    if [ -h ${LOGDIR}/${LogName} ]
    then
        rm -f ${LOGDIR}/${LogName}
    fi

    #
    # move $LogName from old directory to new directory with 
    # dated log name.
    #
    if [ -f ${OLDLOGDIR}/${LogName} ]
    then
        date_time=`suninstall_date_time ${OLDLOGDIR}/${LogName} ${LOGDIR}/${LogName}`
        mv ${OLDLOGDIR}/${LogName} ${LOGDIR}/${LogName}_${date_time}
    fi

    #
    # rename $LogName, in new directory, to dated log name
    #
    if [ -f ${LOGDIR}/${LogName} ]
    then
        date_time=`suninstall_date_time ${LOGDIR}/${LogName} ${LOGDIR}/$LogName`
        mv ${LOGDIR}/${LogName} ${LOGDIR}/${LogName}_${date_time}
    fi

    #
    # If $LogName exists in /tmp, then move it to the new directory,
    # a dated log name, and set up appropriate symbolic links.
    #
    if [ -f /tmp/${LogName} -a -d ${LOGDIR} ]
    then
        date_time=`suninstall_date_time /tmp/${LogName} ${LOGDIR}/${LogName}`
        mv /tmp/${LogName} ${LOGDIR}/${LogName}_${date_time}
        ln -s ${LogName}_${date_time} ${LOGDIR}/${LogName}
        chmod 644 ${LOGDIR}/${LogName}_${date_time}
        echo `gettext "The ${2} script log \'${LogName}\'"`
        echo `gettext "\tis located in ${RBLOGDIR} after reboot."`
        echo
    fi
}


##############################################################################
# process rules.ok file, validate the version, make sure the version is valid
# for this version of suninstall.sh; if so, invoke chkprobe to process the
# rules.ok file looking for a matching entry
#
##############################################################################
validate_and_chkprobe() {
if [ -f ${SI_CONFIG_FILE} ]; then
	ver_line=`egrep "# version=" ${SI_CONFIG_FILE}`
	if [ $? -ne 0 ]; then
		gettext "Error: Could not find rules file "
		echo "(${SI_CONFIG_FILE})"
	else
		VERSION=`expr "${ver_line}" : '.*version=\(.*\) .*'`
		if [ ${VERSION} -gt ${MY_VERSION} ]; then
			gettext "Error: File version is greater than expected: "
			echo "(${SI_CONFIG_FILE})"
			echo
		else
			echo `gettext "Checking rules.ok file..."`
			si_single_unlock
			. /usr/sbin/install.d/chkprobe
			si_single_lock
		fi
	fi
fi
}

##############################################################################
# process pre-installation "begin" script if defined in the rules file
#
##############################################################################
process_preinstall() {
if [ -n "${SI_BEGIN}" -a X"${SI_BEGIN}" != "X-" ]; then
	if [ ! -f "${SI_CONFIG_DIR}/${SI_BEGIN}" ]; then
		echo `gettext "Warning: Could not find begin script "` \
			" (${SI_BEGIN})" | tee -a /tmp/${BEGINLOG}
	else
		echo `gettext "Executing begin script \"${SI_BEGIN}\"..."` | \
			tee -a /tmp/${BEGINLOG}
		si_single_unlock
		(/sbin/sh ${SI_CONFIG_DIR}/${SI_BEGIN} 
		echo $? > /tmp/begin_script_exit) 2>&1 | tee -a /tmp/${BEGINLOG}
		if [ -f /tmp/begin_script_exit ]; then
			read BEGINRET < /tmp/begin_script_exit
			rm -f /tmp/begin_script_exit
		else
			BEGINRET=0
		fi
		if [ ${BEGINRET} -eq 0 ]; then
			echo `gettext "Begin script ${SI_BEGIN} execution completed."` | tee -a /tmp/${BEGINLOG}
		else
			echo `gettext "Begin script ${SI_BEGIN} failed with return value \"${BEGINRET}\"."` | tee -a /tmp/${BEGINLOG}
			echo `gettext "Aborting install."` | tee -a /tmp/${BEGINLOG}
			exit 1
		fi
		si_single_lock
	fi
fi
}


##############################################################################
# process post-installation "finish" script if defined in the rules file
#
##############################################################################
process_postinstall() {
if [ -n "${SI_FINISH}" -a X"${SI_FINISH}" != "X-" ]; then
	if [ ! -f "${SI_CONFIG_DIR}/${SI_FINISH}" ]; then
		echo `gettext "Warning: Could not find finish script "` \
			"(${SI_FINISH})" | tee -a /tmp/${FINISHLOG}
	else
		echo `gettext "Executing finish script \"${SI_FINISH}\"..."`
		echo
		si_single_unlock
		/sbin/sh ${SI_CONFIG_DIR}/${SI_FINISH} 2>&1 | tee -a /tmp/${FINISHLOG}
		si_single_lock
		echo
		gettext "Finish script ${SI_FINISH} execution completed."
		echo
	fi
fi
}

##############################################################################
# Save Private 'SolStart' environment variables
##############################################################################
save_solstart_env() {
	# These environment variables are fixed for the installation 
	# environment
	#_HOME=${HOME};	_LANG=${LANG};	_TERM=${TERM};	_TZ=${TZ}
	#_SI_SYS_STATE=${SI_SYS_STATE}

	_CHECK_INPUT=${CHECK_INPUT}
	_PATH=${PATH}
	_SI_ARCH=${SI_ARCH}
	_SI_BEGIN=${SI_BEGIN}
	_SI_CLASS=${SI_CLASS}
	_SI_CONFIG_DIR=${SI_CONFIG_DIR}
	_SI_CONFIG_FILE=${SI_CONFIG_FILE}
	_SI_CONFIG_PROG=${SI_CONFIG_PROG}
	_SI_CUSTOM_PROBES_FILE=${SI_CUSTOM_PROBES_FILE}
	_SI_DISKLIST=${SI_DISKLIST}
	_SI_DISKSIZES=${SI_DISKSIZES}
	_SI_DOMAINNAME=${SI_DOMAINNAME}
	_SI_FINISH=${SI_FINISH}
	_SI_HOSTADDRESS=${SI_HOSTADDRESS}
	_SI_HOSTID=${SI_HOSTID}
	_SI_HOSTNAME=${SI_HOSTNAME}
	_SI_INSTALL_APP=${SI_INSTALL_APP}
	_SI_INSTALLED=${SI_INSTALLED}
	_SI_INST_OS=${SI_INST_OS}
	_SI_INST_VER=${SI_INST_VER}
	_SI_KARCH=${SI_KARCH}
	_SI_MEMSIZE=${SI_MEMSIZE}
	_SI_MODEL=${SI_MODEL}
	_SI_NETWORK=${SI_NETWORK}
	_SI_NUMDISKS=${SI_NUMDISKS}
	_SI_OSNAME=${SI_OSNAME}
	_SI_PROFILE=${SI_PROFILE}
	_SI_ROOTDISK=${SI_ROOTDISK}
	_SI_ROOTDISKSIZE=${SI_ROOTDISKSIZE}
}


##############################################################################
# Restore Private 'SolStart' environment variables
##############################################################################
restore_solstart_env() {
	# These environment variables are fixed for the installation 
	# environment
	#HOME=${_HOME};	LANG=${_LANG};	TERM=${_TERM};	TZ=${_TZ}
	#SI_SYS_STATE=${_SI_SYS_STATE}

	CHECK_INPUT=${_CHECK_INPUT}
	PATH=${_PATH}
	SI_ARCH=${_SI_ARCH}
	SI_BEGIN=${_SI_BEGIN}
	SI_CLASS=${_SI_CLASS}
	SI_CONFIG_DIR=${_SI_CONFIG_DIR}
	SI_CONFIG_FILE=${_SI_CONFIG_FILE}
	SI_CONFIG_PROG=${_SI_CONFIG_PROG}
	SI_CUSTOM_PROBES_FILE=${_SI_CUSTOM_PROBES_FILE}
	SI_DISKLIST=${_SI_DISKLIST}
	SI_DISKSIZES=${_SI_DISKSIZES}
	SI_DOMAINNAME=${_SI_DOMAINNAME}
	SI_FINISH=${_SI_FINISH}
	SI_HOSTADDRESS=${_SI_HOSTADDRESS}
	SI_HOSTID=${_SI_HOSTID}
	SI_HOSTNAME=${_SI_HOSTNAME}
	SI_INSTALL_APP=${_SI_INSTALL_APP}
	SI_INSTALLED=${_SI_INSTALLED}
	SI_INST_OS=${_SI_INST_OS}
	SI_INST_VER=${_SI_INST_VER}
	SI_KARCH=${_SI_KARCH}
	SI_MEMSIZE=${_SI_MEMSIZE}
	SI_MODEL=${_SI_MODEL}
	SI_NETWORK=${_SI_NETWORK}
	SI_NUMDISKS=${_SI_NUMDISKS}
	SI_OSNAME=${_SI_OSNAME}
	SI_PROFILE=${_SI_PROFILE}
	SI_ROOTDISK=${_SI_ROOTDISK}
	SI_ROOTDISKSIZE=${_SI_ROOTDISKSIZE}
}

##############################################################################
# Save JumpStart environment variables
##############################################################################
save_jumpstart_env() {
	# These environment variables are fixed for the installation 
	# environment
	#JS_HOME=${HOME}; JS_LANG=${LANG}; JS_TERM=${TERM}; JS_TZ=${TZ}
	#JS_SI_SYS_STATE=${SI_SYS_STATE}

	#save this for browser based installation 
	JS_CD_CONFIG_DIR=${CD_CONFIG_DIR}
	JS_CHECK_INPUT=${CHECK_INPUT}
	JS_PATH=${PATH}
	JS_SI_ARCH=${SI_ARCH}
	JS_SI_BEGIN=${SI_BEGIN}
	JS_SI_CLASS=${SI_CLASS}
	JS_SI_CONFIG_DIR=${SI_CONFIG_DIR}
	JS_SI_CONFIG_FILE=${SI_CONFIG_FILE}
	JS_SI_CONFIG_PROG=${SI_CONFIG_PROG}
	JS_SI_CUSTOM_PROBES_FILE=${SI_CUSTOM_PROBES_FILE}
	JS_SI_DISKLIST=${SI_DISKLIST}
	JS_SI_DISKSIZES=${SI_DISKSIZES}
	JS_SI_DOMAINNAME=${SI_DOMAINNAME}
	JS_SI_FINISH=${SI_FINISH}
	JS_SI_HOSTADDRESS=${SI_HOSTADDRESS}
	JS_SI_HOSTID=${SI_HOSTID}
	JS_SI_HOSTNAME=${SI_HOSTNAME}
	JS_SI_INSTALL_APP=${SI_INSTALL_APP}
	JS_SI_INSTALLED=${SI_INSTALLED}
	JS_SI_INST_OS=${SI_INST_OS}
	JS_SI_INST_VER=${SI_INST_VER}
	JS_SI_KARCH=${SI_KARCH}
	JS_SI_MEMSIZE=${SI_MEMSIZE}
	JS_SI_MODEL=${SI_MODEL}
	JS_SI_NETWORK=${SI_NETWORK}
	JS_SI_NUMDISKS=${SI_NUMDISKS}
	JS_SI_OSNAME=${SI_OSNAME}
	JS_SI_PROFILE=${SI_PROFILE}
	JS_SI_ROOTDISK=${SI_ROOTDISK}
	JS_SI_ROOTDISKSIZE=${SI_ROOTDISKSIZE}
}

##############################################################################
# Restore JumpStart environment variables
##############################################################################
restore_jumpstart_env() {
	# These environment variables are fixed for the installation 
	# environment
	#HOME=${JS_HOME}; LANG=${JS_LANG}; TERM=${JS_TERM}; TZ=${JS_TZ}
	#SI_SYS_STATE=${SI_SYS_STATE}

	#restore CD_CONFIG_DIR value
	CD_CONFIG_DIR=${JS_CD_CONFIG_DIR}
	CHECK_INPUT=${JS_CHECK_INPUT}
	PATH=${JS_PATH}
	SI_ARCH=${JS_SI_ARCH}
	SI_BEGIN=${JS_SI_BEGIN}
	SI_CLASS=${JS_SI_CLASS}
	SI_CONFIG_DIR=${JS_SI_CONFIG_DIR}
	SI_CONFIG_FILE=${JS_SI_CONFIG_FILE}
	SI_CONFIG_PROG=${JS_SI_CONFIG_PROG}
	SI_CUSTOM_PROBES_FILE=${JS_SI_CUSTOM_PROBES_FILE}
	SI_DISKLIST=${JS_SI_DISKLIST}
	SI_DISKSIZES=${JS_SI_DISKSIZES}
	SI_DOMAINNAME=${JS_SI_DOMAINNAME}
	SI_FINISH=${JS_SI_FINISH}
	SI_HOSTADDRESS=${JS_SI_HOSTADDRESS}
	SI_HOSTID=${JS_SI_HOSTID}
	SI_HOSTNAME=${JS_SI_HOSTNAME}
	SI_INSTALL_APP=${JS_SI_INSTALL_APP}
	SI_INSTALLED=${JS_SI_INSTALLED}
	SI_INST_OS=${JS_SI_INST_OS}
	SI_INST_VER=${JS_SI_INST_VER}
	SI_KARCH=${JS_SI_KARCH}
	SI_MEMSIZE=${JS_SI_MEMSIZE}
	SI_MODEL=${JS_SI_MODEL}
	SI_NETWORK=${JS_SI_NETWORK}
	SI_NUMDISKS=${JS_SI_NUMDISKS}
	SI_OSNAME=${JS_SI_OSNAME}
	SI_PROFILE=${JS_SI_PROFILE}
	SI_ROOTDISK=${JS_SI_ROOTDISK}
	SI_ROOTDISKSIZE=${JS_SI_ROOTDISKSIZE}
}


##############################################################################
# Main Script Body							MAIN
##############################################################################

# check for the suninstall lock and exit if the lock is present
#
if [ -f ${LOCKFILE} ]; then
	echo `gettext "Solaris installation program is already running."`
	exit 1
else
	echo `gettext "Starting Solaris installation program..."`
	si_single_lock
fi

trap "si_single_unlock" 1 2 15	# ignore traps

# set the terminal type if not already set
#
if [ -z "${TERM}" ]; then
	TERM=`tail -1 /etc/.sysIDtool.state`
	export TERM
fi

TotalRAM=`/usr/sbin/prtconf | grep '^Memory size: ' | \
		sed -e 's/^Memory size: //' -e 's/ .*$//' `

MemUnit=`/usr/sbin/prtconf | grep '^Memory size: ' | \
		sed -e 's/^Memory size: [0-9][0-9]* //' `

case $MemUnit in
	Kilobytes) TotalRAM=`expr $TotalRAM / 1000` ;;
	Megabytes) ;;
	Gigabytes) TotalRAM=`expr $TotalRAM \* 1000` ;;
	*)	   TotalRAM=0 ;;
esac
if [ "$TotalRAM" -le "16" ]
then
	cat </dev/null >/tmp/.nowin
fi

# make sure "/" is exported with root access
# NOTE: this relies on useradd have mode 500 and returning error 2
#	for bad args
# NOTE:	there should be a better test here
#
/usr/sbin/useradd >/dev/null 2>&1
if [ $? -eq 1 ]; then
	gettext "Error: Unable to install system."
	echo
	gettext "       The Solaris installation image is not exported with root access."
	echo
	become_shell
fi


#
# Check for SMI Install configuration directories.  If it exists
# and running factory jumpstart or booting with the smi install
# boot parameter start up the SMI Install browser interface.
#
#if  [ -d ${CD_CONFIG_DIR} ]; then
#	if [ -f ${PREINSTALL} -o -f ${SMI_INSTALL} ]; then
if [ -d ${CD_CONFIG_DIR} -a -f ${SMI_INSTALL} ]; then
	/cdrom/.bbi/bin/smi_install.sh
	#
	# Check the return code
	# if it is non-zero then delete
	# the jumpstart directory so that
	# a normal factory or custom jumpstart
	# will take place
	if [ $? -ne 0 ]; then
		rm -rf ${SI_CONFIG_DIR}	
	fi
fi

#############################################################################
## Use the same JumpStart interfaces/mechanisms for initiating 'begin' and ##
## 'finish' scripts for mandatory Solaris installation procedures without  ##
## interfering with the Custom and Factory JumpStart entries.              ##
##                                                                         ##
## Use a private (_SI_*) set of JumpStart environment variables so a to    ##
## not corrupt the external JumpStart environment variables.               ##
#  1) Mount the path to the JumpStart directory (profind)
#  2) Validate the contents of the JumpStart directory (chkprobe)
#  3) Set the application type (jumpstart or interactive)
#  4) JumpStart (Custom or Factory) begin script
#  5) Save the JumpStart environment variables
#  6) Mount the path to the SolStart directory
#  7) Validate the contents of the SolStart directory (chkprobe)
#  8) SolStart (SunSoft and OEM) begin script
#  9) Save the SolStart environment variables
# 10) Restore the JumpStart environment variables
# 11) Interactive install (installtool/ttinstall)
#       or
#     JumpStart (Custom or Factory) profile install (pfinstall/pfupgrade)
# 12) Restore the SolStart environment variables
# 13) SolStart (SunSoft and OEM) finish script
# 14) Restore the JumpStart environment variables
# 15) JumpStart (Custom or Factory) finish script
# 16) Cleanup
#############################################################################

# mount the appropriate profile directory and search for the for profile
# for JumpStart and custom JumpStart boots; make sure the use hasn't tried
# to restart JumpStart install
#
if [ -f ${PREINSTALL} -o -f ${INSTALLBOOT} ]; then
	if [ -f ${JSLOCKFILE} ]; then
		gettext "You must reboot the system to restart a JumpStart install."
		echo
		si_single_unlock
		exit 1
	else
		touch ${JSLOCKFILE}
		/usr/sbin/install.d/profind
	fi
fi

# process rules.ok file, validate the version, make sure the version is valid
# for this version of suninstall.sh; if so, invoke chkprobe to process the
# rules.ok file looking for a matching entry
#

validate_and_chkprobe

# set the application type for JumpStart and custom JumpStart boots;
# custom JumpStart boots require a profile or else the interactive
# install will run
#
if [ -f ${INSTALLBOOT} ]; then
	# make sure that SI_CLASS is defined; remember it could be
	# '=' for derived classes, so use the 'X' test method
	#
	if [ X"${SI_CLASS}" != "X" ]; then
		SI_INSTALL_APP=jumpstart
	else
		gettext "Warning: Could not find matching rule in "
		echo ${SI_CONFIG_PROG}
		gettext "Press the return key for an interactive Solaris install program..."
		read input
	fi
fi

if [ -f ${PREINSTALL} ]; then
	# make sure that SI_CLASS is defined; remember it could be
	# '=' for derived classes, so use the 'X' test method
	#
	if [ X"${SI_CLASS}" != "X" ]; then
		SI_INSTALL_APP=jumpstart
	fi
fi

# Process the JumpStart preinstall actions
# and save off the JumpStart environment variables to preserve them for the
# JumpStart profile and postinstall script processing.
#
echo `gettext "Executing JumpStart preinstall phase..."`
process_preinstall
save_jumpstart_env

# SolStart processing will take place unless a Custom Jumpstart has
# been specified AND a `*' has been specified as the profile.
if [ ! \( "${SI_INSTALL_APP}" = "jumpstart" -a "${SI_PROFILE}" = "--" \) ]; then
    # Do the equivalent of what is done in 'profind' for the SolStart
    # mechanisms.  Note the use of '/tmp/_install_config' for a mountpoint
    # rather than the JumpStart '/tmp/install_config' mountpoint.
    #
    SI_CONFIG_DIR=/tmp/_install_config
    CD_CONFIG_DIR=/usr/sbin/install.d/install_config
    SI_CONFIG_FILE=${SI_CONFIG_DIR}/${SI_CONFIG_PROG}

    # Make the mount point directory used in searching
    # for the SolStart begin and finish scripts
    #
    if [ ! -d ${SI_CONFIG_DIR} ]; then
	mkdir ${SI_CONFIG_DIR} 2>/dev/null
    fi
    
    echo `gettext "Searching for SolStart directory..."`

    mount -o ro -F lofs ${CD_CONFIG_DIR} ${SI_CONFIG_DIR} > /dev/null 2>&1

    # Validate and run chkprobe on the SolStart 'rules.ok' file
    # and save the resulting SolStart environment variables for future use
    #
    validate_and_chkprobe


    # Process the SolStart preinstall actions.  After the preinstall
    # actions have been processed, the SolStart environment variables
    # are saved for SolStart postinstall processing.
    #
    echo `gettext "Executing SolStart preinstall phase..."`
    process_preinstall
    save_solstart_env

    # Restore the JumpStart environment variables for the profile phase

    restore_jumpstart_env
fi

# process a jumpstart installation
#

if [ "${SI_INSTALL_APP}" = "jumpstart" ]; then
    if [ -n "${SI_PROFILE}" -a "${SI_PROFILE}" != "--" ] ; then
	# User specified a profile
	if [ ! -f "${SI_PROFILE}" ]; then
		# Specified profile file doesn't exist; prompt the
		# user to continue an interactive installation.
		#
		gettext "Error: Could not find the profile "
		echo "(${SI_PROFILE})"
		gettext "Press the return key for an interactive Solaris install..."
		read input
		SI_INSTALL_APP=interactive
	else
		pfinstall ${SI_PROFILE}
		ESTATUS=$?
	fi
    #else - User explicitly didn't specify a profile
    fi
fi



# process an interactive installation
#

if [ "${SI_INSTALL_APP}" = "interactive" ]; then
	if [ -n "${SI_NONINTERACTIVE_EXIT}" ] ; then
	    # whoever called suninstall doesn't want an interactive
	    # session, so exit with the specified code
	    exit ${SI_NONINTERACTIVE_EXIT}
	fi

	# select the helpfile directory based on the status of the
	# L10N environment variables
	#
	if [ -n "${LC_MESSAGES}" ]; then
		HELPPATH=/usr/openwin/lib/locale/${LC_MESSAGES}/help
	elif [ -n "${LANG}" ]; then
		HELPPATH=/usr/openwin/lib/locale/${LANG}/help
	else
		HELPPATH=/usr/openwin/lib/locale/C/help
	fi

	# execute appropriate interactive install app based on the availability
	# of the window system
	#
	if [ -n "${DISPLAY}" ]; then
		# set the path for installtool help text messages
		ADMINHELPHOME=${HELPPATH}/installtool.help
		export ADMINHELPHOME
		/usr/sbin/installtool
		ESTATUS=$?
	else
		# set the path for installtool help text messages
		ADMINHELPHOME=${HELPPATH}/install.help
		export ADMINHELPHOME
		/usr/sbin/ttinstall
		ESTATUS=$?
	fi
fi


# if the installation application executed exited in error, invoke a
# Bourne shell (taken from Solaris 2.6 'suninstall') or if the user
# exited without installing any software.
#	0: successful install/upgrade - machine will be rebooted when
#	   suninstall completes.
#	1: successful install/upgrade - machine will not be rebooted when
#	   suninstall completes.
#	2: "failure exit" - 
#     255: includes the user choosing to exit without installing any software.
#
if [ ${ESTATUS} -ne 0 -a ${ESTATUS} -ne 1 ]; then
	become_shell
fi

# SolStart processing will take place unless a Custom Jumpstart has
# been specified AND a `*' has been specified as the profile.
if [ ! \( "${SI_INSTALL_APP}" = "jumpstart" -a "${SI_PROFILE}" = "--" \) -a \
     ! -f $SUPPRESS_SOLSTART_FINISH ]; then
	# Restore the SolStart environment variables and
	# Process the SolStart preinstall actions

	restore_solstart_env
	echo `gettext "Executing SolStart postinstall phase..."`
	process_postinstall
fi

# Restore the JumpStart environment variables and
# Process the JumpStart preinstall actions.

restore_jumpstart_env
echo `gettext "Executing JumpStart postinstall phase..."`
process_postinstall

# spacing for final messages
#
echo

# Move the begin log into the system log directory
#
move_log $BEGINLOG $BEGIN

# Move the finish log into the system log directory
#
move_log $FINISHLOG $FINISH

#
# Exit actions
#
# If this was a successful interactive install, we run the wizard launcher
# setup script, if it's there.
#
if [ \( ${ESTATUS} -eq 0 -o ${ESTATUS} -eq 1 \) -a \
     "${SI_INSTALL_APP}" = "interactive" -a \
     -x /sbin/setupLauncher ] ; then
    /sbin/setupLauncher
fi

# exiting the install routine so remove the lock file
si_single_unlock

# reboot only if the install application exited with a '0' status
#
if [ ${ESTATUS} -eq 0 ]; then
	reboot
else
	become_shell
fi
