#!/sbin/sh

# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"@(#)lu_activate_sync.sh	1.2	08/05/08 SMI"
#
# Note that the caller of this script (luactivate) depends on the error
# messages produced, and not on the exit value from this script.
#
# setup ROOT
# For global zone it is /
# For non global zone it is /b within the scratch zone
#
ROOT="$1"

#
# mount point for the new BE
# for global zone it is some dir
# For non global zone it is /a
#
BE_MNT_PT="$2"

#
# 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
 
# Check if there's any work to be done first.  If the database hasn't been
# initialized, then there's nothing to do.

if /bin/grep '^<beSyncList type="initial" ' $BE_MNT_PT/$LU_DB_LOCAL \
    > /dev/null 2>&1 ; then 
 
	# Compute source and target synchronization file values.
	$LUETCBIN/lusync -u -d $BE_MNT_PT/$LU_DB_LOCAL \
	    -m $ROOT -t source -s $BE_MNT_PT/$LU_SYNCLIST
 
	$LUETCBIN/lusync -u -d $BE_MNT_PT/$LU_DB_LOCAL \
	    -m $BE_MNT_PT/ -t target \
	    -s $BE_MNT_PT/$LU_SYNCLIST
 
	# Check to see if any 'sourcetarget' synchronization files are
	# in conflict.
 
	ERRMSG=`$LUETCBIN/lusync -R sourcetarget -d \
	    $BE_MNT_PT/$LU_DB_LOCAL -m $BE_MNT_PT/`

	echo $ERRMSG
fi
