#!/sbin/sh
#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"@(#)boot-archive-update.ksh	1.1	07/02/13 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

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

# get rid of transient reboot entry in GRUB menu
if [ -f /stubboot/boot/grub/menu.lst ]; then
	/sbin/bootadm -m update_temp -R /stubboot
else
	/sbin/bootadm -m update_temp
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
