#!/bin/sh
#
# Copyright 2001-2002 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"@(#)setup_sds	1.12	02/03/04 SMI"
#
# Run the korn shell scripts that will create all the SDS objects Be
# sure to capture all the output to the logs

LOGDIR=/var/cluster/spm
LOGFILE=${LOGDIR}/SUNWscvw_log
SDS_DIR=/opt/SUNWscvw/cgi-bin/installation/sds

# Wait for the entire cluster to come up in clustermode and reach
# setup_sds

touch ${LOGDIR}/setup_sds_barrier

ret=1
while [ "$ret" -eq 1 ]
do
        /opt/SUNWscvw/cgi-bin/installation/clustermode_remote.pl
        ret=$?
        sleep 10
done

# Create all of the SDS metadbs
ksh $SDS_DIR/create_metadbs 2>&1 >> ${LOGFILE}

# Timed wait for the entire cluster to complete its metadb replica creation
ret=1
loop=0
while [ "$ret" -eq 1 ]
do
        /opt/SUNWscvw/cgi-bin/installation/check_metadb.pl
        ret=$?
	if [ "$loop" -ge 10 ]
	then
		echo "The creation of the metadb replicas on at least one node of the cluster failed in the allotted time." >> ${LOGFILE}
		break
	else
		loop=`expr $loop + 1`
        	sleep 10
	fi	
done

# Add the /var/cluster/spm/vfstab.spm entries to /etc/vfstab
cat /var/cluster/spm/vfstab.spm >> /etc/vfstab

# After syncing, create the rest of the sds objects
ksh $SDS_DIR/create_global_mount_points 2>&1 >> ${LOGFILE}
ksh $SDS_DIR/create_metasets 2>&1 >> ${LOGFILE}
ksh $SDS_DIR/create_metadevices 2>&1 >> ${LOGFILE}
ksh $SDS_DIR/mount_metadevices 2>&1 >> ${LOGFILE}

# Only run this script once
rm -f ${LOGDIR}/setup_sds_flag
