#!/sbin/sh
#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"@(#)boot-archive	1.2	07/02/13 SMI"

. /lib/svc/share/smf_include.sh
. /lib/svc/share/fs_include.sh

ERRORFILE=/etc/svc/volatile/boot_archive_error
FILELIST=/etc/svc/volatile/boot_archive_filelist
UPDATEFILE=/etc/svc/volatile/boot_archive_needs_update

#
# no boot-archive on sparc...yet
#
if [  `uname -p` = "sparc" ]; then
	exit $SMF_EXIT_OK
fi

if [ "${_INIT_ZONENAME:=`/sbin/zonename`}" != "global" ]; then
	exit $SMF_EXIT_OK
fi

#
# Make sure we return failure only once. If user choose to ignore
# error, we return success to permit boot to continue. The boot
# archive will be updated on the subsequent shutdown.
#
if [ -f "${ERRORFILE}" ]; then
	rm ${ERRORFILE}
	exit $SMF_EXIT_OK
fi

#
# Now check the archive.
#
/sbin/bootadm update-archive -vnC 2> /dev/null
if [ $? = 0 ]; then
	exit $SMF_EXIT_OK
fi

touch $ERRORFILE
touch $UPDATEFILE

cecho ""
cecho "WARNING: The following files in / differ from the boot archive:"
cecho ""

/sbin/bootadm update-archive -vn | grep -v "cannot find" > /dev/msglog

cecho ""
cecho "The recommended action is to reboot and select the \"Solaris failsafe\""
cecho "option from the boot menu. Then follow the prompts to update the"
cecho "boot archive. To continue booting at your own risk, you may clear the"
cecho "service by running: \"svcadm clear system/boot-archive\""
cecho ""

exit $SMF_EXIT_ERR_FATAL
