usr/src/cmd/auto-install/svc/auto-installer
author Ethan Quach <Ethan.Quach@sun.com>
Tue, 31 May 2011 14:21:09 -0700
changeset 1160 6f7e708c38ec
parent 1151 95413393ef67
child 1191 d28635fbc842
permissions -rw-r--r--
16257 Support for zones configuration and installation should be included in AI 7041915 TransferFiles ICT should support transferring a directory that is more than one level deep. 7049824 System installed via AI ends up with incorrect mountpoints for shared ZFS datasets

#!/sbin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
#

# Use tee(1) when posting messages to both console and log file
TEE_LOGTOCONSOLE="/usr/bin/tee /dev/msglog"
# Auto installer
AI_ENGINE=/usr/bin/auto-install
# AI Engine exit codes
# failure
AI_ENGINE_EXIT_FAILURE=1
# invalid or incompatible manifest specified
AI_ENGINE_EXIT_FAILURE_INVALID_MANIFEST=2
# success - do not reboot
AI_ENGINE_EXIT_SUCCESS=0
# success - auto reboot
AI_ENGINE_EXIT_REBOOT=64

# Auto install manifest
AI_MANIFEST=/system/volatile/ai.xml

# Profile directory
PROFILE_DIR=/system/volatile/profile

# Profile used to enable SCI tool
ENABLE_SCI_PROFILE=/usr/share/auto_install/sc_profiles/enable_sci.xml

# Installation service list file
AI_SERVICE_LIST=/var/run/service_list

ISA_INFO=`/usr/bin/uname -p`
PRTCONF=/usr/sbin/prtconf
SVCPROP=/usr/bin/svcprop
SED=/usr/bin/sed
NAWK=/usr/bin/nawk
BEADM=/usr/sbin/beadm
REBOOT=/usr/sbin/reboot
CP=/usr/bin/cp
MKDIR=/usr/bin/mkdir

. /lib/svc/share/smf_include.sh

#
# Exit with SMF_EXIT_ERR_CONFIG if not invoked from Automated Installer
# environment
#
if [ ! -f /.autoinstall ] ; then
	echo "Not running in Automated Installer environment. The service can" \
	    "only be enabled in the Automated Installer environment" |
	    $TEE_LOGTOCONSOLE

	exit $SMF_EXIT_ERR_CONFIG
fi

#
# Call AI engine to carry out real installation and inform the user
# that installation was kicked off
#

if [ ! -x  $AI_ENGINE ] ; then
	echo "Could not find Auto Installer engine" | $TEE_LOGTOCONSOLE
	exit $SMF_EXIT_ERR_FATAL
fi

#
# Set the auto shutdown upon a successful install flag
# if specified on the grub line
#
if [ "$ISA_INFO" = "i386" ]; then
	AI_AUTO_SHUTDOWN=`$PRTCONF -v | /usr/bin/sed -n \
	    '/auto-shutdown/{;n;p;}'| cut -f 2 -d\'`
	if [ "$AI_AUTO_SHUTDOWN" = "enable" ]; then
		echo "Shutdown requested. The system will be shutdown" \
		    "after install"
	fi
fi

#
# Make sure the required manifest is in place, exit with failure otherwise.
#
if [ ! -f $AI_MANIFEST ]; then
	echo "" | $TEE_LOGTOCONSOLE
	echo "Could not find manifest file at <$AI_MANIFEST>" |
	    $TEE_LOGTOCONSOLE
	exit $SMF_EXIT_ERR_FATAL
fi

#
# Copy files required by XML validator to the same directory where AI manifest
# is stored. This is just temporary solution, better approach should be to
# point XML validator to where these file are.
#
for dtd_file in "ai.dtd" "configuration.dtd" "software.dtd" "target.dtd" ; do
	if [ ! -f "/usr/share/install/$dtd_file" ] ; then
		echo "Could not find /usr/share/install/$dtd_file"
		exit $SMF_EXIT_ERR_FATAL
	fi
	$CP "/usr/share/install/$dtd_file" /system/volatile/
done

echo "" | $TEE_LOGTOCONSOLE
echo "Automated Installation started" | $TEE_LOGTOCONSOLE
echo "The progress of the Automated Installation will be output to the console" |
    $TEE_LOGTOCONSOLE
echo "Detailed logging is in the logfile at /system/volatile/install_log" | $TEE_LOGTOCONSOLE
echo "Press RETURN to get a login prompt at any time." | $TEE_LOGTOCONSOLE
echo "" | $TEE_LOGTOCONSOLE

