#!/sbin/sh

# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"@(#)lu_init_sync_start.sh	1.2	08/05/08 SMI"
#
# setup ROOT
# For global it is /.
# For non global zone it is /a within the scratch zone
#
ROOT=$1
	 
#
# Name of LAST BE
#
LAST_BE=$2

#
# for global zone it is mount point of the LASTBE
# for non global zone it is /a within the scratch zone.
#
LASTBE_MNTPT=$3

CURR_BE=$4
zone_name=$5
report_error()
{
       	# A file has changed on the source and on the target
	# - warn user.
	$LUPRINTF -fWp1 "`gettext 'The following files have changed \
on both the current boot environment <%s> and the previous boot environment \
<%s> on zone <%s>:'`" $CURR_BE $LAST_BE $zone_name
       	echo "$ERRMSG" | while read line ; do
               	$LUPRINTF -p1 '   %s' "$line"
       	done

       	$LUPRINTF -fIp1 "`gettext 'The files listed above are in conflict \
between the current boot environment <%s> and the previous boot environment \
<%s>.  These files were not automatically synchronized.'`" \
	    $CURR_BE $LAST_BE
}

#
# This is mainly a check for non global zones.
# If the scratch zone has not created /b there is no matching
# zone to sync with.
# 
[ -d $ROOT ] || exit 0
 
. /etc/default/lu
. $LUBIN/lulib
 
[ -s $ROOT/$LU_DB_LOCAL ] || exit 0
 
# Synchronize the boot environment.
$LUETCBIN/lusync -d $ROOT/$LU_DB_LOCAL -m $LASTBE_MNTPT -n $CURR_BE $LAST_BE \
    $ROOT/$LU_SYNCLIST

# Clear out any first time boot database information.
$LUETCBIN/lusync -i -d $ROOT/$LU_DB_LOCAL
