#!/sbin/sh
#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"@(#)boot-archive-update.ksh	1.2	08/06/06 SMI"

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

UPDATEFILE=/etc/svc/volatile/boot_archive_needs_update

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

# on x86 get rid of transient reboot entry in the GRUB menu
#
if [ `uname -p` = "i386" ]; then
	if [ -f /stubboot/boot/grub/menu.lst ]; then
		/sbin/bootadm -m update_temp -R /stubboot
	else
		/sbin/bootadm -m update_temp
	fi
fi

if [ -f $UPDATEFILE ] || [ -f /reconfigure ]; then
	/usr/sbin/rtc -c > /dev/null 2>&1
	/sbin/bootadm update-archive
	rm -f $UPDATEFILE
fi

exit $SMF_EXIT_OK