# If PROFILE_DIR does not exist, or does not contain any profiles,
# copy into it the profile which will enable SCI tool.
if [ ! -d $PROFILE_DIR ] ; then
	$MKDIR $PROFILE_DIR
	$CP $ENABLE_SCI_PROFILE $PROFILE_DIR
elif [ -z "$(ls -A $PROFILE_DIR)" ] ; then
	$CP $ENABLE_SCI_PROFILE $PROFILE_DIR
fi

OPTS=
#
# Enable the installer to be run in debug mode if requested.
#
AI_DEBUG_MODE=`$SVCPROP -c -p general/install_debug $SMF_FMRI 2>/dev/null`
if [ $? -eq 0 -a "$AI_DEBUG_MODE" = "enable" ] ; then
	echo "Installer will be run in debug mode" | $TEE_LOGTOCONSOLE

	# set verbose mode for invoked beadm(1M) commands
	export BE_PRINT_ERR=true

	# enable verbose mode for logging service and ICT
	export LS_DBG_LVL=4

	OPTS="$OPTS -v"
fi

#
# Pass in installation service list if one exists.
#
if [ -f $AI_SERVICE_LIST ] ; then
	OPTS="$OPTS -r $AI_SERVICE_LIST"
fi

$AI_ENGINE $OPTS -m $AI_MANIFEST -c $PROFILE_DIR	
ret=$?

# Process exit code returned from AI engine

case $ret in
	#
	# Automated Installer finished successfully. Pass the control
	# to the user
	#
	$AI_ENGINE_EXIT_SUCCESS)
		echo "Automated Installation finished successfully" |
		    $TEE_LOGTOCONSOLE
		echo "The system can be rebooted now" | $TEE_LOGTOCONSOLE
		echo "Please refer to the /system/volatile/install_log file" \
		    "for details" | $TEE_LOGTOCONSOLE

		echo "After reboot it will be located at" \
		    "/var/sadm/system/logs/install_log" | $TEE_LOGTOCONSOLE

		if [ "$AI_AUTO_SHUTDOWN" = "enable" ]; then
		    echo "Shutdown requested. Shutting down the system" | \
		        $TEE_LOGTOCONSOLE
		    /usr/sbin/shutdown -y -g 1 -i 5 &
		fi
   
		exit $SMF_EXIT_OK
		;;

	#
	# Automated Installer finished successfully.
	# Automated reboot was enabled in AI manifest, reboot now.
	#
	$AI_ENGINE_EXIT_REBOOT)
		echo "Automated Installation finished successfully" |
		    $TEE_LOGTOCONSOLE
		echo "Auto reboot enabled. The system will be" \
		    "rebooted now" | $TEE_LOGTOCONSOLE
		echo "Log files will be available in /var/sadm/system/logs/" \
		    "after reboot" | $TEE_LOGTOCONSOLE

		# Obtain dataset from beadm: active BE on reboot has a R in
		# the third column of 'beadm list' output, its dataset is
		# column two.
	        dset=`$BEADM list -Hd|$NAWK -F ';' '$3 ~ /R/ {print $2}'`

		# SPARC requires -Z flag on boot command
		if [ "$ISA_INFO" = "sparc" ]; then
			dset="-Z $dset"
		fi

	        # Try a fast reboot
		$REBOOT -f -- $dset

		exit $SMF_EXIT_OK
		;;

	#
	# Invalid or incompatible AI configuration manifest specified
	#
	$AI_ENGINE_EXIT_FAILURE_INVALID_MANIFEST)
		echo "Invalid or incompatible manifest provided" |
		    $TEE_LOGTOCONSOLE
		echo "Please refer to the" \
		    "/var/svc/log/application-auto-installer:default.log "\
		    "file for details" | $TEE_LOGTOCONSOLE

		exit $SMF_EXIT_ERR_FATAL
		;;

	#
	# Automated installation failed.
	#
	$AI_ENGINE_EXIT_FAILURE)
		echo "Automated Installation failed" | $TEE_LOGTOCONSOLE
		echo "Please refer to the /system/volatile/install_log file for" \
		    "details" | $TEE_LOGTOCONSOLE

		exit $SMF_EXIT_ERR_FATAL
		;;

	#
	# Automated installation failed with unknown exit code
	#
	*)
		echo "Automated Installation failed" | $TEE_LOGTOCONSOLE
		echo "Unknown exit code $ret returned" | $TEE_LOGTOCONSOLE

		exit $SMF_EXIT_ERR_FATAL
		;;
esac