#!/bin/sh
# $Id: srvm_setup.sh,v 1.6 2001/03/14 13:32:57 agraham Exp $
#ident "$Source: /project/unixvm-cvs/src/sol/cmd/vxvm/voladm/Attic/srvm_setup.sh,v $"

#   Copyright 1996, 1997, 1998 Horizon Systems Laboratory,
#   Mitsubishi Electric Information Technology Center America.
#       All rights reserved.
# 
#   CONFIDENTIAL AND PROPRIETARY PROPERTY OF MITSUBISHI ELECTRIC ITA.

# Copyright (c) 2001 VERITAS Software Corporation.  ALL RIGHTS RESERVED.
# UNPUBLISHED -- RIGHTS RESERVED UNDER THE COPYRIGHT
# LAWS OF THE UNITED STATES.  USE OF A COPYRIGHT NOTICE
# IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
# OR DISCLOSURE.
# 
# THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND
# TRADE SECRETS OF VERITAS SOFTWARE.  USE, DISCLOSURE,
# OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR
# EXPRESS WRITTEN PERMISSION OF VERITAS SOFTWARE.
# 
#               RESTRICTED RIGHTS LEGEND
# USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT IS
# SUBJECT TO RESTRICTIONS AS SET FORTH IN SUBPARAGRAPH
# (C) (1) (ii) OF THE RIGHTS IN TECHNICAL DATA AND
# COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013.
#               VERITAS SOFTWARE
# 1600 PLYMOUTH STREET, MOUNTAIN VIEW, CA 94043
# 
# This script can be used to set up replication from a Primary to Secondary 
# machines.  It should be run on the Primary machine.  If this script does 
# not complete successfully, then it attempts to undo all changes.
#
# Rev. 2.9 Comment changes. "Quit" asks for confirmation, again.
# Rev. 2.8 Minor tweaks. "Quit" does no longer asks for confirmation.
# Rev. 2.7 Extensive support for editting specifications for Secondary objects.
#          More checking for object name in use (esp. on secondary), and for 
#          Primary and Secondary being same host.  Offers RLINK list before 
#          Secondary set-up.  More "^C" support.
# Rev. 2.6 Added options to delete descriptions of RLINK and Secondary records.
#          Added option to remove an existing RVG hierarchy.
#          Added option to do a quick Primary checkpoint via dd, |, rsh.
# Rev. 2.5 Renamed rvol/replica/master/slave->rvg/rlink/primary/secondary, etc
# Rev. 2.4 Added "m,a,?" options.  Touched up outputting via more(1).
# Rev. 2.3 Uncommented main menu option 5
# Rev. 2.2 Added latency high/low mark menus.
# Rev. 2.1 Ongoing updates. Added create/exists field for non-vol objects
# Rev. 2.0 The first revision to support volume groups
# NOTE:	This program assumes 1 block = 1 sector = 512 bytes
 
if [ $# -ne 0 ] 
then
        echo "srvm_setup:Usage: $0"
        exit 1
fi

VXVM_BIN=/usr/sbin
OS=`/bin/uname`
LOCAL_HOST=`/bin/uname -n`
DEBUG=0
CLEANUP=""
DISKGROUP=rootdg
SYNC_MODE=O; SRLPROT_MODE=D LATENCY_MODE=O; SYNC=off; SRLPROT=dcm; LATENCY=off
DATAVOL_LOGSRVM="yes";
SRVMLOGTYPE="logtype=dcm"
LOW_LATENCY=9950; HIGH_LATENCY=10000
PREFIX=id-
ENABLE_MORE="yes"
SHOW_SUMMARY_ONCE=no
if [ ! -z "$TERM" ] && [ -x /usr/bin/tput ] || [ -x /bin/tput ]
then
	TPUT=tput
fi
clear()
{
if [ "$TPUT" != "" ]
then
	tput clear
	if [ "$?" != 0 ]
	then
		/bin/clear
	fi
else
	/bin/clear
fi
}


# meta files for processing configuration info
CONFIG_FILE="/tmp/vvr.setup.cfg.$$"		       # Config. description
CONFIG_FILE_EMPTY="/tmp/vvr.setup.cfg.empty.$$"       # For Previous test
VXSUMMARY_FILE="/tmp/vvr.summary.$$"		       # Holds Summary output
CONFIG_FILE_OLD="/tmp/vvr.setup.cfg.old.$$"	       # Test: Need new Summary?
VXPRINT_FILE="/tmp/vvr.vxprint.$$"		       # Hold vxprint(1) output
VXPRINT_FILE2="/tmp/vvr.vxprint2.$$"		       # Hold vxprint(1) output
CONFIG_ORIG_FILE="/tmp/vvr.setup.orig.cfg.$$"	       # For Previous test
CONFIG_AUX_ORIG_FILE="/tmp/vvr.setup.aux.orig.cfg.$$" # For Previous test(nest)
CONFIG_2AUX_ORIG_FILE="/tmp/vvr.setup.2aux.orig.cfg.$$" # For Previous (nested)
VERIFY_CFG_FILE="/tmp/vvr.verify_cfg.$$"	       # Non-empty if bad config
CONFIG_BAK_FILE="/tmp/vvr.setup.bak.cfg.$$"	       # Restore bad "load file"
CONFIG_TMP_FILE="/tmp/vvr.setup.tmp.cfg.$$"	       # awk,vxprint,etc output
CONFIG_2TMP_FILE="/tmp/vvr.setup.2tmp.cfg.$$"	       # awk,vxprint,etc output
CONFIG_3TMP_FILE="/tmp/vvr.setup.3tmp.cfg.$$"	       # awk,vxprint,etc output
REMOTE_CHECK="/tmp/vvr.remote_check.$$"	       # Does remote obj exist?
# /tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$	       # cmds to undo on remote

# files for rsh calls
RSH_CMD_STATUS_FILE="/tmp/vvr.cmd_status.$$"
RSH_CMDS_FILE="/tmp/vvr.cmds.$$"

# do_rcp() -- copies $rcp_file to $SECONDARY_HOST:/tmp
# 
# Inputs:
#	SECONDARY_HOST	Remote host name
#	rcp_file 	File to be copied to $SECONDARY_HOST:/tmp
do_rcp()
{
	#echo "do_rcp file: $rcp_file" > /dev/tty 2>&1
	if [ "$SECONDARY_HOST" = "" ] 
	then
		echo "do_rcp: ERROR: Missing remote host name"
		Cleanup
	fi
	if [ "$rcp_file" = "" ] 
	then
		echo "do_rcp: ERROR: Missing file name to copy"
		Cleanup
	fi
        rcp "$rcp_file" $SECONDARY_HOST:/tmp > /dev/null 2>&1
        if [ "$?" -ne 0 ] 
        then		# retry once
		sleep 1
        	rcp $rcp_file $SECONDARY_HOST:/tmp > /dev/null 2>&1
                if [ "$?" -ne 0 ]
                then
                        echo "rcp to $SECONDARY_HOST:/tmp failed"
                        Cleanup
                fi
        fi
}

# do_rsh()
# 
# Inputs:
#	SECONDARY_HOST	Remote host name
#	rsh_cmd 	command to be executed remotely
do_rsh()
{
	#echo rsh $SECONDARY_HOST $rsh_cmd > /dev/tty 2>&1
	if [ "$SECONDARY_HOST" = "" ] 
	then
		echo "do_rsh: ERROR: Missing remote host name"
		Cleanup
	fi
	if [ "$rsh_cmd" = "" ]
	then
		echo "do_rsh: ERROR: Missing remote command"
		Cleanup
	fi
        rsh "$SECONDARY_HOST" "$rsh_cmd"
        if [ "$?" -ne 0 ] 
        then		# retry once
		sleep 1
                rsh "$SECONDARY_HOST" "$rsh_cmd"
                if [ "$?" -ne 0 ]
                then
                        echo "rsh to $SECONDARY_HOST failed"
                        Cleanup
                fi
        fi
}

# Do_Remote_Cmd()
#
# Inputs:
#	SECONDARY_HOST 	remote host name
#	REMOTE_CMD 	string to be executed on remote
Do_Remote_Cmd()
{
	if [ "$SECONDARY_HOST" = "$LOCAL_HOST" ]
	then
		eval $REMOTE_CMD
		return "$?"
	fi
	#echo "Do_Remote_Cmd: $REMOTE_CMD" > /dev/tty 2>&1
	RSH_OLD_CLEANUP="$CLEANUP"
	CLEANUP_RM_RSH_CMDS_FILE
	echo "#!/bin/sh" > $RSH_CMDS_FILE
	echo "$REMOTE_CMD" >> $RSH_CMDS_FILE
	echo 'echo $? > ' $RSH_CMD_STATUS_FILE >> $RSH_CMDS_FILE
	chmod 777 $RSH_CMDS_FILE
	#cat $RSH_CMDS_FILE > /dev/tty
	THE_CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
	if [ ! -f $THE_CLEANUP_FILE ]
	then
		touch $THE_CLEANUP_FILE
	fi
	/bin/cp $THE_CLEANUP_FILE ${THE_CLEANUP_FILE}.save
	REMOTE_CLEANUP_RM_RSH_CMDS_FILE
	REMOTE_CLEANUP_RM_RSH_CMD_STATUS_FILE
	rcp_file="$RSH_CMDS_FILE"
	do_rcp		# rcp $RSH_CMDS_FILE $SECONDARY_HOST:/tmp
	rsh_cmd="$RSH_CMDS_FILE"
	do_rsh		# rsh $SECONDARY_HOST $RSH_CMDS_FILE
	rsh_cmd="/bin/cat $RSH_CMD_STATUS_FILE; /bin/rm -f $RSH_CMDS_FILE $RSH_CMD_STATUS_FILE"
	return_status=`do_rsh`		# rsh $SECONDARY_HOST cat $RSH_CMD_STATUS_FILE
	/bin/mv -f ${THE_CLEANUP_FILE}.save $THE_CLEANUP_FILE
	/bin/rm -f $RSH_CMDS_FILE
	CLEANUP="$RSH_OLD_CLEANUP"
	return $return_status
}

# Do_Remote_Cmd_Status()
# Like Do_Remote_Cmd, but sends output of cmd to /dev/null and just returns 
# exit status of cmd.  Saves one rsh call over Do_Remote_Cmd.
# Inputs:
#	SECONDARY_HOST 	remote host name
#	REMOTE_CMD 	string to be executed on remote
Do_Remote_Cmd_Status()
{
	if [ "$SECONDARY_HOST" = "$LOCAL_HOST" ]
	then
		eval $REMOTE_CMD > /dev/null 2>&1
#		`$REMOTE_CMD > /dev/null 2>&1`
		return "$?"
	fi
	#echo "Do_Remote_Cmd: $REMOTE_CMD" > /dev/tty 2>&1
	RSH_OLD_CLEANUP="$CLEANUP"
	CLEANUP_RM_RSH_CMDS_FILE
	echo "#!/bin/sh" > $RSH_CMDS_FILE
	echo "$REMOTE_CMD > /dev/null 2>&1" >> $RSH_CMDS_FILE
	echo 'echo $?' >> $RSH_CMDS_FILE
	echo "/bin/rm -f $RSH_CMDS_FILE" >> $RSH_CMDS_FILE
	chmod 777 $RSH_CMDS_FILE
	#cat $RSH_CMDS_FILE > /dev/tty
	THE_CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
	if [ ! -f $THE_CLEANUP_FILE ]
	then
		touch $THE_CLEANUP_FILE
	fi
	/bin/cp $THE_CLEANUP_FILE ${THE_CLEANUP_FILE}.save
	REMOTE_CLEANUP_RM_RSH_CMDS_FILE
	rcp_file="$RSH_CMDS_FILE"
	do_rcp		# rcp $RSH_CMDS_FILE $SECONDARY_HOST:/tmp
	rsh_cmd="$RSH_CMDS_FILE"
	return_status=`do_rsh`		# rsh $SECONDARY_HOST $RSH_CMDS_FILE
	/bin/mv -f ${THE_CLEANUP_FILE}.save $THE_CLEANUP_FILE
	/bin/rm -f $RSH_CMDS_FILE
	CLEANUP="$RSH_OLD_CLEANUP"
	return $return_status
}

# Do_Remote_Cmd_Output()
# Like Do_Remote_Cmd, but just prints output of cmd and does not return
# exit status of cmd.  
# MODIFIED 7/7/96 Simplified immensely to just call rsh.
# Inputs:
#	SECONDARY_HOST 	remote host name
#	REMOTE_CMD 	string to be executed on remote
Do_Remote_Cmd_Output()
{
	if [ "$SECONDARY_HOST" = "$LOCAL_HOST" ]
	then
		eval $REMOTE_CMD
#		`$REMOTE_CMD`
	else
		rsh "$SECONDARY_HOST" "$REMOTE_CMD"
	fi
}

# NOTE: CLEANUP methodology
# If the user hits ^C to abort the program, or if an error is encountered 
# while attempting to commit a series of changes, then this program will undo
# changes which were in progress.  The CLEANUP string contains a semi-colon
# separated list of commands to execute which will undo *local* changes in the
# proper order.  [Each time a change is made, the CLEANUP string is pre-pended
# with the command string to undo that change in case ^C is entered before
# all changes are complete.]  For cleanup on REMOTE machines, REMOTE_HOSTS
# contains a white-space separated list of host names which (may) require
# cleanup.  For each of those hosts, a file named 
# /tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$ is created which contains the 
# cleanup commands for that host, one per line, in correct order for cleanup.

#Inputs:
#	RVG_NAME
#	DISKGROUP
CLEANUP_STOP_RVG()
{
    if [ "$CLEANUP" = "" ]
    then
        CLEANUP="$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} stop $RVG_NAME"
    else
        CLEANUP="$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} stop $RVG_NAME; $CLEANUP"
    fi
}

#Inputs:
#	${DISKGROUP:-rootdg}
#	RVG_NAME
CLEANUP_DO_CHECKEND()
{
# Make sure $RVG_NAME is in need of a checkend
    ALREADY_SET=`$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -l "$RVG_NAME" | /bin/egrep -c "awaiting_checkend"`
    if [ "$ALREADY_SET" != 1 ]
    then
        return
    fi

    if [ "$CLEANUP" = "" ]
    then
        CLEANUP="$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME"
    else
        CLEANUP="$CLEANUP; $VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME"
    fi
}

#Inputs:
#	CLEANUP_RL	Rlink to remove
CLEANUP_RM_RLINK()
{
    if [ "$CLEANUP" = "" ]
    then
        CLEANUP="$VXVM_BIN/vxedit -g ${DISKGROUP:-rootdg} -f rm $CLEANUP_RL"
    else
        CLEANUP="$VXVM_BIN/vxedit -g ${DISKGROUP:-rootdg} -f rm $CLEANUP_RL; $CLEANUP"
    fi
}

#Inputs:
#	CLEANUP_RL	Rlink to dissociate
CLEANUP_DIS_RLINK()
{
    if [ "$CLEANUP" = "" ]
    then
        CLEANUP="$VXVM_BIN/vxrlink -g ${DISKGROUP:-rootdg} dis $CLEANUP_RL"
    else
        CLEANUP="$VXVM_BIN/vxrlink -g ${DISKGROUP:-rootdg} dis $CLEANUP_RL; $CLEANUP"
    fi
}

#Inputs:
#	CLEANUP_RL	Rlink to detach
CLEANUP_DET_RLINK()
{
    if [ "$CLEANUP" = "" ]
    then
        CLEANUP="$VXVM_BIN/vxrlink -g ${DISKGROUP:-rootdg} -f det $CLEANUP_RL"
    else
        CLEANUP="$VXVM_BIN/vxrlink -g ${DISKGROUP:-rootdg} -f det $CLEANUP_RL; $CLEANUP"
    fi
}

#Inputs:
#	CLEANUP_DV	Datavol to remove
CLEANUP_RM_DATAVOL()
{
    if [ "$CLEANUP" = "" ]
    then
        CLEANUP="$VXVM_BIN/vxedit -g ${DISKGROUP:-rootdg} -rf rm $CLEANUP_DV"
    else
        CLEANUP="$VXVM_BIN/vxedit -g ${DISKGROUP:-rootdg} -rf rm $CLEANUP_DV; $CLEANUP"
    fi
}

#Inputs:
#	CLEANUP_DV	Datavol to dissociate
CLEANUP_DIS_DATAVOL()
{
    if [ "$CLEANUP" = "" ]
    then
        CLEANUP="$VXVM_BIN/vxvol -g ${DISKGROUP:-rootdg} dis $CLEANUP_DV"
    else
        CLEANUP="$VXVM_BIN/vxvol -g ${DISKGROUP:-rootdg} dis $CLEANUP_DV; $CLEANUP"
    fi
}


CLEANUP_RM_CONFIG_FILE()
{
    if [ "$CLEANUP" = "" ]
    then
        CLEANUP="/bin/rm -f $CONFIG_FILE"
    else
        CLEANUP="/bin/rm -f $CONFIG_FILE; $CLEANUP"
    fi
}

CLEANUP_RM_RSH_CMDS_FILE()
{
    if [ "$CLEANUP" = "" ]
    then
	CLEANUP="/bin/rm -f $RSH_CMDS_FILE"
    else
	CLEANUP="$CLEANUP; /bin/rm -f $RSH_CMDS_FILE"
    fi
}

# Inputs:
#       SECONDARY_HOST      Secondary host machine on which to remove file
REMOTE_CLEANUP_RM_RSH_CMDS_FILE()
{
    if [ "$REMOTE_HOSTS" = "" ]
    then
        REMOTE_HOSTS=" $SECONDARY_HOST "
    else
	echo "$REMOTE_HOSTS" | /bin/egrep " $SECONDARY_HOST " > /dev/null 2>&1
	if [ "$?" != 0 ] 	#Don't keep appending same host name
	then
        	REMOTE_HOSTS=""$REMOTE_HOSTS" "$SECONDARY_HOST" "
	fi
    fi

    CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
    if [ ! -f $CLEANUP_FILE ] || [ ! -s $CLEANUP_FILE ]
    then
        echo "/bin/rm -f $RSH_CMDS_FILE" > $CLEANUP_FILE
    else
        /bin/mv -f $CLEANUP_FILE ${CLEANUP_FILE}.orig
        echo "/bin/rm -f $RSH_CMDS_FILE; " > $CLEANUP_FILE
        /bin/cat ${CLEANUP_FILE}.orig >> $CLEANUP_FILE
        /bin/rm -f ${CLEANUP_FILE}.orig
    fi
}

# Inputs:
#       SECONDARY_HOST      Secondary host machine on which to remove file
REMOTE_CLEANUP_RM_RSH_CMD_STATUS_FILE()
{
    if [ "$REMOTE_HOSTS" = "" ]
    then
        REMOTE_HOSTS=" $SECONDARY_HOST "
    else
	echo "$REMOTE_HOSTS" | /bin/egrep " $SECONDARY_HOST " > /dev/null 2>&1
	if [ "$?" != 0 ] 	#Don't keep appending same host name
	then
        	REMOTE_HOSTS=""$REMOTE_HOSTS" "$SECONDARY_HOST" "
	fi
    fi

    CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
    if [ ! -f $CLEANUP_FILE ] || [ ! -s $CLEANUP_FILE ]
    then
	echo "/bin/rm -f $RSH_CMD_STATUS_FILE" > $CLEANUP_FILE
    else
        /bin/mv -f $CLEANUP_FILE ${CLEANUP_FILE}.orig
        echo "/bin/rm -f $RSH_CMD_STATUS_FILE; " > $CLEANUP_FILE
        /bin/cat ${CLEANUP_FILE}.orig >> $CLEANUP_FILE
        /bin/rm -f ${CLEANUP_FILE}.orig
    fi
}

# Inputs:
#	SECONDARY_HOST	Secondary host machine on which to dissociate the Secondary rlink
#	CLEANUP_SRL	Secondary RLINK to be dissociated
#	SECONDARY_RLINK  	Diskgroup that the Secondary RLINK is in
REMOTE_CLEANUP_DIS_SECONDARY_RLINK()
{
    if [ "$REMOTE_HOSTS" = "" ]
    then
	REMOTE_HOSTS=" $SECONDARY_HOST "
    else
	echo "$REMOTE_HOSTS" | /bin/egrep " $SECONDARY_HOST " > /dev/null 2>&1
	if [ "$?" != 0 ] 	#Don't keep appending same host name
	then
        	REMOTE_HOSTS=""$REMOTE_HOSTS" "$SECONDARY_HOST" "
	fi
    fi

    CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
    if [ ! -f $CLEANUP_FILE ] || [ ! -s $CLEANUP_FILE ]
    then
        echo "$VXVM_BIN/vxrlink -g "$SECONDARY_DISKGROUP" dis "$CLEANUP_SRL"" > $CLEANUP_FILE
    else
	/bin/mv -f $CLEANUP_FILE ${CLEANUP_FILE}.orig
	echo "$VXVM_BIN/vxrlink -g "$SECONDARY_DISKGROUP" dis "$CLEANUP_SRL"; " > $CLEANUP_FILE
	/bin/cat ${CLEANUP_FILE}.orig >> $CLEANUP_FILE
	/bin/rm -f ${CLEANUP_FILE}.orig
    fi
}

# Inputs:
#	SECONDARY_HOST	Secondary host machine on which to remove the Secondary rlink
#	CLEANUP_SRL		Secondary RLINK to be removed
#	SECONDARY_DISKGROUP	Diskgroup that the Secondary datavol is in
REMOTE_CLEANUP_RM_SECONDARY_RLINK()
{
    if [ "$REMOTE_HOSTS" = "" ]
    then
	REMOTE_HOSTS=" $SECONDARY_HOST "
    else
	echo "$REMOTE_HOSTS" | /bin/egrep " $SECONDARY_HOST " > /dev/null 2>&1
	if [ "$?" != 0 ] 	#Don't keep appending same host name
	then
        	REMOTE_HOSTS=""$REMOTE_HOSTS" "$SECONDARY_HOST" "
	fi
    fi

    CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
    if [ ! -f $CLEANUP_FILE ] || [ ! -s $CLEANUP_FILE ]
    then
        echo "$VXVM_BIN/vxedit -g "$SECONDARY_DISKGROUP" -f rm "$CLEANUP_SRL"" > $CLEANUP_FILE
    else
	/bin/mv -f $CLEANUP_FILE ${CLEANUP_FILE}.orig
	echo "$VXVM_BIN/vxedit -g "$SECONDARY_DISKGROUP" -f rm "$CLEANUP_SRL"; " > $CLEANUP_FILE
	/bin/cat ${CLEANUP_FILE}.orig >> $CLEANUP_FILE
	/bin/rm -f ${CLEANUP_FILE}.orig
    fi
}

# Inputs:
#	SECONDARY_HOST	Secondary host machine on which to remove the Secondary rlink
#	SECONDARY_RLINK  	Secondary RLINK to be attached
#	SECONDARY_DISKGROUP	Diskgroup that the Secondary datavol is in
REMOTE_CLEANUP_ATT_RLINK()
{
    if [ "$REMOTE_HOSTS" = "" ]
    then
	REMOTE_HOSTS=" $SECONDARY_HOST "
    else
	echo "$REMOTE_HOSTS" | /bin/egrep " $SECONDARY_HOST " > /dev/null 2>&1
	if [ "$?" != 0 ] 	#Don't keep appending same host name
	then
        	REMOTE_HOSTS=""$REMOTE_HOSTS" "$SECONDARY_HOST" "
	fi
    fi

    CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
    if [ ! -f $CLEANUP_FILE ] || [ ! -s $CLEANUP_FILE ]
    then
        echo "$VXVM_BIN/vxrlink -g "$SECONDARY_DISKGROUP" -f att "$SECONDARY_RLINK"" > $CLEANUP_FILE
    else
	/bin/mv -f $CLEANUP_FILE ${CLEANUP_FILE}.orig
	echo "$VXVM_BIN/vxrlink -g "$SECONDARY_DISKGROUP" -f att "$SECONDARY_RLINK"; " > $CLEANUP_FILE
	/bin/cat ${CLEANUP_FILE}.orig >> $CLEANUP_FILE
	/bin/rm -f ${CLEANUP_FILE}.orig
    fi
}

# Inputs:
#	SECONDARY_HOST	Secondary host machine on which to remove the Secondary rlink
#	SECONDARY_RLINK  	Secondary RLINK to be detached
#	SECONDARY_DISKGROUP	Diskgroup that the Secondary datavol is in
REMOTE_CLEANUP_DET_SECONDARY_RLINK()
{
    if [ "$REMOTE_HOSTS" = "" ]
    then
	REMOTE_HOSTS=" $SECONDARY_HOST "
    else
	echo "$REMOTE_HOSTS" | /bin/egrep " $SECONDARY_HOST " > /dev/null 2>&1
	if [ "$?" != 0 ] 	#Don't keep appending same host name
	then
        	REMOTE_HOSTS=""$REMOTE_HOSTS" "$SECONDARY_HOST" "
	fi
    fi

    CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
    if [ ! -f $CLEANUP_FILE ] || [ ! -s $CLEANUP_FILE ]
    then
        echo "$VXVM_BIN/vxrlink -g "$SECONDARY_DISKGROUP" det "$SECONDARY_RLINK"" > $CLEANUP_FILE
    else
	/bin/mv -f $CLEANUP_FILE ${CLEANUP_FILE}.orig
	echo "$VXVM_BIN/vxrlink -g "$SECONDARY_DISKGROUP" det "$SECONDARY_RLINK"; " > $CLEANUP_FILE
	/bin/cat ${CLEANUP_FILE}.orig >> $CLEANUP_FILE
	/bin/rm -f ${CLEANUP_FILE}.orig
    fi
}

# Inputs:
#	SECONDARY_HOST		Secondary host machine 
#	SECONDARY_RVG		Secondary RVG to be stopped
#	SECONDARY_DISKGROUP	Diskgroup that the Secondary RVG is in
REMOTE_CLEANUP_STOP_SECONDARY_RVG()
{
    if [ "$REMOTE_HOSTS" = "" ]
    then
	REMOTE_HOSTS=" $SECONDARY_HOST "
    else
	echo "$REMOTE_HOSTS" | /bin/egrep " $SECONDARY_HOST " > /dev/null 2>&1
	if [ "$?" != 0 ] 	#Don't keep appending same host name
	then
        	REMOTE_HOSTS=""$REMOTE_HOSTS" "$SECONDARY_HOST" "
	fi
    fi

    CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
    if [ ! -f $CLEANUP_FILE ] || [ ! -s $CLEANUP_FILE ]
    then
        echo "$VXVM_BIN/vxrvg -g "$SECONDARY_DISKGROUP" -f stop "$SECONDARY_RVG"" > $CLEANUP_FILE
    else
	/bin/mv -f $CLEANUP_FILE ${CLEANUP_FILE}.orig
	echo "$VXVM_BIN/vxrvg -g "$SECONDARY_DISKGROUP" -f stop "$SECONDARY_RVG"; " > $CLEANUP_FILE
	/bin/cat ${CLEANUP_FILE}.orig >> $CLEANUP_FILE
	/bin/rm -f ${CLEANUP_FILE}.orig
    fi
}

# Inputs:
#	SECONDARY_HOST	Secondary host machine on which to remove the data volume
#	CLEANUP_SDV	Secondary data volume to be removed
#	SECONDARY_DISKGROUP	Diskgroup that the Secondary datavol is in
REMOTE_CLEANUP_RM_SECONDARY_DATAVOL()
{
    if [ "$REMOTE_HOSTS" = "" ]
    then
	REMOTE_HOSTS=" $SECONDARY_HOST "
    else
	echo "$REMOTE_HOSTS" | /bin/egrep " $SECONDARY_HOST " > /dev/null 2>&1
	if [ "$?" != 0 ] 	#Don't keep appending same host name
	then
        	REMOTE_HOSTS=""$REMOTE_HOSTS" "$SECONDARY_HOST" "
	fi
    fi

    CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
    if [ ! -f $CLEANUP_FILE ] || [ ! -s $CLEANUP_FILE ]
    then
        echo "$VXVM_BIN/vxedit -g "$SECONDARY_DISKGROUP" -rf rm "$CLEANUP_SDV"" > $CLEANUP_FILE
    else
	/bin/mv -f $CLEANUP_FILE ${CLEANUP_FILE}.orig
	echo "$VXVM_BIN/vxedit -g "$SECONDARY_DISKGROUP" -rf rm "$CLEANUP_SDV"; " > $CLEANUP_FILE
	/bin/cat ${CLEANUP_FILE}.orig >> $CLEANUP_FILE
	/bin/rm -f ${CLEANUP_FILE}.orig
    fi
}

# Inputs:
#	SECONDARY_HOST	Secondary host machine on which to remove the rvg
#	SECONDARY_SRLVOL	Secondary SRL volume
#	SECONDARY_DISKGROUP	Diskgroup that the Secondary SRL vol is in
REMOTE_CLEANUP_RM_SECONDARY_SRLVOL()
{
    if [ "$REMOTE_HOSTS" = "" ]
    then
	REMOTE_HOSTS=" $SECONDARY_HOST "
    else
	echo "$REMOTE_HOSTS" | /bin/egrep " $SECONDARY_HOST " > /dev/null 2>&1
	if [ "$?" != 0 ] 	#Don't keep appending same host name
	then
        	REMOTE_HOSTS=""$REMOTE_HOSTS" "$SECONDARY_HOST" "
	fi
    fi

    CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
    if [ ! -f $CLEANUP_FILE ] || [ ! -s $CLEANUP_FILE ]
    then
        echo "$VXVM_BIN/vxedit -g "$SECONDARY_DISKGROUP" -rf rm "$SECONDARY_SRLVOL"" > $CLEANUP_FILE
    else
	/bin/mv -f $CLEANUP_FILE ${CLEANUP_FILE}.orig
	echo "$VXVM_BIN/vxedit -g "$SECONDARY_DISKGROUP" -rf rm "$SECONDARY_SRLVOL"; " > $CLEANUP_FILE
	/bin/cat ${CLEANUP_FILE}.orig >> $CLEANUP_FILE
	/bin/rm -f ${CLEANUP_FILE}.orig
    fi
}

# Inputs:
#	SECONDARY_HOST	Secondary host machine on which to dissociate the datavol
#	CLEANUP_SDV	Secondary data volume
#	SECONDARY_DISKGROUP	Diskgroup that the Secondary datavol is in
REMOTE_CLEANUP_DIS_SECONDARY_DATAVOL()
{
    if [ "$REMOTE_HOSTS" = "" ]
    then
	REMOTE_HOSTS=" $SECONDARY_HOST "
    else
	echo "$REMOTE_HOSTS" | /bin/egrep " $SECONDARY_HOST " > /dev/null 2>&1
	if [ "$?" != 0 ] 	#Don't keep appending same host name
	then
        	REMOTE_HOSTS=""$REMOTE_HOSTS" "$SECONDARY_HOST" "
	fi
    fi

    CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
    if [ ! -f $CLEANUP_FILE ] || [ ! -s $CLEANUP_FILE ]
    then
        echo "$VXVM_BIN/vxvol -g "$SECONDARY_DISKGROUP" dis "$CLEANUP_SDV"" > $CLEANUP_FILE
    else
	/bin/mv -f $CLEANUP_FILE ${CLEANUP_FILE}.orig
	echo "$VXVM_BIN/vxvol -g "$SECONDARY_DISKGROUP" dis "$CLEANUP_SDV"; " > $CLEANUP_FILE
	/bin/cat ${CLEANUP_FILE}.orig >> $CLEANUP_FILE
	/bin/rm -f ${CLEANUP_FILE}.orig
    fi
}

# Inputs:
#	SECONDARY_HOST	Secondary host machine on which to dissociate the SRL vol
#	SECONDARY_SRLVOL	Secondary SRL volume
#	SECONDARY_DISKGROUP	Diskgroup that the Secondary SRL vol is in
REMOTE_CLEANUP_DIS_SECONDARY_SRLVOL()
{
    if [ "$REMOTE_HOSTS" = "" ]
    then
	REMOTE_HOSTS=" $SECONDARY_HOST "
    else
	echo "$REMOTE_HOSTS" | /bin/egrep " $SECONDARY_HOST " > /dev/null 2>&1
	if [ "$?" != 0 ] 	#Don't keep appending same host name
	then
        	REMOTE_HOSTS=""$REMOTE_HOSTS" "$SECONDARY_HOST" "
	fi
    fi

    CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
    if [ ! -f $CLEANUP_FILE ] || [ ! -s $CLEANUP_FILE ]
    then
        echo "$VXVM_BIN/vxvol -g "$SECONDARY_DISKGROUP" dis "$SECONDARY_SRLVOL"" > $CLEANUP_FILE
    else
	/bin/mv -f $CLEANUP_FILE ${CLEANUP_FILE}.orig
	echo "$VXVM_BIN/vxvol -g "$SECONDARY_DISKGROUP" dis "$SECONDARY_SRLVOL"; " > $CLEANUP_FILE
	/bin/cat ${CLEANUP_FILE}.orig >> $CLEANUP_FILE
	/bin/rm -f ${CLEANUP_FILE}.orig
    fi
}

# Inputs:
#	SECONDARY_HOST	Secondary host machine on which to remove the rvg
#	SECONDARY_SRLVOL	Secondary rvg
#	SECONDARY_DISKGROUP	Diskgroup that the Secondary RVG is in
REMOTE_CLEANUP_RM_SECONDARY_RVG()
{
    if [ "$REMOTE_HOSTS" = "" ]
    then
	REMOTE_HOSTS=" $SECONDARY_HOST "
    else
	echo "$REMOTE_HOSTS" | /bin/egrep " $SECONDARY_HOST " > /dev/null 2>&1
	if [ "$?" != 0 ] 	#Don't keep appending same host name
	then
        	REMOTE_HOSTS=""$REMOTE_HOSTS" "$SECONDARY_HOST" "
	fi
    fi

    CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
    if [ ! -f $CLEANUP_FILE ] || [ ! -s $CLEANUP_FILE ]
    then
        echo "$VXVM_BIN/vxedit -g "$SECONDARY_DISKGROUP" -f rm "$SECONDARY_RVG"" > $CLEANUP_FILE
    else
	/bin/mv -f $CLEANUP_FILE ${CLEANUP_FILE}.orig
	echo "$VXVM_BIN/vxedit -g "$SECONDARY_DISKGROUP" -f rm "$SECONDARY_RVG"; " > $CLEANUP_FILE
	/bin/cat ${CLEANUP_FILE}.orig >> $CLEANUP_FILE
	/bin/rm -f ${CLEANUP_FILE}.orig
    fi
}

CLEANUP_RM_RVG()
{
    if [ "$CLEANUP" = "" ]
    then
        CLEANUP="$VXVM_BIN/vxedit -g ${DISKGROUP:-rootdg} -f rm "$RVG""
    else
        CLEANUP="$VXVM_BIN/vxedit -g ${DISKGROUP:-rootdg} -f rm "$RVG"; $CLEANUP"
    fi
}

CLEANUP_DIS_SRLVOL()
{
    if [ "$CLEANUP" = "" ]
    then
        CLEANUP="$VXVM_BIN/vxvol -g ${DISKGROUP:-rootdg} dis "$SRLVOL""
    else
        CLEANUP="$VXVM_BIN/vxvol -g ${DISKGROUP:-rootdg} dis "$SRLVOL"; $CLEANUP"
    fi
}

CLEANUP_RM_SRLVOL()
{
    if [ "$CLEANUP" = "" ]
    then
        CLEANUP="$VXVM_BIN/vxedit -g ${DISKGROUP:-rootdg} -rf rm $SRLVOL"
    else
        CLEANUP="$VXVM_BIN/vxedit -g ${DISKGROUP:-rootdg} -rf rm $SRLVOL; $CLEANUP"
    fi
}

CLEANUP_DIS_SRLVOL()
{
    if [ "$CLEANUP" = "" ]
    then
        CLEANUP="$VXVM_BIN/vxvol -g ${DISKGROUP:-rootdg} dis $SRLVOL"
    else
        CLEANUP="$VXVM_BIN/vxvol -g ${DISKGROUP:-rootdg} dis $SRLVOL; $CLEANUP"
    fi
}


# Cleanup in response to ^C or Q (Quit option selected).  Former is 
# verbose and gives non-zero exit code.
Cleanup()
{
	/bin/rm -f $CONFIG_FILE $CONFIG_FILE_OLD $CONFIG_ORIG_FILE $CONFIG_AUX_ORIG_FILE \
		$CONFIG_2AUX_ORIG_FILE $CONFIG_TMP_FILE $CONFIG_BAK_FILE \
		${CONFIG_2TMP_FILE}* $VERIFY_CFG_FILE $VXPRINT_FILE $VXSUMMARY_FILE \
		$RSH_CMDS_FILE $RSH_CMD_STATUS_FILE $CONFIG_FILE_EMPTY \
		$CONFIG_3TMP_FILE $VXPRINT_FILE2
	if [ "$QUIT" = "" ]
	then
		echo "Cleaning up..."
        	echo "$CLEANUP"
	fi
        eval "$CLEANUP"
	if [ "$REMOTE_HOSTS" != "" ]
	then
	    for SECONDARY_HOST in $REMOTE_HOSTS
	    do
		CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
		if [ ! -f $CLEANUP_FILE ]
		then
			echo "ERROR: Could not find $CLEANUP_FILE,"
			echo "       so skipping clean up of $SECONDARY_HOST"
			continue
		fi
		REMOTE_CLEANUP=`awk '{ printf "%s", $0 }' $CLEANUP_FILE`
		EMPTY_CHECK=`echo "$REMOTE_CLEANUP" | /bin/sed 's/  *//g'`
		if [ "$EMPTY_CHECK" != "" ]
		then
                	echo "$SECONDARY_HOST:Remote cleanup: $REMOTE_CLEANUP"
			REMOTE_CMD="$REMOTE_CLEANUP"
			Do_Remote_Cmd
		fi
		/bin/rm -f $CLEANUP_FILE
	    done
        fi
        trap 0  # So HUP will not trap, so can exit without trapping
	if [ "$QUIT" = "" ]
	then
        	exit 1
	else
		exit 0
	fi
}

Quit()
{
        REALLY_QUIT=""
        while [ "$REALLY_QUIT" = "" ]
        do
                echo "Are you sure you want to quit? (y/n) (default: y): \c"
                read REALLY_QUIT
                case "$REALLY_QUIT" in
                        "" )    REALLY_QUIT=y;;
                        [yY] ) REALLY_QUIT=y;;
                        [nN] ) return 0;;
                        * )     REALLY_QUIT="" ;;
                esac
        done
	QUIT=1
	Cleanup
}

Previous()
{
	echo "If you back up to the previous menu then any changes you may have made using"
	echo "the current menu and sub-menus will be lost."
	BACKUP=""
	while [ "$BACKUP" = "" ]
	do
		echo "Are you sure you want to back up to the previous menu? (y/n) (default: y): \c"
		read BACKUP
		case "$BACKUP" in
			"" )    return 1;;
			[yY] ) return 1;;
			[nN] ) return 0;;
			* )     BACKUP="" ;;
                esac
	done
}

Get_Secondary_Host()
{
	while [ "$SECONDARY_HOST" = "" ]
	do
		echo "Enter name of the Secondary host machine (example: seattle): \c"
		read SECONDARY_HOST
		if [ "$SECONDARY_HOST" = "" ] 	# ping succeeds with ""!
		then
			break
		fi
		ping $SECONDARY_HOST > /dev/null 2>&1
		if [ "$?" != 0 ]
		then
			echo "Could not contact Secondary host $SECONDARY_HOST"
			SECONDARY_HOST=""
		fi
	done
}

Vxprint()
{
	clear
	echo "Doing vxprint -ht..."
	if [ "$ENABLE_MORE" = "yes" ]
	then
		($VXVM_BIN/vxprint -ht; echo ""; echo "Hit return to continue: \c") | more
	else
		$VXVM_BIN/vxprint -ht; echo ""; echo "Hit return to continue: \c"
	fi
	read ANSWER
	clear
}

Remote_Vxprint()
{
	clear
	if [ "$SECONDARY_HOST" = "" ]
	then
		echo "Doing remote vxprint -ht. Enter an empty line to return to the previous menu."
		Get_Secondary_Host
		if [ "$SECONDARY_HOST" = "" ]
		then
			clear
			return
		fi
	else
		echo "Do vxprint -ht for $SECONDARY_HOST? (y/n) (default: y): \c"
		read ANSWER
		case "$ANSWER" in
			"" )	;;
			[yY] )	;;
			* ) 	SECONDARY_HOST=""
				echo "Doing remote vxprint -ht. Enter an empty line to return to the previous menu."
				Get_Secondary_Host 
				if [ "$SECONDARY_HOST" = "" ]
				then
					clear
					return
				fi;;
		esac
	fi
#	/usr/sbin/ping $SECONDARY_HOST 5 > /dev/null 2>/dev/null
#	if [ "$?" != 0 ]
#	then
#		echo "Error contacting $SECONDARY_HOST"
#		echo "Hit return to continue: \c"
#		read Whatever
#		clear
#		return
#	fi
	REMOTE_CMD="$VXVM_BIN/vxprint -ht"
	if [ "$ENABLE_MORE" = "yes" ]
	then
	    (Do_Remote_Cmd; echo ""; echo "Hit return to continue: \c") | more
	else
	    Do_Remote_Cmd; echo ""; echo "Hit return to continue: \c"
	fi
	read ANSWER
	clear
}

#11, #114, #211
Get_Dg ()
{
        $VXVM_BIN/vxdg -q list 2> /dev/null 1> $VXPRINT_FILE
        if [ "$?" != 0 ]
        then
                echo "Error trying to get list of disk groups."
                echo "Hit return to continue: \c"
                read Whatever
                clear
                /bin/rm -f $VXPRINT_FILE
                return
        fi

	if [ ! -s $VXPRINT_FILE ]
	then
                echo "Could not find any local disk groups."
                echo "Hit return to continue: \c"
                read Whatever
                clear
                /bin/rm -f $VXPRINT_FILE
                return
	fi

	echo "Existing disk groups found on local host:"
	awk '{printf "%d\t%s\n", NR, $1}' $VXPRINT_FILE

        echo ""
        echo "Enter number of existing disk group to use. Press Return"
	echo "to go to the previous menu without selecting a disk group."
        echo ""

        LINE=xxxxxx
        while [ "$LINE" != "" ]
        do
                echo "Disk group to use on the Primary (enter a number from the list above): \c"
                read LINE
		if [ "$LINE" = "" ]
		then
			break
		fi
                set -- $LINE

                if [ "$2" != "" ]
                then
                        echo "Only enter one number to select the single disk group to be used."
                        echo "Ignoring that value."
                        continue
                fi

                case "$1" in
                        [0-9] | [0-9][0-9] |  [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9] ) 
			        DGNAME=`awk '{ if (NR == '$1') printf "%s", $1 }' $VXPRINT_FILE`;;
                        * )     echo "Invalid input: $1.  Ignoring that value."
                                continue;;
                esac

                if [ "$1" -gt `wc -l $VXPRINT_FILE | /bin/sed 's/  */ /g' | /bin/cut -d' ' -f2` ]
                then
                        echo "Input number is too big: $1.  Ignoring that value."
                        continue
                fi
                if [ "$1" -lt 1 ]
                then
                        echo "Input number is too small: $1.  Ignoring that value."
                        continue
                fi

                LINE=""
		DISKGROUP=$DGNAME
        done
clear
/bin/rm -f $VXPRINT_FILE
}

#111
Default_prefix_for_names()
{
	clear
	NEW_PREFIX=""
	while [ 1 ]
	do
		echo "The current prefix is: ${PREFIX:-<empty string>}"
		echo ""
		echo "Enter a character string to be used as the prefix for volume names: \c"
		read NEW_PREFIX EXTRA
		if [ "$EXTRA" != "" ]
		then
			echo "Only enter one word for name.  No whitespace."
			continue
		fi
		if [ "$NEW_PREFIX" = "" ]
		then
		    Y_OR_N=""
		    while [ "$Y_OR_N" = "" ]
		    do
			echo "An empty string was entered.  Do not use any prefix? [Enter n to abort without"
			echo "changing the prefix] (default: y) (y/n): \c"
                	read Y_OR_N
                	case "$Y_OR_N" in
                        	"" )    PREFIX=""
					clear
					return;;
                        	[yY] ) PREFIX=""
					clear
					return;;
                        	[nN] ) clear
					return;;
                        	* )     echo "Invalid input"
					Y_OR_N="" ;;
                	esac
		    done
		else
			PREFIX=$NEW_PREFIX
			clear
			return
		fi
	done
	clear
}

#113
New_rvg_name()
{
clear
	NEW_RVG=xxx
	while [ "$NEW_RVG" != "" ]
	do
        	echo "Enter name to be used for the Primary RVG (Return to abort): \c"
		read NEW_RVG EXTRA
		if [ "$NEW_RVG" = "" ]
		then
			return
		fi
		if [ "$EXTRA" != "" ]
		then
			echo "Only enter one word for name.  No whitespace."
			continue
		fi
		NAME=$NEW_RVG
		Check_if_name_is_in_use_by_VXVM
		if [ "$?" = 1 ]
		then
			echo "Cannot use that name.  Object $NAME already exists."
			continue
		fi
		Check_if_name_is_in_use_by_config_file
                if [ "$?" = 1 ]
                then
                        echo "Cannot use that name.  $NAME has already been specified for use."
                        continue
                fi
		RVG="$NEW_RVG"
		return
        done
clear
}

# This routine takes a size string, like 100m, and converts it to a
# numeric length in sectors.
# Inputs: 
#	SIZESTRING	Size string (such as 100m)
# Outputs:
#	LEN		Corresponding length in sectors, or ""
#
SizeString_To_Len()
{
	LEN=""
	case "$SIZESTRING" in
		"" )		break;;
		*[\^\&\*\(\)\-\|\\\~\`\[\]\!\ \/\:\;\'\"\?\<\>\.\,@#$%*_+={}]* | *[a-zA-Z]*[[a-zA-Z]* ) 
				LEN="";;
		[0-9]*s )	LEN=`echo $SIZESTRING | /bin/tr s " "`;;
		[0-9]*b )	LEN=`echo $SIZESTRING | /bin/tr b " "`;;
		[0-9]*k )	TMP=`echo $SIZESTRING | /bin/tr k " "` 
					LEN=`expr $TMP \* 2` ;;
		[0-9]*m )	TMP=`echo $SIZESTRING | /bin/tr m " "`  
					LEN=`expr $TMP \* 2048` ;;
		[0-9]*g )	TMP=`echo $SIZESTRING | /bin/tr g " "`  
					LEN=`expr $TMP \* 2097152` ;;
		[0-9] | [0-9]*[0-9] )LEN="$SIZESTRING";;
		* )			LEN="";;
	esac
}

Verify_Cfg_File_On_Load_Checks()
{
	if [ -s $CONFIG_FILE ]
	then
#		echo "...checking for basic errors in requested configuration...\c"
		awk ' ! /^#/ && ! /^$/ && ! /^ *$/ && ! /^RV/ && ! /^DV/ && ! /^RL/ && ! /^LV/ && ! /^SRV/ && ! /^SDV/ && ! /^SRL/ && ! /^SLV/ && ! /^BEGIN RVG/ && ! /END RVG/ { printf "	Bad line in config file:Line %d:%s\n", NR, $0 }' $CONFIG_FILE > $VERIFY_CFG_FILE

		awk '/^RV/ { 
			if ( NF !=  4 ) 
				printf "	Incorrect number of fields:Line %d:%s\n", NR, $0 }' $CONFIG_FILE >> $VERIFY_CFG_FILE
		awk '/^LV/  {
			if ( $5 != "CREATE" && $5 != "EXISTS" ) 
				printf "	Bad value for CREATE/EXISTS field:Line %d:%s\n", NR, $0
			if ( NF !=  5 ) 
				printf "	Incorrect number of fields:Line %d:%s\n", NR, $0 }' $CONFIG_FILE >> $VERIFY_CFG_FILE

		awk '/^DV/ { 
			if ( $6 != "CREATE" && $6 != "EXISTS" ) 
				printf "	Bad value for CREATE/EXISTS field:Line %d:%s\n", NR, $0
			if ( NF !=  6 ) 
				printf "	Incorrect number of fields:Line %d:%s\n", NR, $0 }' $CONFIG_FILE >> $VERIFY_CFG_FILE

		awk '/^RL/ { 
			if ( $7 != "O" && $7 != "F" && $7 != "V" )
				printf "	Bad value for Sync Mode field:Line %d:%s\n", NR, $0
			if ( $8 != "O" && $8 != "F" && $8 != "V" )
				printf "	Bad value for Latency Mode field:Line %d:%s\n", NR, $0
			if ( $9 != "O" && $9 != "F" && $9 != "V" && $9 != "D" )
				printf "	Bad value for SRL Overflow Protection Mode field:Line %d:%s\n", NR, $0
			if ( $12 != "CREATE" && $12 != "EXISTS" ) 
				printf "	Bad value for CREATE/EXISTS field:Line %d:%s\n", NR, $0
			if ( NF !=  12 ) 
				printf "	Incorrect number of fields:Line %d:%s\n", NR, $0 }' $CONFIG_FILE >> $VERIFY_CFG_FILE

		awk '/^SRV/ { 
			if ( $5 != "CREATE" && $5 != "EXISTS" ) 
				printf "	Bad value for CREATE/EXISTS field:Line %d:%s\n", NR, $0
			if ( NF !=  5 ) 
				printf "	Incorrect number of fields:Line %d:%s\n", NR, $0 }' $CONFIG_FILE >> $VERIFY_CFG_FILE

		awk '/^SDV/ { 
			if ( $6 != "CREATE" && $6 != "EXISTS" ) 
				printf "	Bad value for CREATE/EXISTS field:Line %d:%s\n", NR, $0
			if ( NF !=  6 && NF != 7 && NF != 8) 
				printf "	Incorrect number of fields:Line %d:%s\n", NR, $0 }' $CONFIG_FILE >> $VERIFY_CFG_FILE

		awk '/^SLV/ { 
			if ( $6 != "CREATE" && $6 != "EXISTS" ) 
				printf "	Bad value for CREATE/EXISTS field:Line %d:%s\n", NR, $0
			if ( NF !=  6 ) 
				printf "	Incorrect number of fields:Line %d:%s\n", NR, $0 }' $CONFIG_FILE >> $VERIFY_CFG_FILE

		awk '/^SRL/ { 
			if ( $6 != "O" && $6 != "F" && $6 != "V" )
				printf "	Bad value for Sync Mode field:Line %d:%s\n", NR, $0
			if ( $7 != "O" && $7 != "F" && $7 != "V" )
				printf "	Bad value for Latency Mode field:Line %d:%s\n", NR, $0
			if ( $8 != "O" && $8 != "F" && $8 != "V" && $8 != "D" )
				printf "	Bad value for SRL Overflow Protection Mode field:Line %d:%s\n", NR, $0
			if ( $11 != "CREATE" && $11 != "EXISTS" ) 
				printf "	Bad value for CREATE/EXISTS field:Line %d:%s\n", NR, $0
			if ( NF !=  11 ) 
				printf "	Incorrect number of fields:Line %d:%s\n", NR, $0 }' $CONFIG_FILE >> $VERIFY_CFG_FILE

		SRLVOL_COUNT=`/bin/egrep -c '^LV' $CONFIG_FILE`
		if [ "$SRLVOL_COUNT" -gt 1 ]
		then
			echo "	Multiple SRL volumes specified" >> $VERIFY_CFG_FILE
		fi

		RVG_COUNT=`/bin/egrep -c '^RV' $CONFIG_FILE`
		if [ "$RVG_COUNT" -gt 1 ]
		then
			echo "	Multiple Primary rvgs specified" >> $VERIFY_CFG_FILE
		elif  [ "$RVG_COUNT" -lt 1 ]
		then
			echo "	Primary RVG not specified" >> $VERIFY_CFG_FILE
		fi

		awk '/^SRV/ { printf "%s\n", $2 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		if [ -s "$CONFIG_TMP_FILE" ] 
		then
			sort $CONFIG_TMP_FILE | uniq -d > $CONFIG_2TMP_FILE
			if [ -s "$CONFIG_2TMP_FILE" ]
			then
				awk '{ printf "	Multiple Secondary rvgs specified for RLINK %s\n", $0 }' $CONFIG_2TMP_FILE >> $VERIFY_CFG_FILE
			fi
		fi
		/bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE

		awk '/^SLV/ { printf "%s\n", $2 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		if [ -s "$CONFIG_TMP_FILE" ] 
		then
			sort $CONFIG_TMP_FILE | uniq -d > $CONFIG_2TMP_FILE
			if [ -s "$CONFIG_2TMP_FILE" ]
			then
				awk '{ printf "	Multiple Secondary SRL volumes specified for RLINK %s\n", $0 }' $CONFIG_2TMP_FILE >> $VERIFY_CFG_FILE
			fi
		fi
		/bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE

		awk '/^SRL/ { printf "%s\n", $2 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		if [ -s "$CONFIG_TMP_FILE" ] 
		then
			sort $CONFIG_TMP_FILE | uniq -d > $CONFIG_2TMP_FILE
			if [ -s "$CONFIG_2TMP_FILE" ]
			then
				awk '{ printf "	Multiple Secondary rlinks specified for RLINK %s\n", $0 }' $CONFIG_2TMP_FILE >> $VERIFY_CFG_FILE
			fi
		fi
		/bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE

		if [ -s $VERIFY_CFG_FILE ]
		then
			echo ""
			echo "Invalid entries in current configuration:"
			ABORT=1
			/bin/cat $VERIFY_CFG_FILE
		else
			echo "OK"
		fi
		/bin/rm -f $VERIFY_CFG_FILE

	fi
}

# Sanity checks to perform when loading a new configuration file
Verify_Cfg_File_On_Load()
{
ABORT=0
	#rm -f $VERIFY_CFG_FILE
	echo "...checking for basic errors in requested configuration...\c"
	Verify_Cfg_File_On_Load_Checks
	if [ "$ABORT" != 0 ]
	then
		echo "Aborting file load due to errors in configuration file."
		echo ""
		echo "Hit return to continue: \c"
		read Whatever
		rm -f $VERIFY_CFG_FILE $CONFIG_TMP_FILE $CONFIG_2TMP_FILE
		return 0
	fi
rm -f $VERIFY_CFG_FILE $CONFIG_TMP_FILE $CONFIG_2TMP_FILE
return 1
}


# Minor sanity checks to perform as new entry is added from some sub-menu of
# the Create_An_Rvg menu
# For now, just do all File_Load checks
Verify_Cfg_File()
{
ABORT=0
	Verify_Cfg_File_On_Load_Checks
	if [ "$ABORT" != 0 ]
        then
		echo "Errors listed above were detected in the requested configuration."
		echo ""
		echo "Hit return to continue: \c"
		read Whatever
		rm -f $VERIFY_CFG_FILE $CONFIG_TMP_FILE $CONFIG_2TMP_FILE
		return 0
	fi
	return "$?"
rm -f $VERIFY_CFG_FILE $CONFIG_TMP_FILE $CONFIG_2TMP_FILE
return 1
}

# Extensive sanity checks to perform just before creating RVG hierarchy
Verify_Cfg_File_On_Create()
{
ABORT=0

	/bin/rm -f $VERIFY_CFG_FILE
	echo "...checking for basic errors in requested configuration...\c"
	Verify_Cfg_File_On_Load_Checks
	echo "...confirm that anything marked EXISTS locally really exists locally"
        /bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE
	RVG=`awk '/^RV / { printf "%s", $2 }' $CONFIG_FILE`

	#First check existing volumes...
	awk '/^DV/ || /^LV/ { if ($6 == "EXISTS")
		printf "%s ", $2 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
	if [ -s "$CONFIG_TMP_FILE" ]
	then
		$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -tQqn `/bin/cat "$CONFIG_TMP_FILE"` 1> /dev/null 2> $CONFIG_2TMP_FILE
		if [ -s "$CONFIG_2TMP_FILE" ]
		then
                	ABORT=1
			/bin/cat $CONFIG_2TMP_FILE
		fi
		/bin/rm -f $CONFIG_2TMP_FILE
		echo "...confirm that volumes marked EXISTS locally do not already have another parent"
		$VXVM_BIN/vxprint -g "$DISKGROUP" -htvQq `/bin/cat "$CONFIG_TMP_FILE"` 2> /dev/null 1> $CONFIG_2TMP_FILE
		/bin/rm -f $CONFIG_TMP_FILE
		awk '/^v / { if ($3 != "-" && $3 != "'$RVG'") printf "ERROR: Existing volume %s already has another parent RVG (%s)\n", $2, $3 }' $CONFIG_2TMP_FILE > $CONFIG_TMP_FILE
		if [ -s "$CONFIG_TMP_FILE" ]
		then
			/bin/cat $CONFIG_TMP_FILE
			ABORT=1
		fi
	fi
        /bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE
	#Now check existing rvg...
	awk '/^RV/ { if ($4 == "EXISTS")
		printf "%s ", $2 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
        if [ -s "$CONFIG_TMP_FILE" ]
        then
                $VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -tQqn `/bin/cat "$CONFIG_TMP_FILE"` 1> /dev/null 2> $CONFIG_2TMP_FILE
                if [ -s "$CONFIG_2TMP_FILE" ]
                then
                        ABORT=1
                        /bin/cat $CONFIG_2TMP_FILE
                fi
                /bin/rm -f $CONFIG_2TMP_FILE
	fi
        /bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE
	#Now check existing rlinks
	awk '/^RL/ { if ($12 == "EXISTS")
                printf "%s ", $2 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
        if [ -s "$CONFIG_TMP_FILE" ]
        then
                $VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -tQqn `/bin/cat "$CONFIG_TMP_FILE"` 1> /dev/null 2> $CONFIG_2TMP_FILE
                if [ -s "$CONFIG_2TMP_FILE" ]
                then
                        ABORT=1
                        /bin/cat $CONFIG_2TMP_FILE
                fi
                /bin/rm -f $CONFIG_2TMP_FILE

                echo "...confirm that rlinks marked EXISTS locally do not already have another parent"
                $VXVM_BIN/vxprint -g "$DISKGROUP" -htPQq `/bin/cat "$CONFIG_TMP_FILE"` 2> /dev/null 1> $CONFIG_2TMP_FILE
                /bin/rm -f $CONFIG_TMP_FILE
                awk '/^rl / { if ($3 != "-" && $3 != "'$RVG'") printf "ERROR: Existing RLINK %s already has another parent RVG (%s)\n", $2, $3 }' $CONFIG_2TMP_FILE > $CONFIG_TMP_FILE
                if [ -s "$CONFIG_TMP_FILE" ]
                then
                        /bin/cat $CONFIG_TMP_FILE
                        ABORT=1
                fi
        fi
        /bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE


	echo "...confirm that anything marked EXISTS remotely really exists remotely"
	for RLK in `awk '/^RL/ { printf "%s ", $2 } END { printf "\n" }' $CONFIG_FILE`
	do
		set -- `awk '/^RL  *'$RLK' / { printf "%s %s", $4, $5 }' $CONFIG_FILE`
		SECONDARY_HOST=$1; SECONDARY_DISKGROUP=$2
		echo "	Processing RLINK ${RLK}: Secondary host=$SECONDARY_HOST"

		set -- `awk '/^SRV  *'${RLK}' / { printf "%s %s %s\n", $3, $4, $5 }' $CONFIG_FILE`
		SECONDARY_RVG=$1; SECONDARY2_DISKGROUP=$2; SECONDARY_RVG_EXISTENCE=$3

                REMOTE_CMD="$VXVM_BIN/vxdg list $SECONDARY_DISKGROUP"
		Do_Remote_Cmd_Status 
		if [ "$?" != 0 ]
		then
			echo "ERROR: Disk group $SECONDARY_DISKGROUP not found on host $SECONDARY_HOST"
                        ABORT=1
			continue
		fi

		#First check existing remote volumes...
		awk '/^SDV  *'$RLK' / || /^SLV  *'$RLK' / { if ($6 == "EXISTS")
                	printf "%s ", $3 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
	        if [ -s "$CONFIG_TMP_FILE" ]
        	then
                	REMOTE_CMD="$VXVM_BIN/vxprint -g "$SECONDARY_DISKGROUP" -tQqn `/bin/cat "$CONFIG_TMP_FILE"`" 
			Do_Remote_Cmd_Output 1> /dev/null 2> $CONFIG_2TMP_FILE
			if [ -s "$CONFIG_2TMP_FILE" ]
			then
                		ABORT=1
				awk '{ printf "%s ...on '$SECONDARY_HOST'\n", $0}' $CONFIG_2TMP_FILE
			fi
			echo "...confirm that volumes marked EXISTS remotely do not already have another parent"
			REMOTE_CMD="$VXVM_BIN/vxprint -g "$SECONDARY_DISKGROUP" -htvQq `/bin/cat "$CONFIG_TMP_FILE"`"
			Do_Remote_Cmd_Output 2> /dev/null 1> $CONFIG_2TMP_FILE
			/bin/rm -f $CONFIG_TMP_FILE
			awk '/^v / { if ($3 != "-" && $3 != "'$SECONDARY_RVG'") printf "ERROR: Existing volume %s on %s already has another parent RVG (%s)\n", $2, "'$SECONDARY_HOST'", $3 }' $CONFIG_2TMP_FILE > $CONFIG_TMP_FILE
			if [ -s "$CONFIG_TMP_FILE" ]
			then
				/bin/cat $CONFIG_TMP_FILE
				ABORT=1
			fi
        	fi
        	/bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE
		#Now check existing remote rvg...
                awk '/^SRV  *'$RLK' / { if ($5 == "EXISTS")
                        printf "%s ", $3 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
                if [ -s "$CONFIG_TMP_FILE" ]
                then
                        REMOTE_CMD="$VXVM_BIN/vxprint -g "$SECONDARY_DISKGROUP" -tQqn `/bin/cat "$CONFIG_TMP_FILE"`"
                        Do_Remote_Cmd_Output 1> /dev/null 2> $CONFIG_2TMP_FILE
                        if [ -s "$CONFIG_2TMP_FILE" ]
                        then
                                ABORT=1
                                awk '{ printf "%s ...on '$SECONDARY_HOST'\n", $0}' $CONFIG_2TMP_FILE
                        fi
		fi
                /bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE
		#Now check existing remote rlink...
                awk '/^SRL  *'$RLK' / { if ($11 == "EXISTS")
                        printf "%s ", $3 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
                if [ -s "$CONFIG_TMP_FILE" ]
                then
                        REMOTE_CMD="$VXVM_BIN/vxprint -g "$SECONDARY_DISKGROUP" -tQqn `/bin/cat "$CONFIG_TMP_FILE"`"
                        Do_Remote_Cmd_Output 1> /dev/null 2> $CONFIG_2TMP_FILE
                        if [ -s "$CONFIG_2TMP_FILE" ]
                        then
                                ABORT=1
                                awk '{ printf "%s ...on '$SECONDARY_HOST'\n", $0}' $CONFIG_2TMP_FILE
                        fi
                        echo "...confirm that RLINK marked EXISTS remotely does not already have another parent"
                        REMOTE_CMD="$VXVM_BIN/vxprint -g "$SECONDARY_DISKGROUP" -htPQq `/bin/cat "$CONFIG_TMP_FILE"`"
                        Do_Remote_Cmd_Output 2> /dev/null 1> $CONFIG_2TMP_FILE
                        /bin/rm -f $CONFIG_TMP_FILE
                        awk '/^rl / { if ($3 != "-" && $3 != "'$SECONDARY_RVG'") printf "ERROR: Existing RLINK %s on %s already has another parent RVG (%s)\n", $2, "'$SECONDARY_HOST'", $3 }' $CONFIG_2TMP_FILE > $CONFIG_TMP_FILE
                        if [ -s "$CONFIG_TMP_FILE" ]
                        then
                                /bin/cat $CONFIG_TMP_FILE
                                ABORT=1
                        fi
                fi
                /bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE
	done
        /bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE


	echo "...confirm that anything marked CREATE locally does not already exist locally"
	awk '/^DV/ || /^LV/ { if ($6 == "CREATE")
			printf "%s ", $2 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
	awk '/^RV/ { if ($4 == "CREATE") 
			printf "%s ", $2 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
	awk '/^RL/ { if ($12 == "CREATE") 
			printf "%s ", $2 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
	if [ -s "$CONFIG_TMP_FILE" ]
	then
		$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -tQqn > $CONFIG_2TMP_FILE
		for OBJ in `/bin/cat $CONFIG_TMP_FILE`
		do
			/bin/egrep "^$OBJ$" "$CONFIG_2TMP_FILE" 2> /dev/null 1> /dev/null

			if [ "$?" = 0 ]
			then
				ABORT=1
				echo "Object $OBJ cannot be created -- already exists"
			fi
		done
	fi
	/bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE

	echo "...confirm that anything marked CREATE remotely does not already exist remotely"
	for RLK in `awk '/^RL/ { printf "%s ", $2 } END { printf "\n" }' $CONFIG_FILE`
	do
		set -- `awk '/^RL  *'$RLK' / { printf "%s %s", $4, $5 }' $CONFIG_FILE`
		SECONDARY_HOST=$1; SECONDARY_DISKGROUP=$2

		awk '/^SRV  *'$RLK' / { if ($5 == "CREATE")
                	printf "%s ", $3 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		awk '/^SDV  *'$RLK' / || /^SLV  *'$RLK' / { if ($6 == "CREATE")
                	printf "%s ", $3 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		awk '/^SRL  *'$RLK' / { if ($11 == "CREATE")
                	printf "%s ", $3 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
	        if [ -s "$CONFIG_TMP_FILE" ]
        	then
                	REMOTE_CMD="$VXVM_BIN/vxprint -g $SECONDARY_DISKGROUP -tQqn" 
			Do_Remote_Cmd_Output > $CONFIG_2TMP_FILE
			for OBJ in `/bin/cat $CONFIG_TMP_FILE`
			do
				/bin/egrep "^$OBJ$" "$CONFIG_2TMP_FILE" 2> /dev/null 1> /dev/null
				if [ "$?" = 0 ]
				then
					ABORT=1
					echo "Object $OBJ cannot be created on $SECONDARY_HOST -- already exists on $SECONDARY_HOST"
				fi
			done
        	fi
        	/bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE
	done
        /bin/rm -f $CONFIG_TMP_FILE $CONFIG_2TMP_FILE

	echo "...confirm that Secondary data volumes are as big as matching Primary data volumes"
	for RLK in `awk '/^RL / { printf "%s ", $2 } END { printf "\n" }' $CONFIG_FILE`
	do
	    SECONDARY_HOST=`awk '/^RL  *'$RLK' / { printf "%s", $4 }' $CONFIG_FILE`
	    for SDV in `awk '/^SDV  *'$RLK' / { printf "%s ", $3 } END { printf "\n" }' $CONFIG_FILE`
	    do
		set -- `awk '/^SDV  *'$RLK'  *'$SDV' / { printf "%s %s", $4, $7 }' $CONFIG_FILE`
		SIZESTRING=$1; PRIMARY_DV=$2
		SizeString_To_Len
		SECONDARY_LEN="$LEN"
		if [ "$SECONDARY_LEN" = "" ]
		then
			echo "Error getting Secondary data volume length for record $SDV [for RLINK $RLK, Secondary host $SECONDARY_HOST] to see if it is long enough."
			ABORT=1
			continue
		fi
		if [ "$PRIMARY_DV" = "" ]
		then
			PRIMARY_DV="$SDV"
		fi
		SIZESTRING=`awk '/^DV  *'$PRIMARY_DV' / { printf "%s", $3 }' $CONFIG_FILE`
		if [ "$SIZESTRING" = "" ]
		then
			echo "Error getting record for Primary data volume $PRIMARY_DV to see if Secondary data volume $SDV is long enough [for RLINK $RLK, Secondary host $SECONDARY_HOST]."
			ABORT=1
			continue
		fi
		SizeString_To_Len
		PRIMARY_LEN="$LEN"
		if [ "$PRIMARY_LEN" = "" ]
		then
			echo "Error getting length of Primary data volume $PRIMARY_DV to see if Secondary data volume $SDV is long enough [for RLINK $RLK, Secondary host $SECONDARY_HOST]."
			ABORT=1
			continue
		fi
		if [ "$SECONDARY_LEN" -lt "$PRIMARY_LEN" ]
                then
			echo "ERROR: Size of Secondary data volume $SDV ($SECONDARY_LEN) is smaller than size of Primary data volume $PRIMARY_DV ($PRIMARY_LEN) [for RLINK $RLK, Secondary host $SECONDARY_HOST]."
			ABORT=1
			continue
		fi
	    done
	done

	if [ "$ABORT" != 0 ]
	then
		rm -f $VERIFY_CFG_FILE
		return 0
	fi
rm -f $VERIFY_CFG_FILE $CONFIG_TMP_FILE $CONFIG_2TMP_FILE
return 1
}

Help()
{
clear
	#echo "Help menu"
	#echo ""
	echo "Special options (available from, but not shown on, most menus):"
	echo ""
	echo "    a  Toggle on/off whether the Summary is always shown."
	echo "       The Summary is only available from certain menus.  Toggling this option"
	echo "       \"on\" is equivalent to always selecting the \"s\" option to \"Show the"
	echo "       summary of set-up work specified so far\" after every menu selection."
	echo "       By default, this option is \"off\"."
	echo ""
	echo "    m  Toggle on/off the use of more(1) when all output will not fit in window."
	echo "       By default, this option is \"on\"."
	echo ""
	echo "Hit return to continue: \c"
	read Whatever
clear
}

Toggle_More_Enable()		# mM*
{
	if [ "$ENABLE_MORE" = "no" ]
	then
		echo "Toggling more_enable ON.  Summary output is sent thru more(1)."
		echo "Helpful for small and/or non-scrollable windows."
		ENABLE_MORE="yes"
		echo ""
		echo "Hit return to continue: \c"
		read Whatever
	else
		echo "Toggling more_enable OFF.  Summary output is not sent thru more(1)."
		echo "May be preferable to using more(1) if using scrollable windows."
		ENABLE_MORE="no"
		echo ""
		echo "Hit return to continue: \c"
		read Whatever
	fi
}

Toggle_Always_Show_Summary()	# aA*
{
	if [ "$SHOW_SUMMARY_ALWAYS" != yes ]
	then
		echo "Toggling Always_Show_Summary ON.  Summary output is always shown."
		echo "       This is equivalent to always selecting the \"s\" option to \"Show the"
		echo "       summary of set-up work specified so far\" after every menu selection."
		SHOW_SUMMARY_ALWAYS=yes
		echo ""
		echo "Hit return to continue: \c"
		read Whatever
	else
		echo "Toggling Always_Show_Summary OFF.  Use \"s\" option to show Summary."
		SHOW_SUMMARY_ALWAYS=no
		echo ""
		echo "Hit return to continue: \c"
		read Whatever
	fi
}

# This routine just calls Summarize_Create_an_Rvg2.  The additional code
# is to decide whether to pipe the Summary thru "more -w" or not.
# Also, if the $CONFIG_FILE has not changed since the last Summary was 
# displayed, then just cat(1) the old Summary.
# Inputs:
#	MENU_LENGTH	Number of lines in the menu printed after the summary
#			Used to compute whether to use more(1). If "", use 24.
Summarize_Create_an_Rvg()
{
	if [ "$SHOW_SUMMARY_ONCE" = "yes" ]
	then
		SHOW_SUMMARY_ONCE=no
	else 
		if [ "$SHOW_SUMMARY_ALWAYS" != yes ]
		then
			return
		fi
	fi
	/bin/cmp -s $CONFIG_FILE $CONFIG_FILE_OLD > /dev/null 2>&1
	COMPUTE_NEW_SUMMARY="$?"

	# If we can't get the number of screen rows from "tput lines" we'll always "| more".
	if [ "$TPUT" = "" ]
	then
	    if [ "$COMPUTE_NEW_SUMMARY" != 0 ]
	    then
	    	Summarize_Create_an_Rvg2 > $VXSUMMARY_FILE
		/bin/cp $CONFIG_FILE $CONFIG_FILE_OLD  > /dev/null 2>&1
	    fi
		
	    if [ "$ENABLE_MORE" = "yes" ]
	    then
	    	more -w $VXSUMMARY_FILE
	    else
	    	/bin/cat $VXSUMMARY_FILE
	    fi
	else
		# All menus have at most 24 lines.  If Summary length plus 
		# ${MENU_LENGTH:-24} lines exceeds window size, pipe window 
		# thru "more -w".

		SUM_ROWS=`tput lines`
		# Compute number of lines in Summary: 
		#5 header + [3+#DV] + [3 for LV] + [foreach RL:(9+#SDV for that RL)] +1
		SUM_DVCNT=`egrep -c "^DV " $CONFIG_FILE`
		SUM_RLCNT=`egrep -c "^RL " $CONFIG_FILE`
		SUM_SDVCNT=`egrep -c "^SDV " $CONFIG_FILE`
		SUMMARY_LINECNT=`expr 12 + $SUM_DVCNT + $SUM_SDVCNT + $SUM_RLCNT \* 9`
                SUM_LINECNT=`expr $SUMMARY_LINECNT + ${MENU_LENGTH:-24}`
		if [ "$SUM_LINECNT" -gt "$SUM_ROWS" ]
		then
	               # more(1) the Summary from a file to show percent remaining
		    if [ "$COMPUTE_NEW_SUMMARY" != 0 ]
		    then
	            	Summarize_Create_an_Rvg2 > $VXSUMMARY_FILE
		        /bin/cp $CONFIG_FILE $CONFIG_FILE_OLD  > /dev/null 2>&1
		    fi
	    	    if [ "$ENABLE_MORE" = "yes" ]
	    	    then
	            	more -w $VXSUMMARY_FILE
		    else
			/bin/cat $VXSUMMARY_FILE
		    fi
		else
		  #Speedy updates for windows the Summary and menu both fit on:
                  if [ "$COMPUTE_NEW_SUMMARY" != 0 ]
		  then
		    Summarize_Create_an_Rvg2 | tee $VXSUMMARY_FILE
		    /bin/cp $CONFIG_FILE $CONFIG_FILE_OLD  > /dev/null 2>&1
		  else
		    /bin/cat $VXSUMMARY_FILE
		  fi
		fi
	fi
MENU_LENGTH=""
clear
}

# Print Summary of set-up work specified so far
# NOTE: If output format changes, then the calculation of the number of rows
#       used by the summary in Summarize_Create_an_Rvg might need to be updated.
Summarize_Create_an_Rvg2()
{
	echo "-------------------------------------------------------------------------------"
	echo "Summary of set-up work specified so far:  <Note: E=EXISTS, C=CREATE>"
        echo ""
	if [ -s $CONFIG_FILE ]
	then
	    awk '/^RV / { if ($4 == "EXISTS")
                          printf "E New RVG name: %-17s  Diskgroup: %-17s\n", $2, $3
                        else
                          printf "C New RVG name: %-17s  Diskgroup: %-17s\n", $2, $3 }' $CONFIG_FILE

	    echo ""

	    echo "   Data_Volume_Name  Length  Mirrors   dcmlog"
	    echo "   ----------------  ------  -------   -------"
	    awk '/^DV/ { if ($6 == "EXISTS") printf "E  %-17s %+6s  %7d  %-6s\n", $2, $3, $4, $5
			else
			  printf "C  %-17s %+6s  %7d   %-6s\n", $2, $3, $4, $5 }' $CONFIG_FILE
	    echo ""

	    echo "   SRL_Volume_Name   Length  Mirrors"
	    echo "   ----------------  ------  -------"
	    awk '/^LV/ { if ($5 == "EXISTS")
			  printf "E  %-17s %+6s  %7d\n", $2, $3, $4
			else
			  printf "C  %-17s %+6s  %7d\n", $2, $3, $4 }' $CONFIG_FILE

	    RLCNT=`egrep -c "^RL " "$CONFIG_FILE"`
	    if [ "$RLCNT" = 0 ]
	    then
		echo ""
		echo "   Rlink_Name        Remote_host  Remote_diskgroup  Remote_rlink   "
	 	echo "   ----------------  -----------  ----------------  ----------------"
		echo ""
		echo "     Objects to be set up on the remote host for this RLINK:"
		echo "     RVG:     <none>           diskgroup="
		echo "     DATAVOL: <none>           len=       mirrors=   Map To: "
		echo "     SRLVOL:  <none>           len=       mirrors=   "
		echo "     RLINK:   <none>           Primary_host="
	    else
	      for RLK in `awk '/^RL/ { printf "%s ", $2 } END { printf "\n" }' $CONFIG_FILE`
	      do
	    	echo ""
		echo "   Rlink_Name        local_host   Remote_host  Remote_diskgroup  Remote_rlink  "
		echo "   ----------------  -----------  -----------  ----------------  ----------------"
		awk '/^RL  *'$RLK' / { if ($12 == "EXISTS")
			    printf "E  %-17s %-12s %-12s %-17s %-17s\n", $2, $3, $4, $5, $6
			else
	  		    printf "C  %-17s %-12s %-12s %-17s %-17s\n", $2, $3, $4, $5 , $6} ' $CONFIG_FILE
		echo ""

		echo "     Objects to be set up on `awk '/^RL  *'$RLK' / { printf "%s", $3 }' $CONFIG_FILE` for this RLINK:"
		awk '/^SRV  *'$RLK' / { 
			count=count+1
			if ($5 == "EXISTS")
			    printf "E    RVG:     %-16s diskgroup=%s\n", $3, $4
			else
	  		    printf "C    RVG:     %-16s diskgroup=%s\n", $3, $4 } END { if (count == 0) printf "     RVG:     <none>           diskgroup=\n" }' $CONFIG_FILE
		awk '/^SDV  *'$RLK' / {
			count=count+1
			map_to=$7
			srmv_log=$8
			if (map_to == "") map_to=$3 
			if ($6 == "EXISTS")
	  		  printf "E    DATAVOL: %-16s len=%-6s mirrors=%-1d  Map To: %s\n", $3, $4, $5, map_to
			else
	  		  printf "C    DATAVOL: %-16s len=%-6s mirrors=%-1d  Map To: %s\n", $3, $4, $5, map_to } END { if (count==0) printf "     DATAVOL: <none>           len=       mirrors=   Map To: \n" }' $CONFIG_FILE

		awk '/^SLV  *'$RLK' / {
			count=count+1
			if ($6 == "EXISTS")
	  		  printf "E    SRLVOL:  %-16s len=%-6s mirrors=%-1d\n", $3, $4, $5
			else
	  		  printf "C    SRLVOL:  %-16s len=%-6s mirrors=%-1d\n", $3, $4, $5 } END { if (count == 0) printf "     SRLVOL:  <none>           len=       mirrors=\n" } ' $CONFIG_FILE

		awk '/^SRL  *'$RLK' / { 
			count=count+1
			if ($11 == "EXISTS")
			    printf "E    RLINK:   %-16s Primary_host=%s\n", $3, $4
			else
	  		    printf "C    RLINK:   %-16s Primary_host=%s\n", $3, $4 } END { if (count==0) printf "     RLINK:   <none>           Primary_host=\n" } ' $CONFIG_FILE
	      done
	    fi
	else
	    echo "C New RVG name: $RVG		Diskgroup: $DISKGROUP"
	    echo ""

	    echo "   Data_Volume_Name  Length  Mirrors"
	    echo "   ----------------  ------  -------"
	    echo ""

	    echo "   SRL_Volume_Name   Length  Mirrors"
	    echo "   ----------------  ------  -------"
	    echo ""

		echo "   Rlink_Name        Remote_host  Remote_diskgroup  Remote_rlink  "
	 	echo "   ----------------  -----------  ----------------  ----------------"
		echo ""
		echo "     Objects to be set up on the remote host for this RLINK:"
		echo "     RVG:     <none>           diskgroup="
		echo "     DATAVOL: <none>           len=       mirrors=   Map To: "
		echo "     SRLVOL:  <none>           len=       mirrors="
		echo "     RLINK:   <none>           Primary_host="
	fi
	echo "-------------------------------------------------------------------------------"

	clear
}

Make_remote_rvg_now()
{
	SRV_CNT=`egrep -c "^SRV  *$RL " $CONFIG_FILE`
	if [ "$SRV_CNT" -lt 1 ]
	then
		return 1
	fi
	
	set -- `awk '/^SRV  *'${RL}' / { printf "%s %s %s\n", $3, $4, $5 }' $CONFIG_FILE`
	SECONDARY_RVG=$1; SECONDARY2_DISKGROUP=$2; SECONDARY_RVG_EXISTENCE=$3
	if [ "$SECONDARY2_DISKGROUP" != "$SECONDARY_DISKGROUP" ]
	then
		echo "ERROR: The Secondary diskgroups in the Primary RLINK ($SECONDARY_DISKGROUP) and the secondary"
		echo "       RVG ($SECONDARY2_DISKGROUP) specifications conflict"
		return 0
	fi
	if [ "$SECONDARY_RVG_EXISTENCE" != "CREATE" ]
	then
		return 1
		#echo "ERROR: Secondary RVG $SECONDARY_RVG is not marked CREATE"
		#return 0
	fi
	echo "Creating Secondary RVG $SECONDARY_RVG on $SECONDARY_HOST for RLINK $RL..."
	REMOTE_CMD="$VXVM_BIN/vxmake -g "$SECONDARY_DISKGROUP" rvg "$SECONDARY_RVG" primary=false"
	echo "$SECONDARY_HOST: $REMOTE_CMD"
	Do_Remote_Cmd
	if [ "$?" != 0 ]
	then
		echo "ERROR: Creation of Secondary RVG $SECONDARY_RVG on $SECONDARY_HOST failed"
		return 0
	else
		REMOTE_CLEANUP_RM_SECONDARY_RVG	# Uses $SECONDARY_RVG $SECONDARY_HOST $SECONDARY_DISKGROUP
		return 1
	fi
}

Make_rvg_now()
{
        set -- `awk '/^RV / { printf "%s\n", $0 }' $CONFIG_FILE`
        RVG=$2; DISKGROUP=$3; RVG_EXISTENCE=$4
	if [ "$RVG" = "" ]
	then
		echo "ERROR: No value for RVG.  No RV record in CONFIG_FILE?"
		echo "Hit return to continue: \c"
		read Whatever
		return 0
	fi
	if [ "$4" != "CREATE" ]
	then
		echo "ERROR: RVG $RVG is not marked CREATE"
		echo "Hit return to continue: \c"
                read Whatever
                return 0
	fi
        echo "Creating Primary RVG $RVG..."
        echo "$VXVM_BIN/vxmake -g "$DISKGROUP" rvg "$RVG" primary=true"
        $VXVM_BIN/vxmake -g "$DISKGROUP" rvg "$RVG" primary=true
        if [ "$?" != 0 ]
        then
                echo "ERROR: Creation of RVG $RVG failed"
                return 0
        else
                CLEANUP_RM_RVG
                return 1
        fi
}

Get_throttling_mode_strings()
{
	case "$SYNC_MODE" in
		"O" ) SYNC=off;;
		"F" ) SYNC=fail;;
		"V" ) SYNC=override;;
		* )   return 0;;
	esac
	case "$LATENCY_MODE" in
		"O" ) LATENCY=off;;
		"F" ) LATENCY=fail;;
		"V" ) LATENCY=override;;
		* )   return 0;;
	esac
	case "$SRLPROT_MODE" in
		"O" ) SRLPROT=off;;
		"F" ) SRLPROT=fail;;
		"V" ) SRLPROT=override;;
		"D" ) SRLPROT=dcm;;
		* )   return 0;;
	esac
	return 1
}

Get_throttling_mode_strings_reverse()
{
	case "$SYNC" in
		"off" ) SYNC_MODE=O;;
		"fail" ) SYNC_MODE=F;;
		"override" ) SYNC_MODE=V;;
		* )   return 0;;
	esac
	case "$LATENCY" in
		"off" ) LATENCY_MODE=O;;
		"fail" ) LATENCY_MODE=F;;
		"override" ) LATENCY_MODE=V;;
		* )   return 0;;
	esac
	case "$SRLPROT" in
		"off" ) SRLPROT_MODE=O;;
		"fail" ) SRLPROT_MODE=F;;
		"override" ) SRLPROT_MODE=V;;
		"dcm" ) SRLPROT_MODE=D;;
		* )   return 0;;
	esac
	return 1
}

# Inputs:
#	RL		Secondary RLINK to make
# 	SECONDARY_RVG 	Secondary RVG to associate RL with
Make_remote_rlink_now()
{
        SRL_CNT=`egrep -c "^SRL  *$RL " "$CONFIG_FILE"`
        if [ "$SRL_CNT" -gt 1 ]
        then
		echo "ERROR: Found multiple Secondary RLINK configuration entries for Primary RLINK $RL"
		echo ""
		return 0
	elif [ "$SRL_CNT" -lt 1 ]
	then
                return 1
        fi

        # Create and associate Secondary rlink
	set -- `awk '/^SRL  *'${RL}' / { printf "%s\n", $0 }' $CONFIG_FILE`
	SECONDARY_RLINK=$3
	SECONDARY_PRIMARY_HOST=$4
	SECONDARY_PRIMARY_DISKGROUP=$5
	SYNC_MODE=$6
	LATENCY_MODE=$7
	SRLPROT_MODE=$8
	shift; shift; shift
	HIGH_LATENCY=$6
	LOW_LATENCY=$7
	SECONDARY_RLK_EXISTENCE=$8
	if [ "$SECONDARY_RLK_EXISTENCE" = "EXISTS" ]
	then
		SRV_CNT=`egrep -c "^SRV  *$RL " $CONFIG_FILE`
		if [ "$SRV_CNT" -lt 1 ]
		then
			echo "WARNING: No Secondary RVG exists to associate Secondary RLINK $SECONDARY_RLINK with on $SECONDARY_HOST"
			return 1
		fi
	
		echo "Confirming whether Secondary RLINK $SECONDARY_RLINK is currently associated with $SECONDARY_RVG, yet..."
                REMOTE_CMD="$VXVM_BIN/vxprint -g "$SECONDARY_DISKGROUP" -tqQP "$SECONDARY_RLINK""
		#echo "$SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd 2>/dev/null > $CONFIG_2TMP_FILE
                if [ "$?" != 0 ]
                then
			echo "ERROR: Could not get information about $SECONDARY_RLINK on $SECONDARY_HOST"
			return 0
		fi

		set -- `/bin/cat $CONFIG_2TMP_FILE`
		/bin/rm -f $CONFIG_2TMP_FILE
		if [ "$3" = "$SECONDARY_RVG" ]
		then
			return 1	#already associated, nothing to do
		elif [ "$3" != "(none)" ]
		then
			echo "ERROR: Secondary RLINK $SECONDARY_RLINK is associated with some other RVG ($3) on $SECONDARY_HOST"
			return 0
		fi

        	echo "Associating Secondary RLINK $SECONDARY_RLINK with RVG $SECONDARY_RVG on $SECONDARY_HOST..."
		REMOTE_CMD="$VXVM_BIN/vxrlink -g $SECONDARY_DISKGROUP assoc $SECONDARY_RVG $SECONDARY_RLINK"
		echo "$SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd
		if [ "$?" != 0 ]
		then
			echo "ERROR: Association of Secondary RLINK $SECONDARY_RLINK with $SECONDARY_RVG on $SECONDARY_HOST failed"
			echo ""
			return 0
		fi
		#CLEANUP_SRL=$SECONDARY_RLINK
		REMOTE_CLEANUP_DIS_SECONDARY_RLINK

		return 1
	fi

	if [ "$SECONDARY_PRIMARY_DISKGROUP" != "${DISKGROUP:-rootdg}" ]
	then
		echo "ERROR: The Primary diskgroups in the Secondary RLINK and the Primary rvg"
		echo "       specifications conflict"
                echo ""
                return 0
	fi
	Get_throttling_mode_strings
	if [ "$?" = 0 ]
	then
                echo "ERROR: Bad value(s) for Throttling mode(s) for Secondary RLINK $SECONDARY_RLINK of Primary RLINK $RL"
                echo ""
                return 0
	fi

        echo "Creating Secondary RLINK $SECONDARY_RLINK on $SECONDARY_HOST (for Primary RLINK $RL)..."
	# Don't confuse them by setting high/low latency if they're using the defaults
	if [ "$HIGH_LATENCY" = 10000 ] && [ "$LOW_LATENCY" = 9950 ]
	then
	        REMOTE_CMD="$VXVM_BIN/vxmake -g $SECONDARY_DISKGROUP rlink $SECONDARY_RLINK local_host=$REM_HOST remote_host=$LOCALHOST remote_dg=$SECONDARY_PRIMARY_DISKGROUP remote_rlink=$RL synchronous=$SYNC latencyprot=$LATENCY srlprot=$SRLPROT"
	else
		REMOTE_CMD="$VXVM_BIN/vxmake -g $SECONDARY_DISKGROUP rlink $SECONDARY_RLINK local_host=$REM_HOST remote_host=$LOCALHOST remote_dg=$SECONDARY_PRIMARY_DISKGROUP remote_rlink=$RL synchronous=$SYNC latencyprot=$LATENCY srlprot=$SRLPROT latency_high_mark=$HIGH_LATENCY latency_low_mark=$LOW_LATENCY"
	fi
        echo "$SECONDARY_HOST: $REMOTE_CMD"
        Do_Remote_Cmd
        if [ "$?" != 0 ]
        then
                echo "ERROR: Creation of Secondary RLINK $SECONDARY_RLINK on $SECONDARY_HOST failed."
                echo ""
                return 0
        fi
	CLEANUP_SRL=$SECONDARY_RLINK
        REMOTE_CLEANUP_RM_SECONDARY_RLINK

	SRV_CNT=`egrep -c "^SRV  *$RL " $CONFIG_FILE`
	if [ "$SRV_CNT" -lt 1 ]
	then
		echo "WARNING: No Secondary RVG exists to associate Secondary RLINK $SECONDARY_RLINK with on $SECONDARY_HOST"
		return 1
	fi
	
        echo "Associating Secondary RLINK $SECONDARY_RLINK with RVG $SECONDARY_RVG on $SECONDARY_HOST..."
        REMOTE_CMD="$VXVM_BIN/vxrlink -g $SECONDARY_DISKGROUP assoc $SECONDARY_RVG $SECONDARY_RLINK"
        echo "$SECONDARY_HOST: $REMOTE_CMD"
        Do_Remote_Cmd
        if [ "$?" != 0 ]
        then
                echo "ERROR: Association of Secondary RLINK $SECONDARY_RLINK with $SECONDARY_RVG on $SECONDARY_HOST failed"
                echo ""
                return 0
        fi
	#CLEANUP_SRL=$SECONDARY_RLINK
        REMOTE_CLEANUP_DIS_SECONDARY_RLINK

	return 1
}

Make_rlinks_now()
{
        RL_CNT=`egrep -c "^RL " "$CONFIG_FILE"`
        if [ "$RL_CNT" -lt 1 ]
        then
                return 1
        fi

        # Create and associate rlinks 
        for RL in `awk '/^RL / { printf "%s ", $2 } END { printf "\n" }' $CONFIG_FILE`
        do
            set -- `awk '/^RL  *'${RL}' / { printf "%s\n", $0 }' $CONFIG_FILE`
	    LOCALHOST=$3
	    REM_HOST=$4
	    SECONDARY_DISKGROUP=$5
	    SECONDARY_RLINK=$6
	    SYNC_MODE=$7
	    LATENCY_MODE=$8
	    SRLPROT_MODE=$9
	    shift; shift; shift
	    HIGH_LATENCY=$7
	    LOW_LATENCY=$8
	    RLK_EXISTENCE=$9
	    if [ "$RLK_EXISTENCE" != "CREATE" ]
	    then
		continue
	    fi
	    Get_throttling_mode_strings
	    if [ "$?" = 0 ]
	    then
                echo "ERROR: Bad value(s) for Throttling mode(s) for RLINK $RL."
                echo ""
                return 0
	    fi
            echo "Creating Primary RLINK $RL..."
	    # Don't confuse them by setting high/low latency if they're using the defaults
	    if [ "$HIGH_LATENCY" = 10000 ] && [ "$LOW_LATENCY" = 9950 ]
	    then
            	echo "$VXVM_BIN/vxmake -g $DISKGROUP rlink $RL local_host=$LOCALHOST remote_host=$REM_HOST remote_dg=$SECONDARY_DISKGROUP remote_rlink=$SECONDARY_RLINK synchronous=$SYNC latencyprot=$LATENCY srlprot=$SRLPROT"
            	$VXVM_BIN/vxmake -g $DISKGROUP rlink $RL local_host=$LOCALHOST remote_host=$REM_HOST remote_dg=$SECONDARY_DISKGROUP remote_rlink=$SECONDARY_RLINK synchronous=$SYNC latencyprot=$LATENCY srlprot=$SRLPROT
	    else
            	echo "$VXVM_BIN/vxmake -g $DISKGROUP rlink $RL remote_host=$REM_HOST local_host=$LOCALHOST remote_dg=$SECONDARY_DISKGROUP remote_rlink=$SECONDARY_RLINK synchronous=$SYNC latencyprot=$LATENCY srlprot=$SRLPROT latency_high_mark=$HIGH_LATENCY latency_low_mark=$LOW_LATENCY"
            	$VXVM_BIN/vxmake -g $DISKGROUP rlink $RL remote_host=$REM_HOST local_host=$LOCALHOST remote_dg=$SECONDARY_DISKGROUP remote_rlink=$SECONDARY_RLINK synchronous=$SYNC latencyprot=$LATENCY srlprot=$SRLPROT latency_high_mark=$HIGH_LATENCY latency_low_mark=$LOW_LATENCY
	    fi

            if [ "$?" != 0 ]
            then
                echo "ERROR: Creation of Primary RLINK $RL failed."
                echo ""
                return 0
            fi
	    CLEANUP_RL=$RL
            CLEANUP_RM_RLINK

            echo "Associating Primary RLINK $RL with RVG $RVG..."
            echo "$VXVM_BIN/vxrlink -g $DISKGROUP assoc $RVG $RL"
            $VXVM_BIN/vxrlink -g $DISKGROUP assoc $RVG $RL
            if [ "$?" != 0 ]
            then
                echo "ERROR: Association of Primary RLINK $RL with $RVG failed"
                echo ""
                return 0
            fi
	    CLEANUP_RL=$RL
            CLEANUP_DIS_RLINK
	done
	return 1
}

Make_remote_datavols_now()
{
	SDV_CNT=`egrep -c "^SDV  *$RL " "$CONFIG_FILE"`
	if [ "$SDV_CNT" -lt 1 ]
	then
		return 1
	fi

# Only loops over SDV's marked EXISTS
        for SDV in `awk '/^SDV  *'$RL' .* EXISTS.*/ { printf "%s ", $3 } END { printf "\n" }' $CONFIG_FILE`
        do
		SDV_PRIMARY_DATAVOL=`awk '/^SDV  *'$RL'  *'${SDV}' / { printf "%s", $7 }' $CONFIG_FILE`
		SDV_SRVMLOG=`awk '/^SDV  *'$RL'  *'${SDV}' / { printf "%s", $8 }' $CONFIG_FILE`
		if [ "$SDV_PRIMARY_DATAVOL" != "" ] 
		then
	    	    DV_CNT=`egrep -c "^DV  *$SDV_PRIMARY_DATAVOL " "$CONFIG_FILE"`
		    if [ "$DV_CNT" -lt 1 ]
		    then
			echo "ERROR: Secondary data volume $SDV on $SECONDARY_HOST for Primary RLINK $RL"
			echo "specifies a mapping to a Primary datavol ($SDV_PRIMARY_DATAVOL) which"
			echo "does not exist in the Primary RVG hierarchy"
			echo ""
			return 0
		    elif [ "$DV_CNT" -gt 1 ]
		    then
			echo "ERROR: Found multiple Primary data volumes in the requested configuration named"
			echo "$SDV_PRIMARY_DATAVOL which the Secondary data volume $SDV on"
			echo "$SECONDARY_HOST is to be mapped to."
			echo ""
			return 0
		    fi
	    	fi

	    	# Should check "vxprint -lv" output to see if already set, but
		# it's quicker to just re-set it.  No harm done.
	    	if [ "$SDV_PRIMARY_DATAVOL" != "" ] && [ "$SDV_PRIMARY_DATAVOL" != "$SDV" ]
	    	then
		    echo "Mapping Secondary data volume $SDV on $SECONDARY_HOST to Primary datavol $SDV_PRIMARY_DATAVOL..."
		    REMOTE_CMD="$VXVM_BIN/vxedit -g $SECONDARY_DISKGROUP set primary_datavol=$SDV_PRIMARY_DATAVOL $SDV"
		    echo "$SECONDARY_HOST: $REMOTE_CMD"
		    Do_Remote_Cmd
		    if [ "$?" != 0 ]
		    then
			echo "ERROR: Attempt to set primary_datavol field of Secondary data volume $SDV"
			echo "(on $SECONDARY_HOST) to Primary data volume $SDV_PRIMARY_DATAVOL failed."
			echo ""
			return 0
		    fi
	        fi

		SRV_CNT=`egrep -c "^SRV  *$RL " $CONFIG_FILE`
		if [ "$SRV_CNT" -lt 1 ]
		then
			echo "WARNING: No Secondary RVG exists to associate existing data volume $SDV with on $SECONDARY_HOST"
			continue
		fi

		echo "Confirming if Secondary data volumes logging plexes"
		REMOTE_CMD="$VXVM_BIN/vxprint -g $DISKGROUP -lv $SDV" 
		Do_Remote_Cmd 2>/dev/null > $CONFIG_2TMP_FILE
		cat $CONFIG2_TMP_FILE | grep logging | \
			grep enabled >/dev/null 2>/dev/null
		if [ $? -ne 0 ]; then
		    echo "WARNING: The Specification for dcmlog on Data Volumes"
		    echo "shows logging is needed for data volumes, but $SDV does not have any logs for data volumes"
		    echo "Please Create one before attaching"
		    echo ""
		    echo "Press any key to continue"
		    read whatever
		    return 0
		fi
	
		echo "Confirming whether Secondary data volume $SDV is currently associated with $SECONDARY_RVG, yet..."
                REMOTE_CMD="$VXVM_BIN/vxprint -g "$SECONDARY_DISKGROUP" -tqQv "$SDV""
		#echo "$SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd 2>/dev/null > $CONFIG_2TMP_FILE
                if [ "$?" != 0 ]
                then
			echo "ERROR: Could not get information about $SDV on $SECONDARY_HOST"
			return 0
		fi

		set -- `/bin/cat $CONFIG_2TMP_FILE`
		/bin/rm -f $CONFIG_2TMP_FILE
		if [ "$3" = "$SECONDARY_RVG" ]
		then
			continue	#already associated, nothing to do
		elif [ "$3" != "-" ]
		then
			echo "ERROR: Secondary data volume $SDV is associated with some other RVG ($3) on $SECONDARY_HOST"
			return 0
		fi

		#
		# Add check for logs for data volumes
		#

            	echo "Associate existing Secondary data volume $SDV with $SECONDARY_RVG..."
		REMOTE_CMD="$VXVM_BIN/vxvol -g "$SECONDARY_DISKGROUP" assoc "$SECONDARY_RVG" "$SDV""
                echo "$SECONDARY_HOST: $REMOTE_CMD"
                Do_Remote_Cmd
		if [ "$?" != 0 ]
		then
			echo "ERROR: Association of existing Secondary data volume "$SDV" with RVG "$SECONDARY_RVG" on $SECONDARY_HOST failed"
			return 0
                else
			CLEANUP_SDV=$SDV	#For REMOTE_CLEANUP_DIS_SECONDARY_DATAVOL
			REMOTE_CLEANUP_DIS_SECONDARY_DATAVOL
                fi
	done

        # Create Secondary datavols that don't already exist
        for SDV in `awk '/^SDV  *'$RL' .* CREATE.*/ { printf "%s ", $3 } END { printf "\n" }' $CONFIG_FILE`
        do
            set -- `awk '/^SDV  *'$RL'  *'${SDV}' / { printf "%s\n", $0 }' $CONFIG_FILE`
            SDV_LEN=$4
            SDV_MIR=$5;
	    SDV_PRIMARY_DATAVOL=$7
	    SDV_LOG=$8

	    if [ "$SDV_PRIMARY_DATAVOL" != "" ] 
	    then
	    	DV_CNT=`egrep -c "^DV  *$SDV_PRIMARY_DATAVOL " "$CONFIG_FILE"`
		if [ "$DV_CNT" -lt 1 ]
		then
			echo "ERROR: Secondary data volume $SDV on $SECONDARY_HOST for Primary RLINK $RL"
			echo "specifies a mapping to a Primary datavol ($SDV_PRIMARY_DATAVOL) which"
			echo "does not exist in the Primary RVG hierarchy"
			echo ""
			return 0
		elif [ "$DV_CNT" -gt 1 ]
		then
			echo "ERROR: Found multiple Primary data volumes in the requested configuration named"
			echo "$SDV_PRIMARY_DATAVOL which the Secondary data volume $SDV on"
			echo "$SECONDARY_HOST is to be mapped to."
			echo ""
			return 0
		fi
	    fi
	    LOGTYPE=""
	    if [ "$SDV_LOG" = "yes" ]; then
		LOGTYPE="${SRVMLOGTYPE}"
	    fi
            echo "Creating Secondary data volume $SDV on $SECONDARY_HOST for Primary RLINK $RL..."
            REMOTE_CMD="$VXVM_BIN/vxassist -g $SECONDARY_DISKGROUP make $SDV $SDV_LEN"
            echo "$SECONDARY_HOST: $REMOTE_CMD"
            Do_Remote_Cmd
            if [ "$?" != 0 ]
            then
		echo "ERROR: Creation of Secondary data volume $SDV on $SECONDARY_HOST with length $SDV_LEN failed."
		echo ""
		return 0
            fi
	    CLEANUP_SDV=$SDV
            REMOTE_CLEANUP_RM_SECONDARY_DATAVOL

	    if [ "$SDV_PRIMARY_DATAVOL" != "" ] && [ "$SDV_PRIMARY_DATAVOL" != "$SDV" ]
	    then
		echo "Mapping Secondary data volume $SDV on $SECONDARY_HOST to Primary datavol $SDV_PRIMARY_DATAVOL..."
		REMOTE_CMD="$VXVM_BIN/vxedit -g $SECONDARY_DISKGROUP set primary_datavol=$SDV_PRIMARY_DATAVOL $SDV"
		echo "$SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd
		if [ "$?" != 0 ]
		then
			echo "ERROR: Attempt to set primary_datavol field of Secondary data volume $SDV"
			echo "(on $SECONDARY_HOST) to Primary data volume $SDV_PRIMARY_DATAVOL failed."
			echo ""
			return 0
		fi
	    fi

            while [ "$SDV_MIR" != 0 ]
            do
                echo "Creating new mirror for Secondary data volume $SDV on $SECONDARY_HOST..."
                REMOTE_CMD="$VXVM_BIN/vxassist -g "$SECONDARY_DISKGROUP" mirror $SDV"
                echo "$SECONDARY_HOST: $REMOTE_CMD"
                Do_Remote_Cmd
                if [ "$?" != 0 ]
                then
                    echo "ERROR: Creation of mirror for Secondary data volume $SDV on $SECONDARY_HOST failed"
                    echo ""
                    return 0
                else
		    SDV_MIR=`expr $SDV_MIR - 1`
                fi
            done

	    SRV_CNT=`egrep -c "^SRV  *$RL " $CONFIG_FILE`
	    if [ "$SRV_CNT" -lt 1 ]
	    then
		echo "WARNING: No Secondary RVG exists to associate new data volume $SDV with on $SECONDARY_HOST"
		continue
	    fi

	    # Add logtype if specified
	    if [ "${SDV_LOG}" = "yes" ]; then
		echo "Adding dcmlog to Secondary datavolume $SDV with $SECONDARY_RVG on $SECONDARY_HOST ..."
                REMOTE_CMD="$VXVM_BIN/vxassist -g "$SECONDARY_DISKGROUP" addlog  $SDV ${SRVMLOGTYPE}"
                echo "$SECONDARY_HOST: $REMOTE_CMD"
                Do_Remote_Cmd
                if [ "$?" != 0 ]
                then
                    #echo "ERROR: Creation of dcmlog for Secondary data volume $SDV on $SECONDARY_HOST failed"
                    echo ""
                    return 0
                fi
	    fi
	
	
            echo "Associating Secondary data volume $SDV with $SECONDARY_RVG on $SECONDARY_HOST..."
	    REMOTE_CMD="$VXVM_BIN/vxvol -g $SECONDARY_DISKGROUP assoc $SECONDARY_RVG $SDV"
            echo "$SECONDARY_HOST: $REMOTE_CMD"
            Do_Remote_Cmd
	    if [ "$?" != 0 ]
	    then
		echo "ERROR: Association of new Secondary data volume "$SDV" with "$SECONDARY_RVG" on $SECONDARY_HOST failed"
		return 0
	    else
		CLEANUP_SDV=$SDV
		REMOTE_CLEANUP_DIS_SECONDARY_DATAVOL
	    fi
	done
	return 1
}

Make_datavols_now()
{
	DV_CNT=`egrep -c "^DV " "$CONFIG_FILE"`
	if [ "$DV_CNT" -lt 1 ]
	then
		return 1
	fi

        for DV in `awk '/^DV .* EXISTS.*/ { printf "%s ", $2 } END { printf "\n" }' $CONFIG_FILE`
        do
            set -- `awk '/^DV  *'${DV}' / { printf "%s\n", $0 }' $CONFIG_FILE`
	    DV_SRVMLOG=$5

	    if [ "$DV_SRVMLOG" = "yes" ]; then
		$VXVM_BIN/vxprint -g $DISKGROUP -lv $DV | grep logging | \
			grep enabled >/dev/null 2>/dev/null
		if [ $? -ne 0 ]; then
		    echo "WARNING: The Specification for dcmlog on Data Volumes"
		    echo "shows logging is needed for data volumes, but $DV does not have any logs for data volumes"
		    echo "Please Create one before attaching"
		    echo ""
		    echo "Press any key to continue"
		    read whatever
		    return 0
		fi
	    fi
            	echo "Associate $DV with $RVG..."
		echo "$VXVM_BIN/vxvol -g "$DISKGROUP" assoc "$RVG" "$DV""
		$VXVM_BIN/vxvol -g "$DISKGROUP" assoc "$RVG" "$DV"
		if [ "$?" != 0 ]
		then
			echo "ERROR: Association of existing data volume "$DV" with RVG "$RVG" failed"
			return 0
                else
			CLEANUP_DV=$DV	#For CLEANUP_DIS_DATAVOL
			CLEANUP_DIS_DATAVOL
                fi
	done

	# Find out which dm disks the SRL vol (if any) is using and don't use them.
        /bin/rm -f $VXPRINT_FILE
        /bin/touch $VXPRINT_FILE

        DMCOUNT=0
        DM1=""; DM2=""; DM3=""; DM4=""; DM5=""; DM6=""; DM7=""; DM8=""; DM9="";
        DM10=""; DM11=""; DM12=""; DM13=""; DM14=""; DM15=""; DM16=""; DM17="";
        DM18="";  DM19="";  DM20=""

	LV=`awk '/^LV / { printf "%s", $2 }' $CONFIG_FILE`
        $VXVM_BIN/vxprint -g "$DISKGROUP" -htvQq "$LV" 2> /dev/null 1> $VXPRINT_FILE
	# don't pipe to while -- would make a subshell.
        exec < $VXPRINT_FILE    
        while
                read RECTYPE VXPRINT_LINE
        do
                if [ "$RECTYPE" != sd ]
                then
                        continue
                fi
                set $VXPRINT_LINE
                DMCOUNT=`expr $DMCOUNT + 1`
                eval DM$DMCOUNT='alloc=!'$3
        done
        exec < /dev/tty

        if [ "$DM21" != "" ]
        then
                echo "ERROR: This script cannot handle an SRL volume that uses more than 20 dm disks"
                return 0
        fi

        DMDISKS="$DM1 $DM2 $DM3 $DM4 $DM5 $DM6 $DM7 $DM8 $DM9 $DM10 $DM11 $DM12 $DM13 $DM14 $DM15 $DM16 $DM17 $DM18 $DM19 $DM20"

        # Create datavols that don't already exist
        for DV in `awk '/^DV .* CREATE.*/ { printf "%s ", $2 } END { printf "\n" }' $CONFIG_FILE`
        do
            set -- `awk '/^DV  *'${DV}' / { printf "%s\n", $0 }' $CONFIG_FILE`
            DV_LEN=$3
            DV_MIR=$4;
	    DV_SRVMLOG=$5
	    LOGTYPE=""
	    if [ "$DV_SRVMLOG" = "yes" ]; then
		LOGTYPE="${SRVMLOGTYPE}"
	    fi
            echo "Creating data volume $DV..."
            echo "$VXVM_BIN/vxassist -g $DISKGROUP  make $DV $DV_LEN $DMDISKS "
            $VXVM_BIN/vxassist -g "$DISKGROUP" make $DV $DV_LEN $DMDISS
	    EXIT_STATUS="$?"
            if [ "$EXIT_STATUS" != 0 ]
            then
                echo "ERROR: Creation of data volume $DV with length $DV_LEN failed."
                if [ "$EXIT_STATUS" = 64 ]
                then
                        echo "  May have failed because data volume should not use any dm disks that are "
                        echo "  in use by the SRL volume."
                        echo ""
                        echo "Performance will be significantly degraded if the SRL volume uses the same disk"
			echo "as a data volume."
                        echo "Attempt to create data volume on a disk that may be in use by the SRL volume?"
                        echo "(y/n) (default: n): \c"
                        YES_OR_NO=""
                        while [ "$YES_OR_NO" = "" ]
                        do
                        read YES_OR_NO
                        case "$YES_OR_NO" in
                                "" )    YES_OR_NO=n;;
                                [yY] ) YES_OR_NO=y;;
                                [nN] ) YES_OR_NO=n;;
                                * )     YES_OR_NO="" ;;
                        esac
                        done
                        if [ "$YES_OR_NO" != "y" ]
                        then
                                return 0
                        fi
                        echo "$VXVM_BIN/vxassist -g $DISKGROUP make $DV $DV_LEN"
                        $VXVM_BIN/vxassist -g "$DISKGROUP" make $DV $DV_LEN
                        if [ "$?" != 0 ]
                        then
                                echo "ERROR: Creation of data volume $DV with length $DV_LEN failed."
                                return 0
                        fi
                else
                       echo ""
                        return 0
                fi
            fi
	    CLEANUP_DV=$DV
            CLEANUP_RM_DATAVOL
	 if [ "$DV_SRVMLOG" = "yes" ]; then
		echo "Adding dcm log to Primary datavolume $DV with $RVG..."
                echo "$VXVM_BIN/vxassist -g "$DISKGROUP" addlog  $DV ${SRVMLOGTYPE}"
                $VXVM_BIN/vxassist -g "$DISKGROUP" addlog  $DV ${SRVMLOGTYPE}
                if [ "$?" != 0 ]
                then
                    echo "ERROR: Creation of dcmlog for data volume $DV on $RVG failed"
                    echo ""
                    return 0
                fi
	 fi
	
            while [ "$DV_MIR" != 0 ]
            do
                echo "Creating new mirror for data volume $DV..."
                echo "$VXVM_BIN/vxassist -g "$DISKGROUP" mirror $DV $DMDISKS"
                $VXVM_BIN/vxassist -g "$DISKGROUP" mirror $DV $DMDISKS
                EXIT_STATUS="$?"
                if [ "$EXIT_STATUS" != 0 ]
                then
                    echo "ERROR: Creation of mirror for data volume $DV failed"
                    if [ "$EXIT_STATUS" = 64 ]
                    then
                        echo "  May have failed because data volume should not use any dm disks that are "
                        echo "  in use by the SRL volume."
                        echo ""
                        echo "Performance will be significantly degraded if the SRL volume uses the same disk"
			echo "as a data volume."
                        echo "Attempt to create new mirror on a disk that may be in use by the SRL volume?"
                        echo "(y/n) (default: n): \c"
                        YES_OR_NO=""
                        while [ "$YES_OR_NO" = "" ]
                        do
                        read YES_OR_NO
                        case "$YES_OR_NO" in
                                "" )    YES_OR_NO=n;;
                                [yY] ) YES_OR_NO=y;;
                                [nN] ) YES_OR_NO=n;;
                                * )     YES_OR_NO="" ;;
                        esac
                        done
                        if [ "$YES_OR_NO" != "y" ]
                        then
                                return 0
                        fi
                        echo "$VXVM_BIN/vxassist -g "$DISKGROUP" mirror $DV "
                        $VXVM_BIN/vxassist -g "$DISKGROUP" mirror $DV
                        if [ "$?" != 0 ]
                        then
                                echo "ERROR: Creation of mirror for data volume $DV failed"
                                return 0
                        else
                                DV_MIR=`expr $DV_MIR - 1`
                        fi
                    else
                        echo ""
                        return 0
                    fi
                else
		    DV_MIR=`expr $DV_MIR - 1`
                fi
            done
            echo "Associate $DV with $RVG..."
	    echo "$VXVM_BIN/vxvol -g $DISKGROUP assoc $RVG $DV"
	    $VXVM_BIN/vxvol -g "$DISKGROUP" assoc "$RVG" "$DV"
	    if [ "$?" != 0 ]
	    then
		echo "ERROR: Association of new data volume "$DV" with RVG "$RVG" failed"
		return 0
	    else
		CLEANUP_DV=$DV	#For CLEANUP_DIS_DATAVOL
		CLEANUP_DIS_DATAVOL
	    fi
	done
	return 1
}

Make_remote_srlvol_now()
{
	SLV_CNT=`egrep -c "^SLV  *$RL " "$CONFIG_FILE"`
	if [ "$SLV_CNT" -lt 1 ]
	then
		return 1
	fi

        set -- `awk '/^SLV  *'${RL}' / { printf "%s %s %s %s\n", $3, $4, $5, $6 }' $CONFIG_FILE`
        SECONDARY_SRLVOL=$1; SECONDARY_SRLVOL_LEN=$2; SECONDARY_SRLVOL_MIRROR_COUNT=$3; SECONDARY_SRLVOL_EXISTENCE=$4
        if [ "$SECONDARY_SRLVOL_EXISTENCE" = "EXISTS" ]
        then
		SRV_CNT=`egrep -c "^SRV  *$RL " $CONFIG_FILE`
		if [ "$SRV_CNT" != 1 ]
		then
			echo "WARNING: No Secondary RVG exists to associate existing SRL volume $SECONDARY_SRLVOL with on $SECONDARY_HOST"
			return 1
		fi
	
		echo "Confirming whether Secondary SRL vol $SECONDARY_SRLVOL is currently associated with $SECONDARY_RVG, yet..."
                REMOTE_CMD="$VXVM_BIN/vxprint -g "$SECONDARY_DISKGROUP" -tqQv "$SECONDARY_SRLVOL""
		echo "$SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd 2>/dev/null > $CONFIG_2TMP_FILE
                if [ "$?" != 0 ]
                then
			echo "ERROR: Could not get information about $SECONDARY_SRLVOL on $SECONDARY_HOST"
			return 0
		fi

		set -- `/bin/cat $CONFIG_2TMP_FILE`
		/bin/rm -f $CONFIG_2TMP_FILE
		if [ "$3" = "$SECONDARY_RVG" ]
		then
			return 1	#already associated, nothing to do
		elif [ "$3" != "-" ]
		then
			echo "ERROR: Secondary SRL volume $SECONDARY_SRLVOL is associated with some other RVG ($3) on $SECONDARY_HOST"
			return 0
		fi

		echo "Associating existing Secondary SRL volume $SECONDARY_SRLVOL with $SECONDARY_RVG..."
                REMOTE_CMD="$VXVM_BIN/vxvol -g "$SECONDARY_DISKGROUP" aslog "$SECONDARY_RVG" "$SECONDARY_SRLVOL""
		echo "$SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd
                if [ "$?" != 0 ]
                then
                        echo "ERROR: Association of existing Secondary SRL volume "$SECONDARY_SRLVOL" with "$SECONDARY_RVG" failed"
                        return 0
                else
                        REMOTE_CLEANUP_DIS_SECONDARY_SRLVOL
                        return 1
                fi
        fi

        # Create the Secondary SRL vol

        echo "Creating Secondary SRL volume $SECONDARY_SRLVOL on $SECONDARY_HOST..."
        REMOTE_CMD="$VXVM_BIN/vxassist -g $SECONDARY_DISKGROUP make $SECONDARY_SRLVOL $SECONDARY_SRLVOL_LEN"
	echo "$SECONDARY_HOST: $REMOTE_CMD"
	Do_Remote_Cmd
        if [ "$?" != 0 ]
        then
                echo "ERROR: Creation of Secondary SRL volume $SECONDARY_SRLVOL on $SECONDARY_HOST with length $SECONDARY_SRLVOL_LEN failed."
                echo ""
                return 0
        fi
        REMOTE_CLEANUP_RM_SECONDARY_SRLVOL

        while [ "$SECONDARY_SRLVOL_MIRROR_COUNT" != 0 ]
	do
		echo "Creating new mirror for Secondary SRL volume $SRLVOL on $SECONDARY_HOST..."
		REMOTE_CMD="$VXVM_BIN/vxassist -g "$SECONDARY_DISKGROUP" mirror $SECONDARY_SRLVOL $DMDISKS"
		echo "$SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd
		if [ "$?" != 0 ]
		then
		    echo "ERROR: Creation of mirror for Secondary SRL volume $SECONDARY_SRLVOL on $SECONDARY_HOST failed"
		    echo ""
		    return 0
		else
		    SECONDARY_SRLVOL_MIRROR_COUNT=`expr $SECONDARY_SRLVOL_MIRROR_COUNT - 1`
		fi
	done

	SRV_CNT=`egrep -c "^SRV  *$RL " $CONFIG_FILE`
	if [ "$SRV_CNT" -lt 1 ]
	then
		echo "WARNING: No Secondary RVG exists to associate new SRL volume $SECONDARY_SRLVOL with on $SECONDARY_HOST"
		return 1
	fi
	
        echo "Associating Secondary SRL volume $SECONDARY_SRLVOL with $SECONDARY_RVG on $SECONDARY_HOST..."
        REMOTE_CMD="$VXVM_BIN/vxvol -g $SECONDARY_DISKGROUP aslog $SECONDARY_RVG $SECONDARY_SRLVOL"
        echo "$SECONDARY_HOST: $REMOTE_CMD"
        Do_Remote_Cmd
        if [ "$?" != 0 ]
	then
		echo "ERROR: Associating Secondary SRL volume $SECONDARY_SRLVOL with $SECONDARY_RVG on $SECONDARY_HOST failed"
		return 0
	fi
	REMOTE_CLEANUP_DIS_SECONDARY_SRLVOL

	return 1
}

Make_srlvol_now()
{
	LV_CNT=`egrep -c "^LV " "$CONFIG_FILE"`
	if [ "$LV_CNT" -lt 1 ]
	then
		return 1
	fi

	set -- `awk '/^LV / { printf "%s\n", $0 }' $CONFIG_FILE`
	SRLVOL=$2; SRLVOL_LEN=$3; SRLVOL_MIRROR_COUNT=$4; SRLVOL_EXISTENCE=$5
	if [ "$SRLVOL_EXISTENCE" = "EXISTS" ]
	then
		echo "Associating existing SRL volume $SRLVOL with $RVG..."
		echo "$VXVM_BIN/vxvol -g "$DISKGROUP" aslog "$RVG" "$SRLVOL""
		$VXVM_BIN/vxvol -g "$DISKGROUP" aslog "$RVG" "$SRLVOL"
		if [ "$?" != 0 ]
		then
			echo "ERROR: Association of existing SRL vol "$SRLVOL" with RVG "$RVG" failed"
			return 0
                else
			CLEANUP_DIS_SRLVOL
                        return 1
                fi
	fi

	# Find out which dm disks EXISTing datavols use.  Don't use them.

	/bin/rm -f $VXPRINT_FILE
	/bin/touch $VXPRINT_FILE

	DMCOUNT=0
	DM1=""; DM2=""; DM3=""; DM4=""; DM5=""; DM6=""; DM7=""; DM8=""; DM9="";
	DM10=""; DM11=""; DM12=""; DM13=""; DM14=""; DM15=""; DM16=""; DM17="";
	DM18="";  DM19="";  DM20=""

	for DV in `awk '/^DV .* EXISTS.*/ { printf "%s ", $2 } END { printf "\n" }' $CONFIG_FILE`
        do
		$VXVM_BIN/vxprint -g "$DISKGROUP" -htvQq "$DV" 2> /dev/null 1> $VXPRINT_FILE
		# don't pipe to while -- would make a subshell.
	        exec < $VXPRINT_FILE	
        	while
                	read RECTYPE VXPRINT_LINE
        	do
                	if [ "$RECTYPE" != sd ]
                	then
                        	continue
                	fi
                	set $VXPRINT_LINE
                	DMCOUNT=`expr $DMCOUNT + 1`
                	eval DM$DMCOUNT='alloc=!'$3
        	done
        	exec < /dev/tty
	done

	if [ "$DM21" != "" ]
        then
                echo "ERROR: This script cannot handle a data volume that uses more than 20 dm disks"
		return 0
        fi

	DMDISKS="$DM1 $DM2 $DM3 $DM4 $DM5 $DM6 $DM7 $DM8 $DM9 $DM10 $DM11 $DM12 $DM13 $DM14 $DM15 $DM16 $DM17 $DM18 $DM19 $DM20"

	# Create the SRL vol

	echo "Creating SRL volume $SRLVOL..."
	echo "$VXVM_BIN/vxassist -g $DISKGROUP make $SRLVOL $SRLVOL_LEN $DMDISKS"
	$VXVM_BIN/vxassist -g "$DISKGROUP" make $SRLVOL $SRLVOL_LEN $DMDISKS
	EXIT_STATUS="$?"
	if [ "$EXIT_STATUS" != 0 ] 
	then
		echo "ERROR: Creation of SRL volume $SRLVOL with length $SRLVOL_LEN failed."
		if [ "$EXIT_STATUS" = 64 ]
		then
			echo "	May have failed because SRL volume should not use any dm disks that are "
			echo "	in use by an existing data volume."
			echo ""
			echo "Performance will be significantly degraded if the SRL volume uses the same disk"
			echo "as a data volume."
			echo "Attempt to create SRL volume on a disk that may be in use by an existing data"
			echo "volume? (y/n) (default: n): \c"
			YES_OR_NO=""
			while [ "$YES_OR_NO" = "" ]
			do
		    	read YES_OR_NO 
		    	case "$YES_OR_NO" in
				"" )    YES_OR_NO=n;;
				[yY] ) YES_OR_NO=y;;
				[nN] ) YES_OR_NO=n;;
				* )     YES_OR_NO="" ;;
                    	esac
			done
			if [ "$YES_OR_NO" != "y" ]
			then
				return 0
			fi
        		echo "$VXVM_BIN/vxassist -g $DISKGROUP make $SRLVOL $SRLVOL_LEN"
        		$VXVM_BIN/vxassist -g "$DISKGROUP" make $SRLVOL $SRLVOL_LEN
        		if [ "$?" != 0 ]
        		then
                		echo "ERROR: Creation of SRL volume $SRLVOL with length $SRLVOL_LEN failed."
				return 0
			fi
		else
			echo ""
			return 0
		fi
	fi
	CLEANUP_RM_SRLVOL

	while [ "$SRLVOL_MIRROR_COUNT" != 0 ]
	do
		echo "Creating new mirror for SRL volume $SRLVOL..."
		echo "$VXVM_BIN/vxassist -g "$DISKGROUP" mirror $SRLVOL $DMDISKS"
		$VXVM_BIN/vxassist -g "$DISKGROUP" mirror $SRLVOL $DMDISKS
		EXIT_STATUS="$?"
		if [ "$EXIT_STATUS" != 0 ]
		then
		    echo "ERROR: Creation of mirror for SRL volume $SRLVOL failed"
		    if [ "$EXIT_STATUS" = 64 ]
		    then
			echo "	May have failed because SRL volume should not use any dm disks that are "
			echo "	in use by an existing data volume."
			echo ""
			echo "Performance will be significantly degraded if the SRL volume uses the same disk"
			echo "as a data volume."
			echo "Attempt to create new mirror on a disk that may be in use by an existing data"
			echo "volume? (y/n) (default: n): \c"
			YES_OR_NO=""
			while [ "$YES_OR_NO" = "" ]
			do
		    	read YES_OR_NO 
		    	case "$YES_OR_NO" in
				"" )    YES_OR_NO=n;;
				[yY] ) YES_OR_NO=y;;
				[nN] ) YES_OR_NO=n;;
				* )     YES_OR_NO="" ;;
                    	esac
			done
			if [ "$YES_OR_NO" != "y" ]
			then
				return 0
			fi
			echo "$VXVM_BIN/vxassist -g "$DISKGROUP" mirror $SRLVOL"
			$VXVM_BIN/vxassist -g "$DISKGROUP" mirror $SRLVOL
        		if [ "$?" != 0 ]
        		then
		    		echo "ERROR: Creation of mirror for SRL volume $SRLVOL failed"
				return 0
			else
		    		SRLVOL_MIRROR_COUNT=`expr $SRLVOL_MIRROR_COUNT - 1`
			fi
		    else
			echo ""
			return 0
		    fi
		else
		    SRLVOL_MIRROR_COUNT=`expr $SRLVOL_MIRROR_COUNT - 1`
		fi
	done
        echo "Associate $SRLVOL with $RVG..."
        echo "$VXVM_BIN/vxvol -g $DISKGROUP aslog $RVG $SRLVOL"
        $VXVM_BIN/vxvol -g $DISKGROUP aslog $RVG $SRLVOL
        if [ "$?" != 0 ]
	then
		echo "ERROR: Associating SRL volume $SRLVOL with $RVG failed"
		return 0
	fi
	CLEANUP_DIS_SRLVOL

	return 1
}

Cleanup_no_abort()
{
	# Delete all meta files except $CONFIG_FILE and $VXSUMMARY_FILE
	/bin/rm -f $CONFIG_FILE_OLD $CONFIG_ORIG_FILE $CONFIG_AUX_ORIG_FILE \
		$CONFIG_2AUX_ORIG_FILE $CONFIG_TMP_FILE $CONFIG_BAK_FILE \
		${CONFIG_2TMP_FILE}* $VERIFY_CFG_FILE $VXPRINT_FILE \
                $RSH_CMDS_FILE $RSH_CMD_STATUS_FILE $CONFIG_FILE_EMPTY \
		$CONFIG_3TMP_FILE $VXPRINT_FILE2

	if [ "$CLEANUP" != "" ]
	then
		echo "Cleaning up locally..."
		echo "$CLEANUP"
		eval "$CLEANUP"
		CLEANUP=""
	fi

        if [ "$REMOTE_HOSTS" != "" ]
        then
            for SECONDARY_HOST in $REMOTE_HOSTS
            do
                CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
                if [ ! -f $CLEANUP_FILE ]
                then
                        echo "ERROR: Could not find $CLEANUP_FILE,"
                        echo "       so skipping clean up of $SECONDARY_HOST"
                        continue
                fi
                REMOTE_CLEANUP=`awk '{ printf "%s", $0 }' $CLEANUP_FILE`
		EMPTY_CHECK=`echo "$REMOTE_CLEANUP" | /bin/sed 's/  *//g'`
		if [ "$EMPTY_CHECK" != "" ]
		then
			echo "Cleaning up remote host $SECONDARY_HOST..."
			echo "$SECONDARY_HOST:Remote cleanup: $REMOTE_CLEANUP"
                	REMOTE_CMD="$REMOTE_CLEANUP"
                	Do_Remote_Cmd
		fi
		/bin/rm -f $CLEANUP_FILE
            done
	    REMOTE_HOSTS=""
        fi
}

Make_remote_objects()
{
        # Loop on each Primary RLINK and set up any corresponding Secondary configuration
        for RL in `awk '/^RL / { printf "%s ", $2 } END { printf "\n" }' $CONFIG_FILE`
        do
            set -- `awk '/^RL  *'${RL}' / { printf "%s\n", $0 }' $CONFIG_FILE`
	    LOCALHOST=$3
            REM_HOST=$4
	    SECONDARY_HOST=$4
            SECONDARY_DISKGROUP=$5
            SECONDARY_RLINK=$6
            SYNC_MODE=$7
            LATENCY_MODE=$8
            SRLPROT_MODE=$9
	    shift; shift; shift
	    HIGH_LATENCY=$7
	    LOW_LATENCY=$8
	    RLK_EXISTENCE=$9
            Get_throttling_mode_strings	#this already succeeded earlier
	    echo ""
            echo "Doing remote set-up on $REM_HOST for Primary RLINK $RL..."

	    Make_remote_rvg_now
	    if [ "$?" != 1 ]
	    then
		return 0
	    fi


	    # SECONDARY_RVG is needed for association of other Secondary objects
	    SRV_CNT=`egrep -c "^SRV  *$RL " $CONFIG_FILE`
	    if [ "$SRV_CNT" -lt 1 ]
	    then
		SECONDARY_RVG=""
	    else
	        set -- `awk '/^SRV  *'${RL}' / { printf "%s %s %s\n", $3, $4, $5 }' $CONFIG_FILE`
	        SECONDARY_RVG=$1; SECONDARY2_DISKGROUP=$2; SECONDARY_RVG_EXISTENCE=$3
	        if [ "$SECONDARY2_DISKGROUP" != "$SECONDARY_DISKGROUP" ]
	        then
		    echo "ERROR: The Secondary diskgroups in the Primary RLINK ($SECONDARY_DISKGROUP) and the secondary"
		    echo "       RVG ($SECONDARY2_DISKGROUP) specifications conflict"
		    return 0
	        fi
	    fi

	    Make_remote_srlvol_now
	    if [ "$?" != 1 ]
	    then
		return 0
	    fi

	    Make_remote_datavols_now
	    if [ "$?" != 1 ]
	    then
		return 0
	    fi

	    Make_remote_rlink_now
	    if [ "$?" != 1 ]
	    then
		return 0
	    fi
	done
	return 1
}


#11G
Go_Create_an_Rvg()
{
clear

	if [ "$DISKGROUP" = "" ]
	then
		DISKGROUP=rootdg
	fi
	RVG_COUNT=`/bin/egrep -c '^RV' $CONFIG_FILE`
	if [ "$RVG_COUNT" -eq 0 ]
	then
		echo "#RV  Rvg_Name          Diskgroup_Name  Create/Exists" >> $CONFIG_TMP_FILE
		echo "#    ----------------  --------------  -------------" >> $CONFIG_TMP_FILE
		awk 'END { printf "RV   %-17s %-14s  %-s\n", "'$RVG'", "'$DISKGROUP'", "'$RVG_EXISTENCE'" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		/bin/cat $CONFIG_FILE >> $CONFIG_TMP_FILE
		/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
	elif [ "$RVG" != "" ] || [ "$DISKGROUP" != "" ] # Load new RVG/DISKGROUP values
	then
	    if [ "$RVG" != "" ]
	    then
		awk '{ if ( NF > 0 && $1 == "RV" && $2 != "'$RVG'") printf "RV   %-17s %-14s  %s\n", "'$RVG'", $3, "'$RVG_EXISTENCE'"
			else print $0 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
	    fi
	    if [ "$DISKGROUP" != "" ]
	    then
		awk '{ if ( NF > 0 && $1 == "RV" && $3 != "'$DISKGROUP'") printf "RV   %-17s %-14s  %s\n", $2, "'$DISKGROUP'", "'$RVG_EXISTENCE'"
			else print $0 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
	    fi
	fi
		
	Verify_Cfg_File_On_Create
        if [ "$?" = 0 ]
        then
		echo ""
		echo "Failed due to error(s) detected in requested configuration"
		QUIT=""
		while [ "$QUIT" = "" ]
		do 
			echo "Quit? (y/n) (default: n): \c" 
			read QUIT
			case "$QUIT" in
				"" )    QUIT=NO;;
				[yY] ) Quit;;
				[nN] ) QUIT=NO;;
				* )     QUIT="" ;;
               		esac
		done
		return 0
        fi

	echo ""
	echo "No errors detected in requested configuration.  Setting up configuration..."
	echo ""

	Make_rvg_now
	if [ "$?" != 1 ]
	then
		echo "Hit return to continue: \c"
		read Whatever
		Cleanup_no_abort
		return 0
	fi

	Make_srlvol_now
	if [ "$?" != 1 ]
	then
		echo "Hit return to continue: \c"
		read Whatever
		Cleanup_no_abort
		return 0
	fi

	Make_datavols_now
	if [ "$?" != 1 ]
	then
		echo "Hit return to continue: \c"
		read Whatever
		Cleanup_no_abort
		return 0
	fi

	Make_rlinks_now
	if [ "$?" != 1 ]
	then
		echo "Hit return to continue: \c"
		read Whatever
		Cleanup_no_abort
		return 0
	fi

	# Now make remote objects
	Make_remote_objects
	if [ "$?" = 0 ]
	then
		echo "Hit return to continue: \c"
		read Whatever
		Cleanup_no_abort
		return 0
	fi


#DEBUG
#echo "CLEANUP=$CLEANUP"
#for SECONDARY_HOST in $REMOTE_HOSTS
#do
#	CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
#	if [ ! -f $CLEANUP_FILE ]
#	then
#		echo "ERROR: Could not find $CLEANUP_FILE,"
#		echo "       so skipping clean up of $SECONDARY_HOST"
#		continue
#	fi
#	REMOTE_CLEANUP=`awk '{ printf "%s", $0 }' $CLEANUP_FILE`
#        echo "$SECONDARY_HOST:Remote cleanup: $REMOTE_CLEANUP"
#done
#echo "Hit return to continue: \c"
#read Whatever

	CLEANUP=""
	REMOTE_HOSTS=""
	/bin/rm -f /tmp/vvr.remote_cleanup.*
	echo ""
	echo "Set up was successful."

	if [ "$DV_SRVMLOG" = "yes" ]; then
	   echo "RVG is created with data volumes having dcm log . You may wish to attach the"
	   echo "rlinks in Automatic Synchronization mode to copy the data from Primary to secondary."
	else
	   echo "Now you may wish to select \"Create/Copy Primary Checkpoint Data\" from the main"
	   echo "menu.  Then, after a copy of the data has been loaded onto the new secondary"
	   echo "data volumes, select \"Attach an RLINK\" from the main menu."
	fi
	echo "Hit return to continue: \c"
	read Whatever
	return 1
}

#1143G
Verify_and_then_add_range_of_data_volumes_specified()
{
clear
RANGE_ERRORS=0
I=0
	if [ "$NUM_DATAVOLS_TO_CREATE" = 0 ]
	then
		clear
		/bin/rm -f $CONFIG_TMP_FILE
		return 1
	fi
	/bin/rm -f $CONFIG_2TMP_FILE
	while [ 1 ]
	do
		I=`expr $I + 1`
		if [ "$I" -gt "$NUM_DATAVOLS_TO_CREATE" ]
		then
			break
		fi
		VOLNAME=`echo "$I" | awk '{ printf "'${PREFIX}'vol%02d", $1 }'`

		$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -htQq "$VOLNAME" 2> /dev/null 1> /dev/null
		if [ "$?" = 0 ]
        	then
			echo "Object $VOLNAME already exists."
			RANGE_ERRORS=`expr $RANGE_ERRORS + 1`
			continue
		fi
		NAME=$VOLNAME
		Check_if_name_is_in_use_by_config_file
		if [ "$?" = 1 ]
		then
			echo "Volume name $VOLNAME has already been specified for use."
			RANGE_ERRORS=`expr $RANGE_ERRORS + 1`
			continue
		fi
		/bin/cat -s $CONFIG_FILE $CONFIG_TMP_FILE > $CONFIG_2TMP_FILE
		awk '/#DV  Data_Volume_Name/ { count=count+1 } END { if (count == 0) 
			printf "\n%s\n%s\n", "#DV  Data_Volume_Name  Length  Mirrors  dcmlog  Create/Exists", "#DV  ----------------  ------  -------  -------------    -------------"}' $CONFIG_2TMP_FILE >> $CONFIG_TMP_FILE
		/bin/rm -f $CONFIG_2TMP_FILE
		
awk 'END { printf "DV   %-17s %+6s  %7d  %6s  CREATE\n", "'$VOLNAME'", "'$NEW_DATAVOLS_SIZE'", "'$NEW_DATAVOLS_MIRRORS'", "'${DATAVOL_LOGSRVM}'" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
	done
	if [ "$RANGE_ERRORS" != "0" ]
	then
		echo "Aborting due to $RANGE_ERRORS errors in requested configuration"
		echo "Hit return to continue: \c"
		read Whatever
		clear
		/bin/rm -f $CONFIG_TMP_FILE
		return 0
	else
		/bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
		/bin/rm -f $CONFIG_TMP_FILE
		clear
		return 1
	fi
}

#11434
Default_number_of_mirrors_for_new_data_volumes()
{
clear
        echo "Enter the number of additional mirrors to create for each of the new${SECONDARY}data"
	echo "volumes (newline to back up): \c"
        NEW_DV_MIRRORS=""
        while [ "$NEW_DV_MIRRORS" = "" ]
        do
                read NEW_DV_MIRRORS 
                case "$NEW_DV_MIRRORS" in
		    "" )    break;;
		    [0-9] | [0-9][0-9]) break;;
		    [0-9][0-9][0-9]*) echo "Currently, you can only specify up to 99 mirrors of each${SECONDARY}data volume"
			    NEW_DV_MIRRORS=""
        		    echo "Enter the number of additional mirrors to create for each of the new${SECONDARY}data"
			    echo "volumes (newline to back up): \c"
			    continue;;
		    * )	    echo "Bad input"
			    NEW_DV_MIRRORS=""
        		    echo "Enter the number of additional mirrors to create for each of the new${SECONDARY}data"
			    echo "volumes (newline to back up): \c"
			    continue;;
                esac
        done
	if [ "$NEW_DV_MIRRORS" != "" ]
	then 
		NEW_DATAVOLS_MIRRORS="$NEW_DV_MIRRORS"
	fi
clear
}

#11433
Default_size_for_new_data_volumes()
{
clear
	echo "Default size for new${SECONDARY}data volume(s)"
	echo ""
	echo "Size can be entered using standard VxVM suffix characters:"
	echo "	b    multiply the length by 512 bytes (blocks)"
	echo "	s    multiply the length by the standard sectors size (default)"
	echo "	k    multiply the length by 1024 bytes (Kilobytes)"
	echo "	m    multiply the length by 1,048,576 (1024K) bytes (Megabytes)"
	echo "	g    multiply the length by 1,073,741,824 (1024M) bytes (Gigabytes)"
	echo ""
	echo "Example: 100m"
	echo ""
        echo "Enter the size for the new${SECONDARY}data volumes to create (newline to"
	echo "back up): \c"
        SIZE_DV_TO_CREATE=""
        while [ "$SIZE_DV_TO_CREATE" = "" ]
        do
                read SIZE_DV_TO_CREATE 
	    	case "$SIZE_DV_TO_CREATE" in
			"" )		break;;
			*[\^\&\*\(\)\-\|\\\~\`\[\]\!\ \/\:\;\'\"\?\<\>\.\,@#$%*_+={}]* | *[a-zA-Z]*[[a-zA-Z]* ) 
					LEN="";;
			[0-9]*s )	LEN=`echo $SIZE_DV_TO_CREATE | /bin/tr s " "`;;
			[0-9]*b )	LEN=`echo $SIZE_DV_TO_CREATE | /bin/tr b " "`;;
			[0-9]*k )	TMP=`echo $SIZE_DV_TO_CREATE | /bin/tr k " "` 
						LEN=`expr $TMP \* 2` ;;
			[0-9]*m )	TMP=`echo $SIZE_DV_TO_CREATE | /bin/tr m " "`  
						LEN=`expr $TMP \* 2048` ;;
			[0-9]*g )	TMP=`echo $SIZE_DV_TO_CREATE | /bin/tr g " "`  
						LEN=`expr $TMP \* 2097152` ;;
			[0-9] | [0-9]*[0-9] )LEN="$SIZE_DV_TO_CREATE";;
			* )			LEN="";;
	    	esac
		if [ "$LEN" = "" ]
		then
			echo "Bad length input."
			SIZE_DV_TO_CREATE=""
        		echo "Enter the size for the new${SECONDARY}data volumes to create (newline to"
			echo "back up): \c"
			continue
		fi
        done
	if [ "$SIZE_DV_TO_CREATE" != "" ]
	then 
		NEW_DATAVOLS_SIZE="$SIZE_DV_TO_CREATE"
	fi
clear
}

#11431
Number_of_new_data_volumes_to_create()
{
clear
        echo "Enter the number of${SECONDARY}data volumes to create (newline to back up): \c"
        NUM_DV_TO_CREATE=""
        while [ "$NUM_DV_TO_CREATE" = "" ]
        do
                read NUM_DV_TO_CREATE 
                case "$NUM_DV_TO_CREATE" in
		    "" )    break;;
		    [0-9] | [0-9][0-9] ) break;;
		    [0-9][0-9][0-9] ) echo "Currently, you can only specify up to 99${SECONDARY}data volumes to be created"
			    NUM_DV_TO_CREATE=""
			    echo "Enter the number of${SECONDARY}data volumes to create (newline to return): \c"
			    continue;;
		    * )	    echo "Bad input"
			    NUM_DV_TO_CREATE=""
			    echo "Enter the number of${SECONDARY}data volumes to create (newline to return): \c"
			    continue;;
                esac
        done
	if [ "$NUM_DV_TO_CREATE" != "" ]
	then 
		NUM_DATAVOLS_TO_CREATE="$NUM_DV_TO_CREATE"
	fi
clear
}

#1143
Specify_a_range_of_data_volumes_to_create()
{
clear
/bin/cp $CONFIG_FILE $CONFIG_AUX_ORIG_FILE
NUM_DATAVOLS_TO_CREATE=1
NEW_DATAVOLS_SIZE=100m
NEW_DATAVOLS_MIRRORS=0
SECONDARY=" "

while [ 1 ] 
do
	clear
	MENU_LENGTH=21
	Summarize_Create_an_Rvg
	echo "Specify a Range Of Data Volumes To Create"
	echo ""
	echo "All of the data volumes will have the same size and number of mirrors."
	echo "Volumes will be named {prefix}vol01 thru {prefix}vol{nn} where nn is"
	echo "the number of data volumes to create.  Example: id-vol01 thru id-vol23."
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    Specify a range of data volumes to create (ie id-vol01 thru id-vol23):"
	echo "    1  Number of new data volumes to create:                      `awk 'END { printf "%02d", '$NUM_DATAVOLS_TO_CREATE' }' $CONFIG_FILE`"
	echo "    2  Default prefix for new datavol names (ie id-):             $PREFIX"
	echo "    3  Default size for new data volumes:                         $NEW_DATAVOLS_SIZE"
	echo "    4  Default number of additional mirrors for new data volumes: $NEW_DATAVOLS_MIRRORS"
	echo ""		
	echo "    s  Show summary of set-up work specified so far"
	echo "    g  Go -- verify and then add range of data volumes specified to Summary"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
	case "$CHOICE" in
		1 ) Number_of_new_data_volumes_to_create;;
		2 ) Default_prefix_for_names;;
		3 ) Default_size_for_new_data_volumes;;
		4 ) Default_number_of_mirrors_for_new_data_volumes;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
		[gG] ) Verify_and_then_add_range_of_data_volumes_specified
		    if [ "$?" = 1 ]
		    then
			Verify_Cfg_File
                        if [ "$?" = 0 ]
                        then
				clear
                        fi
		    	break
		    else
			clear
		    fi;;
		[rR] ) Remote_Vxprint;;
		[vV] ) Vxprint;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_AUX_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
                                        /bin/mv -f $CONFIG_AUX_ORIG_FILE $CONFIG_FILE
                                        break
                                else
                                        clear
                                fi
                        else
                                break
                        fi;;
		[qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
		* ) echo "Invalid input: $CHOICE"
			echo "Hit return to continue: \c"
			read Whatever
		    CHOICE="";;
	esac
done
/bin/rm -f $CONFIG_AUX_ORIG_FILE
clear
}


#1151
Select_name_of_existing_volume_to_add_as_the_SRL_volume()
{
SET_SRL_VOL_SUCCESS=0
clear
	ALREADY_HAS_SRLVOL=`/bin/egrep '^LV' $CONFIG_FILE`
	if [ "$?" != 1 ]
	then

		Y_OR_N=""
		while [ "$Y_OR_N" = "" ]
		do
			echo "Volume `awk '/^LV/ { printf "%s", $2 }' $CONFIG_FILE` has already been specified for the SRL volume.  Ignore that"
			echo "specification and specify a different SRL volume? (default: n) (y/n): \c"
			read Y_OR_N
			case "$Y_OR_N" in
				"" )    Y_OR_N=n;;
				[yY] ) Y_OR_N=y;;
				[nN] ) Y_OR_N=n;;
				* )     echo "Invalid input"
				Y_OR_N="" ;;
			esac
		done
		if [ "$Y_OR_N" = "n" ]
		then
			SET_SRL_VOL_SUCCESS=1
			return
		else
			awk '{ if ( $1 != "LV" && $0 != "#LV  SRL_Volume_Name   Length  Mirrors  Create/Exists" && $0 != "#LV  ----------------  ------  -------  -------------" ) print $0 }' $CONFIG_FILE > $CONFIG_TMP_FILE
			/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
			clear
		fi
	fi

	$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -tvQq 2> /dev/null 1> $VXPRINT_FILE
	if [ "$?" != 0 ]
        then
               	echo "Error trying to get list of parent-less existing volumes in diskgroup ${DISKGROUP:-rootdg}."
		echo "Hit return to continue: \c"
		read Whatever
		clear
		/bin/rm -f $VXPRINT_FILE
		return
        fi
	awk '{ if ( $3 == "-" ) print }' $VXPRINT_FILE > ${VXPRINT_FILE}.tmp
	/bin/mv -f ${VXPRINT_FILE}.tmp $VXPRINT_FILE
	if [ -s $VXPRINT_FILE ]
	then
		echo "Existing volumes found in diskgroup ${DISKGROUP:-rootdg} that are not associated with an RVG:"
		awk '{ printf "\t%d\t%-15s  Length=%s\n", NR, $2, $6}  
		       END {printf "\n"}' $VXPRINT_FILE
	else
		echo "Could not find any existing volumes in diskgroup ${DISKGROUP:-rootdg}"
		echo "Hit return to continue: \c"
		read Whatever
		clear
		/bin/rm -f $VXPRINT_FILE
		return
	fi

	echo "Enter number of existing volume to be added as the SRL volume. Enter an"
	echo "empty line to return to previous menu without selecting a volume."
	echo "Note that the SRL volume must have a minimum size of 300 sectors."
	echo ""
	echo "Example:	Existing volumes found in diskgroup rootdg:"
	echo "			1 id-vol01  Length=204800"
	echo "			2 id-vol02  Length=204800"
	echo "			3 id-vol03  Length=204800"
	echo ""
	echo "	Enter \"2\" to select id-vol02 as the SRL volume"
	echo ""

	LINE=xxxxxx
	while [ "$LINE" != "" ]
	do
		echo "Number of volume to add as the SRL volume to $RVG in diskgroup ${DISKGROUP:-rootdg}: \c"
		read LINE
		if [ "$LINE" = "" ]
		then
			break
		fi
                set -- $LINE

		if [ "$2" != "" ] 
		then
			echo "Only enter one number to select the single volume to be used as the SRL volume."
			echo "Ignoring that value."
			continue
		fi

		case "$1" in
			[0-9] | [0-9]*[0-9] ) VOLNAME=`awk '{ if (NR == '$1') printf "%s", $2 }' $VXPRINT_FILE`;;
			* ) 	echo "Invalid input: $1.  Ignoring that value."
				continue;;
		esac

		if [ "$1" -gt `wc -l $VXPRINT_FILE | /bin/sed 's/  */ /g' | /bin/cut -d' ' -f2` ]
		then
			echo "Input number is too big: $1.  Ignoring that value."
			continue
		fi
		if [ "$1" -lt 1 ]
		then
			echo "Input number is too small: $1.  Ignoring that value."
			continue
		fi

		NAME=$VOLNAME
		Check_if_name_is_in_use_by_config_file
		if [ "$?" = 1 ]
		then
			echo "Volume name $VOLNAME has already been specified for use.  Ignoring that volume."
			continue
		fi

		LEN=`awk '/v  '$VOLNAME' / { print $6 }' $VXPRINT_FILE`
	    	case "$LEN" in
			[0-9]*s )	SRLVOL_LEN=`echo $LEN | /bin/tr s " "`;;
			[0-9]*b )	SRLVOL_LEN=`echo $LEN | /bin/tr b " "`;;
			[0-9]*k )	TMP=`echo $LEN | /bin/tr k " "` 
						SRLVOL_LEN=`expr $TMP \* 2` ;;
			[0-9]*m )	TMP=`echo $LEN | /bin/tr m " "`  
						SRLVOL_LEN=`expr $TMP \* 2048` ;;
			[0-9]*g )	TMP=`echo $LEN | /bin/tr g " "`  
						SRLVOL_LEN=`expr $TMP \* 2097152` ;;
			[0-9] | [0-9]*[0-9] )SRLVOL_LEN="$LEN";;
			* )			SRLVOL_LEN=$LEN;;
	    	esac

		if [ "$SRLVOL_LEN" -lt 300 ]
		then
			echo "Length of $VOLNAME (${SRLVOL_LEN}) is too small (less than 300 sectors)."
			continue
		fi

		MIRRORS=`$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -hQq "$VOLNAME" | /bin/egrep -c "^pl "`
		MIRRORS=`expr $MIRRORS - 1`
		echo "" >> $CONFIG_FILE
		echo "#LV  SRL_Volume_Name   Length  Mirrors  Create/Exists" >> $CONFIG_FILE
		echo "#LV  ----------------  ------  -------  -------------" >> $CONFIG_FILE
		awk 'END { printf "LV   %-17s %+6s  %7d  EXISTS", "'$VOLNAME'", "'$SRLVOL_LEN'", "'$MIRRORS'" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		echo "" >> $CONFIG_TMP_FILE
		/bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
		/bin/rm -f $CONFIG_TMP_FILE
		SET_SRL_VOL_SUCCESS=1
		SRLVOL=$VOLNAME; SRLVOL_MIRRORS=$MIRRORS
		SRLVOL_EXISTENCE="EXISTS"
		LINE=""
	done
clear
/bin/rm -f $VXPRINT_FILE
/bin/rm -f $CONFIG_TMP_FILE
}

#33
Select_a_STALE_rlink_to_attach_or_all()
{
clear
	echo "Select a STALE RLINK to attach or \"all\""
	echo ""
        if [ "$RVG_NAME" = "" ]
        then
		echo "No Primary RVG selected, yet."
		echo "Select a Primary RVG first."
		echo "Hit return to continue: \c"
		read Whatever
		return 0
	fi

        $VXVM_BIN/vxprint -g ${DISKGROUP:-rootdg} -htQ $RVG_NAME 2>/dev/null 1> $VXPRINT_FILE
        if [ "$?" != 0 ]
        then
		echo "ERROR: Could not get information about $RVG_NAME in ${DISKGROUP:-rootdg}"
		echo "Hit return to continue: \c"
		read Whatever
		return 0
	fi

	echo "STALE rlinks found for $RVG_NAME in diskgroup ${DISKGROUP:-rootdg}:"
	awk '/^rl / { if ( $5 == "STALE" ) { count=count + 1
		      printf "%-2s %-19s %-8s %-8s %-8s %-9s %s\n", count, $2, $4, $5, $6, $7, $8 } }' $VXPRINT_FILE > ${VXPRINT_FILE}.2
	/bin/mv -f ${VXPRINT_FILE}.2 $VXPRINT_FILE
	if [ ! -s $VXPRINT_FILE ]
	then 
		echo "ERROR: No STALE rlinks found"
		ATTRLK=""
               	echo "Hit return to continue: \c"
               	read Whatever
               	return 0
	fi
	echo "   NAME                KSTATE   STATE    REM_HOST REM_DG    REM_RLK"
# If ambitious, check screen size here and pipe thru "more -w"
	/bin/cat $VXPRINT_FILE

	echo ""
	echo "Enter number (from first column, above) of RLINK to attach, or type all to"
	echo "attach all of the STALE rlinks.  Enter an empty line to return to previous"
	echo "menu without selecting an rlink."
	echo ""
	NUM_LINES=`wc -l $VXPRINT_FILE | /bin/sed 's/  */ /g' | /bin/cut -d' ' -f2`

        LINE=xxxxxx
        while [ "$LINE" != "" ]
	do
		echo "Number of RLINK to add or \"all\" for all: \c"
                read LINE
		if [ "$LINE" = "" ]
		then
			break
		fi
                set -- $LINE

                if [ "$2" != "" ]
                then
                        echo "Only enter one number or the keyword all."
                        echo "Ignoring that value."
                        continue
                fi

                case "$1" in
			all ) 	ATTRLK=all
				return 1;;
                        [0-9] | [0-9]*[0-9] ) ATTRLK=`awk '{ if (NR == '$1') printf "%s", $2 }' $VXPRINT_FILE`;;
                        * )     echo "Invalid input: $1.  Ignoring that value."
                                continue;;
                esac

                if [ "$1" -gt "$NUM_LINES" ]
                then
                        echo "Input number is too big: $1.  Ignoring that value.
"
                        continue
                fi
                if [ "$1" -lt 1 ]
                then
                        echo "Input number is too small: $1.  Ignoring that value."
                        continue
                fi
		LINE=""
	done
	return 1
clear
}

# Inputs:
#	RLK		Rlink to attach
#	RVG_NAME	Parent rvg
Do_rlink_attach()
{
	echo "Starting attach operations for Primary RLINK $RLK of RVG $RVG_NAME..."
	set -- `$VXVM_BIN/vxprint -g ${DISKGROUP:-rootdg} -tqQ $RLK 2>/dev/null`
	if [ "$RLK" != "$2" ]
	then
		echo "ERROR: Could not get information about RLINK $RLK"
		return 0
	fi
	if [ "$RVG_NAME" != "$3" ]
	then
		echo "ERROR: Expected parent RVG for $RLK is $RVG_NAME, actual is $3"
		return 0
	fi
	if [ "$5" != STALE ]
	then
		echo "ERROR: Expected state of $RLK is STALE, actual is $5"
		return 0
	fi
	SECONDARY_HOST=$6
	SECONDARY_DISKGROUP=$7
	SECONDARY_RLINK=$8
	if [ "$SECONDARY_HOST" = "-" ]
	then
		echo "ERROR: Rlink $RLK does not have its remote_host attribute specified"
		return 0
	fi
	if [ "$SECONDARY_DISKGROUP" = "-" ]
	then
		echo "ERROR: Rlink $RLK does not have its remote_dg attribute specified"
		return 0
	fi
	if [ "$SECONDARY_RLINK" = "-" ]
	then
		echo "ERROR: Rlink $RLK does not have its remote_rlink attribute specified"
		return 0
	fi

	echo "Getting information about Secondary RLINK $SECONDARY_RLINK from host ${SECONDARY_HOST}..."
	REMOTE_CMD="$VXVM_BIN/vxprint -g $SECONDARY_DISKGROUP -tQq $SECONDARY_RLINK"
	Do_Remote_Cmd > $CONFIG_3TMP_FILE
	if [ "$?" != 0 ]
	then
		echo "ERROR: Could not get information about Secondary RLINK $SECONDARY_RLINK from host $SECONDARY_HOST"
		/bin/rm -f $CONFIG_3TMP_FILE
		return 0
	fi
	set -- `/bin/cat $CONFIG_3TMP_FILE`
	/bin/rm -f $CONFIG_3TMP_FILE
	if [ "$2" != "$SECONDARY_RLINK" ]
	then
		echo "ERROR: Error getting information about Secondary RLINK $SECONDARY_RLINK from host $SECONDARY_HOST"
		return 0
	fi
	if [ "$7" != "${DISKGROUP:-rootdg}" ]
	then
		echo "ERROR: Conflicting Primary rootdg values: Secondary RLINK $SECONDARY_RLINK says $7, not ${DISKGROUP:-rootdg}"
		return 0
	fi
	if [ "$8" != "$RLK" ]
	then
		echo "ERROR: Conflicting Primary RLINK name values: Secondary RLINK $SECONDARY_RLINK says $8, not $RLK"
		return 0
	fi
	SECONDARY_RVG=$3

	if [ "$5" = STALE ]
	then
		echo "Attaching Secondary RLINK $SECONDARY_RLINK on host $SECONDARY_HOST to its parent $SECONDARY_RVG..."
		REMOTE_CMD="$VXVM_BIN/vxrlink -g "$SECONDARY_DISKGROUP" -f att "$SECONDARY_RLINK""
		echo "$SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd
        	if [ "$?" != 0 ]
        	then
			echo "ERROR: Could not attach Secondary RLINK $SECONDARY_RLINK on $SECONDARY_HOST"
			return 0
		fi
		REMOTE_CLEANUP_DET_SECONDARY_RLINK
	fi

	echo "Getting information about Secondary RVG $SECONDARY_RVG from host ${SECONDARY_HOST}..."
	REMOTE_CMD="$VXVM_BIN/vxprint -g $SECONDARY_DISKGROUP -tQq $SECONDARY_RVG"
	Do_Remote_Cmd > $CONFIG_3TMP_FILE
	if [ "$?" != 0 ]
	then
		echo "ERROR: Could not get information about Secondary RVG $SECONDARY_RVG from host $SECONDARY_HOST"
		/bin/rm -f $CONFIG_3TMP_FILE
		return 0
	fi
        set -- `/bin/cat $CONFIG_3TMP_FILE`
        /bin/rm -f $CONFIG_3TMP_FILE
        if [ "$2" != "$SECONDARY_RVG" ]
        then
                echo "ERROR: Error getting information about Secondary RVG $SECONDARY_RVG from host $SECONDARY_HOST"
                return 0
        fi
	if [ "$6" != "secondary" ]
	then
		echo "ERROR: Secondary RVG $SECONDARY_RVG on host $SECONDARY_HOST has the Primary attribute set"
		return 0
	fi
	if [ "$8" = "(none)" ]
	then
		echo "ERROR: Secondary RVG $SECONDARY_RVG on host $SECONDARY_HOST has no SRL volume"
		return 0
	fi

	if [ "$5" != ACTIVE ]
	then
		echo "Starting Secondary RVG $SECONDARY_RVG on host ${SECONDARY_HOST}..."
		REMOTE_CMD="$VXVM_BIN/vxrvg -g $SECONDARY_DISKGROUP start $SECONDARY_RVG"
		echo "$SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd
		if [ "$?" != 0 ]
		then
			echo "ERROR: Could not start Secondary RVG $SECONDARY_RVG on host ${SECONDARY_HOST}"
			return 0
		fi
		REMOTE_CLEANUP_STOP_SECONDARY_RVG
	fi

	if [ "$ATTACH_MODE" = "yes" ]
	then
	  echo "Attaching Primary RLINK $RLK in autosync mode"
	  echo "$VXVM_BIN/vxrlink -g ${DISKGROUP:-rootdg} -a att $RLK"
	  $VXVM_BIN/vxrlink -g "${DISKGROUP:-rootdg}" -a  att "$RLK"
	else
	  echo "Attaching Primary RLINK $RLK using checkpoint string: \"""$CHECKPOINT_STRING""\""
	  echo "$VXVM_BIN/vxrlink -g ${DISKGROUP:-rootdg} -c \"""$CHECKPOINT_STRING""\" att $RLK"
	  $VXVM_BIN/vxrlink -g "${DISKGROUP:-rootdg}" -c "$CHECKPOINT_STRING" att "$RLK"
	fi
        if [ "$?" != 0 ]
        then
                echo "ERROR: Attach of Primary RLINK $RLINK to $RVG_NAME failed"
		return 0
        fi
	CLEANUP_RL=$RLK
	CLEANUP_DET_RLINK

	return 1
}

# Inputs:
#	RVG_NAME	Primary RVG to start
#	MUST_BE_PRIMARY=yes	Start a Primary rvg
#	MUST_BE_PRIMARY=no	Start either a Primary or a Secondary rvg
Do_rvg_start()
{
	$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -tQq "$RVG_NAME" > $VXPRINT_FILE 2>/dev/null
	if [ "$?" != 0 ]
	then
		echo "ERROR: Could not get information about RVG $RVG_NAME"
		return 0
	fi

	set -- `/bin/cat $VXPRINT_FILE`
	if [ "$2" != "$RVG_NAME" ]
	then
		echo "ERROR: Error getting information about RVG $RVG_NAME"
		return 0
	fi
	if [ "$MUST_BE_PRIMARY" = "yes" ] && [ "$6" != "primary" ]
	then
		echo "ERROR: RVG $RVG_NAME does not have the Primary attribute set"
		return 0
	fi
	if [ "$5" = ACTIVE ]
	then
		echo "WARNING: RVG $RVG_NAME is already ACTIVE"
		LAST_DG=$DISKGROUP
		LAST_RVG=$RVG_NAME
		return 1
	fi

	$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -htQq "$RVG_NAME" 2>/dev/null | /bin/egrep "^rl " > $VXPRINT_FILE

	if [ ! -s $VXPRINT_FILE ]
	then
		echo "WARNING: RVG $RVG_NAME has no rlinks."
	else
		awk '{ if ( $5 == "STALE" ) printf "WARNING: Rlink %s is STALE.  It will require a checkpoint attach to synchronize it\n", $2 }' $VXPRINT_FILE
	fi

	if [ "$MUST_BE_PRIMARY" = "yes" ]
	then
		echo "Starting Primary RVG ${RVG_NAME}..."
	else
		echo "Starting RVG ${RVG_NAME}..."
	fi
	echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" start "$RVG_NAME""
	$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" start "$RVG_NAME"
	if [ "$?" != 0 ]
	then
		echo "ERROR: Failure while trying to start Primary RVG $RVG_NAME"
		return 0
	fi

	return 1
}

Do_rvg_start_if_requested()
{
                START_ANSWER=""
                while [ "$START_ANSWER" = "" ]
                do
                    echo "Start Primary RVG $RVG_NAME now? (y/n) (default: y): \c"
                    read START_ANSWER
                    case "$START_ANSWER" in
                        "" )    START_ANSWER=y;;
                        [yY] ) START_ANSWER=y;;
                        [nN] ) return 1;;
                        * )     START_ANSWER="";;
                    esac
                done

		MUST_BE_PRIMARY=yes
                Do_rvg_start
                EXIT_STATUS="$?"
                if [ "$EXIT_STATUS" = 1 ]
                then
                        echo "Start of Primary RVG $RVG_NAME succeeded"
                fi
                echo "Hit return to continue: \c"
                read Whatever
                return "$EXIT_STATUS"
}

# Inputs:
#	ATTRLK		Rlink to attach or "all"
#	RVG_NAME	Parent rvg
Go_Attach_Rlink_and_Attach_Secondary_Rlink_and_Start_Secondary_Rvg()
{
clear
ABORT=0
	if [ "$ATTRLK" != "all" ]
	then
		RLK="$ATTRLK"
		Do_rlink_attach
		if [ "$?" != 1 ]
		then
			echo "Attach of $RLK failed"
                        echo "Hit return to continue: \c"
                        read Whatever
			CLEANUP=""
			REMOTE_HOSTS=""
			/bin/rm -f /tmp/vvr.remote_cleanup.*
			return 0
		fi
		echo "Attach of $RLK succeeded"
		CLEANUP=""
		REMOTE_HOSTS=""
		/bin/rm -f /tmp/vvr.remote_cleanup.*
		LAST_RVG=$RVG_NAME
		LAST_DG=$DISKGROUP
		echo ""
		Do_rvg_start_if_requested
		return 1
	fi

	# Loop to process "all" STALE rlinks
	 $VXVM_BIN/vxprint -g ${DISKGROUP:-rootdg} -htQ $RVG_NAME 2>/dev/null | awk '/^rl / { if ( $5 == "STALE" ) { count=count + 1
			     printf "%-2s %-12s %-8s %-8s %-8s %-9s %s\n", count, $2, $4, $5, $6, $7, $8 } }' > $VXPRINT_FILE
	for RLK in `awk '{ printf "%s ", $2 }' $VXPRINT_FILE`
	do
		Do_rlink_attach
		EXIT_STATUS="$?"
		if [ "$EXIT_STATUS" = 0 ]
		then
			echo "Ignoring that rlink."
			ABORT=1
		fi
		echo ""
	done

	if [ "$ABORT" != 0 ]
	then
		echo "Attach of one or more rlinks failed."
		echo "Hit return to continue: \c"
		read Whatever
		CLEANUP=""
		REMOTE_HOSTS=""
		/bin/rm -f /tmp/vvr.remote_cleanup.*
		return 0
	fi
	echo "Attach of all STALE rlinks succeeded"
	CLEANUP=""
	REMOTE_HOSTS=""
	/bin/rm -f /tmp/vvr.remote_cleanup.*
	LAST_RVG=$RVG_NAME
	LAST_DG=$DISKGROUP
	echo ""
	Do_rvg_start_if_requested
	return 1
}

#4
Start_an_Rvg()
{
if [ "$LAST_DG" = "$DISKGROUP" ]
then
	RVG_NAME=$LAST_RVG
fi
while [ 1 ]
do
	clear 
	echo "Start an RVG"
	echo ""
	echo "This option should only be selected after all rlinks have been attached."
	echo ""
	if [ "$RVG_NAME" != "" ]
	then
	    $VXVM_BIN/vxprint -g ${DISKGROUP:-rootdg} -htQ $RVG_NAME 2>/dev/null 1> $VXPRINT_FILE
	    if [ "$?" = 0 ]
	    then
		echo "RVG info for current selection: $RVG_NAME in diskgroup ${DISKGROUP:-rootdg}:"
		awk '/^RV / || /^rv / {print $0 }' $VXPRINT_FILE
		echo ""
	    fi
	fi
	echo "Choose an option  (\"?\" for other options):"
	echo "    1  Disk group                                      ${DISKGROUP:-rootdg}"
	echo "    2  RVG to start                                  ${RVG_NAME:-<Unknown>}"
	echo ""
	echo "    g  Go -- Start rvg"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
        case "$CHOICE" in
                1 ) Diskgroup;;
                2 ) MUST_BE_PRIMARY=no
		    Rvg_to_select;;
                [gG] ) if [ "$DISKGROUP" = "" ]
			then 
				DISKGROUP=rootdg
			fi
			if [ "$RVG_NAME" = "" ]
			then
				echo "ERROR: Specify an RVG to start"
                        	echo "Hit return to continue: \c"
                        	read Whatever
				continue
			fi
			MUST_BE_PRIMARY=no
			Do_rvg_start
			if [ "$?" = 1 ]
			then
                        	echo "Start of RVG $RVG_NAME succeeded"
                		echo "Hit return to continue: \c"
				read Whatever
				break
			else
                        	echo "Start of RVG $RVG_NAME failed"
                		echo "Hit return to continue: \c"
				read Whatever
				clear
			fi;;
                [rR] ) Remote_Vxprint;;
                [vV] ) Vxprint;;
                [pP] ) break;;
                [qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
                "" ) CHOICE="";;
                * ) echo "Invalid input: $CHOICE"
                        echo "Hit return to continue: \c"
                        read Whatever
                    CHOICE="";;
        esac
done
clear
}

#3
Attach_a_Rlink()
{
clear
CHECKPOINT_STRING=""

ATTACH_MODE="$DATAVOL_LOGSRVM"
	echo "Attach an RLINK"
	echo ""
	echo "This option enables you to attach an RLINK that has already been"
	echo "set up. Choose this option if the data volumes have DCM logs "
	echo "associated with them. In this case, RLINKs can be attached in "
	echo "automatic synchronization mode to copy data from Primary data "
	echo "volume(s) to Secondary data volume(s)."
	echo "			   OR      "
	echo "Choose this option only after checkpoint data from the Primary "
	echo "has been loaded on to the Secondary data volume(s) for the "
	echo "rlink(s) to be attached."
	echo ""
	ATTACH_IT=""
	while [ "$ATTACH_IT" = "" ]
	do
		echo "Proceed with Attach of RLINK? (y/n) (default: y): \c"
		read ATTACH_IT
		case "$ATTACH_IT" in
			"" )    ATTACH_IT=y
				break;;
			[yY] ) break;;
			[nN] ) return 1;;
                	* )     echo "Invalid input: $ATTACH_IT"
			        ATTACH_IT="" ;;
                esac
	done

if [ "$LAST_DG" = "$DISKGROUP" ]
then
	RVG_NAME=$LAST_RVG	#Make sure this RVG is in current dg
fi
ATTRLK=all
while [ 1 ]
do
	clear 
	echo "Attach an RLINK"
	echo ""
	echo "Specify the Primary rvg, diskgroup and rlink(s) to be attached."

	if [ "$RVG_NAME" != "" ]
	then
	    $VXVM_BIN/vxprint -g ${DISKGROUP:-rootdg} -htQ $RVG_NAME 2>/dev/null 1> $VXPRINT_FILE
	    if [ "$?" = 0 ]
	    then
		echo ""
		echo "Rlinks found for current selection:    $RVG_NAME in diskgroup ${DISKGROUP:-rootdg}:"
		echo "NAME                KSTATE   STATE    REM_HOST REM_DG    REM_RLK"
                awk '/^rl / { printf "%-19s %-8s %-8s %-8s %-9s %s\n", $2, $4, $5, $6, $7, $8 }' $VXPRINT_FILE
		if [ "$CHECKPOINT_STRING" = "" ]
		then
	    		CHECKPOINT_STRING=`$VXVM_BIN/vxprint -g ${DISKGROUP:-rootdg} -l $RVG_NAME 2>/dev/null | /bin/egrep "checkpoint:" | /bin/sed 's/checkpoint: //'`
		fi
	    fi
	fi

	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    1  Disk group                                      ${DISKGROUP:-rootdg}"
	echo "    2  Primary RVG                                    ${RVG_NAME:-<Unknown>}"
	echo "    3  Select a STALE RLINK to attach or \"all\"        ${ATTRLK}"
	echo "    4  Checkpoint string                              ${CHECKPOINT_STRING:-<none>}"
	echo "    5  Attach RLINKS in autosync mode                 ${ATTACH_MODE:-<no>}"
	echo ""
	echo "    g  Go -- Attach RLINK(s).  [On Secondary host(s), attaches RLINK and starts"
	echo "             RVG as needed.]"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
        case "$CHOICE" in
                1 ) Diskgroup;;
                2 ) MUST_BE_PRIMARY=yes
		    Rvg_to_select;;
                3 ) Select_a_STALE_rlink_to_attach_or_all;;
                4 ) ALLOW_BLANK_INPUT="yes"	
		    Checkpoint_string;;
		5 )  Get_rlink_attach_mode;
		     ;;
		
                [gG] ) if [ "$DISKGROUP" = "" ]
			then 
				DISKGROUP=rootdg
			fi
			if [ "$RVG_NAME" = "" ]
			then
				echo "ERROR: Specify an RVG to process rlinks for"
                        	echo "Hit return to continue: \c"
                        	read Whatever
				continue
			fi
			if [ "$ATTRLK" = "" ]
			then
				echo "ERROR: Specify a STALE RLINK to attach (or enter \"all\" for all)"
                        	echo "Hit return to continue: \c"
                        	read Whatever
				continue
			fi
		
		        if [ "$ATTACH_MODE" = "yes" ]
			then
				if [ "$CHECKPOINT_STRING" != "" ]
				then
				  echo "ERROR: Please Specify either of Attach Mode or Checkpoint String"
                        	  echo "Hit return to continue: \c"
                        	  read Whatever
				  continue
				fi
			else
			 if [ "$CHECKPOINT_STRING" = "" ]
			 then
				echo "ERROR: Specify the checkpoint string that was used to make the Primary checkpoint"
				echo "data [See \"Create/Copy Primary Checkpoint Data\" main menu option]".
				echo "Hit return to continue: \c"
                                read Whatever
                                continue
			 fi
			fi
			Go_Attach_Rlink_and_Attach_Secondary_Rlink_and_Start_Secondary_Rvg
			if [ "$?" = 1 ]
			then
				break
			else
				clear
			fi;;
                [rR] ) Remote_Vxprint;;
                [vV] ) Vxprint;;
                [pP] ) break;;
                [qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
                "" ) CHOICE="";;
                * ) echo "Invalid input: $CHOICE"
                        echo "Hit return to continue: \c"
                        read Whatever
                    CHOICE="";;
        esac
done
clear
}

Check_for_existing_secondary_entries()
{
EXISTING_SPEC=""
	SRV_CNT=`/bin/egrep -c "^SRV  *${RLINK}" $CONFIG_FILE`
	if [ "$SRV_CNT" -ne 0 ]
	then
		echo "ERROR: Found existing Secondary RVG set-up specification"
		EXISTING_SPEC="yes"
	fi

	SRL_CNT=`/bin/egrep -c "^SRL  *${RLINK}" $CONFIG_FILE`
	if [ "$SRL_CNT" -ne 0 ]
	then
		echo "ERROR: Found existing Secondary RLINK set-up specification"
		EXISTING_SPEC="yes"
	fi

	SDV_CNT=`/bin/egrep -c "^SDV  *${RLINK}" $CONFIG_FILE`
	if [ "$SDV_CNT" -ne 0 ]
	then
		echo "ERROR: Found existing Secondary data volume set-up specification"
		EXISTING_SPEC="yes"
	fi

	SLV_CNT=`/bin/egrep -c "^SLV  *${RLINK}" $CONFIG_FILE`
	if [ "$SLV_CNT" -ne 0 ]
	then
		echo "ERROR: Found existing Secondary SRL volume set-up specification"
		EXISTING_SPEC="yes"
	fi

	if [ "$EXISTING_SPEC" != "" ]
	then
		echo "From this menu, you cannot edit a Secondary object that you have already"
		echo "specified.  Select \"Create/Edit a custom Secondary RVG hierarchy\"."
		return 0
	fi

	return 1
}

Add_Secondary_Rvg_Hierarchy_To_Config()
{
ABORT=0
	RLK_CNT=`/bin/egrep -c "^RL  *${RLINK}" $CONFIG_FILE`
	if [ "$RLK_CNT" = 0 ]
	then
		echo "Could not find RLINK $RLINK in the current set-up configuration"
		return 0
	elif [ "$RLK_CNT" -gt 1 ]
	then
		echo "ERROR: Found multiple entries for RLINK $RLINK in the set-up configuration"
		return 0
	fi
	RVG=$RVG
	set -- `awk '/^RL  *'$RLINK' / { printf "%s %s", $4, $5 }' $CONFIG_FILE`
	SECONDARY_HOST=$1; SECONDARY_DISKGROUP=$2
	echo "...Processing Primary RLINK $RLINK in RVG $RVG in diskgroup $DISKGROUP"
	echo "...Remote host: $SECONDARY_HOST"

	# Confirm that there are not already SRV, SDV, SLV, or SRL entries for this rlink
	Check_for_existing_secondary_entries
	if [ "$?" = 0 ]
	then
		return 0
	fi

	echo "...adding Secondary RVG entry"
	NAME=$RVG
	Remote_check_if_name_is_in_use_by_VXVM
	if [ "$?" = 1 ]
	then
		echo "ERROR: Cannot create Secondary RVG named $RVG. That name is already in use on $SECONDARY_HOST"
		ABORT=1
	fi
	Check_if_name_is_in_use_by_config_file_for_remote
	if [ "$?" = 1 ]
	then
		echo "ERROR: Cannot create Secondary RVG named $RVG. That name is already specified for use on $SECONDARY_HOST"
		ABORT=1
	fi

	echo "" >> $CONFIG_FILE
	echo "#SRV Primary_Rlink     Rvg_Name          Diskgroup_Name  Create/Exists" >> $CONFIG_FILE
	echo "#    ----------------  ----------------  --------------  -------------" >> $CONFIG_FILE
	awk 'END { printf "SRV  %-17s %-17s %-14s  %s\n", "'$RLINK'", "'$RVG'", "'$SECONDARY_DISKGROUP'", "'${SECONDARY_RVG_EXISTENCE:-CREATE}'" }' $CONFIG_ORIG_FILE >> $CONFIG_FILE

	set -- `awk '/^RL  *'$RLINK' / { printf "%s %s %s %s %s %s %s", $6, $7, $8, $9, $10, $11, $12 }' $CONFIG_FILE`
	SECONDARY_RLINK=$1
	SYNC_MODE=$2; LATENCY_MODE=$3; SRLPROT_MODE=$4; HIGH_LATENCY=$5; LOW_LATENCY=$6
	RLK_EXISTENCE=$7
	Get_throttling_mode_strings
	if [ "$RLINK" != "$SECONDARY_RLINK" ]
	then
		echo "...adding Secondary RLINK $SECONDARY_RLINK for Primary RLINK $RLINK"
	else
		echo "...adding Secondary RLINK $RLINK"
	fi
	NAME=$SECONDARY_RLINK
	Remote_check_if_name_is_in_use_by_VXVM
	if [ "$?" = 1 ]
	then
		echo "ERROR: Cannot create Secondary RLINK named $SECONDARY_RLINK. That name is already in use on $SECONDARY_HOST"
		ABORT=1
	fi
	PARENT_RL_OK=$RLINK
	Check_if_name_is_in_use_by_config_file_for_remote
	if [ "$?" = 1 ]
	then
		echo "ERROR: Cannot create Secondary RLINK named $SECONDARY_RLINK. That name is already specified for use on $SECONDARY_HOST"
		ABORT=1
	fi
	PARENT_RL_OK=""

	echo "" >> $CONFIG_FILE
	echo "#SRL Primary_Rlink     Rlink_Name        Primary_host Primary_diskgroup Modes  HighLatency  LowLatency   Create/Exists" >> $CONFIG_FILE
	echo "#    ----------------  ----------------  -----------  ----------------  -----  -----------  -----------  -------------" >> $CONFIG_FILE
	awk 'END { printf "SRL  %-17s %-17s %-12s %-17s %-1s %-1s %-1s  %-11s  %-11s  %s\n", "'$RLINK'", "'$SECONDARY_RLINK'", "'$LOCAL_HOST'", "'$DISKGROUP'", "'$SYNC_MODE'", "'$LATENCY_MODE'", "'$SRLPROT_MODE'", "'${HIGH_LATENCY:-10000}'", "'${LOW_LATENCY:-9950}'", "CREATE" }' $CONFIG_ORIG_FILE >> $CONFIG_FILE

	if [ `/bin/egrep -c "^DV" $CONFIG_FILE` -ne 0 ]
	then
		echo "" >> $CONFIG_FILE
		echo "#SDV Primary_Rlink     Data_Volume_Name  Length  Mirrors  Create/Exists  Primary_Datavol   dcmlog" >> $CONFIG_FILE
		echo "#    ----------------  ----------------  ------  -------  -------------  ---------------- --------" >> $CONFIG_FILE

	fi
	for DV in `awk '/^DV / { printf "%s ", $2 } END { printf "\n" }' $CONFIG_FILE`
	do
		set -- `awk '/^DV  *'${DV}' / { printf "%s\n", $0 }' $CONFIG_FILE`
		DV_LEN=$3
		#DV_MIR=$4; 
		DV_MIR=0
		DV_CREATE=$6
		DV_LOG=$5
		
		echo "...adding Secondary data volume $DV length=$DV_LEN with no extra mirrors (CREATE)"
		NAME=$DV
		Remote_check_if_name_is_in_use_by_VXVM
		if [ "$?" = 1 ]
		then
			echo "ERROR: Cannot create Secondary data volume named $DV. That name is already"
			echo "in use on $SECONDARY_HOST"
			ABORT=1
		fi
		Check_if_name_is_in_use_by_config_file_for_remote
		if [ "$?" = 1 ]
		then
			echo "ERROR: Cannot create Secondary data volume named $DV. That name is already"
			echo "specified for use on $SECONDARY_HOST"
			ABORT=1
		fi

		awk 'END { printf "SDV  %-17s %-17s %+6s  %7d  %-13s  %s   %-6s\n", "'$RLINK'", "'$DV'", "'$DV_LEN'", "'$DV_MIR'", "CREATE", "'$DV'", "'$DV_LOG'" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		/bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
		/bin/rm -f $CONFIG_TMP_FILE
	done

	LV_CNT=`/bin/egrep -c "^LV" $CONFIG_FILE`
	if [ "$LV_CNT" -eq 1 ]
	then
		echo "" >> $CONFIG_FILE
		echo "#SLV Primary_Rlink     SRL_Volume_Name   Length  Mirrors  Create/Exists" >> $CONFIG_FILE
		echo "#    ----------------  ----------------  ------  -------  -------------" >> $CONFIG_FILE

		set -- `awk '/^LV/ { printf "%s\n", $0 }' $CONFIG_FILE`
		SRLVOL=$2
		SRLVOL_LEN=$3
		SRLVOL_MIRRORS=$4
		SRLVOL_EXISTENCE=$5
		SIZESTRING=$SRLVOL_LEN
		SizeString_To_Len
		if [ "$LEN" -gt 204800 ]
		then
			SRLVOL_LEN=100m
			echo "...NOTE: Reducing the size of the Secondary SRL volume to 100m (it's enough)."
		fi
		echo "...adding Secondary SRL volume $SRLVOL length=$SRLVOL_LEN with $SRLVOL_MIRRORS additional mirrors (CREATE)"
		NAME=$SRLVOL
		Remote_check_if_name_is_in_use_by_VXVM
		if [ "$?" = 1 ]
		then
			echo "ERROR: Cannot create Secondary SRL volume named $SRLVOL. That name is already"
			echo "in use on $SECONDARY_HOST"
			ABORT=1
		fi
		Check_if_name_is_in_use_by_config_file_for_remote
		if [ "$?" = 1 ]
		then
			echo "ERROR: Cannot create Secondary SRL volume named $SRLVOL. That name is already"
			echo "specified for use on $SECONDARY_HOST"
			ABORT=1
		fi

		awk 'END { printf "SLV  %-17s %-17s %+6s  %7d  %6s\n", "'$RLINK'", "'$SRLVOL'", "'$SRLVOL_LEN'", "'$SRLVOL_MIRRORS'", "CREATE" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		/bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
		/bin/rm -f $CONFIG_TMP_FILE
	elif [ "$LV_CNT" -gt 1 ]
	then
		echo "ERROR: Multiple Primary SRL volume entries found in current set-up configuration"
		return 0
	fi

	if [ "$ABORT" -ne 0 ]
	then
		echo ""
		echo "Aborting due to previous error(s)"
		return 0
	fi

	return 1
}

#1172
Set_up_default_secondary_rvg_hierarchy()
{
/bin/cp $CONFIG_FILE $CONFIG_ORIG_FILE
SECONDARY_RVG_EXISTENCE="CREATE"
SECONDARY_RLK_EXISTENCE="CREATE"

clear
	set -- `awk '/^RL  *'$RLINK' / { print $0 }' $CONFIG_FILE`
	RLINK=$2; SECONDARY_HOST=$4; SECONDARY_DISKGROUP=$5; SECONDARY_RLINK=$6
	SYNC_MODE=$7; LATENCY_MODE=$8; SRLPROT_MODE=$9 OTHERSTUFF=$10

        echo "Set up default Secondary RVG hierarchy"
	echo ""
	echo "A hierarchy of objects will be set up on the Secondary host which mirrors the"
	echo "primary RVG hierarchy.  The same names will be used for the RVG, SRL volume and"
	echo "data volumes as on the primary, and the data volumes will be the same size."
	echo "The Secondary SRL volume size will be set to the smaller of 100m and the"
	echo "primary SRL volume size.  The Secondary SRL volume will have the same number of"
	echo "mirrors as the Primary SRL volume, but the Secondary data volumes will have"
	echo "only one plex (no extra copies).  If any of these object names are already in"
	echo "use on the secondary, then the entire operation is aborted."
	echo ""
	echo "Primary RLINK: $RLINK    Secondary host/diskgroup: $SECONDARY_HOST/${SECONDARY_DISKGROUP:-$DISKGROUP}"
	echo ""

	RLK_CNT=`/bin/egrep -c "^RL  *${RLINK}" $CONFIG_FILE`
	if [ "$RLK_CNT" = 0 ]
	then
		echo "Could not find RLINK $RLINK in the current set-up configuration"
                echo "Hit return to continue: \c"
                read Whatever
                /bin/mv -f $CONFIG_ORIG_FILE $CONFIG_FILE
                clear
                return 0
	elif [ "$RLK_CNT" -gt 1 ]
	then
		echo "ERROR: Found multiple entries for RLINK $RLINK in the set-up configuration"
                echo "Hit return to continue: \c"
                read Whatever
                /bin/mv -f $CONFIG_ORIG_FILE $CONFIG_FILE
                clear
		return 0
	fi
	RVG=$RVG
	set -- `awk '/^RL  *'$RLINK' / { printf "%s %s", $4, $5 }' $CONFIG_FILE`
	SECONDARY_HOST=$1; SECONDARY_DISKGROUP=$2

	# Confirm that there are not already SRV, SDV, SLV, or SRL entries for this rlink
	Check_for_existing_secondary_entries
	if [ "$?" = 0 ]
	then
                echo "Hit return to continue: \c"
                read Whatever
                /bin/mv -f $CONFIG_ORIG_FILE $CONFIG_FILE
                clear
		return 0
	fi

	echo "Hit return to continue, anything else to abort and back up: \c"
	read Whatever
	case "$Whatever" in
		"" )    ;;
		* )     /bin/rm -f $CONFIG_ORIG_FILE
			clear
			return 0;;
	esac
	Add_Secondary_Rvg_Hierarchy_To_Config
	if [ "$?" = 0 ]
	then
		echo "Hit return to continue: \c"
		read Whatever
		/bin/mv -f $CONFIG_ORIG_FILE $CONFIG_FILE
		clear
		return 0
	else
		echo "Hit return to continue: \c"
		read Whatever
	fi
clear
while [ 1 ] 
do
	clear
	MENU_LENGTH=16
	Summarize_Create_an_Rvg
        echo "Set up default Secondary RVG hierarchy"
	echo ""
	echo "A default RVG hiearchy for the Secondary has been configured.  "
	echo "Select \"Go\" to accept it or \"Previous\" to abort it"
	echo ""
	echo "Primary RLINK: $RLINK		Secondary host: $SECONDARY_HOST"
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    s  Show summary of set-up work specified so far"
        echo "    g  Go -- keep changes and return to \"Create an RVG\" menu"
        echo "    p  Previous -- abort changes and return to previous menu"
        echo "    r  Remote vxprint -ht"
        echo "    v  Local vxprint -ht"
        echo "    q  Quit"
        echo ""
        echo "    Enter option: \c"
        read CHOICE
        echo ""
        case "$CHOICE" in
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
                [gG] ) Verify_Cfg_File
                    if [ "$?" = 0 ]
                    then
			clear
                    fi
		    /bin/rm -f $CONFIG_ORIG_FILE
		    clear
		    return 1;;
                [rR] ) Remote_Vxprint;;
                [vV] ) Vxprint;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
                                        /bin/mv -f $CONFIG_ORIG_FILE $CONFIG_FILE
					clear
					return 0
                                else
                                        clear
                                fi
                        else
                                clear
				return 0
                        fi;;
                [qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
                * ) echo "Invalid input: $CHOICE"
                        echo "Hit return to continue: \c"
                        read Whatever
                    CHOICE="";;
        esac
done
# Never gets here.  Does a return from G or B
}

#1171
Primary_rlink_to_set_up_hierarchy_for()
{
clear
	/bin/rm -f $VERIFY_CFG_FILE
	awk '/^RL / { count=count+1 
		      printf "%-2s %s\n", count, $2 }' $CONFIG_FILE > $VERIFY_CFG_FILE
	if [ ! -s $VERIFY_CFG_FILE ]
	then
		echo "No Primary rlinks have been specified to be set up, yet"
		echo "Hit return to continue: \c"
		read Whatever
		/bin/rm -f $VERIFY_CFG_FILE
		return
	fi
	/bin/cat $VERIFY_CFG_FILE
	echo ""
        echo "Enter number (from first column, above) of Primary RLINK to select."
	echo "Enter an empty line to return to previous menu without selecting an rlink."
	echo ""
	NUM_LINES=`wc -l $VERIFY_CFG_FILE | /bin/sed 's/  */ /g' | /bin/cut -d' ' -f2`

        LINE=xxxxxx
        while [ "$LINE" != "" ]
	do
		echo "Number of Primary RLINK to select: \c"
                read LINE
		if [ "$LINE" = "" ]
		then
			/bin/rm -f $VERIFY_CFG_FILE
			return
		fi
                set -- $LINE

                if [ "$2" != "" ]
                then
                        echo "Only enter one number or the keyword all."
                        echo "Ignoring that value."
                        continue
                fi

                case "$1" in
                        [0-9] | [0-9]*[0-9] ) RLK_NAME=`awk '{ if (NR == '$1') printf "%s", $2 }' $VERIFY_CFG_FILE`;;
                        * )     echo "Invalid input: $1.  Ignoring that value."
                                continue;;
                esac

                if [ "$1" -gt "$NUM_LINES" ]
                then
                        echo "Input number is too big: $1.  Ignoring that value.
"
                        continue
                fi
                if [ "$1" -lt 1 ]
                then
                        echo "Input number is too small: $1.  Ignoring that value."
                        continue
                fi
		LINE=""
	done
	/bin/rm -f $VERIFY_CFG_FILE
        RLINK="$RLK_NAME"
        set -- `awk '/^RL  *'$RLINK' / { printf "%s %s", $4, $5 }' $CONFIG_FILE`
	SECONDARY_HOST=$1; SECONDARY_DISKGROUP=$2
clear
}

#117312
Secondary_rvg_name()
{
clear
	echo "Primary RLINK: $RLINK		Secondary host: $SECONDARY_HOST"
	echo ""
	echo "The Secondary RVG name defaults to the name of the parent RVG for the"
	echo "primary RLINK ($RVG)".
	echo ""
	echo "Enter name for the parent RVG of the Secondary RLINK (newline to"
	echo "back up): \c"
        NEW_SECONDARY_RVG=""
        while [ "$NEW_SECONDARY_RVG" = "" ]
        do
                read NEW_SECONDARY_RVG EXTRA
		if [ "$EXTRA" != "" ]
		then
			echo "Only enter one word for name.  No whitespace."
			echo "Enter name for the parent RVG of the Secondary RLINK (newline to"
			echo "back up): \c"
                        NEW_SECONDARY_RVG=""
			continue
		fi
                case "$NEW_SECONDARY_RVG" in
                    "" )    break;;
		    [a-z]* | [A-Z]* | _* ) ;;
                    * )     echo "Bad Secondary RVG name input"
                            NEW_SECONDARY_RVG=""
			    echo "Enter name for the parent RVG of the Secondary RLINK (newline to"
			    echo "back up): \c"
                            continue;;
                esac

		NAME=$NEW_SECONDARY_RVG
		Remote_check_if_name_is_in_use_by_VXVM
		if [ "$?" = 1 ]
        	then
			echo "Object $NEW_SECONDARY_RVG already exists on $SECONDARY_HOST.  Ignoring that name."
			echo "Enter name for the parent RVG of the Secondary RLINK (newline to"
			echo "back up): \c"
                        NEW_SECONDARY_RVG=""
			continue
		fi
		Check_if_name_is_in_use_by_config_file_for_remote
		if [ "$?" = 1 ]
        	then
			echo "Object $NEW_SECONDARY_RVG has already been specified for use on $SECONDARY_HOST.  Ignoring that name."
			echo "Enter name for the parent RVG of the Secondary RLINK (newline to"
			echo "back up): \c"
                        NEW_SECONDARY_RVG=""
			continue
		fi

       		/bin/egrep "^SRV  *${RLINK} " $CONFIG_FILE > /dev/null 2>&1
       		if [ "$?" != 1 ]
       		then
               		SECOND_RVG=`awk '/^SRV  *'${RLINK}' / { printf "%s", $3 }' $CONFIG_FILE`
               		echo "Existing specification for old Secondary RVG name ($SECOND_RVG) must be"
			echo "deleted, in order to do this renaming."
                	Y_OR_N=""
                	while [ "$Y_OR_N" = "" ]
                	do
				echo "Okay to delete old specification for $SECOND_RVG? (default: y) (y/n): \c"
                        	read Y_OR_N
                        	case "$Y_OR_N" in
                                	"" )    Y_OR_N=y;;
                                	[yY] ) Y_OR_N=y;;
                                	[nN] ) Y_OR_N=n;;
                                	* )     echo "Invalid input"
                                	Y_OR_N="" ;;
                        	esac
                	done
                	if [ "$Y_OR_N" = n ]
                	then
				echo "Enter name for the parent RVG of the Secondary RLINK (newline to"
				echo "back up): \c"
                        	NEW_SECONDARY_RVG=""
				continue
			else
				#Delete existing SRV entry w/old name
	    			/bin/rm -f $CONFIG_TMP_FILE
	    			awk '{  if ($1 != "SRV" || $2 != "'$RLINK'" )
					print $0 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
				/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
                	fi
		fi
        done
        if [ "$NEW_SECONDARY_RVG" != "" ]
        then
                SECONDARY_RVG="$NEW_SECONDARY_RVG"
	fi
clear
}

#11731G
Add_secondary_rvg_record_to_summary()
{
	OVERWRITE_SRVG=""
	/bin/egrep "^SRV  *${RLINK} " $CONFIG_FILE > /dev/null 2>&1
	if [ "$?" != 1 ]
	then
		SECONDARY_RVG=`awk '/^SRV  *'${RLINK}' / { printf "%s", $3 }' $CONFIG_FILE`
                while [ "$OVERWRITE_SRVG" = "" ]
                do
                        echo "Overwrite existing $SECONDARY_RVG Secondary RVG specification?"
			echo "(default: y) (y/n): \c"
                        read OVERWRITE_SRVG
                        case "$OVERWRITE_SRVG" in
                                "" )    OVERWRITE_SRVG=y;;
                                [yY] ) OVERWRITE_SRVG=y;;
                                [nN] ) return 0;;
                                * )     echo "Invalid input"
                                        OVERWRITE_SRVG="" ;;
                        esac
                done
	fi

	if [ "$OVERWRITE_SRVG" = "" ]
	then
	    echo "" >> $CONFIG_FILE
	    echo "#SRV Primary_Rlink     Rvg_Name          Diskgroup_Name  Create/Exists" >> $CONFIG_FILE
	    echo "#    ----------------  ----------------  --------------  -------------" >> $CONFIG_FILE
	    awk 'END { printf "SRV  %-17s %-17s %-14s  %s\n", "'$RLINK'", "'${SECONDARY_RVG:-$RVG}'", "'${SECONDARY_DISKGROUP:-$DISKGROUP}'", "'${SECONDARY_RVG_EXISTENCE:-CREATE}'" }' $CONFIG_ORIG_FILE >> $CONFIG_FILE
	else
	    /bin/rm -f $CONFIG_TMP_FILE
	    awk '{  if ($1 == "SRV" && $2 == "'$RLINK'" )
	    		printf "SRV  %-17s %-17s %-14s  %s\n", "'$RLINK'", "'${SECONDARY_RVG:-$RVG}'", "'${SECONDARY_DISKGROUP:-$DISKGROUP}'", "'${SECONDARY_RVG_EXISTENCE:-CREATE}'"
		else
			print $0 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
	    /bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
	fi

	PRIMARY_REMOTE_DISKGROUP=`awk '/^RL  *'$RLINK' / { printf "%s", $5 }' $CONFIG_FILE`
	if [ "$PRIMARY_REMOTE_DISKGROUP" != "${SECONDARY_DISKGROUP:-$DISKGROUP}" ]
	then
		echo "WARNING: The Primary RLINK record ($RLINK) specifies $PRIMARY_REMOTE_DISKGROUP"
		echo "as the Secondary disk group, but this Secondary RVG record specifies"
		echo "${SECONDARY_DISKGROUP:-$DISKGROUP}.  Modify one or the other so that they match before"
		echo "attempting to create the Secondary RVG hierarchy."
		echo "Hit return to continue: \c"
		read Whatever
	fi

	clear
	return 1
}

#117331
Select_name_of_existing_secondary_volume_to_add_as_the_srl_secondary_volume()
{
SET_SECONDARY_SRLVOL_SUCCESS=0
clear
	echo "Getting list of existing volumes on host $SECONDARY_HOST..."
	REMOTE_CMD="$VXVM_BIN/vxprint -g ${SECONDARY_DISKGROUP:-$DISKGROUP} -tvQq"
	Do_Remote_Cmd 2> /dev/null 1> $VXPRINT_FILE
	if [ "$?" != 0 ]
        then
		echo ""
               	echo "Error trying to get list of parent-less existing volumes in diskgroup ${SECONDARY_DISKGROUP:-$DISKGROUP} on $SECONDARY_HOST."
		echo "Hit return to continue: \c"
		read Whatever
		clear
		/bin/rm -f $VXPRINT_FILE
		return
        fi
	clear
	awk '{ if ( $3 == "-" ) print }' $VXPRINT_FILE > ${VXPRINT_FILE}.tmp
	/bin/mv -f ${VXPRINT_FILE}.tmp $VXPRINT_FILE
	if [ -s $VXPRINT_FILE ]
	then
		echo "Existing volumes found on $SECONDARY_HOST in diskgroup ${SECONDARY_DISKGROUP:-$DISKGROUP} that are not"
		echo "associated with an RVG:"
		awk '{ printf "\t%d\t%-15s  Length=%s\n", NR, $2, $6}  
		       END {printf "\n"}' $VXPRINT_FILE
	else
		echo "Could not find any existing volumes on $SECONDARY_HOST in diskgroup ${SECONDARY_DISKGROUP:-$DISKGROUP}"
		echo "Hit return to continue: \c"
		read Whatever
		clear
		/bin/rm -f $VXPRINT_FILE
		return
	fi

	echo "Enter number of existing volume to be added as the Secondary SRL volume. Enter"
	echo "an empty line to return to previous menu without selecting a volume."
	echo "NOTE: The Secondary SRL volume size must be at least as big as the smaller of"
	echo "100m and the Primary SRL volume size. It is not necessary to make it any bigger."
	echo ""
	echo "Example:	Existing volumes found on host $SECONDARY_HOST in diskgroup rootdg:"
	echo "			1 id-vol01  Length=204800"
	echo "			2 id-vol02  Length=204800"
	echo "			3 id-vol03  Length=204800"
	echo ""
	echo "	Enter \"2\" to select id-vol02 as the Secondary SRL volume"
	echo ""

	LINE=xxxxxx
	while [ "$LINE" != "" ]
	do
		echo "Number of volume to add as the Secondary SRL volume on host $SECONDARY_HOST to ${SECONDARY_RVG:-$RVG}"
		echo "in diskgroup ${SECONDARY_DISKGROUP:-$DISKGROUP}: \c"
		read LINE
		if [ "$LINE" = "" ]
		then
			break
		fi
                set -- $LINE

		if [ "$2" != "" ] 
		then
			echo "Only enter one number to select the single volume to be used as the Secondary SRL volume."
			echo "Ignoring that value."
			continue
		fi

		case "$1" in
			[0-9] | [0-9]*[0-9] ) VOLNAME=`awk '{ if (NR == '$1') printf "%s", $2 }' $VXPRINT_FILE`;;
			* ) 	echo "Invalid input: $1.  Ignoring that value."
				continue;;
		esac

		if [ "$1" -gt `wc -l $VXPRINT_FILE | /bin/sed 's/  */ /g' | /bin/cut -d' ' -f2` ]
		then
			echo "Input number is too big: $1.  Ignoring that value."
			continue
		fi
		if [ "$1" -lt 1 ]
		then
			echo "Input number is too small: $1.  Ignoring that value."
			continue
		fi

		awk '/^S[A-Z]*  *'$RLINK' / {
                       	if ( "'$VOLNAME'" == $3 )
                               	printf "XXXConfiguration already using that name:Line %d:%s\n", NR, $0 }' $CONFIG_FILE > $VERIFY_CFG_FILE
		if [ -s $VERIFY_CFG_FILE ]
		then
			/bin/rm -f $VERIFY_CFG_FILE
			echo "Name $VOLNAME has already been specified for use on $SECONDARY_HOST.  Ignoring that volume."
			continue
		fi
		/bin/rm -f $VERIFY_CFG_FILE

		LEN=`awk '/v  '$VOLNAME' / { print $6 }' $VXPRINT_FILE`
		PRIMARY_SRLVOL_LEN=`awk '/^LV / { print $3 } ' $CONFIG_FILE`
                SIZESTRING="$PRIMARY_SRLVOL_LEN"
                SizeString_To_Len
                PRIMARY_SRLVOL_LEN=$LEN

		if [ "$LEN" -lt 204800 ] 
		then
                	if [ "$PRIMARY_SRLVOL_LEN" != "" ]
                	then
				if [ "$LEN" -lt "$PRIMARY_SRLVOL_LEN" ]
				then
					echo "Secondary SRL volume should be at least as big as the smaller of 100m and the primary"
					echo "SRL volume size ($SIZESTRING). Ignoring that value."
					continue
				fi
			else
				echo "Secondary SRL volume should be at least as big as the smaller of 100m and the primary"
				echo "SRL volume size (unknown). Ignoring that value."
				continue
			fi
                fi

		echo "Finding number of mirrors for ${SECONDARY_HOST}:${SECONDARY_DISKGROUP:-$DISKGROUP}:$VOLNAME..."

		REMOTE_CMD="$VXVM_BIN/vxprint -g ${SECONDARY_DISKGROUP:-$DISKGROUP} -hQq $VOLNAME"
		MIRRORS=`Do_Remote_Cmd_Output | /bin/egrep -c "^pl "`
		MIRRORS=`expr $MIRRORS - 1`

		#Prompt to overwrite existing SLV, if any
		/bin/egrep "^SLV  *${RLINK} " $CONFIG_FILE > /dev/null 2>&1
		if [ "$?" != 1 ]
		then
		    echo ""
                    echo "Existing specification for SRL volume for $RLINK:"
                    echo "   SRL_Volume_Name   Length  Mirrors"
                    echo "   ----------------  ------  -------"
                    awk '/^SLV  *'$RLINK' / { if ($6 == "EXISTS") printf "E  %-17s %+6s %7d\n", $3, $4, $5
                        else
                            printf "C  %-17s %+6s  %7d\n", $3, $4, $5 }' $CONFIG_FILE
                    Y_OR_N=""
                    while [ "$Y_OR_N" = "" ]
                    do
		        echo "Okay to overwrite existing Secondary SRL specification? (default: y) (y/n): \c"
                        read Y_OR_N
                        case "$Y_OR_N" in
                                "" )    Y_OR_N=y;;
                                [yY] ) Y_OR_N=y;;
                                [nN] ) Y_OR_N=n;;
                                * )     echo "Invalid input"
                                Y_OR_N="" ;;
                        esac
                    done
                    if [ "$Y_OR_N" = n ]
                    then
			echo ""
			echo "Cannot add new Secondary SRL volume specification without removing old spec."
			continue
		    fi
                    #Delete existing SLV entry
                    /bin/rm -f $CONFIG_TMP_FILE
                    awk '{ if ($1 != "SLV" || $2 != "'$RLINK'")
                        print $0 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
                    /bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
		fi

                echo "" >> $CONFIG_FILE
                echo "#SLV Primary_Rlink     SRL_Volume_Name   Length  Mirrors  Create/Exists" >> $CONFIG_FILE
                echo "#    ----------------  ----------------  ------  -------  -------------" >> $CONFIG_FILE
		awk 'END { printf "SLV  %-17s %-17s %+6s  %7d  %6s\n", "'$RLINK'", "'$VOLNAME'", "'$LEN'", "'$MIRRORS'", "EXISTS" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		/bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
		/bin/rm -f $CONFIG_TMP_FILE
		SET_SECONDARY_SRLVOL_SUCCESS=1
		SECONDARY_SRLVOL=$VOLNAME; SECONDARY_SRLVOL_LEN=$LEN; SECONDARYSRLVOL_MIRRORS=$MIRRORS
		SECONDARY_SRLVOL_EXISTENCE="EXISTS"
		LINE=""
	done
clear
/bin/rm -f $VXPRINT_FILE
/bin/rm -f $CONFIG_TMP_FILE
}

#117332
Create_a_new_secondary_SRL_volume()
{
SET_SECONDARY_SRLVOL_SUCCESS=0
clear
	echo "Enter name, size, and number of additional mirrors for new Secondary SRL volume to"
	echo "create.  Enter an empty line to return to previous menu without selecting a"
	echo "volume.  The Secondary SRL volume size must be at least as big as the smaller of"
	echo "100m and the Primary SRL volume size.  It is not necessary to make it any bigger."
	echo ""
	echo "Size can be entered using standard VxVM suffix characters:"
	echo "	b    multiply the length by 512 bytes (blocks)"
	echo "	s    multiply the length by the standard sectors size (default)"
	echo "	k    multiply the length by 1024 bytes (Kilobytes)"
	echo "	m    multiply the length by 1,048,576 (1024K) bytes (Megabytes)"
	echo "	g    multiply the length by 1,073,741,824 (1024M) bytes (Gigabytes)"
	echo ""
	echo "Example: mysrlvol01  200m 0"
	echo ""
	echo "New Secondary SRL volume will be added on host $SECONDARY_HOST to ${SECONDARY_RVG:-$RVG} in diskgroup ${SECONDARY_DISKGROUP:-$DISKGROUP}"
	if [ "$SRLVOL" != "" ]
	then
		echo ""
		echo "Suggestion: Use the Primary SRL vol values: $SRLVOL $SRLVOL_LEN $SRLVOL_MIRRORS"
	fi
	echo ""

	echo "Name, size, # of additional mirrors for new Secondary SRL"
	echo "volume: \c"
	read VOLNAME VOLSIZE VOLMIRRORS
	while [ "$VOLNAME" != "" ]
	do
		NAME=$VOLNAME
		Remote_check_if_name_is_in_use_by_VXVM
		if [ "$?" = 1 ]
        	then
			echo ""
			echo "Object $VOLNAME already exists on $SECONDARY_HOST.  Ignoring that volume."
			echo "Name, size, # of additional mirrors for new Secondary SRL"
			echo "volume: \c"
			read VOLNAME VOLSIZE VOLMIRRORS
			continue
		fi

		Check_if_name_is_in_use_by_config_file_for_remote
		if [ "$?" = 1 ]
        	then
			echo ""
			echo "Object $VOLNAME has already been specified for use on $SECONDARY_HOST.  Ignoring that volume."
			echo "Name, size, # of additional mirrors for new Secondary SRL"
			echo "volume: \c"
			read VOLNAME VOLSIZE VOLMIRRORS
			continue
		fi

		PRIMARY_SRLVOL_SIZE=`awk '/^LV / { print $3 } ' $CONFIG_FILE`
                SIZESTRING="$PRIMARY_SRLVOL_SIZE"
                SizeString_To_Len
                PRIMARY_SRLVOL_LEN=$LEN

		SIZESTRING="$VOLSIZE"
		SizeString_To_Len
		#LEN has volume length in sectors or ""
		if [ "$LEN" = "" ]
		then
			echo "Bad length input.  Ignoring that line."
			echo "Name, size, # of additional mirrors for new Secondary SRL"
			echo "volume: \c"
			read VOLNAME VOLSIZE VOLMIRRORS
			continue
		fi

		if [ "$LEN" -lt 204800 ] 
		then
                	if [ "$PRIMARY_SRLVOL_LEN" != "" ]
                	then
				if [ "$LEN" -lt "$PRIMARY_SRLVOL_LEN" ]
				then
					echo "Secondary SRL volume should be at least as big as the smaller of 100m and the primary"
					echo "SRL volume size ($PRIMARY_SRLVOL_SIZE). Ignoring that value."
					echo ""
					echo "Name, size, # of additional mirrors for new Secondary SRL"
					echo "volume: \c"
					read VOLNAME VOLSIZE VOLMIRRORS
					continue
				fi
			else
				echo "Secondary SRL volume should be at least as big as the smaller of 100m and the primary"
				echo "SRL volume size (unknown). Ignoring that value."
				echo ""
				echo "Name, size, # of additional mirrors for new Secondary SRL"
				echo "volume: \c"
				read VOLNAME VOLSIZE VOLMIRRORS
				continue
			fi
                fi

		case "$VOLMIRRORS" in
			[0-9] | [0-9]*[0-9] ) ;;
			* )	echo "Bad input for number of mirrors.  Ignoring that line."
				echo "Name, size, # of additional mirrors for new Secondary SRL"
				echo "volume: \c"
				read VOLNAME VOLSIZE VOLMIRRORS
				continue;;
		esac

		#Prompt to overwrite existing SLV, if any
		/bin/egrep "^SLV  *${RLINK} " $CONFIG_FILE > /dev/null 2>&1
		if [ "$?" != 1 ]
		then
		    echo ""
                    echo "Existing specification for SRL volume for $RLINK:"
                    echo "   SRL_Volume_Name   Length  Mirrors"
                    echo "   ----------------  ------  -------"
                    awk '/^SLV  *'$RLINK' / { if ($6 == "EXISTS") printf "E  %-17s %+6s %7d\n", $3, $4, $5
                        else
                            printf "C  %-17s %+6s  %7d\n", $3, $4, $5 }' $CONFIG_FILE
                    Y_OR_N=""
                    while [ "$Y_OR_N" = "" ]
                    do
		        echo "Okay to overwrite existing Secondary SRL specification? (default: y) (y/n): \c"
                        read Y_OR_N
                        case "$Y_OR_N" in
                                "" )    Y_OR_N=y;;
                                [yY] ) Y_OR_N=y;;
                                [nN] ) Y_OR_N=n;;
                                * )     echo "Invalid input"
                                Y_OR_N="" ;;
                        esac
                    done
                    if [ "$Y_OR_N" = n ]
                    then
			echo ""
			echo "Cannot add new Secondary SRL volume specification without removing old spec."
			read VOLNAME VOLSIZE VOLMIRRORS
			continue
		    fi
                    #Delete existing SLV entry
                    /bin/rm -f $CONFIG_TMP_FILE
                    awk '{ if ($1 != "SLV" || $2 != "'$RLINK'")
                        print $0 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
                    /bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
		fi

		echo "" >> $CONFIG_FILE
                echo "#SLV Primary_Rlink     SRL_Volume_Name   Length  Mirrors  Create/Exists" >> $CONFIG_FILE
                echo "#    ----------------  ----------------  ------  -------  -------------" >> $CONFIG_FILE
                awk 'END { printf "SLV  %-17s %-17s %+6s  %7d  %6s\n", "'$RLINK'", "'$VOLNAME'", "'$VOLSIZE'", "'$VOLMIRRORS'", "CREATE" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		/bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
		/bin/rm -f $CONFIG_TMP_FILE
		SET_SECONDARY_SRLVOL_SUCCESS=1
                SECONDARY_SRLVOL=$VOLNAME; SECONDARY_SRLVOL_LEN=$VOLSIZE; SECONDARYSRLVOL_MIRRORS=$VOLMIRRORS
                SECONDARY_SRLVOL_EXISTENCE="CREATE"
		VOLNAME=""
	done
/bin/rm -f $CONFIG_TMP_FILE
clear
}

#11733
Specify_secondary_SRLVOL_record()
{
clear
/bin/cp $CONFIG_FILE $CONFIG_AUX_ORIG_FILE
	SECONDARY_SRLVOL=""
	/bin/egrep "^SLV  *${RLINK} " $CONFIG_FILE > /dev/null 2>&1
	if [ "$?" != 1 ]
	then
		SECONDARY_SRLVOL=`awk '/^SLV  *'${RLINK}' / { printf "%s", $3 }' $CONFIG_FILE`
		echo "The name $SECONDARY_SRLVOL has already been specified for the Secondary SRL volume."

		Y_OR_N=""
		while [ "$Y_OR_N" = "" ]
		do
			echo "Modify existing Secondary SRL volume specification? (default: y) (y/n): \c"
			read Y_OR_N
			case "$Y_OR_N" in
				"" )    Y_OR_N=y;;
                                [yY] ) Y_OR_N=y;;
                                [nN] ) Y_OR_N=n;;
                                * )     echo "Invalid input"
                                Y_OR_N="" ;;
			esac
		done
		if [ "$Y_OR_N" = n ]
		then
			/bin/rm -f $CONFIG_AUX_ORIG_FILE
			return
		fi
		set -- `awk '/^SLV  *'${RLINK}' / { print $0 }' $CONFIG_FILE`
		SECONDARY_SRLVOL=$3; SECONDARY_SRLVOL_LEN=$4; SECONDARY_SRLVOL_MIRRORS=$5; SECONDARY_SRLVOL_EXISTENCE=$6
	fi

        set -- `awk '/^RV / { printf "%s\n", $0 }' $CONFIG_FILE`
        RVG=$2; DISKGROUP=$3; RVG_EXISTENCE=$4


while [ 1 ] 
do
	clear
	if [ "$SECONDARY_SRLVOL" != "" ]
	then
		MENU_LENGTH=24
	else
		MENU_LENGTH=19
	fi
	Summarize_Create_an_Rvg
        echo "Specify Secondary SRLVOL record"
	echo ""
        echo "This menu is used to specify the new or pre-existing volume on the secondary"
        echo "host to use as the Secondary SRL volume for $RLINK."
	echo "You must still select Go from the previous menu to commit this change."
	echo ""
	echo "Primary RLINK: $RLINK		Secondary host: $SECONDARY_HOST"
	echo ""
	if [ "$SECONDARY_SRLVOL" != "" ]
	then
	    echo "Existing specification for SRL volume for $RLINK:"
            echo "   SRL_Volume_Name   Length  Mirrors"
            echo "   ----------------  ------  -------"
            awk '/^SLV  *'$RLINK' / { if ($6 == "EXISTS") printf "E  %-17s %+6s  %7d\n", $3, $4, $5
                else
                    printf "C  %-17s %+6s  %7d\n", $3, $4, $5 }' $CONFIG_FILE
	    echo ""
	fi
	echo "Choose an option  (\"?\" for other options):"
        echo "    1  Select name of existing Secondary volume to add as the SRL volume"
        echo "    2  Create a new Secondary SRL volume"
	echo ""
	echo "    s  Show summary of set-up work specified so far"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
	case "$CHOICE" in
                1 ) Select_name_of_existing_secondary_volume_to_add_as_the_srl_secondary_volume
                    if [ "$SET_SECONDARY_SRLVOL_SUCCESS" = "1" ]
                    then
                        /bin/rm -f $CONFIG_AUX_ORIG_FILE
                        break
                    fi ;;
                2) Create_a_new_secondary_SRL_volume
                    if [ "$SET_SECONDARY_SRLVOL_SUCCESS" = "1" ]
                    then
                        /bin/rm -f $CONFIG_AUX_ORIG_FILE
                        break
                    fi ;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_AUX_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
                                        /bin/mv -f $CONFIG_AUX_ORIG_FILE $CONFIG_FILE
                                        break
                                else
                                        clear
                                fi
                        else
                                break
                        fi;;
		[rR] ) Remote_Vxprint;;
		[vV] ) Vxprint;;
		[qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
		* ) echo "Invalid input: $CHOICE"
			echo "Hit return to continue: \c"
			read Whatever
		    CHOICE="";;
	esac
done
/bin/rm -f $CONFIG_AUX_ORIG_FILE
clear
}

#11731
Specify_secondary_RVG_record()
{
clear
SECONDARY_RVG_EXISTENCE="CREATE"
/bin/cp $CONFIG_FILE $CONFIG_AUX_ORIG_FILE

	/bin/egrep "^SRV  *${RLINK} " $CONFIG_FILE > /dev/null 2>&1
	if [ "$?" != 1 ]
	then
		SECONDARY_RVG=`awk '/^SRV  *'${RLINK}' / { printf "%s", $3 }' $CONFIG_FILE`
		echo "The name $SECONDARY_RVG has already been specified for the Secondary rvg."

		Y_OR_N=""
		while [ "$Y_OR_N" = "" ]
		do
			echo "Modify existing Secondary RVG specification? (default: y) (y/n): \c"
			read Y_OR_N
			case "$Y_OR_N" in
				"" )    Y_OR_N=y;;
                                [yY] ) Y_OR_N=y;;
                                [nN] ) Y_OR_N=n;;
                                * )     echo "Invalid input"
                                Y_OR_N="" ;;
			esac
		done
		if [ "$Y_OR_N" = n ]
		then
			/bin/rm -f $CONFIG_AUX_ORIG_FILE
			return
		fi
		set -- `awk '/^SRV  *'${RLINK}' / { print $0 }' $CONFIG_FILE`
		SECONDARY_RVG=$3; SECONDARY_DISKGROUP=$4; SECONDARY_RVG_EXISTENCE=$5
	fi

        set -- `awk '/^RV / { printf "%s\n", $0 }' $CONFIG_FILE`
        RVG=$2; DISKGROUP=$3; RVG_EXISTENCE=$4

while [ 1 ] 
do
	clear
	MENU_LENGTH=16
	Summarize_Create_an_Rvg
        echo "Specify Secondary RVG record"
	echo ""
	echo "Primary RLINK: $RLINK		Secondary host: $SECONDARY_HOST"
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    1  Secondary disk group name:                   ${SECONDARY_DISKGROUP:-$DISKGROUP}"
	echo "    2  Secondary RVG name:                          ${SECONDARY_RVG:-$RVG}"
	echo ""
	echo "    s  Show summary of set-up work specified so far"
        echo "    g  Go -- keep changes and return to previous menu"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
	case "$CHOICE" in
		1 ) Secondary_diskgroup_name;;
		2 ) Secondary_rvg_name;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
		[gG] ) Add_secondary_rvg_record_to_summary
		    if [ "$?" = 0 ]
		    then
			clear
		    fi
                    Verify_Cfg_File
                    if [ "$?" = 0 ]
                    then
                        clear
                    fi
		    break;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_AUX_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
                                        /bin/mv -f $CONFIG_AUX_ORIG_FILE $CONFIG_FILE
                                        break
                                else
                                        clear
                                fi
                        else
                                break
                        fi;;
		[rR] ) Remote_Vxprint;;
		[vV] ) Vxprint;;
		[qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
		* ) echo "Invalid input: $CHOICE"
			echo "Hit return to continue: \c"
			read Whatever
		    CHOICE="";;
	esac
done
/bin/rm -f $CONFIG_AUX_ORIG_FILE
clear
}

#117341
Primary_host_name()
{
clear
	echo ""
        echo "Enter name to be used for the Primary host for this Secondary RLINK (newline to"
	echo "back up): \c"
        NEW_PRIMARY_HOST=""
        while [ "$NEW_PRIMARY_HOST" = "" ]
        do
                read NEW_PRIMARY_HOST
                case "$NEW_PRIMARY_HOST" in
                    "" )    break;;
		    [a-z]* | [A-Z]* | _* ) break;;
                    * )     echo "Bad hostname input"
                            NEW_PRIMARY_HOST=""
        		    echo "Enter name to be used for the Primary host for this Secondary RLINK (newline to"
			    echo "back up): \c"
                            continue;;
                esac
        done
        if [ "$NEW_PRIMARY_HOST" != "" ]
        then
                PRIMARY_HOST="$NEW_PRIMARY_HOST"
        fi
clear
}

# Primary_Local_HostName



#11734G
Add_Secondary_Rlink_To_Config()
{
	NAME=${SECONDARY_RLINK:-$RLINK}
        Remote_check_if_name_is_in_use_by_VXVM
        if [ "$?" = 1 ]
        then
                echo "ERROR: Cannot create Secondary RLINK named $NAME. That name is already in use on $SECONDARY_HOST"
                echo "Hit return to continue: \c"
                read Whatever
                return 0
        fi

	OVERWRITE_EXISTING_SRL_SPEC="n"
       	/bin/egrep "^SRL  *${RLINK} " $CONFIG_FILE > /dev/null 2>&1
       	if [ "$?" != 1 ]
       	then
       		SECOND_RL=`awk '/^SRL  *'${RLINK}' / { printf "%s", $3 }' $CONFIG_FILE`
               	Y_OR_N=""
               	while [ "$Y_OR_N" = "" ]
               	do
       			echo "Overwrite existing specification for this Secondary rlink? (default: y) (y/n): \c"
                       	read Y_OR_N
                       	case "$Y_OR_N" in
                               	"" )    Y_OR_N=y;;
                               	[yY] ) Y_OR_N=y;;
                               	[nN] ) Y_OR_N=n;;
                               	* )     echo "Invalid input"
                               	Y_OR_N="" ;;
                       	esac
               	done
               	if [ "$Y_OR_N" = n ]
               	then
			return 0
		else
			OVERWRITE_EXISTING_SRL_SPEC="y"
               	fi
	else
		PARENT_RL_OK=$RLINK
		Check_if_name_is_in_use_by_config_file_for_remote
        	if [ "$?" = 1 ]
        	then
                	echo "ERROR: Cannot create Secondary RLINK named $NAME. That name has already been specified for use on $SECONDARY_HOST"
                	echo "Hit return to continue: \c"
                	read Whatever
                	return 0
        	fi
		PARENT_RL_OK=""
	fi

	if [ "$OVERWRITE_EXISTING_SRL_SPEC" != "y" ]
	then
            echo "" >> $CONFIG_FILE
            echo "#SRL Primary_Rlink     Rlink_Name        Primary_host Primary_diskgroup Modes  HighLatency  LowLatency   Create/Exists" >> $CONFIG_FILE
            echo "#    ----------------  ----------------  -----------  ----------------  -----  -----------  -----------  -------------" >> $CONFIG_FILE
            awk 'END { printf "SRL  %-17s %-17s %-12s %-17s %-1s %-1s %-1s  %-11s  %-11s  %s\n", "'$RLINK'", "'$NAME'", "'${PRIMARY_HOST:-$LOCAL_HOST}'", "'$DISKGROUP'", "'$SYNC_MODE'", "'$LATENCY_MODE'", "'$SRLPROT_MODE'", "'${HIGH_LATENCY:-10000}'", "'${LOW_LATENCY:-9950}'", "'${SECONDARY_RLK_EXISTENCE:-CREATE}'" }' $CONFIG_ORIG_FILE >> $CONFIG_FILE
	else
		# Overwrite existing SRL record, with possibly new PRIMARY_HOST
		/bin/rm -f $CONFIG_TMP_FILE
		awk '{ if ($1 == "SRL" && $2 == "'$RLINK'") printf "SRL  %-17s %-17s %-12s %-17s %-1s %-1s %-1s  %-11s  %-11s  %s\n", $2, $3, "'${PRIMARY_HOST:-$LOCAL_HOST}'", $5, $6, $7, $8, $9, $10, $11
			else
			    print $0 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
	fi

	return 1
}

#11734
Specify_secondary_RLINK_record()
{
clear
/bin/cp $CONFIG_FILE $CONFIG_AUX_ORIG_FILE
PRIMARY_HOST=""
SECONDARY_RLK_EXISTENCE="CREATE"

	/bin/egrep "^SRL  *${RLINK} " $CONFIG_FILE > /dev/null 2>&1
	if [ "$?" != 1 ]
	then
		SECONDARY_RL=`awk '/^SRL  *'${RLINK}' / { printf "%s", $3 }' $CONFIG_FILE`
		echo "The name $SECONDARY_RL has already been specified for the Secondary rlink."

		Y_OR_N=""
		while [ "$Y_OR_N" = "" ]
		do
			echo "Modify existing Secondary RLINK specification? (default: y) (y/n): \c"
			read Y_OR_N
			case "$Y_OR_N" in
				"" )    Y_OR_N=y;;
                                [yY] ) Y_OR_N=y;;
                                [nN] ) Y_OR_N=n;;
                                * )     echo "Invalid input"
                                Y_OR_N="" ;;
			esac
		done
		if [ "$Y_OR_N" = n ]
		then
			/bin/rm -f $CONFIG_AUX_ORIG_FILE
			return
		fi
		set -- `awk '/^SRL  *'${RLINK}' / { print $0 }' $CONFIG_FILE`
		SECONDARY_RLINK=$3; SECONDARY_PRIMARY_HOST=$4; SECONDARY_PRIMARY_DISKGROUP=5
		shift;shift;shift
		SECONDARY_RVG_EXISTENCE=$8
	fi

	set -- `awk '/^RL  *'$RLINK' / { printf "%s %s %s %s %s %s %s %s", $5, $6, $7, $8, $9, $10, $11, $12 }' $CONFIG_FILE`
	SECONDARY_DISKGROUP=$1; SECONDARY_RLINK=$2; SYNC_MODE=$3; LATENCY_MODE=$4; SRLPROT_MODE=$5; HIGH_LATENCY=$6; LOW_LATENCY=$7; RLK_EXISTENCE=$8
	Get_throttling_mode_strings
while [ 1 ]
do
        clear
	if [ "$RLINK" != "${SECONDARY_RLINK:-$RLINK}" ]
	then
		MENU_LENGTH=24
	else
		MENU_LENGTH=23
	fi
        Summarize_Create_an_Rvg
        echo "Specify Secondary RLINK record"
        echo ""
        echo "This menu is used to specify the Secondary rlink."
	echo ""
	echo "Note that for a Secondary rlink, currently the only attribute which you are"
	echo "permitted to specify is the name of the Primary host.  All other attributes"
	echo "are copied from the Primary rlink, as is appropriate.  The Primary host"
	echo "name is allowed to be modified because that host might have multiple"
	echo "interface cards which are referenced by different host names."
        echo ""
	echo "Primary RLINK: $RLINK		Secondary host: $SECONDARY_HOST"
        if [ "$RLINK" != "${SECONDARY_RLINK:-$RLINK}" ]
        then
                echo "Secondary RLINK:  $SECONDARY_RLINK"
        fi
        echo ""
	echo "Choose an option  (\"?\" for other options):"
        echo "    1  Primary host name:                            ${PRIMARY_HOST:-$LOCAL_HOST}"
        echo ""
	echo "    s  Show summary of set-up work specified so far"
        echo "    g  Go -- keep changes and return to previous menu"
	echo "    p  Previous -- abort changes and return to previous menu"
        echo "    r  Remote vxprint -ht"
        echo "    v  Local vxprint -ht"
        echo "    q  Quit"
        echo ""
        echo "    Enter option: \c"
        read CHOICE
        echo ""
        case "$CHOICE" in
                1 ) Primary_host_name;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
                [gG] ) Add_Secondary_Rlink_To_Config
                    if [ "$?" = 1 ]
                    then
                        Verify_Cfg_File
                        if [ "$?" = 0 ]
                        then
                            clear
                        fi
		    	/bin/rm -f $CONFIG_AUX_ORIG_FILE
                       	break
		    else
			continue
                    fi;;
                [rR] ) Remote_Vxprint;;
                [vV] ) Vxprint;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_AUX_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
                                        /bin/mv -f $CONFIG_AUX_ORIG_FILE $CONFIG_FILE
                                        break
                                else
                                        clear
                                fi
                        else
                                break
                        fi;;
                [qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
                * ) echo "Invalid input: $CHOICE"
                        echo "Hit return to continue: \c"
                        read Whatever
        esac
done
/bin/rm -f $CONFIG_AUX_ORIG_FILE
clear
}

#117321
Specify_existing_secondary_data_volumes_to_add()
{
clear
        echo "Getting list of existing volumes on host $SECONDARY_HOST...\c"
        REMOTE_CMD="$VXVM_BIN/vxprint -g ${SECONDARY_DISKGROUP:-$DISKGROUP} -tvQq"
        Do_Remote_Cmd 2> /dev/null 1> $VXPRINT_FILE
	if [ "$?" != 0 ]
        then
		echo ""
               	echo "Error trying to get list of parent-less existing volumes in diskgroup ${SECONDARY_DISKGROUP:-$DISKGROUP} on $SECONDARY_HOST."
		echo "Hit return to continue: \c"
		read Whatever
		clear
		/bin/rm -f $VXPRINT_FILE
		return 0
        fi
	clear
	awk '{ if ( $3 == "-" ) print }' $VXPRINT_FILE > ${VXPRINT_FILE}.tmp
	/bin/mv -f ${VXPRINT_FILE}.tmp $VXPRINT_FILE
	if [ -s $VXPRINT_FILE ]
	then
		echo "Existing volumes found on $SECONDARY_HOST in diskgroup ${SECONDARY_DISKGROUP:-$DISKGROUP} that are not"
		echo "associated with an RVG:"
		awk '{ printf "\t%d\t%-15s  Length=%s\n", NR, $2, $6}  
		       END {printf "\n"}' $VXPRINT_FILE
	else
		echo "Could not find any existing volumes on $SECONDARY_HOST in diskgroup ${SECONDARY_DISKGROUP:-$DISKGROUP}"
		echo "Hit return to continue: \c"
		read Whatever
		clear
		/bin/rm -f $VXPRINT_FILE
		return
	fi

	echo "Enter number(s) of additional existing Secondary data volume(s) to add, at most 9"
	echo "per line, separated by spaces.  Multiple lines can be entered. Terminate list"
	echo "with an empty line.  You can abort your selections by selecting P (Previous -- "
	echo "abort changes and return to previous menu) from the preceeding menu."
	echo ""
	echo "Example:	Existing volumes found in diskgroup rootdg:"
	echo "			1 id-vol01  Length=204800"
	echo "			2 id-vol02  Length=204800"
	echo "			3 id-vol03  Length=204800"
	echo ""
	echo "	Enter \"1  3\" to select id-vol01 and id-vol03"
	echo ""

	echo "Existing Secondary data volumes to add for ${SECONDARY_RLINK:-$RLINK} in diskgroup"
	echo "${SECONDARY_DISKGROUP:-$DISKGROUP} on $SECONDARY_HOST: \c"
	read LINE
	while [ "$LINE" != "" ]
	do
                set -- $LINE
		while [ "$1" != "" ]
		do
			case "$1" in
				[0-9] | [0-9]*[0-9] ) VOLNAME=`awk '{ if (NR == '$1') printf "%s", $2 }' $VXPRINT_FILE`;;
				* ) 	echo "Invalid input: $1.  Ignoring that value."
				    	shift
					continue;;
			esac

			if [ "$1" -gt `wc -l $VXPRINT_FILE | /bin/sed 's/  */ /g' | /bin/cut -d' ' -f2` ]
			then
				echo "Input number is too big: $1.  Ignoring that value."
				shift
				continue
			fi
			if [ "$1" -lt 1 ]
			then
				echo "Input number is too small: $1.  Ignoring that value."
				shift
				continue
			fi

                	awk '/^S[A-Z]*  *'$RLINK' / {
                        	if ( "'$VOLNAME'" == $3 )
                                	printf "XXXConfiguration already using that name:Line %d:%s\n", NR, $0 }' $CONFIG_FILE > $VERIFY_CFG_FILE
                	if [ -s $VERIFY_CFG_FILE ]
                	then
                        	/bin/rm -f $VERIFY_CFG_FILE
                        	echo "Name $VOLNAME has already been specified for use on $SECONDARY_HOST."
				echo "Ignoring that volume."
				shift
				continue
                	fi
                	/bin/rm -f $VERIFY_CFG_FILE

			LEN=`awk '/v  '$VOLNAME' / { print $6 }' $VXPRINT_FILE`

			echo "Finding number of mirrors for ${SECONDARY_HOST}:${SECONDARY_DISKGROUP:-$DISKGROUP}:$VOLNAME...\c"

                	REMOTE_CMD="$VXVM_BIN/vxprint -g ${SECONDARY_DISKGROUP:-$DISKGROUP} -hQq $VOLNAME"
			MIRRORS=`Do_Remote_Cmd_Output | /bin/egrep -c "^pl "`
			MIRRORS=`expr $MIRRORS - 1`
			echo ""


                	awk '/^SDV *'$RLINK' / { count=count+1 } END { if (count == 0)
				printf "\n%s\n%s\n", "#SDV Primary_Rlink     Data_Volume_Name  Length  Mirrors  Create/Exists  Primary_Datavol  dcmlog", "#    ----------------  ----------------  ------  -------  -------------  ---------------- ---------"}' $CONFIG_FILE >> $CONFIG_TMP_FILE

                	awk 'END { printf "SDV  %-17s %-17s %+6s  %7d  %-13s  %s %-6s \n", "'$RLINK'", "'$VOLNAME'", "'$LEN'", "'$MIRRORS'", "EXISTS", "'$VOLNAME'" , "'$DATAVOL_LOGSRVM'"}' $CONFIG_FILE >> $CONFIG_TMP_FILE
                	/bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
                	/bin/rm -f $CONFIG_TMP_FILE
			echo "Adding ${VOLNAME}..."
			echo "NOTE:  If necessary, use option 4 from the previous menu to map ${VOLNAME}"
			echo "to the appropriate Primary data volume."
			shift
		done
		echo "More existing Secondary data volumes to add (newline to finish): \c"
		read LINE
	done
# May not get here. May return, above
clear
/bin/rm -f $VXPRINT_FILE
/bin/rm -f $CONFIG_TMP_FILE
}

#117322
Add_new_secondary_data_volumes_to_be_created_initially_empty()
{
clear
	if [ -s $CONFIG_FILE ]
	then
		echo "--------------------------------------------------------------------------------"
		echo "Summary of Primary data volumes specified so far:"
        	echo ""
		echo "  New RVG name: $RVG		Diskgroup: $DISKGROUP"
		echo ""
	    	echo "   Data_Volume_Name  Length  Mirrors  dcmlog   Create/Exists"
	    	echo "   ----------------  ------  -------  -------   -------------"
	    	awk '/^DV/ { 
			printf "   %-17s %+6s  %7d  %-6s %-13s\n", $2, $3, $4, $5, $6 }' $CONFIG_FILE
		echo ""
		echo "Summary of Secondary data volumes specified so far for this RLINK:"
        	echo ""
		echo "  Rlink name: $RLINK"
		echo ""
	    	echo "   Data_Volume_Name  Length  Mirrors  dcmlog  Create/Exists  Primary_Vol_To_Map"
	    	echo "   ----------------  ------  -------  -------  -------------  ------------------"
	    	awk '/^SDV  *'$RLINK' / { 
			printf "   %-17s %+6s  %7d  %-13s  %s\n", $3, $4, $5, $6, $7 }' $CONFIG_FILE
		echo "--------------------------------------------------------------------------------"
	fi
	echo "Enter name, size, and number of additional mirrors for each new Secondary data"
	echo "volume to create.  Optional fourth argument indicates the name of the data"
	echo "volume on the Primary from which the Secondary data volume will receive data"
	echo "(default is for Primary and Secondary volumes to have the same names)."
	echo ""
	echo "Enter information for one volume per line separated by spaces.  Multiple"
	echo "lines can be entered.  Terminate list with an empty line."
	echo ""
	echo "Size can be entered using standard VxVM suffix characters:"
	echo "	b    multiply the length by 512 bytes (blocks)"
	echo "	s    multiply the length by the standard sectors size (default)"
	echo "	k    multiply the length by 1024 bytes (Kilobytes)"
	echo "	m    multiply the length by 1,048,576 (1024K) bytes (Megabytes)"
	echo "	g    multiply the length by 1,073,741,824 (1024M) bytes (Gigabytes)"
	echo ""
	echo "Example 1: myvol01  100m 0"
	echo "Example 2: secondary-myvol01  100m 0  primary-myvol01"
	echo ""
	echo "New Secondary data volumes will be added in diskgroup ${SECONDARY_DISKGROUP:-$DISKGROUP} on $SECONDARY_HOST"
	echo ""
	echo "Name, size, # of additional mirrors, <primary volume> for new volume (newline to"
	echo "finish): \c"
	read VOLNAME VOLSIZE VOLMIRRORS VOLPRIMARYVG
	while [ "$VOLNAME" != "" ]
	do
		NAME=$VOLNAME
		Remote_check_if_name_is_in_use_by_VXVM
		if [ "$?" = 1 ]
        	then
			echo "Object $VOLNAME already exists on $SECONDARY_HOST.  Ignoring that volume."
			echo "Name, size, # of additional mirrors, <primary volume> for new volume (newline to"
			echo "finish): \c"
			read VOLNAME VOLSIZE VOLMIRRORS VOLPRIMARYVG
			continue
		fi
		Check_if_name_is_in_use_by_config_file_for_remote
		if [ "$?" = 1 ]
        	then
			echo "Object $VOLNAME has already been specified for use on $SECONDARY_HOST.  Ignoring that volume."
			echo "Name, size, # of additional mirrors, <primary volume> for new volume (newline to"
			echo "finish): \c"
			read VOLNAME VOLSIZE VOLMIRRORS VOLPRIMARYVG
			continue
		fi

		SIZESTRING="$VOLSIZE"
		SizeString_To_Len
		SECONDARY_LEN=$LEN
		if [ "$SECONDARY_LEN" = "" ]
		then
			echo "Bad length input.  Ignoring that line."
			echo "Name, size, # of additional mirrors, <primary volume> for new volume (newline to"
			echo "finish): \c"
			read VOLNAME VOLSIZE VOLMIRRORS VOLPRIMARYVG
			continue
		fi
		case "$VOLMIRRORS" in
			[0-9] | [0-9]*[0-9] ) ;;
			* )	echo "Bad input for number of mirrors.  Ignoring that line."
				echo "Name, size, # of additional mirrors, <primary volume> for new volume (newline to"
				echo "finish): \c"
				read VOLNAME VOLSIZE VOLMIRRORS VOLPRIMARYVG
				continue;;
		esac


		CNT=`egrep -c "^DV  *${VOLPRIMARYVG:-$VOLNAME} " $CONFIG_FILE`
		if [ "$CNT" != 1 ]
		then
			if [ "$CNT" -lt 1 ]
			then
			    echo "ERROR: Could not find a record for Primary data volume ${VOLPRIMARYVG:-$VOLNAME}"
			    if [ "$VOLPRIMARYVG" = "" ]
			    then
			    	echo "Perhaps a fourth argument is needed."
			    fi
			elif [ "$CNT" -gt 1 ]
			then
			    echo "ERROR: Found multiple records for Primary data volume ${VOLPRIMARYVG:-$VOLNAME}"
			else 
			    echo "Error finding the record for Primary data volume ${VOLPRIMARYVG:-$VOLNAME}"
			fi
			echo "Ignoring that volume."
			echo "Name, size, # of additional mirrors, <primary volume> for new volume (newline to"
			echo "finish): \c"
			read VOLNAME VOLSIZE VOLMIRRORS VOLPRIMARYVG
			continue
		fi
		PRIMARY_SIZE=`awk '/^DV  *'${VOLPRIMARYVG:-$VOLNAME}' / { print $3 }' $CONFIG_FILE`
		SIZESTRING=$PRIMARY_SIZE
		SizeString_To_Len
		PRIMARY_LEN=$LEN
		if [ "$PRIMARY_LEN" = "" ]
		then 
			echo "ERROR: Found bad value for Primary data volume length: ${VOLPRIMARYVG:-$VOLNAME}"
			echo "Ignoring that volume."
			echo "Name, size, # of additional mirrors, <primary volume> for new volume (newline to"
			echo "finish): \c"
			read VOLNAME VOLSIZE VOLMIRRORS VOLPRIMARYVG
			continue
		fi
		if [ "$SECONDARY_LEN" -lt "$PRIMARY_LEN" ]
		then
			echo "ERROR: Size of Secondary data volume $VOLNAME ($SECONDARY_LEN) is smaller than"
			echo "size of Primary data volume ${VOLPRIMARYVG:-$VOLNAME} ($PRIMARY_LEN)."
			echo "Ignoring that volume."
			echo "Name, size, # of additional mirrors, <primary volume> for new volume (newline to"
			echo "finish): \c"
			read VOLNAME VOLSIZE VOLMIRRORS VOLPRIMARYVG
			continue
		fi


                awk '/^SDV *'$RLINK' / { count=count+1 } END { if (count == 0)
			printf "\n%s\n%s\n", "#SDV Primary_Rlink     Data_Volume_Name  Length  Mirrors  Create/Exists  Primary_Datavol  dcmlog", "#    ----------------  ----------------  ------  -------  -------------  ----------------  ------"}' $CONFIG_FILE >> $CONFIG_TMP_FILE

                awk 'END { printf "SDV  %-17s %-17s %+6s  %7d  %-13s  %s  %-6s\n", "'$RLINK'", "'$VOLNAME'", "'$VOLSIZE'", "'$VOLMIRRORS'", "CREATE", "'${VOLPRIMARYVG:-$VOLNAME}'" , "'${DATAVOL_LOGSRVM}'" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
                /bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
                /bin/rm -f $CONFIG_TMP_FILE

		echo "Name, size, # of additional mirrors, <primary volume> for new volume (newline to"
		echo "finish): \c"
		read VOLNAME VOLSIZE VOLMIRRORS VOLPRIMARYVG
	done
clear
/bin/rm -f $VXPRINT_FILE
/bin/rm -f $CONFIG_TMP_FILE
}

#117323G
Verify_and_then_add_range_of_secondary_data_volumes_specified()
{
clear
RANGE_ERRORS=0
I=0
	if [ "$NUM_DATAVOLS_TO_CREATE" = 0 ]
	then
		clear
		/bin/rm -f $CONFIG_TMP_FILE
		return 1
	fi
	/bin/rm -f $CONFIG_2TMP_FILE
	while [ 1 ]
	do
		I=`expr $I + 1`
		if [ "$I" -gt "$NUM_DATAVOLS_TO_CREATE" ]
		then
			break
		fi
		VOLNAME=`echo "$I" | awk '{ printf "'${PREFIX}'vol%02d", $1 }'`


                NAME=$VOLNAME
                Remote_check_if_name_is_in_use_by_VXVM
		if [ "$?" = 1 ]
        	then
			echo "Object $VOLNAME already exists."
			RANGE_ERRORS=`expr $RANGE_ERRORS + 1`
			continue
		fi
		Check_if_name_is_in_use_by_config_file_for_remote
		if [ "$?" = 1 ]
        	then
			echo "Object $VOLNAME has already been specified for use on $SECONDARY_HOST."
			RANGE_ERRORS=`expr $RANGE_ERRORS + 1`
			continue
		fi

		/bin/cat -s $CONFIG_FILE $CONFIG_TMP_FILE > $CONFIG_2TMP_FILE
                awk '/^SDV *'$RLINK' / { count=count+1 } END { if (count == 0)
                        printf "\n%s\n%s\n", "#SDV Primary_Rlink     Data_Volume_Name  Length  Mirrors  Create/Exists  Primary_Datavol   dcmlog", "#    ----------------  ----------------  ------  -------  -------------  ---------------- -------"}' $CONFIG_2TMP_FILE >> $CONFIG_TMP_FILE
		/bin/rm -f $CONFIG_2TMP_FILE

                awk 'END { printf "SDV  %-17s %-17s %+6s  %7d  %-13s  %s %-6s\n", "'$RLINK'", "'$VOLNAME'", "'$NEW_DATAVOLS_SIZE'", "'$NEW_DATAVOLS_MIRRORS'", "CREATE", "'$VOLNAME'" , "'$DATAVOL_LOGSRVM'" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
	done
	if [ "$RANGE_ERRORS" != "0" ]
	then
		echo "Aborting due to $RANGE_ERRORS errors in requested configuration"
		echo "Hit return to continue: \c"
		read Whatever
		clear
		/bin/rm -f $CONFIG_TMP_FILE
		return 0
	else
		/bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
		/bin/rm -f $CONFIG_TMP_FILE
		echo "Done.  The primary_datavol field for each new Secondary data volume has been"
		echo "set to the Secondary data volume name.  If any Secondary data volume does not"
		echo "have the same name as the corresponding Primary data volume then use option 4"
		echo "from the previous menu to map it to the appropriate Primary data volume."
		echo "Select \"s\" from menu to review Summary and see if this is necessary."
		echo "Hit return to continue: \c"
		read Whatever
		clear
		return 1
	fi
# Never gets here.  Does return, above
}


#117323
Specify_a_range_of_new_secondary_data_volumes_to_create()
{
clear
/bin/cp $CONFIG_FILE $CONFIG_2AUX_ORIG_FILE

NUM_DATAVOLS_TO_CREATE=1
NEW_DATAVOLS_SIZE=100m
NEW_DATAVOLS_MIRRORS=0
SECONDARY=" Secondary "

while [ 1 ] 
do
	clear
	MENU_LENGTH=22
	Summarize_Create_an_Rvg
	echo "Specify a Range Of New Secondary Data Volumes To Create"
	echo ""
	echo "All of the Secondary data volumes will have the same size and number of mirrors"
	echo "and each will be mapped to a corresponding Primary data volume with the same"
	echo "name.  Volumes will be named {prefix}vol01 thru {prefix}vol{nn} where nn is"
	echo "the number of data volumes to create.  For example, id-vol01 thru id-vol23."
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    Specify a range of Secondary datavols to create (ie id-vol01 thru id-vol23):"
	echo "    1  Number of new Secondary data volumes to create:                  `awk 'END { printf "%02d", '$NUM_DATAVOLS_TO_CREATE' }' $CONFIG_FILE`"
	echo "    2  Default prefix for new Secondary datavol names (ie id-):         $PREFIX"
	echo "    3  Default size for new Secondary data volumes:                     $NEW_DATAVOLS_SIZE"
	echo "    4  Number of additional mirrors for each new Secondary data volume: $NEW_DATAVOLS_MIRRORS"
	echo ""		
	echo "    s  Show summary of set-up work specified so far"
	echo "    g  Go -- verify then add range of Secondary datavols specified to Summary"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
	case "$CHOICE" in
		1 ) Number_of_new_data_volumes_to_create;;
		2 ) Default_prefix_for_names;;
		3 ) Default_size_for_new_data_volumes;;
		4 ) Default_number_of_mirrors_for_new_data_volumes;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
		[gG] ) Verify_and_then_add_range_of_secondary_data_volumes_specified
		    if [ "$?" = 1 ]
		    then
			Verify_Cfg_File
                        if [ "$?" = 0 ]
                        then
				clear
                        fi
		    	break
		    else
			clear
		    fi;;
		[rR] ) Remote_Vxprint;;
		[vV] ) Vxprint;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_2AUX_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
                                        /bin/mv -f $CONFIG_2AUX_ORIG_FILE $CONFIG_FILE
                                        break
                                else
                                        clear
                                fi
                        else
                                break
                        fi;;
		[qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
		* ) echo "Invalid input: $CHOICE"
			echo "Hit return to continue: \c"
			read Whatever
		    CHOICE="";;
	esac
done
/bin/rm -f $CONFIG_2AUX_ORIG_FILE
/bin/rm -f $VXPRINT_FILE
/bin/rm -f $CONFIG_TMP_FILE
clear
}

#117324
# NOTE: Doesn't delete header in comments before the SDV record
Delete_existing_specification_for_a_secondary_data_volume()
{
clear
	echo "Delete existing specification for a Secondary data volume"
	echo ""
	echo "Use this option to remove a Secondary data volume specification which was"
	echo "entered incorrectly.  Then select option 1, 2 or 3 from the previous menu to"
	echo "re-enter the information."
	echo ""
	echo "Secondary data volumes specified so far:"
        echo "   Data_Volume_Name  Length  Mirrors"
        echo "   ----------------  ------  -------"
        awk '/^SDV  *'$RLINK' / { if ($6 == "EXISTS") printf "E  %-17s %+6s  %7d\n", $3, $4, $5
		else
		    printf "C  %-17s %+6s  %7d\n", $3, $4, $5 }' $CONFIG_FILE
        echo ""
	while [ 1 ]
	do
		echo "Enter name of data volume specification to delete (empty line to abort): \c"
		read DV EXTRA
                if [ "$EXTRA" != "" ]
                then
                        echo "Only enter one word for name.  No whitespace."
                        continue
                fi
		if [ "$DV" = "" ]
		then
			return 1
		fi

		/bin/rm -f $CONFIG_2TMP_FILE
		awk '/^SDV  *'$RLINK'  *'$DV' / { print $0 }' $CONFIG_FILE > $CONFIG_2TMP_FILE
		if [ ! -s $CONFIG_2TMP_FILE ]
		then
			echo "Could not find specification for Secondary data volume $DV for RLINK $RLINK"
			/bin/rm -f $CONFIG_2TMP_FILE
			continue
		fi
		set -- `wc -l $CONFIG_2TMP_FILE`
		if [ "$1" -gt 1 ]
		then
			echo "ERROR: Found multiple data volume specifications for $DV"
			/bin/rm -f $CONFIG_2TMP_FILE
                        continue
		fi

		set -- `/bin/cat $CONFIG_2TMP_FILE`
		DV_LEN=$3
		DV_MIRRORS=$4
		DV_EXISTENCE=$5
		echo "Delete the following Secondary data volume specification?"
        	echo "   Data_Volume_Name  Length  Mirrors"
        	echo "   ----------------  ------  -------"
        	awk '/^SDV  *'$RLINK'  '*$DV' / { if ($6 == "EXISTS") printf "E  %-17s %+6s  %7d\n", $3, $4, $5
		    else
		        printf "C  %-17s %+6s  %7d\n", $3, $4, $5 }' $CONFIG_2TMP_FILE
		echo ""
		Y_OR_N=""
                while [ "$Y_OR_N" = "" ]
                do
                	echo "Delete? (default: y) (y/n): \c"
                        read Y_OR_N
                        case "$Y_OR_N" in
                        	"" )    Y_OR_N=y;;
                                [yY] ) Y_OR_N=y;;
                                [nN] ) Y_OR_N=n;;
                                * )     echo "Invalid input"
                                Y_OR_N="" ;;
                        esac
		done
		/bin/rm -f $CONFIG_2TMP_FILE
                if [ "$Y_OR_N" = n ]
                then
			continue
		else
			awk '{ if ( ! ($1 == "SDV" && $2 == "'$RLINK'" && $3 == "'$DV'") )  print $0 }' $CONFIG_FILE > $CONFIG_2TMP_FILE
			/bin/mv -f $CONFIG_2TMP_FILE $CONFIG_FILE
			return 1
		fi
	done
clear
}


#117325
Specify_or_change_the_primary_data_volume_for_a_secondary_data_volume()
{
clear
	if [ -s $CONFIG_FILE ]
	then
		echo "--------------------------------------------------------------------------------"
		echo "Summary of Secondary data volumes specified so far for $RLINK:"
        	echo ""
		awk '/^SDV  *'$RLINK' / { 
			count=count+1
			map_to=$7
			if (map_to == "") map_to=$3 
	  		printf "     DATAVOL: %-16s len=%-6s mirrors=%-1d %-6s Map To: %s\n", $3, $4, $5, $6, map_to } END { if (count==0) printf "     DATAVOL: <none>           len=       mirrors=   Map To: \n" } ' $CONFIG_FILE
		echo "--------------------------------------------------------------------------------"
		echo ""
	fi
	echo "Enter the name of the Secondary data volume to modify, followed by the name of"
	echo "the Primary data volume to which it should be mapped.  The Secondary data"
	echo "volume will receive copies of all of the writes to the Primary data volume to"
	echo "which it is mapped.  Omit second argument to use the Secondary data volume name."
	echo ""
	echo "Example: secondary-vol01  primary-vol01"
	echo ""
	echo "Enter Secondary data volume name and Primary data volume name to which it is"
	echo "mapped, separated by a blank.  Terminate input with an empty line."
	read VOLNAME VOLPRIMARYVG
	while [ "$VOLNAME" != "" ]
	do
		CNT=`egrep -c "^SDV  *${RLINK}  *${VOLNAME} " $CONFIG_FILE`
		if [ "$CNT" != 1 ]
		then
			if [ "$CNT" -lt 1 ]
			then
			    echo "Could not find a record for Secondary data volume $VOLNAME for $RLINK"
			elif [ "$CNT" -gt 1 ]
			then
			    echo "Found multiple records for Secondary data volume $VOLNAME for $RLINK"
			else 
			    echo "Error finding the record for Secondary data volume $VOLNAME for $RLINK"
			fi
			echo "Ignoring that input."
			echo "Enter Secondary data volume name and Primary data volume name to which it is"
			echo "mapped, separated by a blank.  Terminate input with an empty line."
			read VOLNAME VOLPRIMARYVG
			continue
		fi
		CNT=`egrep -c "^DV  *${VOLPRIMARYVG} " $CONFIG_FILE`
		if [ "$CNT" != 1 ]
		then
			if [ "$CNT" -lt 1 ]
			then
			    echo "ERROR: Could not find a record for Primary data volume $VOLPRIMARYVG"
			elif [ "$CNT" -gt 1 ]
			then
			    echo "ERROR: Found multiple records for Primary data volume $VOLPRIMARYVG"
			else 
			    echo "Error finding the record for Primary data volume $VOLPRIMARYVG"
			fi
			echo "Ignoring that input."
			echo "Enter Secondary data volume name and Primary data volume name to which it is"
			echo "mapped, separated by a blank.  Terminate input with an empty line."
			read VOLNAME VOLPRIMARYVG
			continue
		fi
		PRIMARY_SIZE=`awk '/^DV  *'$VOLPRIMARYVG' / { print $3 }' $CONFIG_FILE`
		SIZESTRING=$PRIMARY_SIZE
		SizeString_To_Len
		PRIMARY_LEN=$LEN
		if [ "$PRIMARY_LEN" = "" ]
		then 
			echo "ERROR: Found bad value for Primary data volume length: $PRIMARY_SIZE"
			echo "Ignoring that input."
			echo "Enter Secondary data volume name and Primary data volume name to which it is"
			echo "mapped, separated by a blank.  Terminate input with an empty line."
			read VOLNAME VOLPRIMARYVG
			continue
		fi

		SECONDARY_SIZE=`awk '/^SDV  *'$RLINK'  *'$VOLNAME' / { print $4 }' $CONFIG_FILE`
		SIZESTRING=$SECONDARY_SIZE
		SizeString_To_Len
		SECONDARY_LEN=$LEN
		if [ "$SECONDARY_LEN" = "" ]
		then 
			echo "ERROR: Found bad value for Secondary data volume length: $SECONDARY_SIZE"
			echo "Ignoring that input."
			echo "Enter Secondary data volume name and Primary data volume name to which it is"
			echo "mapped, separated by a blank.  Terminate input with an empty line."
			read VOLNAME VOLPRIMARYVG
			continue
		fi
		if [ "$SECONDARY_LEN" -lt "$PRIMARY_LEN" ]
		then
			echo "ERROR: Size of Secondary data volume $VOLNAME ($SECONDARY_LEN) is smaller than"
			echo "size of Primary data volume $VOLPRIMARYVG ($PRIMARY_LEN)."
			echo "Ignoring that input."
			echo "Enter Secondary data volume name and Primary data volume name to which it is"
			echo "mapped, separated by a blank.  Terminate input with an empty line."
			read VOLNAME VOLPRIMARYVG
			continue
		fi
		awk '{ if ( $1 == "SDV" && $2 == "'$RLINK'" && $3 == "'$VOLNAME'" )
			printf "SDV  %-17s %-17s %+6s  %7d  %-13s  %s  %-6s\n", $2, $3, $4, $5, $6, "'${VOLPRIMARYVG:-$VOLNAME}'", $8
			else
				printf "%s\n", $0 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		/bin/mv -f  $CONFIG_TMP_FILE $CONFIG_FILE

		echo "Enter Secondary data volume name and Primary data volume name to which it is"
		echo "mapped, separated by a blank.  Terminate input with an empty line."
		read VOLNAME VOLPRIMARYVG
	done
clear
}

#11732
Specify_secondary_DATAVOL_records()
{
clear
/bin/cp $CONFIG_FILE $CONFIG_AUX_ORIG_FILE

while [ 1 ] 
do
	clear
	MENU_LENGTH=22
	Summarize_Create_an_Rvg
        echo "Specify Secondary DATAVOL record(s)"
	echo ""
        echo "This menu is used to build a list of entries for new or pre-existing"
        echo "secondary data volumes to be added to the RVG.  You must still select Go"
	echo "from the previous menu to commit these changes."
        echo ""
	echo "Primary RLINK: $RLINK		Secondary host: $SECONDARY_HOST"
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    1  Specify if data volumes require dcm log (def: ${DATAVOL_LOGSRVM})"
        echo "    2  Specify existing Secondary data volume(s) to add"
        echo "    3  Add new Secondary data volume(s), to be created initially empty"
        echo "    4  Specify a range of new Secondary data volumes to create"
        echo "    5  Delete existing specification for a Secondary data volume"
	echo "    6  Specify or change the Primary data volume for a Secondary data volume"
        echo ""
	echo "    s  Show summary of set-up work specified so far"
        echo "    g  Go -- keep changes and return to previous menu"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
	case "$CHOICE" in
		1 ) Specify_if_log_required_on_datavolume;;
		2 ) Specify_existing_secondary_data_volumes_to_add;;
		3 ) Add_new_secondary_data_volumes_to_be_created_initially_empty;;
		4 ) Specify_a_range_of_new_secondary_data_volumes_to_create;;
                5 ) Delete_existing_specification_for_a_secondary_data_volume;;
		6 ) Specify_or_change_the_primary_data_volume_for_a_secondary_data_volume;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
		[gG] ) Verify_Cfg_File
                    if [ "$?" = 0 ]
                    then
                        clear
                    fi
		    break;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_AUX_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
                                        /bin/mv -f $CONFIG_AUX_ORIG_FILE $CONFIG_FILE
                                        break
                                else
                                        clear
                                fi
                        else
                                break
                        fi;;
		[rR] ) Remote_Vxprint;;
		[vV] ) Vxprint;;
		[qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
		* ) echo "Invalid input: $CHOICE"
			echo "Hit return to continue: \c"
			read Whatever
		    CHOICE="";;
	esac
done
/bin/rm -f $CONFIG_AUX_ORIG_FILE
clear
}

#1173
Create_a_custom_secondary_rvg_hierarchy()
{
clear
/bin/cp $CONFIG_FILE $CONFIG_ORIG_FILE
SECONDARY_SRLVOL_EXISTENCE="CREATE"
SECONDARY_RLK_EXISTENCE="CREATE"

	clear

	RLK_CNT=`/bin/egrep -c "^RL  *${RLINK}" $CONFIG_FILE`
	if [ "$RLK_CNT" = 0 ]
	then
		echo "Could not find RLINK $RLINK in the current set-up configuration"
		echo "Hit return to continue: \c"
		read Whatever
		/bin/mv -f $CONFIG_ORIG_FILE $CONFIG_FILE
		clear
		return 0
	elif [ "$RLK_CNT" -gt 1 ]
	then
		echo "ERROR: Found multiple entries for RLINK $RLINK in the set-up configuration"
		echo "Hit return to continue: \c"
		read Whatever
		/bin/mv -f $CONFIG_ORIG_FILE $CONFIG_FILE
		clear
		return 0
	fi

	set -- `awk '/^RL  *'$RLINK' / { printf "%s %s", $4, $5 }' $CONFIG_FILE`
	SECONDARY_HOST=$1; SECONDARY_DISKGROUP=$2

        set -- `awk '/^RV / { printf "%s\n", $0 }' $CONFIG_FILE`
        RVG=$2; DISKGROUP=$3; RVG_EXISTENCE=$4

while [ 1 ] 
do
	clear
	MOD_CNT=`/bin/egrep -c "^SRV  *${RLINK}|^SRL  *${RLINK}|^SDV  *${RLINK}|^SLV  *${RLINK}" $CONFIG_FILE`
	if [ "$MOD_CNT" = 0 ]
	then
		MENU_LENGTH=18
	else
		MENU_LENGTH=`expr 18 + $MOD_CNT + 3`
	fi
	/bin/rm -f $CONFIG_FILE_OLD	#Forces new Summary to be created
	Summarize_Create_an_Rvg
       	echo "Create/Edit a custom Secondary RVG hierarchy"
	echo ""
	echo "Primary RLINK: $RLINK    Secondary host/diskgroup: $SECONDARY_HOST/$SECONDARY_DISKGROUP"
	echo ""

	# Warn if there are already SRV, SDV, SLV, or SRL entries for this rlink
	if [ "$MOD_CNT" != 0 ]
	then
		echo "Found existing Secondary set-up specification entry(s) for $RLINK:"
		awk '/^S[A-Z]*  *'$RLINK' / { if ( $1 == "SRV" ) printf "    Existing Secondary RVG:         %s\n", $3
		    if ( $1 == "SRL" ) printf "    Existing Secondary RLINK:       %s\n", $3
		    if ( $1 == "SDV" ) printf "    Existing Secondary data volume: %s\n", $3
		    if ( $1 == "SLV" ) printf "    Existing Secondary SRL volume:  %s\n", $3 }' $CONFIG_FILE
		echo "Menu options below will ask if you want to modify any of these existing specs."
		echo ""
	fi

	echo "Choose an option  (\"?\" for other options):"
        echo "    1  Specify Secondary RVG record"
        echo "    2  Specify Secondary DATAVOL record(s)"
        echo "    3  Specify Secondary SRLVOL record"
        echo "    4  Specify Secondary RLINK record"
	echo ""
	echo "    s  Show summary of set-up work specified so far"
        echo "    g  Go -- keep changes and return to previous menu"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
	case "$CHOICE" in
		1 ) Specify_secondary_RVG_record;;
		2 ) Specify_secondary_DATAVOL_records;;
		3 ) Specify_secondary_SRLVOL_record;;
		4 ) Specify_secondary_RLINK_record;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
		[gG] ) SHOW_WARNING=n
			SRV_CNT=`/bin/egrep -c "^SRV  *${RLINK}" $CONFIG_FILE`
			SRL_CNT=`/bin/egrep -c "^SRL  *${RLINK}" $CONFIG_FILE`
			SLV_CNT=`/bin/egrep -c "^SLV  *${RLINK}" $CONFIG_FILE`
			SDV_CNT=`/bin/egrep -c "^SDV  *${RLINK}" $CONFIG_FILE`
			DV_CNT=`/bin/egrep -c "^DV " $CONFIG_FILE`
			if [ "$SRV_CNT" != 1 ]
			then
				echo "WARNING: Secondary RVG has not been specified, yet"
				SHOW_WARNING=y
			fi
			if [ "$SRL_CNT" != 1 ]
			then
				echo "WARNING: Secondary RLINK has not been specified, yet"
				SHOW_WARNING=y
			fi
			if [ "$SLV_CNT" != 1 ]
			then
				echo "WARNING: Secondary SRL volume has not been specified, yet"
				SHOW_WARNING=y
			fi
			if [ "$SDV_CNT" != "$DV_CNT" ]
			then
				echo "WARNING: Count of Secondary data volumes ($SDV_CNT) does not match count of"
				echo "         Primary data volumes ($DV_CNT)"
				SHOW_WARNING=y
			fi
			if [ "$SHOW_WARNING" = "y" ]
			then
                        	echo "Hit return to continue: \c"
                        	read Whatever
			fi
		    Verify_Cfg_File
                    if [ "$?" = 0 ]
                    then
                        clear
                    fi
		    /bin/rm -f $CONFIG_ORIG_FILE
		    clear
		    return 1;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
                                        /bin/mv -f $CONFIG_ORIG_FILE $CONFIG_FILE
                                        clear
					return 0
                                else
                                        clear
                                fi
                        else
				clear
                                return 0
                        fi;;
		[rR] ) Remote_Vxprint;;
		[vV] ) Vxprint;;
		[qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
		* ) echo "Invalid input: $CHOICE"
			echo "Hit return to continue: \c"
			read Whatever
		    CHOICE="";;
	esac
done
# Never gets here.  Does a return from G or B
}

# NOTE: Doesn't delete header in comments before the Sxx records
Delete_existing_specification_for_a_secondary_hierarchy()
{
/bin/cp $CONFIG_FILE $CONFIG_ORIG_FILE
clear
	echo "Delete existing specifications for a Secondary hierarchy"
	echo ""
	echo "Use this option to remove Secondary RVG hierarchy specification(s) which were"
	echo "entered incorrectly."
	echo ""
	echo "First select the Primary rlink.  Primary rlinks specified so far:"
                echo "   Rlink_Name        Local_host  Remote_host  Remote_diskgroup  Remote_rlink  "
                echo "   ----------------  ----------  -----------  ----------------  ----------------"
                awk '/^RL  */ { if ($12 == "EXISTS") 
			    printf "E  %-17s %-12s %-12s %-17s %-17s\n", $2, $3, $4, $5, $6
                        else
                            printf "C  %-17s %-12s %-12s %-17s %-17s\n", $2, $3, $4, $5, $6 } ' $CONFIG_FILE
        echo ""
	while [ 1 ]
	do
		echo "Enter name of RLINK specification for which to delete the *secondary* object"
		echo "specifications.  [The Primary RLINK itself is not modified.]"
		echo "(Empty line to abort): \c"
		read RL EXTRA
                if [ "$EXTRA" != "" ]
                then
                        echo "Only enter one word for name.  No whitespace."
                        continue
                fi
		if [ "$RL" = "" ]
		then
			/bin/rm -f $CONFIG_ORIG_FILE
			return 0
		fi

		/bin/rm -f $CONFIG_2TMP_FILE
		awk '/^RL  *'$RL' / { print $0 }' $CONFIG_FILE > $CONFIG_2TMP_FILE
		if [ ! -s $CONFIG_2TMP_FILE ]
		then
			echo "Could not find specification for Primary RLINK $RL"
			/bin/rm -f $CONFIG_2TMP_FILE
			continue
		fi
		set -- `wc -l $CONFIG_2TMP_FILE`
		if [ "$1" -gt 1 ]
		then
			echo "ERROR: Found multiple RLINK specifications for $RL"
			/bin/rm -f $CONFIG_2TMP_FILE
                        continue
		fi

		set -- `/bin/cat $CONFIG_2TMP_FILE`
		RL_REM_HOST=$3
		RL_REM_DG=$4
		RL_REM_RLINK=$5
		shift; shift
		RL_EXISTENCE=$9
		echo "You selected this Primary RLINK specification"
                echo "   Rlink_Name        local_host  Remote_host  Remote_diskgroup  Remote_rlink  "
                echo "   ----------------  ----------  -----------  ----------------  ----------------"
                awk '/^RL  *'$RL' / { if ($12 == "EXISTS")
                            printf "E  %-17s %-12s %-12s %-17s %-17s\n", $2, $3, $4, $5, $6
                        else
                            printf "C  %-17s %-12s %-12s %-17s %-17s\n", $2, $3, $4, $5, $6 } ' $CONFIG_FILE
		echo ""
		/bin/rm -f $CONFIG_2TMP_FILE
		awk '/^S*/ { if ($2 == "'$RL'" && ( $1 == "SRL" || $1 == "SRV" || $1 == "SDV" || $1 == "SLV") ) print $0 }' $CONFIG_FILE > $CONFIG_2TMP_FILE
		if [ ! -s $CONFIG_2TMP_FILE ]
		then
			echo "Could not find any Secondary object specifications for RLINK $RL"
			/bin/rm -f $CONFIG_2TMP_FILE
			continue
		else
		    echo "Found record(s) specifying object(s) to be set up on the Secondary for this"
		    echo "rlink.  Delete these specification(s)?"
		    echo ""
		    awk '/^SRV  *'$RL' / { 
			if ($5 == "EXISTS")
			    printf "E    RVG:     %-16s diskgroup=%s\n", $3, $4
			else
	  		    printf "C    RVG:     %-16s diskgroup=%s\n", $3, $4 }' $CONFIG_FILE
		    awk '/^SDV  *'$RL' / {
			map_to=$7
			if (map_to == "") map_to=$3 
			if ($6 == "EXISTS")
	  		  printf "E    DATAVOL: %-16s len=%-6s mirrors=%-1d  Map To: %s\n", $3, $4, $5, map_to
			else
	  		  printf "C    DATAVOL: %-16s len=%-6s mirrors=%-1d  Map To: %s\n", $3, $4, $5, map_to }' $CONFIG_FILE

		    awk '/^SLV  *'$RL' / {
			if ($6 == "EXISTS")
	  		  printf "E    SRLVOL:  %-16s len=%-6s mirrors=%-1d\n", $3, $4, $5
			else
	  		  printf "C    SRLVOL:  %-16s len=%-6s mirrors=%-1d\n", $3, $4, $5 }' $CONFIG_FILE

		    awk '/^SRL  *'$RL' / { 
			if ($11 == "EXISTS")
			    printf "E    RLINK:   %-16s Primary_host=%s\n", $3, $4
			else
	  		    printf "C    RLINK:   %-16s Primary_host=%s\n", $3, $4 }' $CONFIG_FILE
		fi
		echo ""
		Y_OR_N=""
                while [ "$Y_OR_N" = "" ]
                do
                	echo "Delete? (default: y) (y/n): \c"
                        read Y_OR_N
                        case "$Y_OR_N" in
                        	"" )    Y_OR_N=y;;
                                [yY] ) Y_OR_N=y;;
                                [nN] ) Y_OR_N=n;;
                                * )     echo "Invalid input"
                                Y_OR_N="" ;;
                        esac
		done
		/bin/rm -f $CONFIG_2TMP_FILE
                if [ "$Y_OR_N" = y ]
                then
			awk '{ if ( ! ($2 == "'$RL'" && ( $1 == "SRL" || $1 == "SRV" || $1 == "SDV" || $1 == "SLV") ) ) print $0 }' $CONFIG_FILE > $CONFIG_2TMP_FILE
			/bin/mv -f $CONFIG_2TMP_FILE $CONFIG_FILE
			break
		else
			/bin/rm -f $CONFIG_ORIG_FILE
			return 0
		fi
	done
clear
while [ 1 ] 
do
	echo ""
	echo ""

	clear
	MENU_LENGTH=14
	Summarize_Create_an_Rvg
	echo "Delete existing specifications for a Secondary hierarchy"
	echo ""
	echo "Deletion of Secondary RVG hierarchy for Primary RLINK $RL was"
	echo "successful.  Select \"Go\" to commit it or \"Previous\" to abort it"
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    s  Show summary of set-up work specified so far"
        echo "    g  Go -- keep changes and return to \"Create an RVG\" menu"
        echo "    p  Previous -- abort changes and return to previous menu"
        echo "    r  Remote vxprint -ht"
        echo "    v  Local vxprint -ht"
        echo "    q  Quit"
        echo ""
        echo "    Enter option: \c"
        read CHOICE
        echo ""
        case "$CHOICE" in
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
                [gG] ) Verify_Cfg_File
                    if [ "$?" = 0 ]
                    then
			clear
                    fi
		    /bin/rm -f $CONFIG_ORIG_FILE
		    clear
		    return 1;;
                [rR] ) Remote_Vxprint;;
                [vV] ) Vxprint;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
                                        /bin/mv -f $CONFIG_ORIG_FILE $CONFIG_FILE
					clear
					return 0
                                else
                                        clear
                                fi
                        else
                                clear
				return 0
                        fi;;
                [qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
                * ) echo "Invalid input: $CHOICE"
                        echo "Hit return to continue: \c"
                        read Whatever
                    CHOICE="";;
        esac
done
# Never gets here.  Does a return from G or B
}

#117
Set_up_secondary_rvg_hierarchy_now()
{
if [ "$RLINK" = "" ]
then
	RLINK=${{SECONDARY_HOST:-hostname}}_rlk
fi
while [ 1 ] 
do
	clear
	MENU_LENGTH=22
	Summarize_Create_an_Rvg
        echo "Set Up Secondary RVG Hierarchy For an Rlink"
	echo ""
	echo "By default, a hierarchy of objects will be set up on the Secondary host which"
	echo "mirrors the Primary RVG hierarchy.  The same names will be used for the"
	echo "RVG, SRL vol, RLINK and datavols as on the primary, and the volumes will"
	echo "be the same size and have the same number of mirrors.  If any of these"
	echo "object names are already in use on the secondary, then the entire operation is"
	echo "aborted."
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    1  Primary RLINK to set up hierarchy for:                  $RLINK"
	echo "    2  Set up default Secondary RVG hierarchy"
	echo "    3  Create/Edit a custom Secondary RVG hierarchy"
        echo "    4  Delete existing specification for a Secondary hierarchy"
	echo ""
	echo "    s  Show summary of set-up work specified so far"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
	case "$CHOICE" in
		1 ) Primary_rlink_to_set_up_hierarchy_for;;
		2 ) Set_up_default_secondary_rvg_hierarchy
		    if [ "$?" = 1 ]
		    then 
			break
		    else
			continue
		    fi;;
		3 ) Create_a_custom_secondary_rvg_hierarchy
		    if [ "$?" = 1 ]
		    then 
			break
		    else
			continue
		    fi;;
		4 ) Delete_existing_specification_for_a_secondary_hierarchy
		    if [ "$?" = 1 ]
		    then 
			break
		    else
			continue
		    fi;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
		[pP] ) break;;
		[rR] ) Remote_Vxprint;;
		[vV] ) Vxprint;;
		[qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
		* ) echo "Invalid input: $CHOICE"
			echo "Hit return to continue: \c"
			read Whatever
		    CHOICE="";;
	esac
done
clear
}

#11653
SRL_Overflow_Protection_mode()
{
clear
        echo "Select the SRL overflow protection mode for this rlink"
	echo ""
	echo "The srlprot (SRL Overflow Protection mode) attribute determines whether the"
	echo "rlink is prevented from overflowing its SRL volume, causing it to become"
	echo "stale. If SRL protection is enabled and the next write would overflow the SRL,"
	echo "then throttling is enabled and all subsequent write requests are stalled"
	echo "until throttling is disabled. Throttling is not disabled until a pre-determined"
	echo "amount of space is available on the Primary SRL volume. Set it to:"
	echo "    off      -- SRL overflow protection is disabled (default)."
	echo "    override -- SRL overflow protection is enabled, but will automatically be"
	echo "                disabled if the RLINK becomes inactive due to a disconnection"
	echo "                or administrative action."
	echo "    fail     -- SRL overflow protection is enabled. If the RLINK becomes"
	echo "                inactive for any reason, and SRL overflow is imminent,"
	echo "                subsequent write requests are failed with an EIO error."
	echo "    dcm      -- SRL Overflow protection is enabled. If the RLINK becomes"
	echo "                inactive for any reason, and SRL overflow is imminent,"
	echo "                RLINK will go into dcm active mode, where the dirty"
	echo "                blocks are stored in the DCM log and then replayed "
        echo "                when RLINK becomes active for each volume."
	echo ""
	echo "Choose an option :"
	echo "    1 off"
	echo "    2 fail"
	echo "    3 override"
	echo "    4 dcm"
	echo ""
        echo "Select the SRL overflow protection mode for this RLINK (newline to back up): \c"
        NEW_SRLPROT_MODE=""
        while [ "$NEW_SRLPROT_MODE" = "" ]
        do
                read NEW_SRLPROT_MODE
                case "$NEW_SRLPROT_MODE" in
                    "" )    break;;
		    1 ) NEW_SRLPROT_MODE=O;;
		    2 ) NEW_SRLPROT_MODE=F;;
		    3 ) NEW_SRLPROT_MODE=V;;
		    4 ) NEW_SRLPROT_MODE=D;;
                    * )     echo "Bad input"
                            NEW_SRLPROT_MODE=""
        		    echo "Select the SRL overflow protection mode for this RLINK (newline to back up): \c"
                            continue;;
                esac
        done
        if [ "$NEW_SRLPROT_MODE" != "" ]
        then
                SRLPROT_MODE="$NEW_SRLPROT_MODE"
		Get_throttling_mode_strings
        fi
clear
}

#1165241
Set_latency_high_mark()
{
clear
	echo "Set the latency_high_mark"
	echo ""
	echo "Current latency_high_mark: ${HIGH_LATENCY:-10000}"
	while [ 1 ]
	do
		echo "Enter a new value for the latency_high_mark (newline to back up): \c"
		read NEW_HIGH_LATENCY
		case "$NEW_HIGH_LATENCY" in
			"" ) break;;
			[0-9] | [0-9]*[0-9] ) HIGH_LATENCY=$NEW_HIGH_LATENCY
			     break;;
			* ) echo "Invalid input: $NEW_HIGH_LATENCY"
			    NEW_HIGH_LATENCY="";;
		esac
	done
clear
}

#1165242
Set_latency_low_mark()
{
clear
	echo "Set the latency_low_mark"
	echo ""
	echo "Current latency_low_mark: ${LOW_LATENCY:-9950}"
	while [ 1 ]
	do
		echo "Enter a new value for the latency_low_mark (newline to back up): \c"
		read NEW_LOW_LATENCY
		case "$NEW_LOW_LATENCY" in
			"" ) break;;
			[0-9] | [0-9]*[0-9] ) LOW_LATENCY=$NEW_LOW_LATENCY
			     break;;
			* ) echo "Invalid input: $NEW_LOW_LATENCY"
			    NEW_LOW_LATENCY="";;
		esac
	done
clear
}

#116524
Set_latency_high_mark_and_or_latency_low_mark()
{
SAVED_HIGH_LATENCY=$HIGH_LATENCY
SAVED_LOW_LATENCY=$LOW_LATENCY
while [ 1 ]
do
	clear
	echo "Set the latency_high_mark/latency_low_mark"
	echo ""
	echo "When latency protection is enabled, if the number of outstanding write requests"
	echo "which have not been written to the Secondary data volume, yet reaches"
	echo "latency_high_mark, then all new write requests are stalled until the number of"
	echo "outstanding write requests falls below latency_low_mark."
	echo ""
        echo "Choose an option :"
        echo "    1 latency_high_mark                               ${HIGH_LATENCY:-10000}"
        echo "    2 latency_low_mark                                ${LOW_LATENCY:-9950}"
	echo ""
        echo "    g  Go -- keep changes and return to previous menu"
        echo "    p  Previous -- abort changes and return to previous menu"
	echo ""
        echo "    Enter option: \c"
        read CHOICE
        echo ""
        case "$CHOICE" in
                1 ) Set_latency_high_mark;;
                2 ) Set_latency_low_mark;;
		[gG] ) if [ "${HIGH_LATENCY:-10000}" -lt "${LOW_LATENCY:-9950}" ]
			then
				echo "ERROR: latency_high_mark cannot be less than latency_low_mark"
				echo "Hit return to continue: \c"
				read Whatever
			else
				break
			fi;;
                [pP] ) if [ "$SAVED_HIGH_LATENCY" != "$HIGH_LATENCY" ] || [ "$SAVED_LOW_LATENCY" != "$LOW_LATENCY" ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
					HIGH_LATENCY=$SAVED_HIGH_LATENCY
					LOW_LATENCY=$SAVED_LOW_LATENCY
                                        break
                                else
                                        clear
                                fi
                        else
                                break
                        fi;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
                "" ) CHOICE="";;
                * ) echo "Invalid input: $CHOICE"
                        echo "Hit return to continue: \c"
                        read Whatever
                    CHOICE="";;
        esac
done
clear
}

#11652
Latency_Protection_mode()
{
while [ 1 ]
do
	clear
        echo "Select the latency mode for this rlink"
	echo ""
	echo "The latencyprot (Latency Protection mode) attribute determines whether the"
	echo "rlink is prevented from having more than a preset number (default 10,000) of"
	echo "outstanding write requests. If the preset number (the latency_high_mark) of"
	echo "outstanding write requests have not been written to the Secondary data volume,"
	echo "then throttling is enabled. All new write requests are stalled until the number"
	echo "of outstanding write requests falls below another preset number (the"
	echo "latency_low_mark, which defaults to 9950).  Set it to:"
	echo "    off      -- Latency protection is disabled (default)."
	echo "    fail     -- Latency protection is enabled. If the RLINK becomes inactive"
	echo "                for any reason, and the latency_high_mark is reached, subsequent"
	echo "                write requests are failed with an EIO error."
	echo "    override -- Latency protection is enabled, but will automatically be"
	echo "                disabled if the RLINK becomes inactive due to a disconnection"
	echo "                or administrative action."
	echo ""
	echo "Choose an option :   [Current=${LATENCY:-off} High=$HIGH_LATENCY Low=${LOW_LATENCY}]"
	echo "    1 off"
	echo "    2 fail"
	echo "    3 override"
	echo "    4 Set latency_high_mark and/or latency_low_mark"
	echo ""
	echo "    Enter option (newline to accept and back up): \c"
        NEW_LATENCY_MODE=""
	read NEW_LATENCY_MODE
        case "$NEW_LATENCY_MODE" in
		"" )    break;;
		1 ) NEW_LATENCY_MODE=O
		    break;;
		2 ) NEW_LATENCY_MODE=F
		    break;;
		3 ) NEW_LATENCY_MODE=V
		    break;;
		4 ) Set_latency_high_mark_and_or_latency_low_mark
       	            NEW_LATENCY_MODE="";;
		* ) echo "Invalid input: $NEW_LATENCY_MODE"
		    echo "Hit return to continue: \c"
		    read Whatever
       	            NEW_LATENCY_MODE="";;
	esac
done
        if [ "$NEW_LATENCY_MODE" != "" ]
        then
                LATENCY_MODE="$NEW_LATENCY_MODE"
		Get_throttling_mode_strings
        fi
clear
}

#11651
Sync_mode()
{
while [ 1 ]
do
	clear
        echo "Select the sync mode for this rlink"
	echo ""
	echo "The synchronous (Sync mode) attribute determines whether write requests to"
	echo "secondary volumes complete when the data has just been recorded in the primary"
	echo "SRL volume (asynchronous mode) or whether the data has actually reached the"
	echo "secondary node (synchronous mode).  Set it to:"
	echo "    off      -- The mode is asynchronous.  Write requests are completed when "
	echo "                the data has been recorded in the Primary SRL volume."
	echo "    override -- The mode is synchronous, but will automatically switch to"
	echo "                asynchronous if the RLINK becomes inactive due to a"
	echo "                disconnection or administrative action."
	echo "    fail     -- The mode is synchronous.  If the RLINK becomes inactive for"
	echo "                any reason, subsequent write requests are failed with an EIO"
	echo "                error."
	echo ""
	echo "Choose an option :"
	echo "    1 off"
	echo "    2 fail"
	echo "    3 override"
	echo ""
        echo "Select the sync mode for this RLINK (newline to back up): \c"
        NEW_SYNC_MODE=""
	read NEW_SYNC_MODE
	case "$NEW_SYNC_MODE" in
                    "" )    break;;
		    1 ) NEW_SYNC_MODE=O;;
		    2 ) NEW_SYNC_MODE=F;;
		    3 ) NEW_SYNC_MODE=V;;
                    * ) echo "Bad input"
		    	echo "Hit return to continue: \c"
		    	read Whatever
                        continue;;
	esac
        if [ "$NEW_SYNC_MODE" != "" ]
        then
                SYNC_MODE="$NEW_SYNC_MODE"
		Get_throttling_mode_strings
		break
        fi
done
clear
}

#1165
Throttling_modes()
{
clear
/bin/cp $CONFIG_FILE $CONFIG_AUX_ORIG_FILE

while [ 1 ]
do
        clear
	MENU_LENGTH=20
        Summarize_Create_an_Rvg
	echo "Configure for RLINK ${RLINK:-${SECONDARY_HOST:-hostname}_rlk}."
	echo ""
	echo "There are 3 attributes related to the configuration of RLINK "
	echo "synchronous (Sync mode), latencyprot (Latency Protection mode), and"
	echo "srlprot (SRL Overflow Protection mode).  Each of these can be set to off"
	echo "(default), fail, or override.  Select an option to get more info on that option."
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    1 Sync mode                         ${SYNC:-off}"
	echo "    2 Latency Protection mode           ${LATENCY:-off}\tHigh=$HIGH_LATENCY Low=$LOW_LATENCY"
	echo "    3 SRL Overflow Protection mode      ${SRLPROT:-off}"
	echo ""
	echo "    s  Show summary of set-up work specified so far"
        echo "    g  Go -- keep changes and return to previous menu"
        echo "    p  Previous -- abort changes and return to previous menu"
        echo "    r  Remote vxprint -ht"
        echo "    v  Local vxprint -ht"
        echo "    q  Quit"
        echo ""
        echo "    Enter option: \c"
        read CHOICE
        echo ""
        case "$CHOICE" in
		1 ) Sync_mode;;
		2 ) Latency_Protection_mode;;
		3 ) SRL_Overflow_Protection_mode;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
                [gG] ) Verify_Cfg_File
                    if [ "$?" = 0 ]
                    then
                        clear
                    fi
                    break;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_AUX_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
                                        /bin/mv -f $CONFIG_AUX_ORIG_FILE $CONFIG_FILE
                                        break
                                else
                                        clear
                                fi
                        else
                                break
                        fi;;
                [rR] ) Remote_Vxprint;;
                [vV] ) Vxprint;;
                [qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
                "" ) CHOICE="";;
                * ) echo "Invalid input: $CHOICE"
                        echo "Hit return to continue: \c"
                        read Whatever
                    CHOICE="";;
        esac
done
/bin/rm -f $CONFIG_AUX_ORIG_FILE
clear
}

#1164
Secondary_rlink_name()
{
clear
        echo "Enter name of the remote RLINK for this RLINK (newline to"
	echo "back up): \c"
        NEW_SECONDARY_RLINK=""
        while [ "$NEW_SECONDARY_RLINK" = "" ]
        do
                read NEW_SECONDARY_RLINK
                case "$NEW_SECONDARY_RLINK" in
                    "" )    break;;
		    [a-z]* | [A-Z]* | _* ) ;;
                    * )     echo "Bad remote hostname input"
                            NEW_SECONDARY_RLINK=""
        		    echo "Enter name of the remote RLINK for this RLINK (newline to"
			    echo "back up): \c"
                            continue;;
                esac

		if [ "$SECONDARY_HOST" = "$LOCAL_HOST" ] 
		then
		    if [ "${SECONDARY_DISKGROUP:-$DISKGROUP}" = "$DISKGROUP" ]
		    then
			if [ "$RLINK" = "$NEW_SECONDARY_RLINK" ]
			then
				echo "ERROR: Since both the Primary and Secondary host names and diskgroups are the,"
				echo "same, you can not use the same name for the Primary RLINK and Secondary rlink."
                        	NEW_SECONDARY_RLINK=""
        			echo "Enter name of the remote RLINK for this RLINK (newline to"
				echo "back up): \c"
                        	continue
			fi
		    fi
		fi

		NAME=$NEW_SECONDARY_RLINK
		Remote_check_if_name_is_in_use_by_VXVM
		if [ "$?" = 1 ]
		then
			echo "ERROR: The name $NEW_SECONDARY_RLINK is already in use in diskgroup ${SECONDARY_DISKGROUP:-$DISKGROUP} on $SECONDARY_HOST."
                        NEW_SECONDARY_RLINK=""
        		echo "Enter name of the remote RLINK for this RLINK (newline to"
			echo "back up): \c"
                        continue
		fi

		Check_if_name_is_in_use_by_config_file_for_remote
		if [ "$?" = 1 ]
		then
			echo "Name $NEW_SECONDARY_RLINK has already been specified for use on the Secondary ($SECONDARY_HOST/${SECONDARY_DISKGROUP:-$DISKGROUP})"
                        NEW_SECONDARY_RLINK=""
        		echo "Enter name of the remote RLINK for this RLINK (newline to"
			echo "back up): \c"
                        continue
			
		fi
        done
        if [ "$NEW_SECONDARY_RLINK" != "" ]
        then
                SECONDARY_RLINK="$NEW_SECONDARY_RLINK"
        fi
clear
}

#1163, #117311
Secondary_diskgroup_name()
{
clear
        echo "The Secondary diskgroup name should be the name of the disk group that the"
        echo "secondary objects are in.  It defaults to the name used for the primary"
        echo "diskgroup ($DISKGROUP)."
        echo ""
        echo "Enter name of diskgroup for the Secondary (newline to back up): \c"
        NEW_SECONDARY_DISKGROUP=""
        while [ "$NEW_SECONDARY_DISKGROUP" = "" ]
        do
                read NEW_SECONDARY_DISKGROUP
                case "$NEW_SECONDARY_DISKGROUP" in
                    "" )    break;;
		    [a-z]* | [A-Z]* | _* ) break;;
                    * )     echo "Bad remote hostname input"
                            NEW_SECONDARY_DISKGROUP=""
        		    echo "Enter name of diskgroup for the Secondary (newline to back up): \c"
                            continue;;
                esac
        done
        if [ "$NEW_SECONDARY_DISKGROUP" != "" ]
        then
                SECONDARY_DISKGROUP="$NEW_SECONDARY_DISKGROUP"
        fi
clear
}

Local_host_name()
{
	clear
	echo ""
        echo "The local_host is the value of the local_host field"
        echo "in the RLINK (not to be confused with the name of the"
        echo "host that the RLINK itself is on)."
        echo ""
        echo "Enter name of the local host for this RLINK (default: <${RLK_LOCAL_HOST}> ): \c"
        NEW_RLK_LOCAL_HOST=""
        while [ "$NEW_RLK_LOCAL_HOST" = "" ]
        do
                read NEW_RLK_LOCAL_HOST
                case "$NEW_RLK_LOCAL_HOST" in
                    "" )    break;;
		    [a-z]* | [A-Z]* | _* ) break;;
                    * )     echo "Bad local hostname input"
                            NEW_RLK_LOCAL_HOST=""
        		    echo "Enter name of the local host for this RLINK (newline to back up): \c"
                            continue;;
                esac
        done
        if [ "$NEW_RLK_LOCAL_HOST" != "" ]
        then
                RLK_LOCAL_HOST="$NEW_RLK_LOCAL_HOST"
        fi
clear
}

Remote_host_name()
{
clear
	echo ""
        echo "The remote_host is the value of the remote_host field"
        echo "in the remote RLINK (not to be confused with the name of the"
        echo "host that the remote RLINK itself is on)."
        echo ""
        echo "Enter name of the remote host for this RLINK (newline to back up): \c"
        NEW_RLK_REMHOST=""
        while [ "$NEW_RLK_REMHOST" = "" ]
        do
                read NEW_RLK_REMHOST
                case "$NEW_RLK_REMHOST" in
                    "" )    break;;
		    [a-z]* | [A-Z]* | _* ) break;;
                    * )     echo "Bad remote hostname input"
                            NEW_RLK_REMHOST=""
        		    echo "Enter name of the remote host for this RLINK (newline to back up): \c"
                            continue;;
                esac
        done
        if [ "$NEW_RLK_REMHOST" != "" ]
        then
                RLK_REM_HOST="$NEW_RLK_REMHOST"
        fi
clear
}

#1162
Secondary_host_name()
{
clear
	echo "Secondary host name"
	echo ""
	echo "This menu will also modify the value of the default new Primary RLINK name and"
	echo "the Secondary RLINK name (options 1 and 4 from the previous menu) if no values"
	echo "have been explicitly set for them, yet."
	echo "NOTE: If the resulting new Primary RLINK name or Secondary RLINK name is in use"
	echo "by VVR or the configuration set-up so far, then the substitution is not made"
	echo "and you must explicitly set the name for that RLINK or Secondary rlink."
	echo ""
        echo "Enter name of the Secondary host machine for this RLINK (newline to"
	echo "back up): \c"
        NEW_SECONDARY_HOST=""
        while [ "$NEW_SECONDARY_HOST" = "" ]
        do
                read NEW_SECONDARY_HOST EXTRA
		if [ "$EXTRA" != "" ]
		then
			echo "Only enter one word for name.  No whitespace."
			NEW_SECONDARY_HOST=""
        		echo "Enter name of the Secondary host machine for this RLINK (newline to"
			echo "back up): \c"
                        continue
		fi
                case "$NEW_SECONDARY_HOST" in
                    "" )    break;;
		    [a-z]* | [A-Z]* | _* ) ;;
                    * )     echo "Bad remote hostname input"
                            NEW_SECONDARY_HOST=""
        		    echo "Enter name of the Secondary host machine for this RLINK (newline to"
			    echo "back up): \c"
                            continue;;
                esac
		/usr/sbin/ping $NEW_SECONDARY_HOST 10 > /dev/null 2>/dev/null
		if [ "$?" != 0 ]
		then
			echo "Error contacting $NEW_SECONDARY_HOST"
			NEW_SECONDARY_HOST=""
			echo "Enter name of the Secondary host machine for this RLINK (newline to"
                        echo "back up): \c"
                        continue
		fi
        done
        if [ "$NEW_SECONDARY_HOST" != "" ]
        then
                SECONDARY_HOST="$NEW_SECONDARY_HOST"
		if [ "$RLINK" = "" ]
		then
			NAME=${SECONDARY_HOST}_rlk
			Check_if_name_is_in_use_by_config_file
			if [ "$?" = 1 ]
			then
				RLINK=hostname_rlk
				SECONDARY_RLINK=hostname_rlk
				echo "WARNING: Not setting the default Primary (or secondary) RLINK name to"
				echo "$NAME since that name has already been specified for use."
				echo "Hit return to continue: \c"
				read Whatever
			else
	        		Check_if_name_is_in_use_by_VXVM
	        		if [ "$?" = 1 ]
	        		then
					RLINK=hostname_rlk
					SECONDARY_RLINK=hostname_rlk
					echo "WARNING: Not setting the default Primary (or secondary) RLINK name to"
					echo "$NAME since that name is already in use locally."
					echo "Hit return to continue: \c"
					read Whatever
	        		fi
			fi
		fi
		if [ "$SECONDARY_RLINK" = "" ] && [ "$RLINK" != "hostname_rlk" ]
		then
			NAME=${RLINK:-${SECONDARY_HOST}_rlk}
			Check_if_name_is_in_use_by_config_file_for_remote
			if [ "$?" = 1 ]
			then
				echo "WARNING: Not setting the default Secondary RLINK name to $NAME since that"
				echo "name has already been specified for use for ${RLINK:-${SECONDARY_HOST}_rlk}.  Set it explicitly."
				SECONDARY_RLINK=hostname_rlk
				echo "Hit return to continue: \c"
				read Whatever
			else
				Remote_check_if_name_is_in_use_by_VXVM
				if [ "$?" = 1 ]
				then
					echo "WARNING: Not setting the default Secondary RLINK name to $NAME since that"
					echo "name is in use on $SECONDARY_HOST.  Set it explicitly."
					SECONDARY_RLINK=hostname_rlk
					echo "Hit return to continue: \c"
					read Whatever
				else
					echo "Hit return to continue: \c"
					read Whatever
				fi
			fi
		fi
        fi
clear
}

#1161
New_primary_rlink_name()
{
clear
	echo "New Primary RLINK name"
	echo ""
	echo "This menu will also modify the value of the default Secondary RLINK name (option"
	echo "4 from the previous menu) if no value has been explicitly set for it, yet."
	echo ""
        echo "Enter name to be used for new RLINK (newline to back up): \c"
        NEW_RLK_NAME=""
        while [ "$NEW_RLK_NAME" = "" ]
        do
                read NEW_RLK_NAME EXTRA
		if [ "$EXTRA" != "" ]
		then
			echo "Only enter one word for name.  No whitespace."
			NEW_RLK_NAME=""
        		echo "Enter name to be used for new RLINK (newline to back up): \c"
                        continue
		fi
                case "$NEW_RLK_NAME" in
                    "" )    break;;
		    [a-z]* | [A-Z]* | _* ) ;;
                    * )     echo "Bad RLINK name input"
                            NEW_RLK_NAME=""
        		    echo "Enter name to be used for new RLINK (newline to back up): \c"
                            continue;;
                esac
                $VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -htQq "$NEW_RLK_NAME" 2> /dev/null 1> /dev/null
                if [ "$?" = 0 ]
                then
                        echo "Object $NEW_RLK_NAME already exists."
        		echo "Enter name to be used for new RLINK (newline to back up): \c"
			NEW_RLK_NAME=""
                        continue
                fi
		NAME=$NEW_RLK_NAME
		Check_if_name_is_in_use_by_config_file
		if [ "$?" = 1 ]
		then
			FOUND_RLK=`egrep -c "^RL  *$NEW_RLK_NAME " $CONFIG_FILE`
			if [ "$FOUND_RLK" != 1 ]
			then
                        	echo "Object name $NEW_RLK_NAME has already been specified for use."
        			echo "Enter name to be used for new RLINK (newline to back up): \c"
				NEW_RLK_NAME=""
                        	continue
			fi
		    	Y_OR_N=""
		    	while [ "$Y_OR_N" = "" ]
		    	do
				echo "Found existing specification for RLINK $NEW_RLK_NAME."
				echo "Modify existing specification for RLINK $NEW_RLK_NAME? (default: y) (y/n): \c"
                		read Y_OR_N
                		case "$Y_OR_N" in
                        		"" )    Y_OR_N=y;;
                        		[yY] ) Y_OR_N=y;;
                        		[nN] ) Y_OR_N=n;;
                        		* )     echo "Invalid input"
						Y_OR_N="" ;;
                		esac
		    	done
			if [ "$Y_OR_N" = n ]
			then
				echo "Enter name to be used for new RLINK (newline to back up): \c"
				NEW_RLK_NAME=""
				continue
			fi
			set -- `awk '/^RL  *'$NEW_RLK_NAME' / { print $0 }' $CONFIG_FILE`
			RLINK=$2; SECONDARY_HOST=$4; SECONDARY_DISKGROUP=$5; SECONDARY_RLINK=$6
			SYNC_MODE=$9; LATENCY_MODE=$8; SRLPROT_MODE=$9
			shift; shift; shift
			HIGH_LATENCY=$7; LOW_LATENCY=$8; RLK_EXISTENCE=$9
			if [ "$RLK_EXISTENCE" != "CREATE" ]
			then
				echo "ERROR: Rlink $NEW_RLK_NAME is a pre-existing rlink.  You can not edit it from this menu."
        			echo "Enter name to be used for new RLINK (newline to back up): \c"
				NEW_RLK_NAME="" 
				continue
			fi
			Get_throttling_mode_strings
			if [ "$?" = 0 ]
			then
				echo "ERROR: Bad value(s) for Throttling mode(s) for RLINK $NEW_RLK_NAME"
				echo "Giving up on trying to use that record."
				echo ""
				echo "Enter name to be used for new RLINK (newline to back up): \c"
				NEW_RLK_NAME=""
				continue
			fi
                fi
        done
        if [ "$NEW_RLK_NAME" != "" ]
        then
                RLINK="$NEW_RLK_NAME"
        fi
clear
}

# Inputs:
#       NAME            VVR object name to check existence of 
Check_if_name_is_in_use_by_VXVM()
{
	$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -htQq "$NAME" 2> /dev/null 1> /dev/null
	if [ "$?" = 0 ]
	then
		return 1
	else 
		return 0
	fi
}

# Remote_check_if_name_is_in_use_by_VXVM
#
# Inputs:
#	NAME		VVR object name to check existence of on remote
#	SECONDARY_HOST        remote host name
#	SECONDARY_DISKGROUP diskgroup in which to check for the object name on the secondary
Remote_check_if_name_is_in_use_by_VXVM()
{
	echo "	Checking to see if the name $NAME is in use by an existing object in ${SECONDARY_DISKGROUP:-$DISKGROUP} on $SECONDARY_HOST...\c"
        REMOTE_CMD="$VXVM_BIN/vxprint -g "${SECONDARY_DISKGROUP:-$DISKGROUP}" -htQq "$NAME""
	Do_Remote_Cmd >/dev/null 2> $REMOTE_CHECK
	if [ "$?" = 0 ]
	then
		echo "EXISTS"
		/bin/rm -f $REMOTE_CHECK
		return 1
	else 
		echo "DOESN'T EXIST"
		grep 'No such disk group' $REMOTE_CHECK
		/bin/rm -f $REMOTE_CHECK
	fi
# NOTE: Moved this test to Check_if_name_is_in_use_by_config_file_for_remote
#	if [ "$LOCAL_HOST" = "$SECONDARY_HOST" ]
#	then
#	    if [ "${SECONDARY_DISKGROUP:-$DISKGROUP}" = "${DISKGROUP}" ]
#	    then
#		Check_if_name_is_in_use_by_config_file
#        	if [ "$?" = 1 ]
#        	then
#			echo "        Remote_check_if_name_is_in_use_by_VXVM: Detected that local and"
#			echo "        Secondary host are the same, and, although the object name \"$NAME\""
#			echo "        is not currently in use by VxVM in ${SECONDARY_DISKGROUP:-$DISKGROUP} here, it has already"
#			echo "        been specified for use via this script for another object."
#                	return 1
#		fi
#	    fi
#	fi
	return 0
}

# Inputs: 
#	NAME	name of object to check for name conflicts
#
Check_if_name_is_in_use_by_config_file()
{
	/bin/rm -f $VERIFY_CFG_FILE
	awk '/^DV/ || /^LV/ || /^RL/ || /^RV/ {	# All implicitly in same dg
		if ( "'$NAME'" == $2 )
			printf "XXXConfiguration already using object name: Line %d:%s\n", NR, $0 }' $CONFIG_FILE > $VERIFY_CFG_FILE
	if [ -s $VERIFY_CFG_FILE ]
	then
		/bin/rm -f $VERIFY_CFG_FILE
		return 1
	else
		/bin/rm -f $VERIFY_CFG_FILE
		return 0
	fi
}

# Check for whether this Secondary object NAME will cause a conflict once it is
# created.  (What if primaryhost=secondaryhost?)
# Inputs:
#	${SECONDARY_HOST:-hostname}
#	${SECONDARY_DISKGROUP:-$DISKGROUP}	Used if available
#       NAME    	name of Secondary object associated with Primary RLINK
#	PARENT_RL_OK 	For SRL records, set this to RL name to avoid finding 
#			"name in use as Secondary RL for this RL record"
#
Check_if_name_is_in_use_by_config_file_for_remote()
{
	# Even if no conflicting S* record has been created, yet, check for
	# a Primary RL record with same Secondary_host and Secondary_diskgroup 
	# that intends to use this name for the Secondary rlink
	CONFLICT_RL=""
	CONFLICT_RL=`awk '/^RL / { if ( "'$NAME'" == $6 && "'$SECONDARY_HOST'" == $4 && "'${SECONDARY_DISKGROUP:-$DISKGROUP}'" == $5 && "'$PARENT_RL_OK'" != $2 ) print $2 }' $CONFIG_FILE`
	if [ "$CONFLICT_RL" != "" ]
	then
		return 1
	fi

	# If Primary and Secondary host are the same, and diskgroups match,
	# also check that no other objects in Primary RVG hierarchy are using
	# this NAME.
	if [ "$SECONDARY_HOST" = "$LOCAL_HOST" ] && [ "${SECONDARY_DISKGROUP:-$DISKGROUP}" = "$DISKGROUP" ]
	then
		Check_if_name_is_in_use_by_config_file
		if [ "$?" = 1 ]
                then
			return 1
		fi
	fi

	# If NAME matches a SECONDARY record in the set-up config, see if 
	# NAME and record use the same remote diskgroup
	CONFLICTING_RLKS=`awk '/^S/  { if ("'$NAME'" == $3 )
		printf "%s ", $2 }' $CONFIG_FILE`

	for CONFLICT_RLK in $CONFLICTING_RLKS
	do
		# Make sure SECONDARY HOSTS match
		CONFLICT_HOST=""
		CONFLICT_HOST=`awk '/^RL  *'$CONFLICT_RLK' / { print $3 }' $CONFIG_FILE`
		if [ "$CONFLICT_HOST" = "" ]
		then
			: #No RL record?! We don't know which host, so assume worst?
		else
			if [ "$CONFLICT_HOST" != "$SECONDARY_HOST" ]
			then
				continue
			fi
		fi

		CONFLICT_SDG=""
		CONFLICT_SDG=`awk '/^SRV  *'$CONFLICT_RLK' / { print $4 }' $CONFIG_FILE`
		if [ "$CONFLICT_SDG" = "" ]
		then
			# May not be an SRV record, yet.  Report name conflict.
			return 1
		else
			if [ "$CONFLICT_SDG" = "${SECONDARY_DISKGROUP:-$DISKGROUP}" ]
			then
				return 1
			else
				continue
			fi
		fi
	done
	return 0
}

# Inputs:
#	RLINK SECONDARY_HOST SECONDARY_DISKGROUP SECONDARY_RLINK
#	SYNC_MODE LATENCY_MODE SRLPROT_MODE
#	HIGH_LATENCY LOW_LATENCY RLK_EXISTENCE
Add_Rlink_To_Config()
{


	NAME=$RLINK
	Check_if_name_is_in_use_by_VXVM
	if [ "$?" = 1 ]
	then
		echo "Cannot use that RLINK name.  Object $NAME already exists."
                echo "Hit return to continue: \c"
                read Whatever
                return 0
	fi

	Get_throttling_mode_strings
	if [ "$?" = 0 ]
	then
                echo "ERROR: Bad value(s) for Throttling mode(s) for RLINK $RLINK."
                echo "Hit return to continue: \c"
                read Whatever
		return 0
	fi

	OVERWRITE_RL=n
	Check_if_name_is_in_use_by_config_file
	if [ "$?" = 1 ]
	then
		FOUND_RLK=`egrep -c "^RL  *$NEW_RLK_NAME " $CONFIG_FILE`
		if [ "$FOUND_RLK" != 1 ]
		then
			echo "Cannot use that RLINK name.  \"$NAME\" has already been specified for use."
                	echo "Hit return to continue: \c"
                	read Whatever
			return 0
		fi
		OVERWRITE_RL=""
		while [ "$OVERWRITE_RL" = "" ]
		do
			echo "Overwrite existing specification for RLINK $NEW_RLK_NAME? (default: y) (y/n): \c"
                	read OVERWRITE_RL
                	case "$OVERWRITE_RL" in
                       		"" )    OVERWRITE_RL=y;;
                       		[yY] ) OVERWRITE_RL=y;;
                       		[nN] ) return 0;;
                       		* )     echo "Invalid input"
					OVERWRITE_RL="" ;;
                	esac
		done
	fi

	SECOND_DISKGROUP=`awk '/^SRV  *'$RLINK' / { print $4 }' $CONFIG_FILE`
	if [ "$SECOND_DISKGROUP" != "" ]
	then
	    if [ "$SECOND_DISKGROUP" != "$SECONDARY_DISKGROUP" ]
	    then
		SECOND_RVG=`awk '/^SRV  *'$RLINK' / { print $3 }' $CONFIG_FILE`
		echo "WARNING: The Primary RLINK record ($RLINK) specifies $SECONDARY_DISKGROUP as the"
		echo "secondary disk group, but the Secondary RVG record ($SECOND_RVG) specifies"
		echo "$SECOND_DISKGROUP.  Modify one or the other so that they match before attempting"
		echo "to create the Secondary RVG hierarchy."
		echo "Hit return to continue: \c"
		read Whatever
	    fi
	fi

	if [ "$OVERWRITE_RL" = n ]
	then
		echo "" >> $CONFIG_FILE
		echo "#RL  Rlink_Name        local_host    Remote_host  Remote_diskgroup  Remote_rlink      Modes  HighLatency  LowLatency   Create/Exists"  >> $CONFIG_FILE
		echo "#    ----------------  -----------  ----------------  ----------------  -----  -----------  -----------  ------------- ---------"  >> $CONFIG_FILE
		awk 'END { printf "RL   %-17s %-12s %-12s %-17s %-17s %-1s %-1s %-1s  %-11s  %-11s  %s\n", "'${RLINK:-${SECONDARY_HOST:-hostname}_rlk}'", "'${RLK_LOCAL_HOST:-$LOCAL_HOST}'","'${RLK_REM_HOST:-$SECONDARY_HOST}'", "'${SECONDARY_DISKGROUP:-$DISKGROUP}'", "'${SECONDARY_RLINK:-$RLINK}'", "'${SYNC_MODE:-O}'", "'${LATENCY_MODE:-O}'", "'${SRLPROT_MODE:-O}'", "'${HIGH_LATENCY:-10000}'", "'${LOW_LATENCY:-9950}'", "'${RLK_EXISTENCE:-CREATE}'" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		echo "" >> $CONFIG_TMP_FILE
		/bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
		/bin/rm -f $CONFIG_TMP_FILE
	else
		awk '{	if ($1 == "RL" && $2 == "'$RLINK'" ) 
				printf "RL   %-17s %-12s %-12s %-17s %-17s %-1s %-1s %-1s  %-11s  %-11s  %s\n", "'${RLINK:-${SECONDARY_HOST:-hostname}_rlk}'",  "'${RLK_LOCAL_HOST:-$PRIMARYHOST}'","'${RLK_REM_HOST:-$SECONDARY_HOST}'", "'${SECONDARY_DISKGROUP:-$DISKGROUP}'", "'${SECONDARY_RLINK:-$RLINK}'", "'${SYNC_MODE:-O}'", "'${LATENCY_MODE:-O}'", "'${SRLPROT_MODE:-O}'", "'${HIGH_LATENCY:-10000}'", "'${LOW_LATENCY:-9950}'", "'${RLK_EXISTENCE:-CREATE}'"
			else print $0 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
	fi

	clear
	return 1
}

# NOTE: Doesn't delete header in comments before the RL and Sxx records
Delete_existing_specification_for_an_rlink()
{
clear
	echo "Delete existing specification for an RLINK"
	echo ""
	echo "Use this option to remove a Primary RLINK specification which was entered"
	echo "incorrectly."
	echo ""
	echo "Primary rlinks specified so far:"
                echo "   Rlink_Name        local_host   Remote_host  Remote_diskgroup  Remote_rlink  "
                echo "   ----------------  -----------  ------------  --------------  ----------------"
                awk '/^RL  */ { if ($11 == "EXISTS") 
			    printf "E  %-17s %-12s %-12s %-17s %-17s\n", $2, $3, $4, $5, $6
                        else
                            printf "C  %-17s %-12s %-12s %-17s %-17s\n", $2, $3, $4, $5 , $6} ' $CONFIG_FILE
        echo ""
	while [ 1 ]
	do
		echo "Enter name of RLINK specification to delete (empty line to abort): \c"
		read RL EXTRA
                if [ "$EXTRA" != "" ]
                then
                        echo "Only enter one word for name.  No whitespace."
                        continue
                fi
		if [ "$RL" = "" ]
		then
			return 1
		fi

		/bin/rm -f $CONFIG_2TMP_FILE
		awk '/^RL  *'$RL' / { print $0 }' $CONFIG_FILE > $CONFIG_2TMP_FILE
		if [ ! -s $CONFIG_2TMP_FILE ]
		then
			echo "Could not find specification for Primary RLINK $RL"
			/bin/rm -f $CONFIG_2TMP_FILE
			continue
		fi
		set -- `wc -l $CONFIG_2TMP_FILE`
		if [ "$1" -gt 1 ]
		then
			echo "ERROR: Found multiple RLINK specifications for $RL"
			/bin/rm -f $CONFIG_2TMP_FILE
                        continue
		fi

		set -- `/bin/cat $CONFIG_2TMP_FILE`
		RL_REM_HOST=$3
		RL_REM_DG=$4
		RL_REM_RLINK=$5
		shift; shift
		RL_EXISTENCE=$9
		echo "Delete the following Primary RLINK specification?"
                echo "   Rlink_Name        local_host    Remote_host  Remote_diskgroup  Remote_rlink  "
                echo "   ----------------  ----------    -----------  ----------------  ----------------"
                awk '/^RL  *'$RL' / { if ($12 == "EXISTS")
                            printf "E  %-17s %-12s %-12s %-17s %-17s\n", $2, $3, $4, $5, $6
                        else
                            printf "C  %-17s %-12s %-12s %-17s %-17s\n", $2, $3, $4, $5 , $6} ' $CONFIG_FILE
		echo ""
		Y_OR_N=""
                while [ "$Y_OR_N" = "" ]
                do
                	echo "Delete? (default: y) (y/n): \c"
                        read Y_OR_N
                        case "$Y_OR_N" in
                        	"" )    Y_OR_N=y;;
                                [yY] ) Y_OR_N=y;;
                                [nN] ) Y_OR_N=n;;
                                * )     echo "Invalid input"
                                Y_OR_N="" ;;
                        esac
		done
		/bin/rm -f $CONFIG_2TMP_FILE
                if [ "$Y_OR_N" = n ]
                then
			continue
		else
			awk '{ if ( ! ($1 == "RL" && $2 == "'$RL'") )  print $0 }' $CONFIG_FILE > $CONFIG_2TMP_FILE
			/bin/mv -f $CONFIG_2TMP_FILE $CONFIG_FILE
		fi
		awk '/^S*/ { if ($2 == "'$RL'" && ( $1 == "SRL" || $1 == "SRV" || $1 == "SDV" || $1 == "SLV") ) print $0 }' $CONFIG_FILE > $CONFIG_2TMP_FILE
		if [ -s $CONFIG_2TMP_FILE ]
		then
		    echo "Found record(s) specifying object(s) to be set up on the Secondary for this"
		    echo "rlink.  Delete these specification(s), too?"
		    echo ""
		    awk '/^SRV  *'$RL' / { 
			if ($5 == "EXISTS")
			    printf "E    RVG:     %-16s diskgroup=%s\n", $3, $4
			else
	  		    printf "C    RVG:     %-16s diskgroup=%s\n", $3, $4 }' $CONFIG_FILE
		    awk '/^SDV  *'$RL' / {
			map_to=$7
			if (map_to == "") map_to=$3 
			if ($6 == "EXISTS")
	  		  printf "E    DATAVOL: %-16s len=%-6s mirrors=%-1d  Map To: %s\n", $3, $4, $5, map_to
			else
	  		  printf "C    DATAVOL: %-16s len=%-6s mirrors=%-1d  Map To: %s\n", $3, $4, $5, map_to }' $CONFIG_FILE

		    awk '/^SLV  *'$RL' / {
			if ($6 == "EXISTS")
	  		  printf "E    SRLVOL:  %-16s len=%-6s mirrors=%-1d\n", $3, $4, $5
			else
	  		  printf "C    SRLVOL:  %-16s len=%-6s mirrors=%-1d\n", $3, $4, $5 }' $CONFIG_FILE

		    awk '/^SRL  *'$RL' / { 
			if ($11 == "EXISTS")
			    printf "E    RLINK:   %-16s Primary_host=%s\n", $3, $4
			else
	  		    printf "C    RLINK:   %-16s Primary_host=%s\n", $3, $4 }' $CONFIG_FILE
		    echo ""
		    Y_OR_N=""
                    while [ "$Y_OR_N" = "" ]
                    do
                	echo "Delete? (default: y) (y/n): \c"
                        read Y_OR_N
                        case "$Y_OR_N" in
                        	"" )    Y_OR_N=y;;
                                [yY] ) Y_OR_N=y;;
                                [nN] ) Y_OR_N=n;;
                                * )     echo "Invalid input"
                                Y_OR_N="" ;;
                        esac
		    done
		    /bin/rm -f $CONFIG_2TMP_FILE
                    if [ "$Y_OR_N" = y ]
                    then
			awk '{ if ( ! ($2 == "'$RL'" && ( $1 == "SRL" || $1 == "SRV" || $1 == "SDV" || $1 == "SLV") ) ) print $0 }' $CONFIG_FILE > $CONFIG_2TMP_FILE
			/bin/mv -f $CONFIG_2TMP_FILE $CONFIG_FILE
		    fi
		fi
		return 1
	done
clear
}




#116
Set_up_a_rlink_now()
{
clear
SAVE_RLK_EXISTENCE=$RLK_EXISTENCE
RLK_EXISTENCE=CREATE
SAVE_RLINK="$RLINK"; RLINK=""
SAVE_SECONDARY_HOST="$SECONDARY_HOST"; SECONDARY_HOST=""
SAVE_SECONDARY_DISKGROUP="$SECONDARY_DISKGROUP"; SECONDARY_DISKGROUP=""
SAVE_SECONDARY_RLINK="$SECONDARY_RLINK"; SECONDARY_RLINK=""
SAVE_RLK_REM_HOST="$RLK_REM_HOST"; RLK_REM_HOST=""
SAVE_RLK_LOCAL_HOST="$RLK_LOCAL_HOST"; RLK_LOCAL_HOST=""
SET_UP_A_RLINK_ABORT=0
SAVE_SYNC_MODE=$SYNC_MODE; SAVE_SRLPROT_MODE=$SRLPROT_MODE; SAVE_LATENCY_MODE=$LATENCY_MODE
SAVE_HIGH_LATENCY=$HIGH_LATENCY; SAVE_LOW_LATENCY=$LOW_LATENCY
SYNC_MODE=O; SRLPROT_MODE=D LATENCY_MODE=O; SYNC=off; SRLPROT=dcm; LATENCY=off
HIGH_LATENCY=10000; LOW_LATENCY=9950
/bin/cp $CONFIG_FILE $CONFIG_ORIG_FILE
RLK_LOCAL_HOST=${LOCAL_HOST:-hostname}

while [ 1 ]
do
        clear
	if [ "$ADDING_A_NEW_RLINK_FROM_MAIN_MENU" = "" ]
	then
		MENU_LENGTH=24
	else
		MENU_LENGTH=22
	fi
        Summarize_Create_an_Rvg

	TEMP_RLK_REM_HOST=${SECONDARY_HOST:-hostname}

        echo "Set Up an Rlink"
        echo ""
        echo "This menu is used to specify a new RLINK for the RVG.  First, Set the secondary"
	echo "hostname using option 2, first, to let VVR automatically give the primary"
	echo "and Secondary rlinks default names of <secondaryhostname>_rlk, for example  london_rlk."
	if [ "$ADDING_A_NEW_RLINK_FROM_MAIN_MENU" = "" ]
	then
	echo "A Primary RLINK that has already been specified may be edited "
	echo "(but not renamed) by explicitly requesting that RLINK with option 1."
	fi
        echo ""
	echo "Choose an option  (\"?\" for other options):-"
        echo "    1  New Primary RLINK name:                      ${RLINK:-${SECONDARY_HOST:-hostname}_rlk}"
	echo "    2  Local host name of RLINK:                    ${RLK_LOCAL_HOST:-$TEMP_RLK_LOCAL_HOST}"
        echo "    3  Secondary host name:                         ${SECONDARY_HOST:-hostname}"
	echo "    4  Remote host name of RLINK:                   ${RLK_REM_HOST:-$TEMP_RLK_REM_HOST}"
        echo "    5  Secondary diskgroup name:                    ${SECONDARY_DISKGROUP:-$DISKGROUP}"
	if [ "$SECONDARY_RLINK" != "" ]
	then
        echo "    6  Secondary RLINK name:                        $SECONDARY_RLINK"
	else
        echo "    6  Secondary RLINK name:                        ${RLINK:-${SECONDARY_HOST:-hostname}_rlk}"
	fi
	Get_throttling_mode_strings
        echo "    7  Configure RLINK:                             ${SYNC:-off} ${LATENCY:-off} ${SRLPROT:-off}"
        echo "    8  Delete existing specification for an RLINK"
        echo ""
	echo "    s  Show summary of set-up work specified so far"
        echo "    g  Go -- keep changes and return to previous menu"
	echo "    p  Previous -- abort changes and return to previous menu"
        echo "    r  Remote vxprint -ht"
        echo "    v  Local vxprint -ht"
        echo "    q  Quit"
        echo ""
        echo "    Enter option: \c"
        read CHOICE
        echo ""
        case "$CHOICE" in
                1 ) New_primary_rlink_name;;
		2 ) Local_host_name;;
                3 ) Secondary_host_name;;
		4 ) Remote_host_name;;
                5 ) Secondary_diskgroup_name;;
                6 ) Secondary_rlink_name;;
		7 ) Throttling_modes;;
		8 ) Delete_existing_specification_for_an_rlink
                    Verify_Cfg_File
                    if [ "$?" = 0 ]
                    then
                            clear
                    fi
		    /bin/rm -f $CONFIG_ORIG_FILE
                    break;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
                [gG] ) if [ "$RLINK" = "" ]
		    then
			RLINK=${SECONDARY_HOST:-hostname}_rlk
		    fi
		    if [ "$RLK_REM_HOST" = "" ]; then
			  RLK_REM_HOST=${SECONDARY_HOST:-hostname}
		    fi
		    Add_Rlink_To_Config
                    if [ "$?" = 1 ]
                    then
                        Verify_Cfg_File
                        if [ "$?" = 0 ]
                        then
                            clear
                        fi
		    	/bin/rm -f $CONFIG_ORIG_FILE
                       	break
		    else
			continue
                    fi;;
                [rR] ) Remote_Vxprint;;
                [vV] ) Vxprint;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
                                        /bin/mv -f $CONFIG_ORIG_FILE $CONFIG_FILE
					SET_UP_A_RLINK_ABORT=1
                                        break
                                else
                                        clear
                                fi
                        else
				SET_UP_A_RLINK_ABORT=1
                                break
                        fi;;
                [qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
                * ) echo "Invalid input: $CHOICE"
                        echo "Hit return to continue: \c"
                        read Whatever
        esac
done
if [ "$SET_UP_A_RLINK_ABORT" = 1 ]
then
	RLINK="$SAVE_RLINK_NAME"
	RLK_EXISTENCE=$SAVE_RLK_EXISTENCE
	SECONDARY_HOST="$SAVE_SECONDARY_HOST"
	SECONDARY_DISKGROUP="$SAVE_SECONDARY_DISKGROUP"
	SECONDARY_RLINK="$SAVE_SECONDARY_RLINK"
	SYNC_MODE=$SAVE_SYNC_MODE; SRLPROT_MODE=$SAVE_SRLPROT_MODE; LATENCY_MODE=$SAVE_LATENCY_MODE
	HIGH_LATENCY=$SAVE_HIGH_LATENCY; LOW_LATENCY=$SAVE_LOW_LATENCY
	RLK_REM_HOST=$SAVE_RLK_REM_HOST
	RLK_LOCAL_HOST=$SAVE_RLK_LOCAL_HOST
	Get_throttling_mode_strings
else
	if [ "$RLINK" = "" ]
	then
		RLINK="$SAVE_RLINK_NAME"
		RLK_EXISTENCE=$SAVE_RLK_EXISTENCE
		SYNC_MODE=$SAVE_SYNC_MODE; SRLPROT_MODE=$SAVE_SRLPROT_MODE; LATENCY_MODE=$SAVE_LATENCY_MODE
		HIGH_LATENCY=$SAVE_HIGH_LATENCY; LOW_LATENCY=$SAVE_LOW_LATENCY
	fi
	if [ "$SECONDARY_HOST" = "" ]
	then
		SECONDARY_HOST="$SAVE_SECONDARY_HOST"
	fi
	if [ "$SECONDARY_DISKGROUP" = "" ]
	then
		SECONDARY_DISKGROUP="$SAVE_SECONDARY_DISKGROUP"
	fi
	if [ "$SECONDARY_RLINK" = "" ]
	then
		SECONDARY_RLINK="$SAVE_SECONDARY_RLINK"
	fi
	if [ "$RLK_REM_HOST" = "" ]
	 then
		RLK_REM_HOST="$SAVE_RLK_REM_HOST"
	fi
	if [ "$RLK_LOCAL_HOST" = "" ]
	then
		RLK_LOCAL_HOST="$SAVE_RLK_LOCAL_HOST"
	fi
fi
/bin/rm -f $CONFIG_ORIG_FILE
#clear
}
#1152
Create_a_new_SRL_volume()
{
SET_SRL_VOL_SUCCESS=0
clear
	ALREADY_HAS_SRLVOL=`/bin/egrep '^LV' $CONFIG_FILE`
	if [ "$?" != 1 ]
	then

		Y_OR_N=""
		while [ "$Y_OR_N" = "" ]
		do
			echo "Volume `awk '/^LV/ { printf "%s", $2 }' $CONFIG_FILE` has already been specified for the SRL volume.  Ignore that"
			echo "specification and specify a different SRL volume? (default: n) (y/n): \c"
			read Y_OR_N
			case "$Y_OR_N" in
				"" )    Y_OR_N=n;;
				[yY] ) Y_OR_N=y;;
				[nN] ) Y_OR_N=n;;
				* )     echo "Invalid input"
				Y_OR_N="" ;;
			esac
		done
		if [ "$Y_OR_N" = "n" ]
		then
			SET_SRL_VOL_SUCCESS=1
			return
		else
			awk '{ if ( $1 != "LV" && $0 != "#LV  SRL_Volume_Name   Length  Mirrors  Create/Exists" && $0 != "#LV  ----------------  ------  -------  -------------" ) print $0 }' $CONFIG_FILE > $CONFIG_TMP_FILE
			/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
			clear
		fi
	fi

	echo "Enter name, size, and number of additional mirrors for new SRL volume to create."
	echo "Enter an empty line to return to previous menu without selecting a volume."
	echo "Note that the SRL volume must have a minimum size of 300 sectors."
	echo ""
	echo "Size can be entered using standard VxVM suffix characters:"
	echo "	b    multiply the length by 512 bytes (blocks)"
	echo "	s    multiply the length by the standard sectors size (default)"
	echo "	k    multiply the length by 1024 bytes (Kilobytes)"
	echo "	m    multiply the length by 1,048,576 (1024K) bytes (Megabytes)"
	echo "	g    multiply the length by 1,073,741,824 (1024M) bytes (Gigabytes)"
	echo ""
	echo "Example: mysrlvol01  100m 0"
	echo ""
	echo "New SRL volume will be added to $RVG in diskgroup ${DISKGROUP:-rootdg}"
	echo ""

	echo "Name, size, # of additional mirrors for new SRL volume: \c"
	read VOLNAME VOLSIZE VOLMIRRORS
	while [ "$VOLNAME" != "" ]
	do
		$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -htQq "$VOLNAME" 2> /dev/null 1> /dev/null
		if [ "$?" = 0 ]
        	then
			echo "Object $VOLNAME already exists.  Ignoring that volume."
			echo "Name, size, # of additional mirrors for new SRL volume: \c"
			read VOLNAME VOLSIZE VOLMIRRORS
			continue
		fi
		NAME=$VOLNAME
		Check_if_name_is_in_use_by_config_file
		if [ "$?" = 1 ]
		then
			echo "Volume name $VOLNAME has already been specified for use.  Ignoring that volume."
			echo "Name, size, # of additional mirrors for new SRL volume: \c"
			read VOLNAME VOLSIZE VOLMIRRORS
			continue
		fi

	    	case "$VOLSIZE" in
			"" )		LEN="";;
			*[\^\&\*\(\)\-\|\\\~\`\[\]\!\ \/\:\;\'\"\?\<\>\.\,@#$%*_+={}]* | *[a-zA-Z]*[[a-zA-Z]* ) 
					LEN="";;
			[0-9]*s )	LEN=`echo $VOLSIZE | /bin/tr s " "`;;
			[0-9]*b )	LEN=`echo $VOLSIZE | /bin/tr b " "`;;
			[0-9]*k )	TMP=`echo $VOLSIZE | /bin/tr k " "` 
						LEN=`expr $TMP \* 2` ;;
			[0-9]*m )	TMP=`echo $VOLSIZE | /bin/tr m " "`  
						LEN=`expr $TMP \* 2048` ;;
			[0-9]*g )	TMP=`echo $VOLSIZE | /bin/tr g " "`  
						LEN=`expr $TMP \* 2097152` ;;
			[0-9] | [0-9]*[0-9] )LEN="$VOLSIZE";;
			* )			LEN="";;
	    	esac
		if [ "$LEN" = "" ]
		then
			echo "Bad length input.  Ignoring that line."
			echo "Name, size, # of additional mirrors for new SRL volume: \c"
			read VOLNAME VOLSIZE VOLMIRRORS
			continue
		fi
		if [ "$LEN" -lt 300 ]
		then
			echo "Minimum SRL volume length is 300 sectors.  Ignoring that line."
			echo "Name, size, # of additional mirrors for new SRL volume: \c"
			read VOLNAME VOLSIZE VOLMIRRORS
			continue
		fi
		case "$VOLMIRRORS" in
			[0-9] | [0-9]*[0-9] ) ;;
			* )	echo "Bad input for number of mirrors.  Ignoring that line."
				echo "Name, size, # of additional mirrors for new SRL volume: \c"
				read VOLNAME VOLSIZE VOLMIRRORS
				continue;;
		esac

		echo "" >> $CONFIG_FILE
		echo "#LV  SRL_Volume_Name   Length  Mirrors  Create/Exists" >> $CONFIG_FILE
		echo "#LV  ----------------  ------  -------  -------------" >> $CONFIG_FILE
		awk 'END { printf "LV   %-17s %+6s  %7d  CREATE", "'$VOLNAME'", "'$VOLSIZE'", "'$VOLMIRRORS'" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		echo "" >> $CONFIG_TMP_FILE
		/bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
		/bin/rm -f $CONFIG_TMP_FILE
		SET_SRL_VOL_SUCCESS=1
		SRLVOL=$VOLNAME; SRLVOL_LEN=$VOLSIZE; SRLVOL_MIRRORS=$VOLMIRRORS
		SRLVOL_EXISTENCE="CREATE"
		VOLNAME=""
	done
/bin/rm -f $CONFIG_TMP_FILE
clear
}


#1141
Select_names_of_additional_existing_data_volumes_to_add()
{
clear
	$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -tvQq 2> /dev/null 1> $VXPRINT_FILE
	if [ "$?" != 0 ]
        then
               	echo "Error trying to get list of parent-less existing volumes in diskgroup ${DISKGROUP:-rootdg}."
		echo "Hit return to continue: \c"
		read Whatever
		clear
		/bin/rm -f $VXPRINT_FILE
		return 0
        fi
	awk '{ if ( $3 == "-" ) print }' $VXPRINT_FILE > ${VXPRINT_FILE}.tmp
	/bin/mv -f ${VXPRINT_FILE}.tmp $VXPRINT_FILE
	if [ -s $VXPRINT_FILE ]
	then
		echo "Existing volumes found in diskgroup ${DISKGROUP:-rootdg} that are not associated with an RVG:"
		awk '{ printf "\t%d\t%-15s  Length=%s\n", NR, $2, $6}  
		       END {printf "\n"}' $VXPRINT_FILE
	else
		echo "Could not find any existing volumes in diskgroup ${DISKGROUP:-rootdg}"
		echo "Hit return to continue: \c"
		read Whatever
		clear
		/bin/rm -f $VXPRINT_FILE
		return
	fi

	echo "Enter number(s) of additional existing data volume(s) to add, at most 9 per"
	echo "line, separated by spaces.  Multiple lines can be entered. Terminate list"
	echo "with an empty line.  You can abort your selections by selecting P (Previous--"
	echo "abort changes and return to previous menu) from the preceding menu."
	echo ""
	echo "Example:	Existing volumes found in diskgroup rootdg:"
	echo "			1 id-vol01  Length=204800"
	echo "			2 id-vol02  Length=204800"
	echo "			3 id-vol03  Length=204800"
	echo ""
	echo "	Enter \"1  3\" to select id-vol01 and id-vol03"
	echo ""

	echo "Existing data volumes to add to $RVG in diskgroup ${DISKGROUP:-rootdg}: \c"
	read LINE
	while [ "$LINE" != "" ]
	do
                set -- $LINE
		if [ "$1" = "" ]
		then
			break
		fi
		while [ "$1" != "" ]
		do
			case "$1" in
				[0-9] | [0-9]*[0-9] ) VOLNAME=`awk '{ if (NR == '$1') printf "%s", $2 }' $VXPRINT_FILE`;;
				* ) 	echo "Invalid input: $1.  Ignoring that value."
				    	shift
					continue;;
			esac

			if [ "$1" -gt `wc -l $VXPRINT_FILE | /bin/sed 's/  */ /g' | /bin/cut -d' ' -f2` ]
			then
				echo "Input number is too big: $1.  Ignoring that value."
				shift
				continue
			fi
			if [ "$1" -lt 1 ]
			then
				echo "Input number is too small: $1.  Ignoring that value."
				shift
				continue
			fi

			$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -htvQq "$VOLNAME" 2> /dev/null 1> /dev/null
			if [ "$?" != 0 ]
        		then
                		echo "Cannot find volume $VOLNAME.  Ignoring that volume."
				shift
                		continue
        		fi

			NAME=$VOLNAME
			Check_if_name_is_in_use_by_config_file
			if [ "$?" = 1 ]
			then
				echo "Volume name $VOLNAME has already been specified for use.  Ignoring that volume."
				shift
				continue
			fi

			LEN=`awk '/v  '$VOLNAME' / { print $6 }' $VXPRINT_FILE`
			MIRRORS=`$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -hQq "$VOLNAME" | /bin/egrep -c "^pl "`
			MIRRORS=`expr $MIRRORS - 1`

			awk '/#DV  Data_Volume_Name/ { count=count+1 } END { if (count == 0) 
				printf "\n%s\n%s\n", "#DV  Data_Volume_Name  Length  Mirrors  dcmlog Create/Exists", "#DV  ----------------  ------  -------  ----- -------------"}' $CONFIG_FILE >> $CONFIG_TMP_FILE
			awk 'END { printf "DV   %-17s %+6s  %7d  no EXISTS\n", "'$VOLNAME'", "'$LEN'", "'$MIRRORS'" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
			/bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
			/bin/rm -f $CONFIG_TMP_FILE

			echo "Adding ${VOLNAME}..."
			shift
		done
		echo "More existing data volumes to add (newline to finish): \c"
		read LINE
	done
# May not get here. May return, above
clear
/bin/rm -f $VXPRINT_FILE
/bin/rm -f $CONFIG_TMP_FILE
}


Specify_if_log_required_on_datavolume()
{
	clear
	echo ""
	echo "To use the Automatic Synchronization option,or the SRL log"
	echo "Overflow Protection with DCM, the SRL overflow protection"
	echo "must be set DCM in the RLINK Configuration, and each data"
	echo "volume must have a DCM log associated with it"

	echo ""
	echo "  no     Do Not Create a DCM log on data volumes."
	echo ""
	echo "         Select this option if srl overflow protection"
	echo "         will not be set to dcm and Automatic Synchronization"
	echo "         will not be used"
	echo ""
	echo "  yes    Create DCM log on data volumes. To use the Automatic"
	echo "         Synchronization option, or the SRL log overflow"
	echo "         protection with DCM, each data volume must be"
	echo "         associated with a DCM log"
	echo ""
	echo ""
	LINE=xxxx
        while [ "$LINE" != "" ]
        do
		LINE=
                echo " Enter option (y/n)(default: y) \c"
                read LINE
		if [ "$LINE" = "" ]
		then
			LINE=Y;
		fi
                case $LINE in
                       [Yy]) DATAVOL_LOGSRVM="yes"; break;;
		       [Nn]) DATAVOL_LOGSRVM="no"; break;;
                       *) echo "Invalid input: $LINE.  Ignoring that value."
                          continue;;
                esac
	done

	clear

}


#1142
Enter_info_for_new_data_volume_to_create()
{
clear
	echo "Enter name, size, and number of additional mirrors for each new data volume to"
	echo "create."
	echo "Enter information for one volume per line separated by spaces.  Multiple"
	echo "lines can be entered.  Terminate list with an empty line."
	echo ""
	echo "Size can be entered using standard VxVM suffix characters:"
	echo "	b    multiply the length by 512 bytes (blocks)"
	echo "	s    multiply the length by the standard sectors size (default)"
	echo "	k    multiply the length by 1024 bytes (Kilobytes)"
	echo "	m    multiply the length by 1,048,576 (1024K) bytes (Megabytes)"
	echo "	g    multiply the length by 1,073,741,824 (1024M) bytes (Gigabytes)"
	echo ""
	echo "Example: myvol01  100m 0"
	echo ""
	echo "New data volumes will be added to $RVG in diskgroup ${DISKGROUP:-rootdg}"
	echo ""
	echo "Name, size, # of additional mirrors for new volume (newline to"
	echo "finish): \c"
	read VOLNAME VOLSIZE VOLMIRRORS
	while [ "$VOLNAME" != "" ]
	do
		$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -htQq "$VOLNAME" 2> /dev/null 1> /dev/null
		if [ "$?" = 0 ]
        	then
			echo "Object $VOLNAME already exists.  Ignoring that volume."
			echo "Name, size, # of additional mirrors for new volume (newline to"
			echo "finish): \c"
			read VOLNAME VOLSIZE VOLMIRRORS
			continue
		fi
		NAME=$VOLNAME
		Check_if_name_is_in_use_by_config_file
		if [ "$?" = 1 ]
		then
			echo "Volume name $VOLNAME has already been specified for use.  Ignoring that volume."
			echo "Name, size, # of additional mirrors for new volume (newline to"
			echo "finish): \c"
			read VOLNAME VOLSIZE VOLMIRRORS
			continue
		fi

	    	case "$VOLSIZE" in
			"" )		LEN="";;
			*[\^\&\*\(\)\-\|\\\~\`\[\]\!\ \/\:\;\'\"\?\<\>\.\,@#$%*_+={}]* | *[a-zA-Z]*[[a-zA-Z]* ) 
					LEN="";;
			[0-9]*s )	LEN=`echo $VOLSIZE | /bin/tr s " "`;;
			[0-9]*b )	LEN=`echo $VOLSIZE | /bin/tr b " "`;;
			[0-9]*k )	TMP=`echo $VOLSIZE | /bin/tr k " "` 
						LEN=`expr $TMP \* 2` ;;
			[0-9]*m )	TMP=`echo $VOLSIZE | /bin/tr m " "`  
						LEN=`expr $TMP \* 2048` ;;
			[0-9]*g )	TMP=`echo $VOLSIZE | /bin/tr g " "`  
						LEN=`expr $TMP \* 2097152` ;;
			[0-9] | [0-9]*[0-9] )LEN="$VOLSIZE";;
			* )			LEN="";;
	    	esac
		if [ "$LEN" = "" ]
		then
			echo "Bad length input.  Ignoring that line."
			echo "Name, size, # of additional mirrors for new volume (newline to"
			echo "finish): \c"
			read VOLNAME VOLSIZE VOLMIRRORS
			continue
		fi
		case "$VOLMIRRORS" in
			[0-9] | [0-9]*[0-9] ) ;;
			* )	echo "Bad input for number of mirrors.  Ignoring that line."
				echo "Name, size, # of additional mirrors for new volume (newline to"
				echo "finish): \c"
				read VOLNAME VOLSIZE VOLMIRRORS
				continue;;
		esac

		awk '/#DV  Data_Volume_Name/ { count=count+1 } END { if (count == 0) 
			printf "\n%s\n%s\n", "#DV  Data_Volume_Name  Length  Mirrors  dcmlog Create/Exists", "#DV  ----------------  ------  -------  ------  -------------"}' $CONFIG_FILE >> $CONFIG_TMP_FILE
		awk 'END { printf "DV   %-17s %+6s  %7d  %6s CREATE\n", "'$VOLNAME'", "'$VOLSIZE'", "'$VOLMIRRORS'" , "'$DATAVOL_LOGSRVM'"}' $CONFIG_FILE >> $CONFIG_TMP_FILE
		/bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
		/bin/rm -f $CONFIG_TMP_FILE

		echo "Name, size, # of additional mirrors for new volume (newline to"
		echo "finish): \c"
		read VOLNAME VOLSIZE VOLMIRRORS
	done
clear
/bin/rm -f $CONFIG_TMP_FILE
}

#115
Set_up_SRL_volume_now()
{
clear
/bin/cp $CONFIG_FILE $CONFIG_ORIG_FILE

while [ 1 ] 
do
	clear
	ALREADY_HAS_SRLVOL=`/bin/egrep '^LV' $CONFIG_FILE`
	if [ "$?" != 1 ]
	then

		Y_OR_N=""
		while [ "$Y_OR_N" = "" ]
		do
			echo "Volume `awk '/^LV/ { printf "%s", $2 }' $CONFIG_FILE` has already been specified for the SRL volume.  Ignore that"
			echo "specification and specify a different SRL volume? (default: n) (y/n): \c"
			read Y_OR_N
			case "$Y_OR_N" in
				"" )    Y_OR_N=n;;
				[yY] ) Y_OR_N=y;;
				[nN] ) Y_OR_N=n;;
				* )     echo "Invalid input"
				Y_OR_N="" ;;
			esac
		done
		if [ "$Y_OR_N" = "n" ]
		then
			SET_SRL_VOL_SUCCESS=1
			return
		else
			awk '{ if ( $1 != "LV" && $0 != "#LV  SRL_Volume_Name   Length  Mirrors  Create/Exists" && $0 != "#LV  ----------------  ------  -------  -------------" ) print $0 }' $CONFIG_FILE > $CONFIG_TMP_FILE
			/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
			clear
		fi
	fi

	MENU_LENGTH=17
	Summarize_Create_an_Rvg
	echo "Set Up SRL Volume"
	echo ""
	echo "This menu is used to specify the new or pre-existing volume to use as the SRL"
	echo "volume for the RVG.  You must still select Go from the previous menu to commit"
	echo "this change."
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    1  Select name of existing volume to add as the SRL volume"
	echo "    2  Create a new SRL volume"
	echo ""
	echo "    s  Show summary of set-up work specified so far"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
	case "$CHOICE" in
		1 ) Select_name_of_existing_volume_to_add_as_the_SRL_volume
		    if [ "$SET_SRL_VOL_SUCCESS" = "1" ] 
		    then
			/bin/rm -f $CONFIG_ORIG_FILE
		    	break
		    fi ;;
		2) Create_a_new_SRL_volume
		    if [ "$SET_SRL_VOL_SUCCESS" = "1" ] 
		    then
			/bin/rm -f $CONFIG_ORIG_FILE
		    	break
		    fi ;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
		[rR] ) Remote_Vxprint;;
		[vV] ) Vxprint;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                Previous
                                if [ "$?" = 1 ]
                                then
                                        /bin/mv -f $CONFIG_ORIG_FILE $CONFIG_FILE
                                        break
                                else
                                        clear
                                fi
                        else
                                break
                        fi;;
		[qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
		* ) echo "Invalid input: $CHOICE"
			echo "Hit return to continue: \c"
			read Whatever
		    CHOICE="";;
	esac
done
/bin/rm -f $CONFIG_ORIG_FILE
clear
}

# NOTE: Doesn't delete header in comments before the DV record
Delete_existing_specification_for_a_data_volume()
{
clear
	echo "Delete existing specification for a data volume"
	echo ""
	echo "Use this option to remove a Primary data volume specification which was"
	echo "entered incorrectly.  Then select option 1, 2 or 3 from the previous menu to"
	echo "re-enter the information."
	echo ""
	echo "Primary data volumes specified so far:"
        echo "   Data_Volume_Name  Length  Mirrors  dcmlog "
        echo "   ----------------  ------  -------  --------"
        awk '/^DV/ { if ($6 == "EXISTS") printf "E  %-17s %+6s  %7d   %-6s\n", $2, $3, $4, $5
		else
		    printf "C  %-17s %+6s  %7d    %-6s\n", $2, $3, $4, $5 }' $CONFIG_FILE
        echo ""
	while [ 1 ]
	do
		echo "Enter name of data volume specification to delete (empty line to abort): \c"
		read DV EXTRA
                if [ "$EXTRA" != "" ]
                then
                        echo "Only enter one word for name.  No whitespace."
                        continue
                fi
		if [ "$DV" = "" ]
		then
			return 1
		fi

		/bin/rm -f $CONFIG_2TMP_FILE
		awk '/^DV  *'$DV' / { print $0 }' $CONFIG_FILE > $CONFIG_2TMP_FILE
		if [ ! -s $CONFIG_2TMP_FILE ]
		then
			echo "Could not find specification for Primary data volume $DV"
			/bin/rm -f $CONFIG_2TMP_FILE
			continue
		fi
		set -- `wc -l $CONFIG_2TMP_FILE`
		if [ "$1" -gt 1 ]
		then
			echo "ERROR: Found multiple data volume specifications for $DV"
			/bin/rm -f $CONFIG_2TMP_FILE
                        continue
		fi

		set -- `/bin/cat $CONFIG_2TMP_FILE`
		DV_LEN=$3
		DV_MIRRORS=$4
		DV_EXISTENCE=$5
		echo "Delete the following Primary data volume specification?"
        	echo "   Data_Volume_Name  Length  Mirrors   dcmlog"
        	echo "   ----------------  ------  -------   -------"
        	awk '/^DV/ { if ($5 == "EXISTS") printf "E  %-17s %+6s  %7d   %-6s\n", $2, $3, $4, $5
		    else
		        printf "C  %-17s %+6s  %7d    %-6s\n", $2, $3, $4, $5 }' $CONFIG_2TMP_FILE
		echo ""
		Y_OR_N=""
                while [ "$Y_OR_N" = "" ]
                do
                	echo "Delete? (default: y) (y/n): \c"
                        read Y_OR_N
                        case "$Y_OR_N" in
                        	"" )    Y_OR_N=y;;
                                [yY] ) Y_OR_N=y;;
                                [nN] ) Y_OR_N=n;;
                                * )     echo "Invalid input"
                                Y_OR_N="" ;;
                        esac
		done
		/bin/rm -f $CONFIG_2TMP_FILE
                if [ "$Y_OR_N" = n ]
                then
			continue
		else
			awk '{ if ( ! ($1 == "DV" && $2 == "'$DV'") )  print $0 }' $CONFIG_FILE > $CONFIG_2TMP_FILE
			/bin/mv -f $CONFIG_2TMP_FILE $CONFIG_FILE
			return 1
		fi
	done
clear
}

#114
Set_up_data_volumes_now()
{
clear
/bin/cp $CONFIG_FILE $CONFIG_ORIG_FILE
NUM_DATAVOLS_TO_CREATE=1
NEW_DV_MIRRORS=0

while [ 1 ] 
do
	clear
	MENU_LENGTH=20
	Summarize_Create_an_Rvg
	echo "Set Up Data Volumes"
	echo ""
	echo "This menu is used to build a list of entries for new or pre-existing"
	echo "data volumes to be added to the rvg.  You must still select Go from the"
	echo "previous menu to commit these changes."
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    1  Specify if data volumes require dcm log (def: ${DATAVOL_LOGSRVM})"
	echo "    2  Specify existing data volume(s) to add"
	echo "    3  Add new data volume(s), to be created initially empty"
	echo "    4  Specify a range of new data volumes to create"
	echo "    5  Delete existing specification for a data volume"
	echo ""
	
	echo "    s  Show summary of set-up work specified so far"
	echo "    g  Go -- keep changes and return to previous menu"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
	case "$CHOICE" in
		1 ) Specify_if_log_required_on_datavolume;;
		2 ) Select_names_of_additional_existing_data_volumes_to_add;;
		3 ) Enter_info_for_new_data_volume_to_create;;
		4 ) Specify_a_range_of_data_volumes_to_create;;
		5 ) Delete_existing_specification_for_a_data_volume;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
		[gG] ) Verify_Cfg_File
                    if [ "$?" = 0 ]
                    then
                        clear
                    fi
		    /bin/rm -f $CONFIG_ORIG_FILE
		    break;;
		[rR] ) Remote_Vxprint;;
		[vV] ) Vxprint;;
		[pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_ORIG_FILE > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
				Previous
		    		if [ "$?" = 1 ]
		    		then 
					/bin/mv -f $CONFIG_ORIG_FILE $CONFIG_FILE
					break
				else
					clear
				fi
			else
				break
			fi;;
		[qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
		* ) echo "Invalid input: $CHOICE"
			echo "Hit return to continue: \c"
			read Whatever
		    CHOICE="";;
	esac
done
/bin/rm -f $CONFIG_ORIG_FILE
clear
}

Save_current_configuration_to_a_file()
{
clear
FILE=""
	echo ""
	echo "Save current configuration to a text file"
	echo ""
	echo "Enter the name of a file to in which to save the current configuration."
	echo "Specify the full path of the file unless it is to be saved in the same"
	echo "directory from which this program was started.  Enter a newline to return"
	echo "to the previous menu."
	echo ""
	echo "	Examples:"
	echo "	           srvm_setup.cfg"
	echo "	           /home/usr/foo/srvm_setup.cfg"
	echo ""
	while [ "$FILE" = "" ]
	do
		echo "Enter filename to save configuration in: \c"
		read FILE
		if [ "$FILE" = "" ]
		then
			break;
		fi
		if [ -f "$FILE" ]
		then
		    ANSWER=""
		    while [ "$ANSWER" = "" ]
		    do
			echo "File $FILE exists.  Okay to overwrite it? (y/n) (default: n): \c"
			read ANSWER
			case "$ANSWER" in
				[nN] )	FILE=""
					continue 2;;
				"" )	FILE=""
					continue 2;;
				[yY] )	/bin/rm -f "$FILE"
					if [ "$?" != 0 ]
					then
						echo "Error while trying to delete existing copy of $FILE"
						FILE=""
						continue 2
					fi;;
				* ) 	ANSWER="";;
			esac
		    done
		fi

		#Write out RV entry for RVG to file, too
		/bin/rm -f $CONFIG_TMP_FILE
		RVG_COUNT=`/bin/egrep -c '^RV' $CONFIG_FILE`
		if [ "$RVG_COUNT" -eq 0 ]
		then
			echo "#RV  Rvg_Name         Diskgroup_Name  Create/Exists" >> $CONFIG_TMP_FILE
			echo "#    ----------------  --------------  -------------" >> $CONFIG_TMP_FILE
			awk 'END { printf "RV   %-17s %-14s  %s\n", "'$RVG'", "'$DISKGROUP'", "'$RVG_EXISTENCE'" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
			/bin/cat $CONFIG_FILE >> $CONFIG_TMP_FILE
		else
			awk '{ if ( NF > 0 && $1 == "RV") printf "RV   %-17s %-14s  %s\n", "'$RVG'", "'$DISKGROUP'", "'$RVG_EXISTENCE'"
				else print $0 }' $CONFIG_FILE >> $CONFIG_TMP_FILE
		fi
		/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
		touch $FILE > /dev/null 2>&1
		if [ "$?" != 0 ]
                then
                        echo "Error while trying to create $FILE"
                        FILE=""
			continue
		fi
		/bin/cp -f $CONFIG_FILE $FILE
		if [ "$?" != 0 ]
		then
			echo "Error while trying to write to $FILE"
			FILE=""
			continue
		else
			echo "Saved current configuration into file: $FILE"
			echo ""
			echo "Hit return to continue: \c"
			read Whatever
		fi
	done
/bin/rm -f $CONFIG_TMP_FILE
clear
}

Load_configuration_from_a_file()
{
clear
FILE=""
	echo ""
	echo "Load configuration from a text file"
	echo ""
	echo "Enter the name of a file to from which to load the current configuration."
	echo "Specify the full path of the file unless it is to be loaded from the same"
	echo "directory from which this program was started.  Enter a newline to return"
	echo "to the previous menu."
	echo ""
	echo "	Examples:"
	echo "	           srvm_setup.cfg"
	echo "	           /home/usr/foo/srvm_setup.cfg"
	echo ""
	while [ "$FILE" = "" ]
	do
		echo "Enter filename to load configuration from: \c"
		read FILE
		if [ "$FILE" = "" ]
		then
			break;
		fi
		if [ ! -f "$FILE" ]
		then
			echo "File $FILE not found"
			FILE=""
			continue
		fi

		/bin/mv -f $CONFIG_FILE $CONFIG_BAK_FILE
		/bin/sed 's/	/        /g' $FILE > $CONFIG_FILE
		#/bin/cp -f $FILE $CONFIG_FILE
		cat $CONFIG_FILE > /tmp/config
		ABORT=0
		if [ "$?" != 0 ]
		then
			echo "Error while trying to load $FILE into configuration."
			FILE=""
			/bin/mv -f $CONFIG_BAK_FILE $CONFIG_FILE
			break
		else
			echo "Loaded current configuration from file: $FILE"
			echo ""
			Verify_Cfg_File_On_Load
			if [ "$?" = 0 ]
			then 
				/bin/mv -f $CONFIG_BAK_FILE $CONFIG_FILE
				ABORT=1
			else
				/bin/rm -f $CONFIG_BAK_FILE
			fi

			RVG=""
			DISKGROUP=rootdg
			SYNC_MODE="O"; SYNC="off"
			LATENCY_MODE="O"; LATENCY="off"
			SRLPROT_MODE="O"; SRLPROT="off"
			HIGH_LATENCY=10000; LOW_LATENCY=9950
			if [ `egrep -c "^RV" $CONFIG_FILE` != 0 ]
			then
			    set -- `awk '/^RV/ { printf "%s %s %s", $2, $3, $4 }' $CONFIG_FILE`
			    RVG=$1; DISKGROUP=$2; RVG_EXISTENCE=$3
			fi
			# Initialize RLINK and SECONDARY_HOST from first RL record
			if [ `egrep -c "^RL" $CONFIG_FILE` != 0 ]
			then
			    set -- `awk '/^RL/ { printf "%s %s %s %s %s %s %s %s", $2, $3, $4, $5, $6, $7, $8, $9 }' $CONFIG_FILE`
			    RLINK=$1; RLK_LOCAL_HOST=$2;
			    RLK_REMOTE_HOST=$3; SECONDARY_DISKGROUP=$4;
			    SECONDARY_RLINK=$5;
			    SYNC_MODE=$6; LATENCY_MODE=$7;
			    SRLPROT_MODE=$8
			fi
			if [ `egrep -c "^LV" $CONFIG_FILE` != 0 ]
			then
			    set -- `awk '/^LV/ { printf "%s %s %s %s", $2, $3, $4, $5 }' $CONFIG_FILE`
			    SRLVOL=$1; SRLVOL_LEN=$2; SRLVOL_MIRRORS=$3; SRLVOL_EXISTENCE=$4
			fi
			# Initialize SECONDARY_RVG and SECONDARY_DISKGROUP from first SRV record
			if [ `egrep -c "^SRV  *${RLINK}" $CONFIG_FILE` != 0 ]
			then
			    set -- `awk '/^SRV  *'$RLINK' / { printf "%s %s", $3, $4 }' $CONFIG_FILE`
			    SECONDARY_RVG=$1; SECONDARY_DISKGROUP=$2
			fi
			if [ "$ABORT" != 1 ]
			then
				echo "Hit return to continue: \c"
				read Whatever
			fi
		fi
		/bin/rm -f $CONFIG_BAK_FILE
	done
clear
}

Diskgroup()
{
	clear
		Get_Dg
	clear
}

#11
Create_an_Rvg()
{
clear
HEADER="Create an RVG"
if [ "$CLEANUP" != "" ] || [ "$REMOTE_HOSTS" != "" ]
then
	if [ "$DEBUG" = 1 ]
	then
		HEADER="$HEADER	DEBUG: CLEANUP="$CLEANUP"; REMOTE_HOSTS requiring cleanup="$REMOTE_HOSTS""
	fi
fi
RVG=rvg01
RVG_EXISTENCE=CREATE
touch $CONFIG_FILE
echo "#RV  Rvg_Name          Diskgroup_Name  Create/Exists" >> $CONFIG_FILE
echo "#    ----------------  --------------  -------------" >> $CONFIG_FILE
echo "xxx" | awk 'END { printf "RV   %-17s %-14s  %-s\n", "'$RVG'", "'$DISKGROUP'", "'$RVG_EXISTENCE'" }' >> $CONFIG_FILE 
/bin/cp $CONFIG_FILE $CONFIG_FILE_EMPTY
/bin/rm -f $CONFIG_FILE_OLD

Summarize_Create_an_Rvg2 > $VXSUMMARY_FILE	#Initialize empty Summary screen
while [ 1 ] 
do
	clear
	MENU_LENGTH=23
	Summarize_Create_an_Rvg
	#echo "Create an RVG"
	echo "$HEADER"
	echo ""
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    1  Disk group:                                        $DISKGROUP"
	echo "    2  Specify New RVG name:                             $RVG"
	echo "    3  Set up data volume(s) now"
	echo "    4  Set up SRL volume now"
	echo "    5  Set up an RLINK now"
	echo "    6  Set up Secondary RVG hierarchy for an RLINK now"
	echo "    l  Load configuration from a text file"
	echo "    f  Save current configuration to a text file"
	echo ""		
	echo "    s  Show summary of set-up work specified so far"
	echo "    g  Go -- submit changes for verification and commit"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
	case "$CHOICE" in
		1 ) OLD_DISKGROUP_NAME=$DISKGROUP
		    Diskgroup
		    if [ "$OLD_DISKGROUP_NAME" != "$DISKGROUP" ]
		    then
			awk '{ if ( $1 == "RV" )
				    printf "RV   %-17s %-14s  CREATE\n", $2, "'$DISKGROUP'"
				else
				    print $0 }' $CONFIG_FILE > $CONFIG_TMP_FILE
			/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
		    fi;;
		2 ) OLD_RVG_NAME=$RVG
		    New_rvg_name
		    if [ "$OLD_RVG_NAME" != "$RVG" ]
		    then
			awk '{ if ( $1 == "RV" )
				    printf "RV   %-17s %-14s  CREATE\n", "'$RVG'", $3
				else
				    print $0 }' $CONFIG_FILE > $CONFIG_TMP_FILE
			/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
		    fi;;
		3 ) Set_up_data_volumes_now;;
		4 ) Set_up_SRL_volume_now;;
		5 ) Set_up_a_rlink_now;;
		6 ) Set_up_secondary_rvg_hierarchy_now;;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
		[gG] ) Go_Create_an_Rvg
		    if [ "$?" = 1 ]
		    then 
			/bin/rm -f $CONFIG_FILE
			LAST_RVG=$RVG
			LAST_DG=$DISKGROUP
			break
		    else
			clear
		    fi;;
		[lL] ) Load_configuration_from_a_file;;
		[fF] ) Save_current_configuration_to_a_file;;
		[rR] ) Remote_Vxprint;;
		[vV] ) Vxprint;;
		[pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_FILE_EMPTY > /dev/null 2>&1
			if [ "$?" != 0 ]
			then
				echo "Current configuration summary will be lost.  (Use l option to save a copy.)"
		        	BACKUP=""
				while [ "$BACKUP" = "" ]
				do
					echo "Are you sure you want to back up to the previous menu? (y/n) (default: y): \c"
					read BACKUP
					case "$BACKUP" in
						"" )    BACKUP=y;;
						[yY] ) BACKUP=y;;
						[nN] ) BACKUP=n
							clear;;
						* )     BACKUP="" ;;
					esac
				done
			else
				/bin/rm -f $CONFIG_FILE $CONFIG_FILE_EMPTY $CONFIG_FILE_OLD
				break	# No changes, just back up
			fi
			if [ "$BACKUP" = "y" ]
			then
				/bin/rm -f $CONFIG_FILE $CONFIG_FILE_EMPTY $CONFIG_FILE_OLD
				break
			else
				clear
			fi;;
		[qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
		* ) echo "Invalid input: $CHOICE"
			echo "Hit return to continue: \c"
			read Whatever
		    CHOICE="";;
	esac
done
clear
}

Change_an_Rvg()
{
	clear
	echo "Change an RVG"
	echo ""
	echo "Not implemented, yet"
	echo "Hit return to continue: \c"
	read Whatever
}

# For remote host, doesn't check that object name is actually an rvg
Remove_an_Rvg()
{
clear
	echo "Remove an RVG"
	echo ""
	echo "Unconditionally removes an RVG and all of its child rlink, data volume and SRL"
	echo "objects."
	echo ""

	SECONDARY_HOST=""
        while [ "$SECONDARY_HOST" = "" ]
        do
                echo "Enter name of the host machine containing the RVG to be deleted."
		echo "Host name (default: $LOCAL_HOST): \c"
                read SECONDARY_HOST
                if [ "$SECONDARY_HOST" = "" ]   
                then
                        SECONDARY_HOST=$LOCAL_HOST
                fi
                ping $SECONDARY_HOST > /dev/null 2>&1
                if [ "$?" != 0 ]
                then
                        echo "Could not contact Secondary host $SECONDARY_HOST"
                        SECONDARY_HOST=""
                fi
        done

	echo ""
	DISKGROUP=""
	if [ "$SECONDARY_HOST" != "$LOCAL_HOST" ]
	then
	    echo "Enter the name of the disk group which contains the existing RVG to be deleted."
	    echo "[Enter an empty line to abort \"Remove an RVG\" operation]: \c"
	    read DISKGROUP
	else
		Get_Dg
	fi

        if [ "$DISKGROUP" = "" ]
        then
		clear
		return
	fi

	if [ "$SECONDARY_HOST" = "$LOCAL_HOST" ]
	then
            MUST_BE_PRIMARY=no
            RVG_NAME=""
            Rvg_to_select
	else
	    echo "Enter name of RVG on $SECONDARY_HOST to be deleted (empty line to abort): \c"
	    read RVG_NAME
	fi
        if [ "$RVG_NAME" = "" ]
        then
                clear
                return
        fi
        Y_OR_N=""
        while [ "$Y_OR_N" = "" ]
        do
		echo "Delete RVG hierarchy for $RVG_NAME on $SECONDARY_HOST ? (default: y) (y/n): \c"
                read Y_OR_N
                case "$Y_OR_N" in
			"" )    Y_OR_N=y;;
                        [yY] ) Y_OR_N=y;;
                        [nN] ) Y_OR_N=n;;
                        * )     echo "Invalid input"
                        Y_OR_N="" ;;
                esac
        done
	if [ "$Y_OR_N" = y ]
	then
            	Y_OR_N=""
            	while [ "$Y_OR_N" = "" ]
            	do
			echo ""
			echo "Are you absolutely sure?  [This will delete all of the underlying data volumes"
			echo "as well] (default: y) (y/n): \c"
                	read Y_OR_N
                	case "$Y_OR_N" in
				"" )    Y_OR_N=y;;
                        	[yY] ) Y_OR_N=y;;
                        	[nN] ) Y_OR_N=n;;
                        	* )     echo "Invalid input"
                        	Y_OR_N="" ;;
                	esac
            	done
		if [ "$Y_OR_N" = n ]
		then
			clear 
			return
		fi

		if [ "$SECONDARY_HOST" != "$LOCAL_HOST" ]
		then
                    REMOTE_CMD="$VXVM_BIN/vxedit -g $DISKGROUP -rf rm $RVG_NAME"
                    echo "$SECONDARY_HOST: $REMOTE_CMD"
                    Do_Remote_Cmd
                    if [ "$?" != 0 ]
                    then
			echo "ERROR: Attempt to remove RVG $RVG_NAME from host $SECONDARY_HOST failed."
                	echo "Hit return to continue: \c"
                	read Whatever
		    fi
		else
			echo "$VXVM_BIN/vxedit -g $DISKGROUP -rf rm $RVG_NAME"
                        $VXVM_BIN/vxedit -g "$DISKGROUP" -rf rm "$RVG_NAME"
			if [ "$?" != 0 ]
			then
			    echo "ERROR: Attempt to remove RVG $RVG_NAME from local host $SECONDARY_HOST failed."
                            echo "Hit return to continue: \c"
                            read Whatever
			fi
		fi
	fi
	return 
clear
}

#1
Create_Remove_Change_an_Rvg()
{
clear
while [ 1 ] 
do
	clear
	echo "Create/Remove/Change an RVG"
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    1  Create an RVG"
	echo "    2  Remove an RVG"
	echo "    3  Change an RVG"
	echo ""		
	echo "    p  Previous -- return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
	case "$CHOICE" in
		1 ) Create_an_Rvg;;
		2 ) Remove_an_Rvg;;
		3 ) Change_an_Rvg;;
		[rR] ) Remote_Vxprint;;
		[vV] ) Vxprint;;
		[pP] ) break;;
		[qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
		* ) echo "Invalid input: $CHOICE"
			echo "Hit return to continue: \c"
			read Whatever
		    CHOICE="";;
	esac
done
CLEANUP=""
REMOTE_HOSTS=""
/bin/rm -f /tmp/vvr.remote_cleanup.*
clear
}

# Inputs:
#	MUST_BE_PRIMARY=yes	Must be a Primary rvg
#	MUST_BE_PRIMARY=no	May be either a Primary or a Secondary rvg
#212
Rvg_to_select()
{
clear
	if [ "$MUST_BE_PRIMARY" = "yes" ]
	then
		echo "Existing Primary rvgs detected in diskgroup ${DISKGROUP:-rootdg}:"
	else
		echo "Existing rvgs detected in diskgroup ${DISKGROUP:-rootdg}:"
	fi
        $VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -tVqQ 2> /dev/null 1> $VXPRINT_FILE
        if [ "$?" != 0 ]
        then
		echo ""
                echo "ERROR: Could not get list of existing rvgs in diskgroup ${DISKGROUP:-rootdg}."
                echo "Hit return to continue: \c"
                read Whatever
                clear
                /bin/rm -f $VXPRINT_FILE
                return 0
        fi

	if [ "$MUST_BE_PRIMARY" = "yes" ]
	then
	    awk '{ if ($6 == "primary") 
		print $0 }' $VXPRINT_FILE 1> $CONFIG_3TMP_FILE 2>/dev/null
	    if [ ! -s $CONFIG_3TMP_FILE ]
	    then
		echo ""
		echo "ERROR: No Primary rvgs detected in diskgroup ${DISKGROUP:-rootdg}"
		echo "Hit return to continue: \c"
		read Whatever
		/bin/rm -f $CONFIG_3TMP_FILE $VXPRINT_FILE
		clear
		return 0
	    fi
	    /bin/mv -f $CONFIG_3TMP_FILE $VXPRINT_FILE
	else
	    if [ ! -s $VXPRINT_FILE ]
	    then
		echo ""
		echo "ERROR: No rvgs detected in diskgroup ${DISKGROUP:-rootdg}"
		echo "Hit return to continue: \c"
		read Whatever
		/bin/rm -f $VXPRINT_FILE
		clear
		return 0
	    fi
	fi 

	awk 'BEGIN { print "   NAME         RLK_CNT      KSTATE   STATE    DATAVOLS  SRLVOL" }
		{ printf "%-2d %-12s %-12d %-8s %-8s %-9d %s\n", NR, $2, $3, $4, $5, $7, $8 }
                       END {printf "\n"}' $VXPRINT_FILE

        echo "Enter number of existing RVG to select.  Enter an empty line to return to"
	echo "previous menu without selecting an rvg."
        echo ""
	if [ "$MUST_BE_PRIMARY" = "yes" ]
	then
		echo "Example:  Existing Primary rvgs detected in diskgroup rootdg:"
	else
		echo "Example:  Existing rvgs detected in diskgroup rootdg:"
	fi
	echo "       NAME         RLK_CNT      KSTATE   STATE    DATAVOLS  SRLVOL"
	echo "    1  tmp-rvgA    1            ENABLED  ACTIVE   3         tmp-srlA"
	echo "    2  tmp-rvgB    1            ENABLED  ACTIVE   3         tmp-srlB"
	echo "    3  tmp-rvgC    1            ENABLED  ACTIVE   3         tmp-srlC"
        echo ""
        echo "  Enter \"2\" to select tmp-rvgB as the RVG to use"
        echo ""

        LINE=xxxxxx
        while [ "$LINE" != "" ]
        do
                echo "RVG to select: \c"
                read LINE
		if [ "$LINE" = "" ]
		then
			break
		fi

		set -- $LINE

                if [ "$2" != "" ]
                then
                        echo "Only enter one number to select the single RVG to select."
                        echo "Ignoring that value."
                        continue
                fi

                case "$1" in
                        [0-9] | [0-9]*[0-9] ) RVG_NAME=`awk '{ if (NR == '$1') printf "%s", $2 }' $VXPRINT_FILE`;;
                        * )     echo "Invalid input: $1.  Ignoring that value."
                                continue;;
                esac

                if [ "$1" -gt `wc -l $VXPRINT_FILE | /bin/sed 's/  */ /g' | /bin/cut -d' ' -f2` ]
                then
                        echo "Input number is too big: $1.  Ignoring that value.
"
                        continue
                fi

                if [ "$1" -lt 1 ]
                then
                        echo "Input number is too small: $1.  Ignoring that value."
                        continue
                fi

		LINE=""
	done
	/bin/rm -f $VXPRINT_FILE
clear
}

#213
# Inputs:
#	ALLOW_BLANK_INPUT	Non-null if "" is allowed to clear the string
Checkpoint_string()
{
clear
	echo "Enter unique checkpoint string of up to 19 characters.  [Leading whitespace is"
	echo "ignored.]"
	if [ "$ALLOW_BLANK_INPUT" = "yes" ]
	then
		echo "Enter an empty line to clear the checkpoint string field"
	fi
        echo ""
        echo "Enter checkpoint string (newline to back up): \c"
        NEW_CHECKPOINT_STRING=""
	read NEW_CHECKPOINT_STRING
	if [ "$NEW_CHECKPOINT_STRING" = "" ]
	then
		if [ "$ALLOW_BLANK_INPUT" = "yes" ]
		then
			CHECKPOINT_STRING=""
		fi
		break
	else
		CHECKPOINT_STRING="$NEW_CHECKPOINT_STRING"
	fi
clear
}

#213
# Inputs:
Get_rlink_attach_mode()
{
        clear
	Y_OR_N=""
	
       	while [ "$Y_OR_N" = "" ]
       	do
		echo "Do You Want To Attach the RLINK in autosync mode (default: y) (y/n): \c"
                read Y_OR_N
                case "$Y_OR_N" in
                 [yY] ) 
			if [ "$CHECKPOINT_STRING" != "" ]; then
			   echo "ERROR: Cannot set checkpoint_string and Autosync mode attach at the same time"
			   Y_OR_N=""
			   
			else
				ATTACH_MODE="yes";
                        	return;
			fi
			;;
                 [nN] ) ATTACH_MODE="no";
                 	return;;
                 * )     echo "Invalid input"
                 	Y_OR_N="" ;;
               esac
        done

}


Go_Checkpoint_an_Rvg()
{
	echo "Data volumes detected in ${DISKGROUP:-rootdg} with $RVG_NAME as parent:"
        $VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -htqQ "$RVG_NAME" 2> /dev/null 1> $VXPRINT_FILE
        if [ "$?" != 0 ]
        then
		echo ""
                echo "ERROR: Could not get list of data volumes for $RVG_NAME in diskgroup ${DISKGROUP:-rootdg}."
                echo "Hit return to continue: \c"
                read Whatever
                clear
                /bin/rm -f $VXPRINT_FILE
                return 0
	fi

	SRLVOL=`$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -tQq "$RVG_NAME" 2> /dev/null | awk '{ printf "%s", $8 }'`
	if [ "$SRLVOL" != "(none)" ]
	then
		awk '{ if ( $2 != "'$SRLVOL'" ) print $0 }' $VXPRINT_FILE > ${VXPRINT_FILE}.2
		/bin/mv -f ${VXPRINT_FILE}.2 $VXPRINT_FILE
	fi

	DV_CNT=`egrep -c "^v " $VXPRINT_FILE`
	if [ "$DV_CNT" -lt 1 ]
	then
		echo ""
                echo "ERROR: Could not find any data volumes for $RVG_NAME in diskgroup ${DISKGROUP:-rootdg}."
                echo "Hit return to continue: \c"
                read Whatever
                clear
                /bin/rm -f $VXPRINT_FILE
                return 0
	fi

	echo "   NAME         KSTATE   STATE    LENGTH   USETYPE   PREFPLEX RDPOL"
	awk '/^v / { printf "   %-12s %-8s %-8s %-8s %-9s %-8s %s\n", $2, $4, $5, $6, $7, $8, $9 }' $VXPRINT_FILE
	/bin/rm -f $VXPRINT_FILE
	echo ""
	echo "Doing checkstart operation on RVG $RVG_NAME in diskgroup "${DISKGROUP:-rootdg}"..."
	echo "$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} -c \"""$CHECKPOINT_STRING""\" checkstart $RVG_NAME"

        $VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" -c "$CHECKPOINT_STRING" checkstart "$RVG_NAME"
	if [ "$?" != 0 ]
	then
                echo ""
                echo "ERROR: Error while check-starting RVG $RVG_NAME in diskgroup ${DISKGROUP:-rootdg}."
                echo "Hit return to continue: \c"
                read Whatever
                clear
		return 0
	fi
	OLD_CLEANUP="$CLEANUP"
        CLEANUP_DO_CHECKEND
	OLD_CHECKPOINT_STRING="$CHECKPOINT_STRING"

	RVG_STATE=`$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -tQq "$RVG_NAME" 2> /dev/null | awk '{ printf "%s", $5 }'`
	if [ "$RVG_STATE" != "ACTIVE" ]
	then
		echo ""
		echo "NOTE: The Primary RVG has not been started, yet.  You will have to start it"
		echo "before you can read from the Primary data volumes."
                Y_OR_N=""
                while [ "$Y_OR_N" = "" ]
                do
			echo "Shall I start $RVG_NAME for you now? ((default: y) (y/n): \c"
			read Y_OR_N
			case "$Y_OR_N" in
				"" )    Y_OR_N=y;;
                                [yY] ) Y_OR_N=y;;
                                [nN] ) Y_OR_N=n;;
                                * )     echo "Invalid input"
                                Y_OR_N="" ;;
			esac
		done
		if [ "$Y_OR_N" = n ]
		then
			echo "OK. Should you wish to start $RVG_NAME yourself, do this:"
			echo "	$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} start $RVG_NAME"
		else
                	echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" start "$RVG_NAME""
                	$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" start "$RVG_NAME"
                	if [ "$?" != 0 ]
                	then
                        	echo "ERROR: Failure while trying to start Primary RVG $RVG_NAME"
                        	echo "Hit return to continue: \c"
                        	read Whatever
				echo "Cleaning up--doing checkend"
				echo "$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME"
				$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME
				clear
                        	return 0
                	fi
			CLEANUP_STOP_RVG
		fi
	fi

	echo ""
        echo "Now make a local copy of each data volume for RVG $RVG_NAME (listed above)"
	echo ""
        echo "Hit return when done (^C to abort entire program): \c"
        read WAIT_FOR_USER_ACTION
	echo "Doing checkend operation on RVG $RVG_NAME in diskgroup "${DISKGROUP:-rootdg}"..."
	echo "$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME"
	$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME
	if [ "$?" != 0 ]
	then
                echo ""
                echo "ERROR: Error while check-ending RVG $RVG_NAME in diskgroup ${DISKGROUP:-rootdg}."
                echo "Hit return to continue: \c"
                read Whatever
                clear
		return 0
	fi
        CLEANUP="$OLD_CLEANUP"
        echo ""
	echo "Primary checkpoint is complete."
	echo ""
        echo "Now transfer your new copy of each data volume to the RLINK sites.  Note that"
	echo "secondary rlinks have to be temporarily detached (at the Secondary site),"
	echo "before you can write to corresponding Secondary data volumes."
	echo "To detach:    vxrlink -g diskgroupname det rlinkname"
	echo "To re-attach: vxrlink -g diskgroupname -f att rlinkname"
	echo "Also, if any Primary rlinks are currently ACTIVE, but are to be updated with new"
	echo "checkpoint data as well, then they will have to be detached (via \"vxrlink -g"
	echo "diskgroupname det rlinkname\") in preparation for the subsequent checkpoint"
	echo "attach (via \"Attach an RLINK\" from the Main Menu)."
	echo ""
        echo "After transferring the new copy of each data volume to the RLINK sites, select"
	echo "the \"Attach an RLINK\" option from the main menu."

        echo ""
	echo "Hit return to continue: \c"
	read Whatever
	LAST_RVG=$RVG_NAME
	LAST_DG=$DISKGROUP
	return 1
}

# Outputs:
#	COPYRLK		List of rlinks to copy checkpoint data to
#	VXPRINT_FILE2	vxprint RLINK output
#22g
Go_Select_Rlinks_To_Be_Updated()
{
clear
	echo "Primary Checkpoint -- Let this program use dd(1), a pipe (|), and rsh(1)"
	echo ""
	echo "Now select rlinks to copy checkpoint data to"
	echo ""
	echo "       Disk group                                    ${DISKGROUP:-rootdg}"
	echo "       Primary RVG to checkpoint                    ${RVG_NAME:-<Unknown>}"
	echo "       Checkpoint string                            ${CHECKPOINT_STRING:-<Unknown>}"
	echo ""
        $VXVM_BIN/vxprint -g ${DISKGROUP:-rootdg} -htQV $RVG_NAME 2>/dev/null 1> $VXPRINT_FILE
        if [ "$?" != 0 ]
        then
                echo "ERROR: Could not get information about $RVG_NAME in ${DIS
KGROUP:-rootdg}"
                echo "Hit return to continue: \c"
                read Whatever
		/bin/rm -f $VXPRINT_FILE
                return 0
        fi
        echo "Rlinks found for $RVG_NAME in diskgroup ${DISKGROUP:-rootdg}:"
        awk '/^rl / { count=count + 1
                      printf "%-2s %-19s %-19s %-8s %-8s %-8s %-9s %s\n", count, $2, $3, $4, $5, $6, $7, $8 }' $VXPRINT_FILE > $VXPRINT_FILE2
        if [ ! -s $VXPRINT_FILE2 ]
        then
                echo "ERROR: No rlinks were found"
                COPYRLK=""
                echo "Hit return to continue: \c"
                read Whatever
		/bin/rm -f $VXPRINT_FILE $VXPRINT_FILE2
                return 0
        fi
        echo "   NAME                KSTATE   STATE    REM_HOST REM_DG    REM_RLK"
        awk '{ printf "%-2s %-19s %-8s %-8s %-8s %-9s %s\n", $1, $2, $4, $5, $6, $7, $8 }' $VXPRINT_FILE2

        echo ""
        echo "Enter number(s) (from first column, above) of RLINK to copy checkpoint data"
	echo "to, or type \"all\" to process all of the rlinks.  Enter an empty line to"
	echo "return to previous menu without selecting an rlink."
        echo ""
        NUM_LINES=`wc -l $VXPRINT_FILE2 | /bin/sed 's/  */ /g' | /bin/cut -d' ' -f2`

        LINE=xxxxxx
        while [ "$LINE" != "" ]
        do
		COPYRLK=""
                echo "Number(s) of RLINK to process or \"all\" for all: \c"
                read LINE
                if [ "$LINE" = "" ]
                then
                        break
                fi
                set -- $LINE

		while [ "$1" != "" ]
		do
                    case "$1" in
                        all )   COPYRLK=`awk '{ printf "%s ", $2 }' $VXPRINT_FILE2`
				clear
				/bin/rm -f $VXPRINT_FILE
                                return 1;;
                        [0-9] | [0-9]*[0-9] ) TEMP=`awk '{ if (NR == '$1') printf "%s", $2 }' $VXPRINT_FILE2`;;
                        * )     echo "Invalid input: $1.  Ignoring that line."
				COPYRLK=""
				break;;
                    esac

                    if [ "$1" -gt "$NUM_LINES" ]
                    then
                        echo "Input number is too big: $1.  Ignoring that line."
			COPYRLK=""
                        break
                    fi
                    if [ "$1" -lt 1 ]
                    then
                        echo "Input number is too small: $1.  Ignoring that line."
			COPYRLK=""
			break
                    fi
		    COPYRLK="$COPYRLK $TEMP"
		    shift
		done
		TEMP=`echo $COPYRLK`
		if [ "$TEMP" != "" ]
		then
			/bin/rm -f $VXPRINT_FILE
			return 1
			#LINE=""
		fi
        done
	/bin/rm -f $VXPRINT_FILE $VXPRINT_FILE2
	return 0
clear
}

# Inputs:
#	COPYRLK 
Go_get_and_process_rlinks()
{
	Go_Select_Rlinks_To_Be_Updated	#Sets VXPRINT_FILE2:
	#	VXPRINT_FILE2		Contains info about rlinks to be processed:
	#1  rlk-molokini        DISABLED STALE    molokini awedg     Srlk-molokini
	if [ "$?" = 0 ]
	then
		return 0
	fi
	clear
        echo "Primary Checkpoint -- Let this program use dd(1), a pipe (|), and rsh(1)"
        echo ""
        echo "       Disk group                                    ${DISKGROUP:-rootdg}"
        echo "       Primary RVG to checkpoint                    ${RVG_NAME:-<Unknown>}"
        echo "       Checkpoint string                            ${CHECKPOINT_STRING:-<Unknown>}"
        echo ""
        echo "Selected rlinks to copy checkpoint data to:"
	echo "    $COPYRLK"
	echo ""

	# Now check for non-stale rlinks, and warn that they're current data 
	# will be overwritten.
	NON_STALE_RLKS=""
	for MAYBE_STALE_RLK in $COPYRLK
	do
		NON_STALE_RLK=`awk '/[0-9]*  *'$MAYBE_STALE_RLK' / { if ( $5 != "STALE" ) 
			printf "%s ", $2 }' $VXPRINT_FILE2`
		if [ "$NON_STALE_RLK" != "" ]
		then
			NON_STALE_RLKS="$NON_STALE_RLKS $NON_STALE_RLK"
		fi
	done
	if [ "$NON_STALE_RLKS" != "" ]
	then
	    	echo "NOTE: The following rlink(s) are not STALE:"
	    	echo "    $NON_STALE_RLKS"
	    	echo "These rlinks will be detached before copying checkpoint data."
	    	echo ""
	fi

	Y_OR_N=""
	while [ "$Y_OR_N" = "" ]
	do
		echo "Start copying checkpoint data? (default: y) (y/n): \c"
		read Y_OR_N
		case "$Y_OR_N" in
			"" )    Y_OR_N=y;;
			[yY] ) Y_OR_N=y;;
			[nN] ) Y_OR_N=n;;
			* )     echo "Invalid input"
			Y_OR_N="" ;;
		esac
	done
	if [ "$Y_OR_N" = n ]
	then
		return 0
	fi

	for RLK in $NON_STALE_RLKS
	do
		echo "$VXVM_BIN/vxrlink -g "$DISKGROUP" det $RLK"
		$VXVM_BIN/vxrlink -g "$DISKGROUP" det "$RLK"
	done

	#Get list of Primary datavol pathnames
        $VXVM_BIN/vxprint -g "$DISKGROUP" -htQqV "$RVG_NAME" 2>/dev/null >$VXPRINT_FILE
	if [ "$?" != 0 ]
	then
		echo "ERROR: Could not get inforation about RVG $RVG_NAME"
                echo "Hit return to continue: \c"
                read Whatever
		/bin/rm -f $VXPRINT_FILE
		return 0
	fi
	SRLVOL=`awk '/rv / { print $8 }' $VXPRINT_FILE`
	RVG_STATE=`awk '/rv / { print $5 }' $VXPRINT_FILE`
	DVS=`awk '/^v / { if ( $2 != "'$SRLVOL'" ) 
				printf "%s ", $2 }' $VXPRINT_FILE`
	TEMP=`echo $DVS`
	if [ "$TEMP" = "" ]
	then
		echo "WARNING: No Primary data volumes detected.  Nothing to copy."
                echo "Hit return to continue: \c"
                read Whatever
		/bin/rm -f $VXPRINT_FILE
		return 1
	fi
	$VXVM_BIN/vxprint -g "$DISKGROUP" -lv $DVS | /bin/egrep "^device:" | /bin/cut -d'=' -f5  | /bin/sed 's/\/dsk\//\/rdsk\//' > $VXPRINT_FILE 2>/dev/null

	if [ ! -s $VXPRINT_FILE ]
	then
		echo "ERROR: Could not get information about data volumes: $DVS"
                echo "Hit return to continue: \c"
                read Whatever
                /bin/rm -f $VXPRINT_FILE
                return 0
	fi
	echo ""
#	echo "Primary data volume source files:"
#	/bin/cat $VXPRINT_FILE
#	echo ""

	for RLK in $COPYRLK
	do
		echo "Analyzing $RLK..."
		set -- `awk '/ '$RLK' / { printf "%s %s %s", $6, $7, $8 }' $VXPRINT_FILE2`
		SECONDARY_HOST=$1
		SECONDARY_DISKGROUP=$2
		SECONDARY_RLINK=$3

		echo "    Getting information about Secondary RLINK $SECONDARY_RLINK from $SECONDARY_HOST..."
		REMOTE_CMD="$VXVM_BIN/vxprint -g $SECONDARY_DISKGROUP -tQqP $SECONDARY_RLINK"
		echo "    $SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd 2>/dev/null > $CONFIG_TMP_FILE
		if [ "$?" != 0 ] || [ ! -s $CONFIG_TMP_FILE ]
		then
		    echo "ERROR: Could not get information about Secondary RLINK: $SECONDARY_RLINK"
                    echo "Hit return to continue: \c"
                    read Whatever
                    /bin/rm -f $VXPRINT_FILE $CONFIG_TMP_FILE
                    return 0
		fi
		set -- `/bin/cat $CONFIG_TMP_FILE`
		SECONDARY_RVG=$3

		echo "    Getting information about Secondary RVG $SECONDARY_RVG from $SECONDARY_HOST.."
		REMOTE_CMD="$VXVM_BIN/vxprint -g $SECONDARY_DISKGROUP -htQqV $SECONDARY_RVG"
		echo "    $SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd 2>/dev/null > $CONFIG_TMP_FILE
		if [ "$?" != 0 ] || [ ! -s $CONFIG_TMP_FILE ]
		then
		    echo "ERROR: Could not get information about Secondary RVG: $SECONDARY_RVG"
                    echo "Hit return to continue: \c"
                    read Whatever
                    /bin/rm -f $VXPRINT_FILE $CONFIG_TMP_FILE
                    return 0
		fi
		SECONDARY_SRLVOL=`awk '/^rv / { print $8 }' $CONFIG_TMP_FILE`

		SDVS=`awk '/^v / { if ( $2 != "'$SECONDARY_SRLVOL'" ) printf "%s ", $2 }' $CONFIG_TMP_FILE`

		echo "    Getting information about Secondary data volumes from $SECONDARY_HOST..."
		REMOTE_CMD="$VXVM_BIN/vxprint -g $SECONDARY_DISKGROUP -lMv $SDVS"
		echo "    $SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd 2>/dev/null > $CONFIG_TMP_FILE
		if [ "$?" != 0 ] || [ ! -s $CONFIG_TMP_FILE ]
		then
			echo "ERROR: Could not get information about Secondary data volumes"
			echo "Hit return to continue: \c"
			read Whatever
			/bin/rm -f $VXPRINT_FILE $CONFIG_TMP_FILE
			return 0
		fi

		/bin/egrep "^Volume:|primary_datavol=|^device:" $CONFIG_TMP_FILE |
		awk '{ if ($1 == "Volume:") printf "%s ", $2
		       if ($1 == "device:") {
				split($5, a, "=")
				printf "%s\n", a[2] }
		       if ( substr($1, 0, 16) == "primary_datavol=" ) {
				split($1, b, "=")
				printf "%s ", b[2] } }' > $CONFIG_2TMP_FILE
		 /bin/sed 's/\/dsk\//\/rdsk\//' $CONFIG_2TMP_FILE > $CONFIG_2TMP_FILE.$RLK
		/bin/rm -f $$CONFIG_2TMP_FILE
	done

	# Start the Primary RVG so that dd(1) can read from the data volumes
	if [ "$RVG_STATE" != "ACTIVE" ]
	then
		echo "Temporarily starting Primary RVG $RVG_NAME (for dd(1) to succeed)"
        	echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" start "$RVG_NAME""
        	$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" start "$RVG_NAME"
        	if [ "$?" != 0 ]
        	then
                	echo "ERROR: Failure while trying to start Primary RVG $RVG_NAME"
                	echo "Hit return to continue: \c"
                	read Whatever
                	return 0
        	fi
		CLEANUP_STOP_RVG
	fi

	echo "$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} -c \"""$CHECKPOINT_STRING""\" checkstart $RVG_NAME"
        $VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" -c "$CHECKPOINT_STRING" checkstart "$RVG_NAME"
        if [ "$?" != 0 ]
        then
                echo "ERROR: Checkstart failed for $RVG_NAME"
                echo "Hit return to continue: \c"
                read Whatever
		/bin/rm -f $VXPRINT_FILE $CONFIG_TMP_FILE ${CONFIG_2TMP_FILE}*
		if [ "$RVG_STATE" != "ACTIVE" ] 
		then
		    echo "Returning Primary RVG to stopped state"
                    echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME""
                    $VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME"
		fi
                return 0
        fi
	CLEANUP_PRE_CHECKSTART=$CLEANUP
	CLEANUP_DO_CHECKEND

        for RLK in $COPYRLK
        do
		echo "Processing $RLK..."
		set -- `awk '/ '$RLK' / { printf "%s %s %s %s", $3, $6, $7, $8 }' $VXPRINT_FILE2`
		PRIMARY_RVG=$1
		SECONDARY_HOST=$2
		SECONDARY_DISKGROUP=$3
		SECONDARY_RLINK=$4

		# This is gross getting the Secondary RVG again.  Rewrite it to
		# save SECONDARY_RVG in Analyzing loop, above...
                echo "    Getting information about Secondary RLINK $SECONDARY_RLINK from $SECONDARY_HOST..."
                REMOTE_CMD="$VXVM_BIN/vxprint -g $SECONDARY_DISKGROUP -tQqP $SECONDARY_RLINK"
                echo "    $SECONDARY_HOST: $REMOTE_CMD"
                Do_Remote_Cmd 2>/dev/null > $CONFIG_TMP_FILE
                if [ "$?" != 0 ] || [ ! -s $CONFIG_TMP_FILE ]
                then
                    echo "ERROR: Could not get information about Secondary RLINK: $SECONDARY_RLINK"
                    echo "Hit return to continue: \c"
                    read Whatever
		    /bin/rm -f $VXPRINT_FILE $CONFIG_TMP_FILE ${CONFIG_2TMP_FILE}*
		    echo "$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME"
		    $VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME
		    if [ "$RVG_STATE" != "ACTIVE" ] 
		    then
		        echo "Returning Primary RVG to stopped state"
                        echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME""
                        $VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME"
		    fi
                    return 0
                fi
                set -- `/bin/cat $CONFIG_TMP_FILE`
                SECONDARY_RVG=$3
		SECONDARY_RLK_STATE=$5

		#Start the Secondary RVG so that dd(1) can write to the datavols
		echo "    Starting Secondary RVG $SECONDARY_RVG (for dd(1) to succeed)"
		REMOTE_CMD="$VXVM_BIN/vxrvg -g ${SECONDARY_DISKGROUP} start $SECONDARY_RVG"
		echo "    $SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd_Status
		STATUS="$?"
		if [ "$STATUS" != 0 ] && [ "$STATUS" != 20 ] #Okay if already started
		then
                	echo "ERROR: Failure while trying to start Secondary RVG $SECONDARY_RVG"
                	echo "Hit return to continue: \c"
                	read Whatever
			/bin/rm -f $VXPRINT_FILE $CONFIG_TMP_FILE ${CONFIG_2TMP_FILE}*
			echo "$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME"
			$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME
		        if [ "$RVG_STATE" != "ACTIVE" ] 
		        then
		            echo "Returning Primary RVG to stopped state"
                            echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME""
                            $VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME"
		        fi
                	return 0
		fi

		# If one of the Primary data volumes is not mapped on the 
		# secondary, yet, let's find out about it ahead of time to 
		# avoid doing any of the dd(1)'s.
		for DV in $DVS
		do 
			PRIMARY_VOLPATH=`awk '/\/'$DV'$/ { print $0 }' $VXPRINT_FILE`
			if [ "$PRIMARY_VOLPATH" = "" ]
			then
				echo "ERROR while trying to get device path names for the Primary data volume $DV"
				echo "Hit return to continue: \c"
				read Whatever
				/bin/rm -f $VXPRINT_FILE $CONFIG_TMP_FILE ${CONFIG_2TMP_FILE}*
				echo "$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME"
				$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME
		    		if [ "$RVG_STATE" != "ACTIVE" ] 
		    		then
		        		echo "Returning Primary RVG to stopped state"
                        		echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME""
                        		$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME"
		    		fi
				return 0
			fi
			SECONDARY_VOLPATH=`awk '/ '$DV' / { print $3 }' $CONFIG_2TMP_FILE.$RLK`
			if [ "$SECONDARY_VOLPATH" = "" ]
			then
				echo "ERROR while trying to get device path of the Secondary data volume mapped to"
				echo "primary data volume $DV.  Make sure that this data volume is mapped to some"
				echo "data volume on the secondary."
				echo "Hit return to continue: \c"
				read Whatever
				/bin/rm -f $VXPRINT_FILE $CONFIG_TMP_FILE ${CONFIG_2TMP_FILE}*
				echo "$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME"
				$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME
		    		if [ "$RVG_STATE" != "ACTIVE" ] 
		    		then
		        		echo "Returning Primary RVG to stopped state"
                        		echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME""
                        		$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME"
		    		fi
				return 0
			fi
		done

		if [ "$SECONDARY_RLK_STATE" != "STALE" ]
		then
		    echo "    Temporarily detach Secondary RLINK $SECONDARY_RLINK so that writes to the"
		    echo "    Secondary data volume can succeed"
                    REMOTE_CMD="$VXVM_BIN/vxrlink -g $SECONDARY_DISKGROUP det $SECONDARY_RLINK"
                    echo "    $SECONDARY_HOST: $REMOTE_CMD"
                    Do_Remote_Cmd
                    if [ "$?" != 0 ] 
                    then
			echo "ERROR: Trying to detach Secondary RLINK $SECONDARY_RLINK before copying data"
			echo "Hit return to continue: \c"
			read Whatever
			/bin/rm -f $VXPRINT_FILE $CONFIG_TMP_FILE ${CONFIG_2TMP_FILE}*
			echo "$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME"
			$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME
		        if [ "$RVG_STATE" != "ACTIVE" ] 
		        then
		            echo "Returning Primary RVG to stopped state"
                            echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME""
                            $VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME"
		        fi
			return 0
		    fi
		    REMOTE_CLEANUP_ATT_RLINK
		fi

		for DV in $DVS
		do
			PRIMARY_VOLPATH=`awk '/\/'$DV'$/ { print $0 }' $VXPRINT_FILE`
			SECONDARY_VOLPATH=`awk '/ '$DV' / { print $3 }' $CONFIG_2TMP_FILE.$RLK`
			# First make sure that we can write to the secondary
			# data volume, since we won't get an error return about
			# it from the rsh during the actual write.
			echo "    Test write to Secondary data volume to check for errors (lest rsh eat them)"
			REMOTE_CMD="/bin/dd if=/dev/zero count=1 of=$SECONDARY_VOLPATH"
                	echo "    $SECONDARY_HOST: $REMOTE_CMD"
			Do_Remote_Cmd 
			if [ "$?" != 0 ]
			then
				echo "ERROR writing to Secondary data volume"
				echo "Hit return to continue: \c"
				read Whatever
				/bin/rm -f $VXPRINT_FILE $CONFIG_TMP_FILE ${CONFIG_2TMP_FILE}*
				echo "$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME"
				$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME
		    		if [ "$RVG_STATE" != "ACTIVE" ] 
		    		then
		        		echo "Returning Primary RVG to stopped state"
                        		echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME""
                        		$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME"
		    		fi
				if [ "$SECONDARY_RLK_STATE" != "STALE" ]
				then
                		    REMOTE_CMD="$VXVM_BIN/vxprint -g $SECONDARY_DISKGROUP -f att $SECONDARY_RLINK"
                		    echo "$SECONDARY_HOST: $REMOTE_CMD"
                		    Do_Remote_Cmd
				fi
				return 0
			fi

			echo "    /bin/dd if=$PRIMARY_VOLPATH | rsh $SECONDARY_HOST /bin/dd of=$SECONDARY_VOLPATH"
			/bin/dd if=$PRIMARY_VOLPATH | rsh $SECONDARY_HOST /bin/dd of=$SECONDARY_VOLPATH
			if [ "$?" != 0 ]
			then
				echo "ERROR while copying data to Secondary data volume"
				echo "Hit return to continue: \c"
				read Whatever
				/bin/rm -f $VXPRINT_FILE $CONFIG_TMP_FILE ${CONFIG_2TMP_FILE}*
				echo "$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME"
				$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME
		    		if [ "$RVG_STATE" != "ACTIVE" ] 
		    		then
		        		echo "Returning Primary RVG to stopped state"
                        		echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME""
                        		$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME"
		    		fi
				if [ "$SECONDARY_RLK_STATE" != "STALE" ]
				then
                		    REMOTE_CMD="$VXVM_BIN/vxprint -g $SECONDARY_DISKGROUP -f att $SECONDARY_RLINK"
                		    echo "$SECONDARY_HOST: $REMOTE_CMD"
                		    Do_Remote_Cmd
				fi
				return 0
			fi
		done
		if [ "$SECONDARY_RLK_STATE" != "STALE" ]
		then
			echo "    Re-attach the Secondary RLINK now that the data volumes have been updated."
			echo "    Ignore warning about attaching RLINK to an enabled rvg."
			REMOTE_CMD="$VXVM_BIN/vxrlink -g $SECONDARY_DISKGROUP -f att $SECONDARY_RLINK"
			echo "    $SECONDARY_HOST: $REMOTE_CMD"
			Do_Remote_Cmd_Output
		fi
	done
	/bin/rm -f /tmp/vvr.remote_cleanup.*
	REMOTE_HOSTS=""
	/bin/rm -f $VXPRINT_FILE $CONFIG_TMP_FILE ${CONFIG_2TMP_FILE}.*

	# The checkend is done whether checkstart succeeded or failed.
	echo "$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME"
	$VXVM_BIN/vxrvg -g ${DISKGROUP:-rootdg} checkend $RVG_NAME
	if [ "$?" != 0 ]
	then
                echo ""
                echo "ERROR: Error while check-ending RVG $RVG_NAME in diskgroup ${DISKGROUP:-rootdg}."
                echo "Hit return to continue: \c"
                read Whatever
		if [ "$RVG_STATE" != "ACTIVE" ] 
		then
		    echo "Returning Primary RVG to stopped state"
                    echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME""
                    $VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME"
		fi
                clear
		return 0
	fi
	CLEANUP=$CLEANUP_PRE_CHECKSTART

	# Stop the Primary RVG if it had not been ACTIVE
	if [ "$RVG_STATE" != "ACTIVE" ]
	then
		echo "Returning the Primary RVG to the stopped state"
        	echo "$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME""
        	$VXVM_BIN/vxrvg -g "${DISKGROUP:-rootdg}" stop "$RVG_NAME"
        	if [ "$?" != 0 ]
        	then
                	echo "ERROR: Failure while trying to stop Primary RVG $RVG_NAME"
                	echo "Hit return to continue: \c"
                	read Whatever
                	return 0
        	fi
	fi
	CLEANUP=""

        echo ""
	echo "Primary checkpoint is complete."
	echo ""
        echo "Now select the \"Attach an RLINK\" option from the main menu."
        echo ""
	echo "Hit return to continue: \c"
	read Whatever
	LAST_RVG=$RVG_NAME
	LAST_DG=$DISKGROUP
	return 1
}

#21 and #22
# Inputs:
#	USE_PIPE_AND_RSH	"no":  User will copy data using own mechanism
#				"yes": Script copies data using dd/pipe/rsh
Checkpoint_User_Makes_Copy()
{
CHECKPOINT_STRING=""
#RVG_NAME=""
if [ "$LAST_DG" = "$DISKGROUP" ]
then
	RVG_NAME=$LAST_RVG	#Make sure this RVG is in current dg
fi
while [ 1 ]
do
	clear
	if [ "$USE_PIPE_AND_RSH" != "yes" ]
	then
	    echo "Primary Checkpoint -- Copy the data using your own mechanism"
	else
	    echo "Primary Checkpoint -- Let this program use dd(1), a pipe (|), and rsh(1)"
	fi
	echo ""
	echo "Specify the diskgroup and RVG to be checkpointed.  Also enter a unique"
	echo "\"checkpoint string\" of up to 19 characters which will be associated with this"
	echo "checkpoint (or just use the default auto-generated value)."
	if [ "$CHECKPOINT_STRING" = "" ]
	then
		CHECKPOINT_STRING=checkpoint.$$
	fi
	if [ "$OLD_CHECKPOINT_STRING" != "" ]
	then
		echo "Previous checkpoint string entered: $OLD_CHECKPOINT_STRING"
	fi

	if [ "$RVG_NAME" != "" ]
	then
	    $VXVM_BIN/vxprint -g ${DISKGROUP:-rootdg} -l $RVG_NAME 2>/dev/null 1> $CONFIG_3TMP_FILE
	    if [ "$?" = 0 ]
	    then
        	CHECK=`/bin/egrep "checkpoint:" $CONFIG_3TMP_FILE`
        	if [ "$CHECK" != "" ]
        	then
                	set $CHECK
                	if [ "$1" = "checkpoint:" ]     # Found old checkpoint
                	then
				echo ""
                        	echo "NOTE: Last Primary checkpoint that was taken on $RVG_NAME in ${DISKGROUP:-rootdg}: \c"
				/bin/egrep "checkpoint:" $CONFIG_3TMP_FILE | /bin/sed 's/checkpoint: //'
                	fi
        	fi
	    fi
	    /bin/rm -f $CONFIG_3TMP_FILE
	fi

	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo "    1  Disk group                                    ${DISKGROUP:-rootdg}"
	echo "    2  Primary RVG to checkpoint                    ${RVG_NAME:-<Unknown>}"
	echo "    3  Checkpoint string                            ${CHECKPOINT_STRING:-<Unknown>}"
	echo ""
	if [ "$USE_PIPE_AND_RSH" != "yes" ]
	then
	echo "    g  Go -- Checkstart the rvg, wait at prompt for user to make a copy of all"
	echo "             data volumes, then checkend the rvg"
	else
	echo "    g  Go -- select which RLINKS to copy checkpoint to"
	fi
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
        case "$CHOICE" in
                1 ) Diskgroup;;
                2 ) MUST_BE_PRIMARY=yes
		    Rvg_to_select;;
                3 ) ALLOW_BLANK_INPUT="no"
		    Checkpoint_string;;
                [gG] ) if [ "$DISKGROUP" = "" ]
			then 
				DISKGROUP=rootdg
			fi
			if [ "$RVG_NAME" = "" ]
			then
				echo "ERROR: Specify an RVG to checkpoint"
                        	echo "Hit return to continue: \c"
                        	read Whatever
				continue
			fi
			if [ "$CHECKPOINT_STRING" = "" ]
			then
				echo "ERROR: Specify a checkpoint string to use"
                        	echo "Hit return to continue: \c"
                        	read Whatever
				continue
			fi
			if [ "$USE_PIPE_AND_RSH" != "yes" ]
			then
				Go_Checkpoint_an_Rvg
			else
				Go_get_and_process_rlinks
			fi
			if [ "$?" = 1 ]
			then
				break
			else
				clear
			fi;;
                [rR] ) Remote_Vxprint;;
                [vV] ) Vxprint;;
                [pP] ) break;;
                [qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
                "" ) CHOICE="";;
                * ) echo "Invalid input: $CHOICE"
                        echo "Hit return to continue: \c"
                        read Whatever
                    CHOICE="";;
        esac
done
clear
}

#2
Create_Copy_Primary_Checkpoint_Data()
{
clear
echo "Create/Copy Primary Checkpoint Data"
echo ""
echo "You can use one of the following  methods to copy data to the Secondary"
echo ""
echo "    1. Backup the Primary using a preferred method such as magnetic"
echo "        tape."
echo ""
echo "        This script will start the checkpoint procedure, then prompt you "
echo "        to backup the Primary.  When you  finish making a copy of each "
echo "        of the Primary data volumes (it is not necessary that the data"
echo "        actually be loaded onto the Secondary nodes(s) immediately), "
echo "        continue from the prompt so that this utility can finish the "
echo "        checkpoint procedure.  [Attach the Primary RLINKS(s) any time "
echo "        after restoring the data to all of the Secondary data volumes.]"
echo ""
echo "    2. Let this utility use dd(1), a pipe (|), and rsh(1)"
echo ""
echo "       This approach is extremely inefficient, especially for large data"
echo "       volumes, and is only recommended if you are just experimenting with"
echo "       the the software using small data volumes.  It uses dd(1) to read"
echo "       the data in turn from each Primary data volume and send it through a"
echo "       pipe to rsh(1) to the corresponding Secondary data volume for each "
echo "       Secondary.  [The rlink(s) can be attached immediately if using this"
echo "       approach.]"
echo ""
        CHECKSTART_ANSWER=""
        while [ "$CHECKSTART_ANSWER" = "" ]
        do
		echo "Select an option (or Press return to go the to previous menu): \c"
                read CHECKSTART_ANSWER 
                case "$CHECKSTART_ANSWER" in
                        "" )    break;;
                        1 ) 	USE_PIPE_AND_RSH=no
				Checkpoint_User_Makes_Copy;;
                        2 ) 	USE_PIPE_AND_RSH=yes
				Checkpoint_User_Makes_Copy;;
                        * )     echo "Invalid input: $CHECKSTART_ANSWER"
                        	echo "Hit return to continue: \c"
                        	read Whatever
				CHECKSTART_ANSWER="";;
                esac
        done
clear
}

# Inputs:
#	RVG DISKGROUP RL SECONDARY_HOST SECONDARY_DISKGROUP SECONDARY_RLINK
# Outputs:
#	1 = success; 0 = failure
Load_config_from_existing_secondary_rvg()
{
	echo "Loading Secondary configuration information from $SECONDARY_HOST..."
	REMOTE_CMD="$VXVM_BIN/vxprint -g "${SECONDARY_DISKGROUP:-rootdg}" -tQqP $SECONDARY_RLINK" 
	#echo "$SECONDARY_HOST: $REMOTE_CMD"
	Do_Remote_Cmd 2> /dev/null 1> $CONFIG_3TMP_FILE
	if [ "$?" != 0 ]
	then
		echo "Could not get information from $SECONDARY_HOST about Secondary RLINK $RL in disk group $SECONDARY_DISKGROUP"
		echo "Hit return to continue: \c"
		read Whatever
		return 0
	fi
	set -- `/bin/cat $CONFIG_3TMP_FILE`
	if [ "$2" != "$SECONDARY_RLINK" ]
	then
		echo "Could not get information from $SECONDARY_HOST about RLINK $SECONDARY_RLINK in disk group $SECONDARY_DISKGROUP"
		echo "Hit return to continue: \c"
		read Whatever
		return 0
	fi

	SECONDARY_RVG="$3"

	echo "Getting information about Secondary RLINK from $SECONDARY_HOST..."
	REMOTE_CMD="$VXVM_BIN/vxprint -g "${SECONDARY_DISKGROUP:-rootdg}" -l $SECONDARY_RLINK" 
	#echo "$SECONDARY_HOST: $REMOTE_CMD"
	Do_Remote_Cmd 2> /dev/null 1> $CONFIG_3TMP_FILE
        if [ "$?" != 0 ]
	then
		echo "ERROR: Error getting information from $SECONDARY_HOST about Secondary RLINK $SECONDARY_RLINK"
		echo "Hit return to continue: \c"
		read Whatever
		return 0
	fi

	TEMP=`/bin/grep 'latencyprot=' $CONFIG_3TMP_FILE 2>/dev/null`
	if [ "$TEMP" = "" ]
	then
		echo "ERROR: Error getting latencyprot information from $SECONDARY_HOST about Secondary RLINK $SECONDARY_RLINK"
		echo "Hit return to continue: \c"
		read Whatever
		return 0
	fi
	set -- $TEMP
	SYNC_STRING=$1; LATENCYPROT_STRING=$2; SRLPROT_STRING=$3
	SYNC=`echo $SYNC_STRING | /bin/cut -d'=' -f2`
	LATENCY=`echo $LATENCYPROT_STRING | /bin/cut -d'=' -f2`
	SRLPROT=`echo $SRLPROT_STRING | /bin/cut -d'=' -f2`
	Get_throttling_mode_strings_reverse
	if [ "$?" = 0 ]
	then
		echo "ERROR: Error getting throttling information about Secondary RLINK $SECONDARY_RLINK"
		echo "Hit return to continue: \c"
		read Whatever
		return 0
	fi
	TEMP=`/bin/grep 'latency_high_mark=' $CONFIG_3TMP_FILE 2>/dev/null`
	if [ "$TEMP" = "" ]
	then
		echo "ERROR: Error getting latency_high_mark information from $SECONDARY_HOST about Secondary RLINK $SECONDARY_RLINK"
		echo "Hit return to continue: \c"
		read Whatever
		return 0
	fi

	set -- $TEMP
	HIGH_LATENCY_STRING=$1; LOW_LATENCY_STRING=$2
	HIGH_LATENCY=`echo $HIGH_LATENCY_STRING | /bin/cut -d'=' -f2`
	LOW_LATENCY=`echo $LOW_LATENCY_STRING | /bin/cut -d'=' -f2`

	echo "#SRL Primary_Rlink     Rlink_Name        Primary_host Primary_diskgroup Modes  HighLatency  LowLatency   Create/Exists" >> $CONFIG_FILE
	echo "#    ----------------  ----------------  -----------  ----------------  -----  -----------  -----------  -------------" >> $CONFIG_FILE
	awk 'END { printf "SRL  %-17s %-17s %-12s %-17s %-1s %-1s %-1s  %-11s  %-11s  %s\n", "'$RL'", "'$SECONDARY_RLINK'", "'$LOCAL_HOST'", "'$DISKGROUP'", "'$SYNC_MODE'", "'$LATENCY_MODE'", "'$SRLPROT_MODE'", "'${HIGH_LATENCY:-10000}'", "'${LOW_LATENCY:-9950}'", "EXISTS" }' $CONFIG_3TMP_FILE >> $CONFIG_FILE

	if [ "$SECONDARY_RVG" = "(none)" ]
	then
		return 1
	fi

	echo "" >> $CONFIG_FILE
	echo "#SRV Primary_Rlink     Rvg_Name          Diskgroup_Name  Create/Exists" >> $CONFIG_FILE
	echo "#    ----------------  ----------------  --------------  -------------" >> $CONFIG_FILE
	awk 'END { printf "SRV  %-17s %-17s %-14s  %s\n", "'$RL'", "'$SECONDARY_RVG'", "'$SECONDARY_DISKGROUP'", "EXISTS" }' $CONFIG_3TMP_FILE >> $CONFIG_FILE

	REMOTE_CMD="$VXVM_BIN/vxprint -g "${SECONDARY_DISKGROUP:-rootdg}" -htQqV "$SECONDARY_RVG"" 
	#echo "$SECONDARY_HOST: $REMOTE_CMD"
        Do_Remote_Cmd 2> /dev/null 1> $CONFIG_3TMP_FILE
        if [ "$?" != 0 ]
	then
		echo "Could not get information from $SECONDARY_HOST about Secondary RVG $SECONDARY_RVG in disk group $SECONDARY_DISKGROUP"
		echo "Hit return to continue: \c"
		read Whatever
		return 0
	fi

	SECONDARY_SRLVOL=""; SECONDARY_SRLVOL_LEN=""; SECONDARY_SRLVOL_MIRROR_CNT=""
	TEMP=`egrep "^rv "  $CONFIG_3TMP_FILE`
	if [ "$TEMP" = "" ]
	then
		echo "Could not find RVG record in vxprint output from $SECONDARY_HOST for diskgroup $SECONDARY_DISKGROUP"
		echo "Hit return to continue: \c"
		read Whatever
		return 0
	fi
	set -- $TEMP
	SECONDARY_SRLVOL=$8
	if [ "$SECONDARY_SRLVOL" != "(none)" ]
	then
		echo "Getting information about the Secondary SRL volume from $SECONDARY_HOST..."
		TEMP=`egrep "^v  $SECONDARY_SRLVOL " $CONFIG_3TMP_FILE`
		if [ "$TEMP" = "" ]
		then
			echo "Could not find volume record info in vxprint output from $SECONDARY_HOST for diskgroup $SECONDARY_DISKGROUP"
			echo "Hit return to continue: \c"
			read Whatever
			return 0
		fi
		set -- $TEMP
		SECONDARY_SRLVOL_LEN=$6
		REMOTE_CMD="$VXVM_BIN/vxprint -g "${SECONDARY_DISKGROUP:-rootdg}" -htQqv $SECONDARY_SRLVOL"
		#echo "$SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd 2> /dev/null 1> $CONFIG_2AUX_ORIG_FILE
		if [ "$?" != 0 ]
		then
			echo "Could not get information from $SECONDARY_HOST about Secondary SRL volume $SECONDARY_SRLVOL in disk group $SECONDARY_DISKGROUP"
			echo "Hit return to continue: \c"
			read Whatever
			return 0
		fi

                SECONDARY_SRLVOL_MIRROR_CNT=`/bin/egrep -c "^pl " $CONFIG_2AUX_ORIG_FILE 2> /dev/null`
		SECONDARY_SRLVOL_MIRROR_CNT=`expr $SECONDARY_SRLVOL_MIRROR_CNT - 1`

		echo "" >> $CONFIG_FILE
                echo "#SLV Primary_Rlink     SRL_Volume_Name   Length  Mirrors  Create/Exists" >> $CONFIG_FILE
                echo "#    ----------------  ----------------  ------  -------  -------------" >> $CONFIG_FILE
		awk 'END { printf "SLV  %-17s %-17s %+6s  %7d  %6s\n", "'$RL'", "'$SECONDARY_SRLVOL'", "'$SECONDARY_SRLVOL_LEN'", "'$SECONDARY_SRLVOL_MIRROR_CNT'", "EXISTS" }' $CONFIG_3TMP_FILE >> $CONFIG_FILE
	fi

	echo "Getting information about the Secondary data volume(s) from $SECONDARY_HOST..."
	for DV in `awk '/^v / { printf "%s ", $2 } END { printf "\n" }' $CONFIG_3TMP_FILE`
	do
		if [ "$DV" = "$SECONDARY_SRLVOL" ]
		then
			continue
		fi
		set -- `awk '/^v  '${DV}' / { printf "%s\n", $0 }' $CONFIG_3TMP_FILE`
		DV_LEN=$6

		REMOTE_CMD="$VXVM_BIN/vxprint -g "${SECONDARY_DISKGROUP:-rootdg}" -htQqv $DV"
		#echo "$SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd 2> /dev/null 1> $CONFIG_2AUX_ORIG_FILE
		if [ "$?" != 0 ]
		then
			echo "Could not get information from $SECONDARY_HOST about Secondary data volume $DV in disk group $SECONDARY_DISKGROUP"
			echo "Hit return to continue: \c"
			read Whatever
			return 0
		fi
		DV_MIRROR_CNT=`/bin/egrep -c "^pl " $CONFIG_2AUX_ORIG_FILE 2> /dev/null`
               	DV_MIRROR_CNT=`expr $DV_MIRROR_CNT - 1`

		REMOTE_CMD="$VXVM_BIN/vxprint -g "${SECONDARY_DISKGROUP:-rootdg}" -l $DV"
		#echo "$SECONDARY_HOST: $REMOTE_CMD"
		Do_Remote_Cmd 2> /dev/null 1> $CONFIG_2AUX_ORIG_FILE
		if [ "$?" != 0 ]
		then
			echo "Could not get information from $SECONDARY_HOST about Secondary data volume $DV in disk group $SECONDARY_DISKGROUP"
			echo "Hit return to continue: \c"
			read Whatever
			return 0
		fi
		
		TEMP=`/bin/grep 'primary_datavol=' $CONFIG_2AUX_ORIG_FILE 2>/dev/null`
		if [ "$TEMP" = "" ]
		then
			PRIMARY_DATAVOL=$DV
		else
			set -- $TEMP
			PRIMARY_DATAVOL=`echo "$1" | /bin/cut -d'=' -f2`
		fi

		echo "" >> $CONFIG_FILE
		echo "#SDV Primary_Rlink     Data_Volume_Name  Length  Mirrors  Create/Exists  Primary_Datavol   dcmlog" >> $CONFIG_FILE
		echo "#    ----------------  ----------------  ------  -------  -------------  ---------------- -------" >> $CONFIG_FILE
               	awk 'END { printf "SDV  %-17s %-17s %+6s  %7d  %-13s  %s %-6s\n", "'$RL'", "'$DV'", "'$DV_LEN'", "'$DV_MIRROR_CNT'", "EXISTS", "'$PRIMARY_DATAVOL'" , "'$DV_LOG'"}' $CONFIG_3TMP_FILE >> $CONFIG_FILE

	done

/bin/rm -f $CONFIG_3TMP_FILE $CONFIG_TMP_FILE $CONFIG_2AUX_ORIG_FILE
return 1
}

#Inputs:
#	RVG, DISKGROUP
Load_config_from_existing_rvg()
{
	echo "Loading configuration information for existing RVG $RVG..."
/bin/cp $CONFIG_FILE $CONFIG_AUX_ORIG_FILE
	$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -htQqV "$RVG" 2> /dev/null 1> $CONFIG_2TMP_FILE
	if [ "$?" != 0 ]
	then
		echo "Could not get information about RVG $RVG in disk group $DISKGROUP"
		echo "Hit return to continue: \c"
		read Whatever
		/bin/rm -f $CONFIG_2TMP_FILE $CONFIG_TMP_FILE $CONFIG_AUX_ORIG_FILE $CONFIG_2AUX_ORIG_FILE
		return 0
	fi
	SRLVOL=""; SRLVOL_LEN=""; SRLVOL_MIRROR_CNT=""

	TEMP=`egrep "^rv "  $CONFIG_2TMP_FILE`
	if [ "$TEMP" = "" ]
	then
		echo "Could not find RVG record in vxprint output for diskgroup $DISKGROUP"
		echo "Hit return to continue: \c"
		read Whatever
		/bin/rm -f $CONFIG_2TMP_FILE $CONFIG_TMP_FILE $CONFIG_AUX_ORIG_FILE $CONFIG_2AUX_ORIG_FILE
		return 0
	fi
	set -- $TEMP
	SRLVOL=$8
	if [ "$SRLVOL" != "(none)" ]
	then
		echo "Getting information about the SRL volume..."
		TEMP=`egrep "^v  $SRLVOL " $CONFIG_2TMP_FILE`
		if [ "$TEMP" = "" ]
		then
			echo "Could not find SRL volume record in vxprint output for diskgroup $DISKGROUP"
			echo "Hit return to continue: \c"
			read Whatever
			/bin/rm -f $CONFIG_2TMP_FILE $CONFIG_TMP_FILE $CONFIG_AUX_ORIG_FILE $CONFIG_2AUX_ORIG_FILE
			return 0
		fi
		set -- $TEMP
		SRLVOL_LEN=$6
                SRLVOL_MIRROR_CNT=`$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -htQqv $SRLVOL | /bin/egrep -c "^pl " 2> /dev/null`
		SRLVOL_MIRROR_CNT=`expr $SRLVOL_MIRROR_CNT - 1`

		echo "" >> $CONFIG_FILE
                echo "#LV  SRL_Volume_Name   Length  Mirrors  Create/Exists" >> $CONFIG_FILE
                echo "#LV  ----------------  ------  -------  -------------" >> $CONFIG_FILE
                awk 'END { printf "LV   %-17s %+6s  %7d  EXISTS\n", "'$SRLVOL'", "'$SRLVOL_LEN'", "'$SRLVOL_MIRROR_CNT'" }' $CONFIG_2TMP_FILE >> $CONFIG_FILE
	fi

	echo "Getting information about the data volume(s)..."
        for DV in `awk '/^v / { printf "%s ", $2 } END { printf "\n" }' $CONFIG_2TMP_FILE`
        do
		if [ "$DV" = "$SRLVOL" ]
		then
			continue
		fi
                set -- `awk '/^v  '${DV}' / { printf "%s\n", $0 }' $CONFIG_2TMP_FILE`
                DV_LEN=$6
		DV_MIRROR_CNT=`$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -htQqv $DV | /bin/grep -v LOGONLY |  /bin/egrep -c "^pl " 2> /dev/null`
                DV_MIRROR_CNT=`expr $DV_MIRROR_CNT - 1`
		# check if logging is enabled
		$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -lv $DV | /bin/grep logtype | grep -i DCM 2>/dev/null 1>/dev/null
	        if [ $? -eq 0 ]; then
			DV_LOGSRVM="yes"
		else
			DV_LOGSRVM="no"
		fi
		DATAVOL_LOGSRVM="yes"
		set +x
                awk '/#DV  Data_Volume_Name/ { count=count+1 } END { if (count == 0)
                        printf "\n%s\n%s\n", "#DV  Data_Volume_Name  Length  Mirrors  dcmlog  Create/Exists", "#DV  ----------------  ------  -------  -------------  ---------"}' $CONFIG_FILE >> $CONFIG_TMP_FILE
                awk 'END { printf "DV   %-17s %+6s  %7d  %6s EXISTS\n", "'$DV'", "'$DV_LEN'", "'$DV_MIRROR_CNT'", "'$DV_LOGSRVM'" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
                /bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
                /bin/rm -f $CONFIG_TMP_FILE
	done

	echo "Getting information about the rlink(s)..."

		echo ""
		echo "Do you wish to load in information about the existing configuration for each "
		echo "secondary rlink?  This will take longer because the information has to be "
		echo "queried from (each) Secondary host.  In addition, once you commit the addition"
		echo "of your new rlink(s), sanity checks will be performed on those existing"
		echo "secondary hosts as well, which takes longer.  If you do not load information"
		echo "about existing Secondary rlinks, then the sections of the Summary which"
		echo "summarize the objects to be set up on the remote host for each RLINK will be"
		echo "left empty."
		echo ""
		echo "Load in and verify information about existing Secondary rlinks [this takes "
		echo "longer]? (y/n) (default: n): \c"
                LOAD_REMOTE_INFO=""
                while [ "$LOAD_REMOTE_INFO" = "" ]
                do
                        read LOAD_REMOTE_INFO
                        case "$LOAD_REMOTE_INFO" in
                                "" )    LOAD_REMOTE_INFO=n;;
                                [yY] ) LOAD_REMOTE_INFO=y;;
                                [nN] ) LOAD_REMOTE_INFO=n;;
                                * )     LOAD_REMOTE_INFO="" ;;
                        esac
                done
		if [ "$LOAD_REMOTE_INFO" = n ]
		then
			echo "WARNING: Leaving remote host object information empty in the Summary"
		fi

	cp $CONFIG_2TMP_FILE /tmp/myfile

        for RL in `awk '/^rl / { printf "%s ", $2 } END { printf "\n" }' $CONFIG_2TMP_FILE`
        do
                set -- `awk '/^rl '${RL}' / { printf "%s\n", $0 }' $CONFIG_2TMP_FILE`
                SECONDARY_HOST=$6
		SECONDARY_DISKGROUP=$7
		SECONDARY_RLINK=$8
		RLK_LOCAL_HOST=$9
		RLK_EXISTENCE=EXISTS
		$VXVM_BIN/vxprint -g "${DISKGROUP:-rootdg}" -l $RL > $CONFIG_2AUX_ORIG_FILE
		if [ "$?" != 0 ]
		then
			echo "ERROR: Error getting information about the existing RLINK $RL"
			echo "Hit return to continue: \c"
			read Whatever
			/bin/mv -f $CONFIG_AUX_ORIG_FILE $CONFIG_FILE
			/bin/rm -f $CONFIG_2TMP_FILE $CONFIG_TMP_FILE $CONFIG_AUX_ORIG_FILE $CONFIG_2AUX_ORIG_FILE
			return 0
		fi
		TEMP=`/bin/grep "latencyprot=" $CONFIG_2AUX_ORIG_FILE 2>/dev/null`
		if [ "$TEMP" = "" ]
		then
			echo "ERROR: Error getting information about latencyprot for the existing RLINK $RL"
			echo "Hit return to continue: \c"
			read Whatever
			/bin/mv -f $CONFIG_AUX_ORIG_FILE $CONFIG_FILE
			/bin/rm -f $CONFIG_2TMP_FILE $CONFIG_TMP_FILE $CONFIG_AUX_ORIG_FILE $CONFIG_2AUX_ORIG_FILE
			return 0
		fi
		set -- $TEMP
		SYNC_STRING=$1; LATENCYPROT_STRING=$2; SRLPROT_STRING=$3
		SYNC=`echo $SYNC_STRING | /bin/cut -d'=' -f2`
		LATENCY=`echo $LATENCYPROT_STRING | /bin/cut -d'=' -f2`
		SRLPROT=`echo $SRLPROT_STRING | /bin/cut -d'=' -f2`
		Get_throttling_mode_strings_reverse
		if [ "$?" = 0 ]
		then
			echo "ERROR: Error getting throttling information about existing RLINK $RL"
			echo "Hit return to continue: \c"
			read Whatever
			/bin/mv -f $CONFIG_AUX_ORIG_FILE $CONFIG_FILE
			/bin/rm -f $CONFIG_2TMP_FILE $CONFIG_TMP_FILE $CONFIG_AUX_ORIG_FILE $CONFIG_2AUX_ORIG_FILE
			return 0
		fi
		TEMP=`/bin/grep 'latency_high_mark=' $CONFIG_2AUX_ORIG_FILE 2>/dev/null`
		if [ "$TEMP" = "" ]
		then
			echo "ERROR: Error getting information about latency_high_mark for the existing RLINK $RL"
			echo "Hit return to continue: \c"
			read Whatever
			/bin/mv -f $CONFIG_AUX_ORIG_FILE $CONFIG_FILE
			/bin/rm -f $CONFIG_2TMP_FILE $CONFIG_TMP_FILE $CONFIG_AUX_ORIG_FILE $CONFIG_2AUX_ORIG_FILE
			return 0
		fi
		set -- $TEMP
		HIGH_LATENCY_STRING=$1; LOW_LATENCY_STRING=$2
		HIGH_LATENCY=`echo $HIGH_LATENCY_STRING | /bin/cut -d'=' -f2`
		LOW_LATENCY=`echo $LOW_LATENCY_STRING | /bin/cut -d'=' -f2`

		# have to read the local_host and remote_host paramter here.

                awk '/^#RL  Rlink_Name/ { count=count+1 } END { if (count == 0)
                        printf "\n%s\n%s\n", "#RL    Rlink_Name    local_host  Remote_host  Remote_diskgroup  Remote_rlink      Modes  HighLatency  LowLatency   Create/Exists", "#    ----------------  -----------  ------------- ----------------  ----------------  -----  -----------  -----------  -------------"}' $CONFIG_FILE >> $CONFIG_TMP_FILE
                awk 'END { printf "RL   %-17s %-12s %-12s %-17s %-17s %-1s %-1s %-1s  %-11s  %-11s  %s\n", "'$RL'", "'$RLK_LOCAL_HOST'", "'$SECONDARY_HOST'", "'$SECONDARY_DISKGROUP'", "'$SECONDARY_RLINK'", "'${SYNC_MODE:-O}'", "'${LATENCY_MODE:-O}'", "'${SRLPROT_MODE:-O}'", "'${HIGH_LATENCY:-10000}'", "'${LOW_LATENCY:-9950}'", "'${RLK_EXISTENCE:-CREATE}'" }' $CONFIG_FILE >> $CONFIG_TMP_FILE
                /bin/cat $CONFIG_TMP_FILE >> $CONFIG_FILE
                /bin/rm -f $CONFIG_TMP_FILE $CONFIG_2AUX_ORIG_FILE 

		# Now get SRV, SRL, SLV and SDV info for this rlink
		if [ "$LOAD_REMOTE_INFO" = y ]
		then
		    Load_config_from_existing_secondary_rvg
		    if [ "$?" = 0 ]
		    then
			/bin/mv -f $CONFIG_AUX_ORIG_FILE $CONFIG_FILE
			/bin/rm -f $CONFIG_2TMP_FILE $CONFIG_TMP_FILE $CONFIG_AUX_ORIG_FILE $CONFIG_2AUX_ORIG_FILE $CONFIG_3TMP_FILE
			return 0
		    fi
		fi
	done
	/bin/rm -f $CONFIG_2TMP_FILE $CONFIG_3TMP_FILE $CONFIG_TMP_FILE $CONFIG_AUX_ORIG_FILE $CONFIG_2AUX_ORIG_FILE
	return 1
}

Go_Create_a_Rlink()
{
clear
	Verify_Cfg_File_On_Create
        if [ "$?" = 0 ]
        then
		echo ""
		echo "Failed due to error(s) detected in requested configuration"
		QUIT=""
		while [ "$QUIT" = "" ]
		do 
			echo "Quit? (y/n) (default: n): \c" 
			read QUIT
			case "$QUIT" in
				"" )    QUIT=NO;;
				[yY] ) Quit;;
				[nN] ) QUIT=NO;;
				* )     QUIT="" ;;
               		esac
		done
		return 0
        fi

	echo ""
	echo "No errors detected in requested configuration.  Setting up configuration..."
	echo ""

	Make_rlinks_now
        if [ "$?" != 1 ]
        then
                echo "Hit return to continue: \c"
                read Whatever
                Cleanup_no_abort
                return 0
        fi

	# Now make remote objects
	Make_remote_objects
	if [ "$?" = 0 ]
	then
		echo "Hit return to continue: \c"
		read Whatever
		Cleanup_no_abort
		return 0
	fi

#DEBUG
#echo "CLEANUP=$CLEANUP"
#for SECONDARY_HOST in $REMOTE_HOSTS
#do
#	CLEANUP_FILE=/tmp/vvr.remote_cleanup.$SECONDARY_HOST.$$
#	if [ ! -f $CLEANUP_FILE ]
#	then
#		echo "ERROR: Could not find $CLEANUP_FILE,"
#		echo "       so skipping clean up of $SECONDARY_HOST"
#		continue
#	fi
#	REMOTE_CLEANUP=`awk '{ printf "%s", $0 }' $CLEANUP_FILE`
#        echo "$SECONDARY_HOST:Remote cleanup: $REMOTE_CLEANUP"
#done
#echo "NOW HIT ^C TO TEST CLEANUP, or just"
#echo "Hit return to continue: \c"
#read Whatever

	CLEANUP=""
	REMOTE_HOSTS=""
	/bin/rm -f /tmp/vvr.remote_cleanup.*
	echo "\nSet up was successful."
	if [ "$SRLPROT" = "dcm" ]; then
	   echo "RVG is created with data volumes having dcm logs . You may wish to attach the"
	   echo "rlinks in autosync mode to copy the data from Primary to secondary."
	else
	  echo "Now select \"Create/Copy Primary Checkpoint Data\" from the main menu.  Then,"
	  echo "after a copy of the data has been loaded onto the new Secondary data volumes,"
	  echo "select \"Attach an RLINK\" from the main menu."
	fi
	echo "Hit return to continue: \c"
	read Whatever

	LAST_DG=$DISKGROUP
	LAST_RVG=$RVG_NAME
	return 1
}

Add_a_New_Rlink()
{
clear
RLINK=""
RVG_NAME=rvg_name
RVG=rvg_name
if [ "$LAST_DG" = "$DISKGROUP" ]
then
	RVG_NAME=$LAST_RVG	#Make sure this RVG is in current dg
	RVG=$RVG_NAME
fi
RVG_EXISTENCE=EXISTS
RLK_EXISTENCE=CREATE
touch $CONFIG_FILE
echo "#RV  Rvg_Name          Diskgroup_Name  Create/Exists" >> $CONFIG_FILE
echo "#    ----------------  --------------  -------------" >> $CONFIG_FILE
echo "xxx" | awk 'END { printf "RV   %-17s %-14s  %-s\n", "'$RVG_NAME'", "'$DISKGROUP'", "'$RVG_EXISTENCE'" }' >> $CONFIG_FILE
/bin/cp $CONFIG_FILE $CONFIG_FILE_EMPTY
	echo "Answer preliminary questions before going to the \"Add a New Rlink\" menu"
	echo ""

	# Get Diskgroup
	echo "First specify the disk group which contains the existing Primary RVG to use."
        OLD_DISKGROUP_NAME=$DISKGROUP
	DISKGROUP=""
	Get_Dg
	if [ "$DISKGROUP" = "" ]
	then
		DISKGROUP=$OLD_DISKGROUP_NAME
		/bin/rm -f $CONFIG_FILE $CONFIG_FILE_EMPTY
		clear
		return
	fi
	if [ "$OLD_DISKGROUP_NAME" != "$DISKGROUP" ]
	then
		awk '{ if ( $1 == "RV" )
		  printf "RV   %-17s %-14s  EXISTS\n", $2, "'$DISKGROUP'"
		else
		  print $0 }' $CONFIG_FILE > $CONFIG_TMP_FILE
		/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
	fi
	clear

	# Get Rvg
	OLD_RVG_NAME=$RVG_NAME
	MUST_BE_PRIMARY=yes
	RVG_NAME=""
        Rvg_to_select
	if [ "$RVG_NAME" = "" ]
	then
		RVG_NAME=$OLD_RVG_NAME
		/bin/rm -f $CONFIG_FILE $CONFIG_FILE_EMPTY
		clear
		return
	fi
        if [ "$OLD_RVG_NAME" != "$RVG_NAME" ]
        then
		awk '{ if ( $1 == "RV" )
		  	 printf "RV   %-17s %-14s  EXISTS\n", "'$RVG_NAME'", $3
			else
                       	 print $0 }' $CONFIG_FILE > $CONFIG_TMP_FILE
		/bin/mv -f $CONFIG_TMP_FILE $CONFIG_FILE
	fi
	RVG=$RVG_NAME
	Load_config_from_existing_rvg
	if [ "$?" = 1 ]
	then
		echo "\nSelect \"s\" from menu to show summary of rvg"
	else
		echo ""
	fi
	echo "Hit return to continue: \c"
	read Whatever

	SECONDARY_SETUP_DONE=""
Summarize_Create_an_Rvg2 > $VXSUMMARY_FILE     #Initialize empty Summary screen
while [ 1 ]
do
        clear
	if [ "$RLINK" != "" ]
	then
		MENU_LENGTH=21
	else
		MENU_LENGTH=20
	fi
        Summarize_Create_an_Rvg
	echo "Add a New Rlink"
	echo ""
	echo "Use menu selections below to select the specifications for the rlink,"
	echo "then select \"Go\" from this menu."
	echo ""
	echo "Primary RVG: $RVG_NAME        Primary diskgroup: $DISKGROUP"
	if [ "$RLINK" != "" ]
	then
	echo "New Primary RLINK: $RLINK"
	fi
	echo ""
	echo "Choose an option  (\"?\" for other options):"
	echo ""
	echo "    1  Set up a Primary RLINK now"
	echo "    2  Set up Secondary RVG hierarchy for an RLINK now"
	echo ""
	echo "    s  Show summary of set-up work specified so far"
	echo "    g  Go -- submit changes for verification and commit"
	echo "    p  Previous -- abort changes and return to previous menu"
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
        read CHOICE
        echo ""
        case "$CHOICE" in
		1 )   ADDING_A_NEW_RLINK_FROM_MAIN_MENU=y
		      Set_up_a_rlink_now
		      ADDING_A_NEW_RLINK_FROM_MAIN_MENU="";;
		2 )   if [ "$RLINK" = "" ]
		      then
			echo "Select option 1 to set up a Primary rlink, first."
			echo "Hit return to continue: \c"
			read Whatever
			continue
		      fi
		      Set_up_secondary_rvg_hierarchy_now
		      SECONDARY_SETUP_DONE="YES";;
		[sS] ) SHOW_SUMMARY_ONCE=yes;;
		[gG*] ) if [ "$RLINK" = "" ]
		      then
			echo "Select option 1 to set up a Primary rlink, first."
			echo "Hit return to continue: \c"
			read Whatever
			continue
		      fi
		      if [ "$SECONDARY_SETUP_DONE" = "" ]
		      then
                	Y_OR_N=""
                	while [ "$Y_OR_N" = "" ]
                	do
				echo "You have not selected option 2, yet. Proceed anyway? (default: n) (y/n): \c"
                        	read Y_OR_N
                        	case "$Y_OR_N" in
                                	"" )    Y_OR_N=n;;
                                	[yY] ) Y_OR_N=y;;
                                	[nN] ) Y_OR_N=n;;
                                	* )     echo "Invalid input"
                                	Y_OR_N="" ;;
                        	esac
			done
			if [ "$Y_OR_N" = "n" ]
			then
				continue
			fi
		      fi
		      Go_Create_a_Rlink
                      if [ "$?" = 1 ]
                      then
                        /bin/rm -f $CONFIG_FILE
                        break
                      else
                        clear
                      fi;;
		[lL] ) Load_configuration_from_a_file;;
		[fF] ) Save_current_configuration_to_a_file;;
                [rR] ) Remote_Vxprint;;
                [vV] ) Vxprint;;
                [pP] ) /bin/cmp -s $CONFIG_FILE $CONFIG_FILE_EMPTY > /dev/null 2>&1
                        if [ "$?" != 0 ]
                        then
                                echo "Current configuration summary will be lost."
                                BACKUP=""
                                while [ "$BACKUP" = "" ]
                                do
                                        echo "Are you sure you want to back up to the previous menu? (y/n) (default: y): \c"
                                        read BACKUP
                                        case "$BACKUP" in
                                                "" )    BACKUP=y;;
                                                [yY] ) BACKUP=y;;
                                                [nN] ) BACKUP=n
                                                        clear;;
                                                * )     BACKUP="" ;;
                                        esac
                                done
                        else
                                /bin/rm -f $CONFIG_FILE $CONFIG_FILE_EMPTY
                                break   # No changes, just back up
                        fi
                        if [ "$BACKUP" = "y" ]
                        then
                                /bin/rm -f $CONFIG_FILE $CONFIG_FILE_EMPTY
                                break
                        else
                                clear
                        fi;;
                [qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
                "" ) CHOICE="";;
                * ) echo "Invalid input: $CHOICE"
                        echo "Hit return to continue: \c"
                        read Whatever
                    CHOICE="";;
        esac
done
clear
}

########################################################################
if [ "$OS" = SunOS ]	#Must be at least Solaris 2.x Make this test better!
then
	set -- `/usr/xpg4/bin/id -un`
else
	set -- `/bin/id -un`
fi

if [ "$1" != root ]
then
	echo "ERROR: Must be run as root"
	exit 1
fi

trap "Cleanup" 0 1 2 3 15

clear
while [ 1 ] 
do
	FULL_DATAVOL=1	# Forces need for a checkpoint before attaching
clear
	echo "VVR Setup Main Menu"
	echo ""
	echo "Choose an option  (\"?\" for other options):"
#	echo "    1  Create/Remove/Change an RVG"
	echo "    1  Create/Remove/Change an RVG Hierarchy"
	echo "    2  Create/Copy Primary Checkpoint Data"
	echo "    3  Attach an RLINK"
	echo "    4  Start an RVG"
#	echo "    5  Add/Remove/Change a Data Volume"
#	echo "    6  Add/Remove/Change an SRL Volume"
#	echo "    7  Add/Remove/Change an Rlink"
	echo "    5  Add a New RLINK"
	echo ""
	echo "    r  Remote vxprint -ht"
	echo "    v  Local vxprint -ht"
#	echo "    m  Toggle use of more(1) for long output (default: ON)"
	echo "    q  Quit"
	echo ""
	echo "    Enter option: \c"
	read CHOICE
	echo ""
	case "$CHOICE" in
		1 ) Create_Remove_Change_an_Rvg;;
		2 ) Create_Copy_Primary_Checkpoint_Data;;
		3 ) Attach_a_Rlink;;
		4 ) Start_an_Rvg;;
#		5 ) Add_Remove_Change_a_Data_Volume;;
#		6 ) Add_Remove_Change_an_SRL_Volume;;
#		7 ) Add_Remove_Change_a_Rlink;;
		5 ) Add_a_New_Rlink;;
		[rR] ) Remote_Vxprint;;
		[vV] ) Vxprint;;
		[qQ] ) Quit;;
		[mM] ) Toggle_More_Enable;;
		[aA] ) Toggle_Always_Show_Summary;;
		[?] ) Help;;
		"" ) CHOICE="";;
		* ) echo "Invalid input: $CHOICE"
			echo "Hit return to continue: \c"
			read Whatever
		    CHOICE="";;
	esac
	CLEANUP=""
	REMOTE_HOSTS=""
	/bin/rm -f /tmp/vvr.remote_cleanup.*
done

trap 0 		# So HUP will not trap, so can exit without calling Cleanup
exit 0
