#!/usr/bin/pfksh
#
# Copyright (c) 2001 by Sun Microsystems, Inc.
# All rights reserved.
#
#ident	"@(#)create_metadevices	1.10	01/10/02 SMI"
#
# This scripts reads the datafile 'ifile' local to this node and
# writes the metadevice configuration info to 'ofile'.

ifile=/var/cluster/spm/metadevice_db
ofile=/etc/lvm/md.tab
SUNWscvw_dir=/opt/SUNWscvw/cgi-bin/installation/sds

# Take the line and convert the CTD to DID, if necessary.
# We append the newline to the 'ofile'.
# format of the $line are :
# mirror-n/d0 -m mirror-1/d1 mirror-1/d2
# mirror-n/d1 1 1 c#t#d#
function append_to_ofile {
	line=$1
	echo $line | grep '\-m' >/dev/null
	if [[ $? -eq 0 ]]
	then
		echo $line >> $ofile
	else
		# We must convert the CTD name to the DID name
		# Creating the submirror.
		ctd_disk1=$(echo $line | awk '{print $4}')
		did_disk1=$($SUNWscvw_dir/ctd2did $ctd_disk1)
		# Construct the new line to append to md.tab
		newline=$(echo $line | awk '{ $4=""; print }')
		newline=$(echo $newline /dev/did/dsk/${did_disk1}s0)
		echo $newline >> $ofile
	fi
}

if [[ ! -f $ifile ]]
then
	echo "Node `uname -n` is not responsible for creating any metadevices."
else
	# We must process this file one line at a time
	exec 0<$ifile
	while read line
	do
		append_to_ofile "$line"
	done
		

fi
