#!/bin/ksh
#
# Version V2
#
#############################################################################

#set +x

# Script to modify masking view IG or SG

clear

# Unset variables
unset TMPDIR
unset LOGDIR
unset LOGFILE
unset SITE
unset SID
unset HOSTNAME
unset ALLDONE
unset NUMHBA
unset PORT
unset DEV1
unset PORT1
unset DEV2
unset PORT2
unset PORTPAIR
unset CAPACITY
unset REPLY
unset CONFIRM
unset CHANGE
unset NPLIST
unset SOEID

errchk () {
if [ ${ERRCODE} -ne 0 ]
then
        if [ "${FAST}" = "YES" -a ${ATTEMPT} -le 4 ]
        then
                print "Waiting for SYMAPI DB..."
                sleep 10
                fastpolicy
        else
                print "Error detected...exiting script"
                sleep 2
                DATE=`date +'%b%d %H:%M:%S'`
                print "${DATE} ${SOEID} mod_mv.ksh exiting with error code ${ERRCODE}" >> ${LOGFILE}
                exit
        fi
fi
}

outro () {
cleanup
DATE=`date +'%b%d %H:%M:%S'`
print "${DATE} ${SOEID} mod_mv.ksh exiting because ${REASON}" >> ${LOGFILE}
exit
}

setsid () {
SITE=`uname -n | cut -c1-3`

if [ ${SITE} = "rdc" ]
then
	LOGDIR=/export/home/san/capacity/log
	TMPDIR=/var/tmp
	PBRUN=pbrun
	setrdcsid
elif [ ${SITE} = "fdc" ]
then
	LOGDIR=/export/home/san/capacity/log
	TMPDIR=/var/tmp
	PBRUN=pbrun
	setfdcsid
elif [ ${SITE} = "cgc" ]
then
	LOGDIR=/var/opt/san/log
	TMPDIR=/var/opt/san/tmp
	PBRUN=pbrun
	setcgcsid
fi

setlogs
}

setrdcsid () {
clear
print "Which VMAX array are you allocating from? "
print
print "1) 0552 - Tier 3 Replicated to/from 0745 (CGC)"
print "2) 0678 - Tier 4 Non-Replicated"
print "3) 2230 - Tier 3 Replicated to 2231 (FDC)"
print "4) 3286 - Tier 3 Replicated from 2804 (FDC)"
print "5) 3073 - Tier 4 Non-Replicated"
print
print -n "Please enter 1, 2, 3, 4, 5 or q to quit: "

read RDCSID

case ${RDCSID} in
        1) SID=0552
           ;;
        2) SID=0678
           ;;
        3) SID=2230
           ;;
        4) SID=3286
           ;;
        5) SID=3073
	   FAST=YES
	   ATTEMPT=0
           ;;
        *) REASON="user selected quit"
           outro;;
esac
}

setcgcsid () {
clear
print "Which VMAX array have you allocating from? "
print
print "1) 0745 - Tier 3 Replicated to/from 0552 (RDC)"
print "2) 0623 - Tier 4 Non-Replicated"
print
print -n "Please enter 1 or 2 or q to quit: "
read CGCSID

case ${CGCSID} in
	1) SID=0745;;
	2) SID=0623
	   FAST=YES
	   ATTEMPT=0;;
	*) REASON="user selected quit"
	   outro;;
esac

setlogs
}

setfdcsid () {
clear
print "Which VMAX array are you allocating from? "
print
print "1) 0879 - Tier 4 Non-Replicated"
print "2) 2231 - Tier 3 Replicated from 2230 (RDC)"
print "3) 2804 - Tier 3 Replicated to 3286 (RDC)"
print "4) 3004 - Tier 4 Non-Replicated"
print
print -n "Please enter 1, 2, 3, 4 or q to quit: "
read FDCSID

case ${FDCSID} in
        1) SID=0879
           ;;
        2) SID=2231
           ;;
        3) SID=2804
           ;;
        4) SID=3004
	   FAST=YES
	   ATTEMPT=0
           ;;
        *) REASON="user selected quit"
           outro;;
esac
}

setlogs () {
LOGDATE=`date +%b%y`
LOGFILE=${LOGDIR}/mod_mv_${LOGDATE}.log
ALIASLOG=${LOGDIR}/alias.log

#if [ ! -f ${LOGFILE} ]
#then
	#touch ${LOGFILE}
#fi

ALLDONE=Y

#TMPDIR=/var/tmp

SOEID=`/usr/ucb/whoami`

DATE=`date +'%b%d %H:%M:%S'`
print "${DATE} ${SOEID} mod_mv.ksh starting" >> ${LOGFILE}

actionmenu
}

actionmenu () {
ADD2IG=NO
ADD2SG=NO
SETFLAGS=NO
clear
print "What would you like to do?"
print
print "    1) Add two WWNs to Initiator Group"
print "    2) Add six NPIV/LPM WWNs to Initiator Group"
print "    3) Add storage to Storage Group"
print "    4) Set port flags on Initiator Group"
print "    5) Associate Storage Group with FAST Policy"
print
print -n "Enter 1, 2, 3, 4, 5 or q to quit: "
read ACTION

case ${ACTION} in
	1) ADD2IG=YES;;
	2) ADDNPIV2IG=YES;;
	3) ADD2SG=YES;;
	4) SETFLAGS=YES;;
	5) FASTPOLICY=YES;;
	q) REASON="user selected quit"
	   outro;;
	*) print "Invalid selection"
           sleep 2
           actionmenu;;
esac


if [ "${FASTPOLICY}" = "YES" ]
then
	if [ "${FAST}" != "YES" ]
	then
		clear
		print "Array ${SID} is not FAST enabled"
		print "Exiting..."
		REASON="not FAST array"
		outro
	fi
fi

if [ "${ADD2SG}" = "YES" ]
then
	nplist
else
	enterhost
fi

}

nplist () {
NPLIST=${TMPDIR}/${SID}_noport
${PBRUN} symdev -sid ${SID} -noport list > ${NPLIST}

enterhost
}

enterhost () {
clear
typeset -l HOSTNAME

if [ "${ADD2IG}" = "YES" -o "${SETFLAGS}" = "YES" -o "${ADDNPIV2IG}" = "YES" ]
then
	print -n "Please enter the Initiator Group: "
	read IG
	HOSTNAME=${IG}
	checkig
elif [ "${ADD2SG}" = "YES" -o "${FASTPOLICY}" = "YES" ]
then
	print -n "Please enter the Storage Group: "
	read SG
	HOSTNAME=${SG}
	checksg
fi
}

checkig () {
if ${PBRUN} symaccess -sid ${SID} list -name ${IG} -type init > /dev/null
then
	continue
else
	print "Initiator Group ${IG} does not exist"
	sleep 2
	REASON="IG ${IG} not found"
	outro
fi

if [ "${ADD2IG}" = "YES" ]
then
	setportpair
elif [ "${SETFLAGS}" = "YES" ]
then
	enteros
elif [ "${ADDNPIV2IG}" = "YES" ]
then
	npiv
fi

}

setportpair () {
clear
${PBRUN} symaccess -sid ${SID} list view -name ${HOSTNAME} | grep ${HOSTNAME} > ${TMPDIR}/mv.txt
LINES=`wc -l ${TMPDIR}/mv.txt | awk '{print $1}'`
if [ ${LINES} -eq 0 ]
then
	HOST=`echo ${HOSTNAME} | cut -c1-9`
	${PBRUN} symaccess -sid ${SID} list view  | grep ${HOST} > ${TMPDIR}/mv.txt
	LINES=`wc -l ${TMPDIR}/mv.txt | awk '{print $1}'`
fi

if [ ${LINES} -eq 0 ]
then
	print "Can't find a masking view to match against ${HOST}"
	print "Exiting"
	sleep 2
	REASON="MV not found"
	outro
elif [ ${LINES} -gt 1 ]
then
	print "Found multiple possible masking views"
	print
	cat ${TMPDIR}/mv.txt
	print
	print -n "Please type the name of the correct masking view: "
	read MV
	${PBRUN} symaccess -sid ${SID} list view -name ${MV} | grep ${MV} > ${TMPDIR}/mv.txt
	LINES=`wc -l ${TMPDIR}/mv.txt | awk '{print $1}'`
fi

if [ ${LINES} -eq 1 ]
then
	read MV MVIG PG MVSG < ${TMPDIR}/mv.txt
else
	print "Can't find a masking view to match against"
	print "Exiting"
        sleep 2
        REASON="MV not found"
        outro
fi


if [ ${SID} = "0678" ]
then
case ${PG} in
	0678_7E0_10E1)
	    DIR1=7E
	    PORT1=0
	    DIR2=10E
	    PORT2=1;;
	0678_7E1_10E0)
	    DIR1=7E
	    PORT1=1
	    DIR2=10E
	    PORT2=0;;
	0678_8E0_9E1)
	    DIR1=8E
	    PORT1=0
	    DIR2=9E
	    PORT2=1;;
	0678_8E1_9E0)
	    DIR1=8E
	    PORT1=1
	    DIR2=9E
	    PORT2=0;;
	0678_7F0_10F1)
	    DIR1=7F
	    PORT1=0
	    DIR2=10F
	    PORT2=1;;
	M_0678_7F1_10F0)
	    DIR1=7F
	    PORT1=1
	    DIR2=10F
	    PORT2=0;;
	0678_8F0_9F1)
	    DIR1=8F
	    PORT1=0
	    DIR2=9F
	    PORT2=1;;
	0678_8F1_9F0)
	    DIR1=8F
	    PORT1=1
	    DIR2=9F
	    PORT2=0;;
	0678_7G0_10G1)
	    DIR1=7G
	    PORT1=0
	    DIR2=10G
	    PORT2=1;;
	0678_7G1_10G0)
	    DIR1=7G
	    PORT1=1
	    DIR2=10G
	    PORT2=0;;
	0678_8G0_9G1)
	    DIR1=8G
	    PORT1=0
	    DIR2=9G
	    PORT2=1;;
	0678_8G1_9G0)
	    DIR1=8G
	    PORT1=1
	    DIR2=9G
	    PORT2=0;;
	0678_7H0_10H1)
	    DIR1=7H
	    PORT1=0
	    DIR2=10H
	    PORT2=1;;
	0678_7H1_10H0)
	    DIR1=7H
	    PORT1=1
	    DIR2=10H
	    PORT2=0;;
	M_0678_8H0_9H1)
	    DIR1=8H
	    PORT1=0
	    DIR2=9H
	    PORT2=1;;
	0678_8H1_9H0)
	    DIR1=8H
	    PORT1=1
	    DIR2=9H
	    PORT2=0;;
	q)  REASON="user selected quit"
	    outro;;
	*)  print "Invalid selection"
	    sleep 2
	    setportpair;;
esac
elif [ ${SID} = "0879" ]
then 
case ${PG} in
        0879_7E0_10E1)
	    DIR1=7E
	    PORT1=0
	    DIR2=10E
	    PORT2=1;;
        0879_7E1_10E0)
	    DIR1=7E
	    PORT1=1
	    DIR2=10E
	    PORT2=0;;
        0879_8E0_9E1)
	    DIR1=8E
	    PORT1=0
	    DIR2=9E
	    PORT2=1;;
        0879_8E1_9E0)
	    DIR1=8E
	    PORT1=1
	    DIR2=9E
	    PORT2=0;;
        0879_7F0_10F1)
	    DIR1=7F
	    PORT1=0
	    DIR2=10F
	    PORT2=1;;
        0879_7F1_10F0)
	    DIR1=7F
	    PORT1=1
	    DIR2=10F
	    PORT2=0;;
        0879_8F0_9F1)
	    DIR1=8F
	    PORT1=0
	    DIR2=9F
	    PORT2=1;;
        0879_8F1_9F0)
	    DIR1=8F
	    PORT1=1
	    DIR2=9F
	    PORT2=0;;
        0879_7G0_10G1)
	    DIR1=7G
	    PORT1=0
	    DIR2=10G
	    PORT2=1;;
        0879_7G1_10G0)
	    DIR1=7G
	    PORT1=1
	    DIR2=10G
	    PORT2=0;;
        0879_8G0_9G1)
	    DIR1=8G
	    PORT1=0
	    DIR2=9G
	    PORT2=1;;
        0879_8G1_9G0)
	    DIR1=8G
	    PORT1=1
	    DIR2=9G
	    PORT2=0;;
        0879_7H0_10H1)
	    DIR1=7H
	    PORT1=0
	    DIR2=10H
	    PORT2=1;;
        0879_7H1_10H0)
	    DIR1=7H
	    PORT1=1
	    DIR2=10H
	    PORT2=0;;
        0879_8H0_9H1)
	    DIR1=8H
	    PORT1=0
	    DIR2=9H
	    PORT2=1;;
        0879_8H1_9H0)
	    DIR1=8H
	    PORT1=1
	    DIR2=9H
	    PORT2=0;;
        q)  REASON="user selected quit"
	    outro;;
        *)  print "Invalid selection"
	    sleep 2
            setportpair;;
esac
elif [ ${SID} = "0623" ]
then 
case ${PG} in
        M_0623_7E0_10E1)
	    DIR1=7E
	    PORT1=0
	    DIR2=10E
	    PORT2=1;;
        M_0623_7E1_10E0)
	    DIR1=7E
	    PORT1=1
	    DIR2=10E
	    PORT2=0;;
        M_0623_8E0_9E1)
	    DIR1=8E
	    PORT1=0
	    DIR2=9E
	    PORT2=1;;
        M_0623_8E1_9E0)
	    DIR1=8E
	    PORT1=1
	    DIR2=9E
	    PORT2=0;;
        M_0623_7F0_10F1)
	    DIR1=7F
	    PORT1=0
	    DIR2=10F
	    PORT2=1;;
        M_0623_7F1_10F0)
	    DIR1=7F
	    PORT1=1
	    DIR2=10F
	    PORT2=0;;
        C_0623_8F0_9F1)
	    DIR1=8F
	    PORT1=0
	    DIR2=9F
	    PORT2=1;;
        C_0623_8F1_9F0)
	    DIR1=8F
	    PORT1=1
	    DIR2=9F
	    PORT2=0;;
        M_0623_7G0_10G1)
	    DIR1=7G
	    PORT1=0
	    DIR2=10G
	    PORT2=1;;
        M_0623_7G1_10G0)
	    DIR1=7G
	    PORT1=1
	    DIR2=10G
	    PORT2=0;;
        C_0623_8G0_9G1)
	    DIR1=8G
	    PORT1=0
	    DIR2=9G
	    PORT2=1;;
        C_0623_8G1_9G0)
	    DIR1=8G
	    PORT1=1
	    DIR2=9G
	    PORT2=0;;
        M_0623_7H0_10H1)
	    DIR1=7H
	    PORT1=0
	    DIR2=10H
	    PORT2=1;;
        M_0623_7H1_10H0)
	    DIR1=7H
	    PORT1=1
	    DIR2=10H
	    PORT2=0;;
        C_0623_8H0_9H1)
	    DIR1=8H
	    PORT1=0
	    DIR2=9H
	    PORT2=1;;
        C_0623_8H1_9H0)
	    DIR1=8H
	    PORT1=1
	    DIR2=9H
	    PORT2=0;;
        q)  REASON="user selected quit"
	    outro;;
        *)  print "Invalid selection"
	    sleep 2
            setportpair;;
esac
elif [ ${SID} = "0745" ]
then 
case ${PG} in
        M_0745_7E0_10E1)
	    DIR1=7E
	    PORT1=0
	    DIR2=10E
	    PORT2=1;;
        C_0745_7E1_10E0)
	    DIR1=7E
	    PORT1=1
	    DIR2=10E
	    PORT2=0;;
        M_0745_8E0_9E1)
	    DIR1=8E
	    PORT1=0
	    DIR2=9E
	    PORT2=1;;
        C_0745_8E1_9E0)
	    DIR1=8E
	    PORT1=1
	    DIR2=9E
	    PORT2=0;;
        M_0745_7F0_10F1)
	    DIR1=7F
	    PORT1=0
	    DIR2=10F
	    PORT2=1;;
        C_0745_7F1_10F0)
	    DIR1=7F
	    PORT1=1
	    DIR2=10F
	    PORT2=0;;
        M_0745_8F0_9F1)
	    DIR1=8F
	    PORT1=0
	    DIR2=9F
	    PORT2=1;;
        C_0745_8F1_9F0)
	    DIR1=8F
	    PORT1=1
	    DIR2=9F
	    PORT2=0;;
        M_0745_7G0_10G1)
	    DIR1=7G
	    PORT1=0
	    DIR2=10G
	    PORT2=1;;
        C_0745_7G1_10G0)
	    DIR1=7G
	    PORT1=1
	    DIR2=10G
	    PORT2=0;;
        M_0745_8G0_9G1)
	    DIR1=8G
	    PORT1=0
	    DIR2=9G
	    PORT2=1;;
        C_0745_8G1_9G0)
	    DIR1=8G
	    PORT1=1
	    DIR2=9G
	    PORT2=0;;
        C_0745_05E0_12E1)
            DIR1=5E
            PORT1=0
            DIR2=12E
            PORT2=1;;
        C_0745_06F0_11E1)
            DIR1=6F
            PORT1=0
            DIR2=11F
            PORT2=1;;
        C_0745_05E1_12E0)
            DIR1=5E
            PORT1=1
            DIR2=12E
            PORT2=0;;
        C_0745_06F1_11F0)
            DIR1=6F
            PORT1=1
            DIR2=11F
            PORT2=0;;
        C_0745_05F0_12F1)
            DIR1=5F
            PORT1=0
            DIR2=12F
            PORT2=1;;
        C_0745_05F1_12F0)
            DIR1=5F
            PORT1=1
            DIR2=12F
            PORT2=0;;
        C_0745_06E0_11E1)
            DIR1=6E
            PORT1=0
            DIR2=11E
            PORT2=1;;
        C_0745_06E1_11E0)
            DIR1=6E
            PORT1=1
            DIR2=11E
            PORT2=0;;
        q)  REASON="user selected quit"
	    outro;;
        *)  print "Invalid selection"
	    sleep 2
            setportpair;;
esac
elif [ ${SID} = "0552" ]
then 
case ${PG} in
        0552_7E0_10E1)
	    DIR1=7E
	    PORT1=0
	    DIR2=10E
	    PORT2=1;;
        0552_7E1_10E0)
	    DIR1=7E
	    PORT1=1
	    DIR2=10E
	    PORT2=0;;
        0552_8E0_9E1)
	    DIR1=8E
	    PORT1=0
	    DIR2=9E
	    PORT2=1;;
        0552_8E1_9E0)
	    DIR1=8E
	    PORT1=1
	    DIR2=9E
	    PORT2=0;;
        0552_7F0_10F1)
	    DIR1=7F
	    PORT1=0
	    DIR2=10F
	    PORT2=1;;
        0552_7F1_10F0)
	    DIR1=7F
	    PORT1=1
	    DIR2=10F
	    PORT2=0;;
        0552_8F0_9F1)
	    DIR1=8F
	    PORT1=0
	    DIR2=9F
	    PORT2=1;;
        0552_8F1_9F0)
	    DIR1=8F
	    PORT1=1
	    DIR2=9F
	    PORT2=0;;
        0552_7G0_10G1)
	    DIR1=7G
	    PORT1=0
	    DIR2=10G
	    PORT2=1;;
        0552_7G1_10G0)
	    DIR1=7G
	    PORT1=1
	    DIR2=10G
	    PORT2=0;;
        0552_8G0_9G0)
	    DIR1=8G
	    PORT1=0
	    DIR2=9G
	    PORT2=0;;
        0552_8G1_9G1)
	    DIR1=8G
	    PORT1=1
	    DIR2=9G
	    PORT2=1;;
        0552_05E0_12E1)
            DIR1=5E
            PORT1=0
            DIR2=12E
            PORT2=1;;
        0552_06F0_11E1)
            DIR1=6F
            PORT1=0
            DIR2=11F
            PORT2=1;;
        0552_05E1_12E0)
            DIR1=5E
            PORT1=1
            DIR2=12E
            PORT2=0;;
        0552_06F1_11F0)
            DIR1=6F
            PORT1=1
            DIR2=11F
            PORT2=0;;
        0552_05F0_12F1)
            DIR1=5F
            PORT1=0
            DIR2=12F
            PORT2=1;;
        0552_05F1_12F0)
            DIR1=5F
            PORT1=1
            DIR2=12F
            PORT2=0;;
        0552_06E0_11E1)
            DIR1=6E
            PORT1=0
            DIR2=11E
            PORT2=1;;
        0552_06E1_11E0)
            DIR1=6E
            PORT1=1
            DIR2=11E
            PORT2=0;;
        q)  REASON="user selected quit"
	    outro;;
        *)  print "Invalid selection"
	    sleep 2
            setportpair;;
esac
elif [ ${SID} = "2230" ]
then
case ${PG} in
        2230_07E0_10E0)
            DIR1=7E
            PORT1=0
            DIR2=10E
            PORT2=0;;
        2230_05E0_12E0)
            DIR1=5E
            PORT1=0
            DIR2=12E
            PORT2=0;;
        2230_05E1_12E1)
            DIR1=5E
            PORT1=1
            DIR2=12E
            PORT2=1;;
        2230_05F0_12F0)
            DIR1=5F
            PORT1=0
            DIR2=12F
            PORT2=0;;
        2230_05F1_12F1)
            DIR1=5F
            PORT1=1
            DIR2=12F
            PORT2=1;;
        2230_05G0_12G0)
            DIR1=5G
            PORT1=0
            DIR2=12G
            PORT2=0;;
        2230_05G1_12G1)
            DIR1=5G
            PORT1=1
            DIR2=12G
            PORT2=1;;
        2230_06F0_11F0)
            DIR1=6F
            PORT1=0
            DIR2=11F
            PORT2=0;;
        2230_06F1_11F1)
            DIR1=6F
            PORT1=1
            DIR2=11F
            PORT2=1;;
        2230_06G0_11G0)
            DIR1=6G
            PORT1=0
            DIR2=11G
            PORT2=0;;
        2230_06G1_11G1)
            DIR1=6G
            PORT1=1
            DIR2=11G
            PORT2=1;;
        q)  REASON="user selected quit"
            outro;;
        *)  print "Invalid selection"
            sleep 2
            setportpair;;
esac
elif [ ${SID} = "3073" ]
then
case ${PG} in
        3073_05E0_12E0)
            DIR1=5E
            PORT1=0
            DIR2=12E
            PORT2=0;;
        3073_05E1_12E1)
            DIR1=5E
            PORT1=1
            DIR2=12E
            PORT2=1;;
        3073_05F0_12F0)
            DIR1=5F
            PORT1=0
            DIR2=12F
            PORT2=0;;
        3073_05G0_12G0)
            DIR1=5G
            PORT1=0
            DIR2=12G
            PORT2=0;;
        3073_05G1_12G1)
            DIR1=5G
            PORT1=1
            DIR2=12G
            PORT2=1;;
        3073_06E1_11E1)
            DIR1=6E
            PORT1=1
            DIR2=11E
            PORT2=1;;
        3073_06F0_11F0)
            DIR1=6F
            PORT1=0
            DIR2=11F
            PORT2=0;;
        3073_06G0_11G0)
            DIR1=6G
            PORT1=0
            DIR2=11G
            PORT2=0;;
        3073_06G1_11G1)
            DIR1=6G
            PORT1=1
            DIR2=11G
            PORT2=1;;
        3073_07E1_10E1)
            DIR1=7E
            PORT1=1
            DIR2=10E
            PORT2=1;;
        3073_07F0_10F0)
            DIR1=7F
            PORT1=0
            DIR2=10F
            PORT2=0;;
        3073_07G0_10G0)
            DIR1=7G
            PORT1=0
            DIR2=10G
            PORT2=0;;
        3073_07G1_10G1)
            DIR1=7G
            PORT1=1
            DIR2=10G
            PORT2=1;;
        3073_08E1_09E1)
            DIR1=8E
            PORT1=1
            DIR2=9E
            PORT2=1;;
        3073_08F0_09F0)
            DIR1=8F
            PORT1=0
            DIR2=9F
            PORT2=0;;
        3073_08G0_09G0)
            DIR1=8G
            PORT1=0
            DIR2=9G
            PORT2=0;;
        3073_08G1_09G1)
            DIR1=8G
            PORT1=1
            DIR2=9G
            PORT2=1;;
        q)  REASON="user selected quit"
            outro;;
        *)  print "Invalid selection"
            sleep 2
            setportpair;;
esac
elif [ ${SID} = "3286" ]
then
case ${PG} in
        3286_05E1_12E1)
            DIR1=5E
            PORT1=1
            DIR2=12E
            PORT2=1;;
        3286_05F0_12F0)
            DIR1=5F
            PORT1=0
            DIR2=12F
            PORT2=0;;
        3286_05G0_12G0)
            DIR1=5G
            PORT1=0
            DIR2=12G
            PORT2=0;;
        3286_05G1_12G1)
            DIR1=5G
            PORT1=1
            DIR2=12G
            PORT2=1;;
        3286_06E1_11E1)
            DIR1=6E
            PORT1=1
            DIR2=11E
            PORT2=1;;
        3286_06F0_11F0)
            DIR1=6F
            PORT1=0
            DIR2=11F
            PORT2=0;;
        3286_06G0_11G0)
            DIR1=6G
            PORT1=0
            DIR2=11G
            PORT2=0;;
        3286_06G1_11G1)
            DIR1=6G
            PORT1=1
            DIR2=11G
            PORT2=1;;
        3286_07E1_10E1)
            DIR1=7E
            PORT1=1
            DIR2=10E
            PORT2=1;;
        3286_07F0_10F0)
            DIR1=7F
            PORT1=0
            DIR2=10F
            PORT2=0;;
        3286_07G0_10G0)
            DIR1=7G
            PORT1=0
            DIR2=10G
            PORT2=0;;
        3286_07G1_10G1)
            DIR1=7G
            PORT1=1
            DIR2=10G
            PORT2=1;;
        3286_08E1_09E1)
            DIR1=8E
            PORT1=1
            DIR2=9E
            PORT2=1;;
        3286_08F0_09F0)
            DIR1=8F
            PORT1=0
            DIR2=9F
            PORT2=0;;
        3286_08G0_09G0)
            DIR1=8G
            PORT1=0
            DIR2=9G
            PORT2=0;;
        3286_08G1_09G1)
            DIR1=8G
            PORT1=1
            DIR2=9G
            PORT2=1;;
        q)  REASON="user selected quit"
            outro;;
        *)  print "Invalid selection"
            sleep 2
            setportpair;;
esac
elif [ ${SID} = "2231" ]
then
case ${PG} in
        2231_07E0_10E0)
            DIR1=7E
            PORT1=0
            DIR2=10E
            PORT2=0;;
        2231_07E1_10E1)
            DIR1=7E
            PORT1=1
            DIR2=10E
            PORT2=1;;
        2231_07F0_10F0)
            DIR1=7F
            PORT1=0
            DIR2=10F
            PORT2=0;;
        2231_07F1_10F1)
            DIR1=7F
            PORT1=1
            DIR2=10F
            PORT2=1;;
        2231_07G0_10G0)
            DIR1=7G
            PORT1=0
            DIR2=10G
            PORT2=0;;
        2231_07G1_10G1)
            DIR1=7G
            PORT1=1
            DIR2=10G
            PORT2=1;;
        2231_08E0_09E0)
            DIR1=8E
            PORT1=0
            DIR2=9E
            PORT2=0;;
        2231_08E1_09E1)
            DIR1=8E
            PORT1=1
            DIR2=9E
            PORT2=1;;
        2231_08F0_09F0)
            DIR1=8F
            PORT1=0
            DIR2=9F
            PORT2=0;;
        2231_08F1_09F1)
            DIR1=8F
            PORT1=1
            DIR2=9F
            PORT2=1;;
        2231_08G0_09G0)
            DIR1=8G
            PORT1=0
            DIR2=9G
            PORT2=0;;
        2231_08G1_09G1)
            DIR1=8G
            PORT1=1
            DIR2=9G
            PORT2=1;;
        2231_05E0_12E0)
            DIR1=5E
            PORT1=0
            DIR2=12E
            PORT2=0;;
        2231_05E1_12E1)
            DIR1=5E
            PORT1=1
            DIR2=12E
            PORT2=1;;
        2231_05F0_12F0)
            DIR1=5F
            PORT1=0
            DIR2=12F
            PORT2=0;;
        2231_05F1_12F1)
            DIR1=5F
            PORT1=1
            DIR2=12F
            PORT2=1;;
        2231_05G0_12G0)
            DIR1=5G
            PORT1=0
            DIR2=12G
            PORT2=0;;
        2231_05G1_12G1)
            DIR1=5G
            PORT1=1
            DIR2=12G
            PORT2=1;;
        2231_06F0_11F0)
            DIR1=6F
            PORT1=0
            DIR2=11F
            PORT2=0;;
        2231_06F1_11F1)
            DIR1=6F
            PORT1=1
            DIR2=11F
            PORT2=1;;
        2231_06G0_11G0)
            DIR1=6G
            PORT1=0
            DIR2=11G
            PORT2=0;;
        2231_06G1_11G1)
            DIR1=6G
            PORT1=1
            DIR2=11G
            PORT2=1;;
        q)  REASON="user selected quit"
            outro;;
        *)  print "Invalid selection"
            sleep 2
            setportpair;;
esac
elif [ ${SID} = "2804" ]
then
case ${PG} in
        2804_05E1_12E1)
            DIR1=5E
            PORT1=1
            DIR2=12E
            PORT2=1;;
        2804_05F0_12F0)
            DIR1=5F
            PORT1=0
            DIR2=12F
            PORT2=0;;
        2804_05G0_12G0)
            DIR1=5G
            PORT1=0
            DIR2=12G
            PORT2=0;;
        2804_05G1_12G1)
            DIR1=5G
            PORT1=1
            DIR2=12G
            PORT2=1;;
        2804_06E1_11E1)
            DIR1=6E
            PORT1=1
            DIR2=11E
            PORT2=1;;
        2804_06F0_11F0)
            DIR1=6F
            PORT1=0
            DIR2=11F
            PORT2=0;;
        2804_06G0_11G0)
            DIR1=6G
            PORT1=0
            DIR2=11G
            PORT2=0;;
        2804_06G1_11G1)
            DIR1=6G
            PORT1=1
            DIR2=11G
            PORT2=1;;
        2804_07E1_10E1)
            DIR1=7E
            PORT1=1
            DIR2=10E
            PORT2=1;;
        2804_07F0_10F0)
            DIR1=7F
            PORT1=0
            DIR2=10F
            PORT2=0;;
        2804_07G0_10G0)
            DIR1=7G
            PORT1=0
            DIR2=10G
            PORT2=0;;
        2804_07G1_10G1)
            DIR1=7G
            PORT1=1
            DIR2=10G
            PORT2=1;;
        2804_08E1_09E1)
            DIR1=8E
            PORT1=1
            DIR2=9E
            PORT2=1;;
        2804_08F0_09F0)
            DIR1=8F
            PORT1=0
            DIR2=9F
            PORT2=0;;
        2804_08G0_09G0)
            DIR1=8G
            PORT1=0
            DIR2=9G
            PORT2=0;;
        2804_08G1_09G1)
            DIR1=8G
            PORT1=1
            DIR2=9G
            PORT2=1;;
        q)  REASON="user selected quit"
            outro;;
        *)  print "Invalid selection"
            sleep 2
            setportpair;;
esac
elif [ ${SID} = "3004" ]
then
case ${PG} in
        3004_05E0_12E0)
            DIR1=5E
            PORT1=0
            DIR2=12E
            PORT2=0;;
        3004_05E1_12E1)
            DIR1=5E
            PORT1=1
            DIR2=12E
            PORT2=1;;
        3004_05F0_12F0)
            DIR1=5F
            PORT1=0
            DIR2=12F
            PORT2=1;;
        3004_05G0_12G0)
            DIR1=5G
            PORT1=0
            DIR2=12G
            PORT2=0;;
        3004_05G1_12G1)
            DIR1=5G
            PORT1=1
            DIR2=12G
            PORT2=1;;
        3004_06E0_11E0)
            DIR1=6E
            PORT1=0
            DIR2=11E
            PORT2=0;;
        3004_06E1_11E1)
            DIR1=6E
            PORT1=1
            DIR2=11E
            PORT2=1;;
        3004_06F0_11F0)
            DIR1=6F
            PORT1=0
            DIR2=11F
            PORT2=0;;
        3004_06F1_11F1)
            DIR1=6F
            PORT1=1
            DIR2=11F
            PORT2=1;;
        3004_06G0_11G0)
            DIR1=6G
            PORT1=0
            DIR2=11G
            PORT2=0;;
        3004_06G1_11G1)
            DIR1=6G
            PORT1=1
            DIR2=11G
            PORT2=1;;
        3004_08E0_09E0)
            DIR1=8E
            PORT1=0
            DIR2=9E
            PORT2=0;;
        3004_08E1_09E1)
            DIR1=8E
            PORT1=1
            DIR2=9E
            PORT2=1;;
        3004_08F0_09F0)
            DIR1=8F
            PORT1=0
            DIR2=9F
            PORT2=0;;
        3004_08F1_09F1)
            DIR1=8F
            PORT1=1
            DIR2=9F
            PORT2=1;;
        3004_08G0_09G0)
            DIR1=8G
            PORT1=0
            DIR2=9G
            PORT2=0;;
        3004_08G1_09G1)
            DIR1=8G
            PORT1=1
            DIR2=9G
            PORT2=1;;
        3004_08E0_10E0)
            DIR1=7E
            PORT1=0
            DIR2=10E
            PORT2=0;;
        3004_07E1_09E1)
            DIR1=7E
            PORT1=1
            DIR2=10E
            PORT2=1;;
        3004_07F0_10F0)
            DIR1=7F
            PORT1=0
            DIR2=10F
            PORT2=0;;
        3004_07F1_10F1)
            DIR1=7F
            PORT1=1
            DIR2=10F
            PORT2=1;;
        3004_07G0_10G0)
            DIR1=7G
            PORT1=0
            DIR2=10G
            PORT2=0;;
        3004_07G1_10G1)
            DIR1=7G
            PORT1=1
            DIR2=10G
            PORT2=1;;
        q)  REASON="user selected quit"
            outro;;
        *)  print "Invalid selection"
            sleep 2
            setportpair;;
esac

fi

if [ ${ALLDONE} = "N" ]
then
	confirmation
fi

listlogins0
}

listlogins0 () {
${PBRUN} symaccess -sid ${SID} list logins -dirport ${DIR1}:${PORT1} > ${TMPDIR}/logins0
clear
print "Here is a list of HBA logins on ${DIR1}:${PORT1}"
print
grep -v ^$ ${TMPDIR}/logins0

enterwwn0
}

enterwwn0 () {
typeset -l LPFC0
typeset -l ALIAS0
print
print -n "Please enter WWPN to add to IG: "
read LPFC0

if [ `echo ${LPFC0}|wc -c` -gt 17 ]
then
	print "WWPN specified has more than 16 characters"
	enterwwn0
elif [ `echo ${LPFC0}|wc -c` -lt 17 ]
then
	print "WWPN specified has less than 16 characters"
	enterwwn0
fi


print
print -n "Please enter alias for this WWPN, e.g. lpfc2 : "
read ALIAS0

listlogins1
}

listlogins1 () {
${PBRUN} symaccess -sid ${SID} list logins -dirport ${DIR2}:${PORT2} > ${TMPDIR}/logins1
clear
print "Here is a list of HBA logins on ${DIR2}:${PORT2}"
grep -v ^$ ${TMPDIR}/logins1

enterwwn1
}

enterwwn1 () {
typeset -l LPFC1
typeset -l ALIAS1
print
print -n "Please enter WWPN to add to IG: "
read LPFC1

if [ `echo ${LPFC1}|wc -c` -gt 17 ]
then
	print "WWPN specified has more than 16 characters"
	enterwwn1
elif [ `echo ${LPFC1}|wc -c` -lt 17 ]
then
	print "WWPN specified has less than 16 characters"
	enterwwn1
fi


print
print -n "Please enter alias for this WWPN, e.g. lpfc3 : "
read ALIAS1

confirmation
}

npiv () {
${PBRUN} symaccess -sid ${SID} show ${IG} -type init > ${TMPDIR}/ig
WWN0=`awk '/lpfc0/{print $2}' ${TMPDIR}/ig |sed -e 's/://'`
WWN1=`awk '/lpfc1/{print $2}' ${TMPDIR}/ig |sed -e 's/://'`

if [ `echo ${WWN0}|wc -c` -ne 17 ]
then
        print "Couldn't find alias for ${HOSTNAME}/lpfc0 in Initiator Group"
	REASON="alias for lpfc0 not found"
	outro
fi

if [ `echo ${WWN1}|wc -c` -ne 17 ]
then
        print "Couldn't find alias for ${HOSTNAME}/lpfc1 in Initiator Group"
	REASON="alias for lpfc1 not found"
	outro
fi

typeset -u LPFC0
typeset -u LPFC1
LPFC0=`echo ${WWN0} | cut -c11-16 `
LPFC1=`echo ${WWN1} | cut -c11-16 `
#echo LPFC0=${LPFC0}
#echo LPFC1=${LPFC1}

framehead=`echo $WWN0 | cut -c1-10`
#echo framehead=${framehead}

DLPFC0=$((echo ibase=16; echo "${LPFC0}")|bc)
DLPFC1=$((echo ibase=16; echo "${LPFC1}")|bc)
let DLPFC2=DLPFC0+4
let DLPFC3=DLPFC1+4
let DLPFC4=DLPFC0+1
let DLPFC5=DLPFC1+1
let DLPFC6=DLPFC0+5
let DLPFC7=DLPFC1+5
#echo DLPFC2=${DLPFC2}
#echo DLPFC3=${DLPFC3}
#echo DLPFC4=${DLPFC4}
#echo DLPFC5=${DLPFC5}
#echo DLPFC6=${DLPFC6}
#echo DLPFC7=${DLPFC7}
typeset -l LPFC2
typeset -l LPFC3
typeset -l LPFC4
typeset -l LPFC5
typeset -l LPFC6
typeset -l LPFC7
LPFC2=$((echo obase=16; echo "${DLPFC2}")|bc)
LPFC3=$((echo obase=16; echo "${DLPFC3}")|bc)
LPFC4=$((echo obase=16; echo "${DLPFC4}")|bc)
LPFC5=$((echo obase=16; echo "${DLPFC5}")|bc)
LPFC6=$((echo obase=16; echo "${DLPFC6}")|bc)
LPFC7=$((echo obase=16; echo "${DLPFC7}")|bc)
#echo LPFC2=${LPFC2}
#echo LPFC3=${LPFC3}
#echo LPFC4=${LPFC4}
#echo LPFC5=${LPFC5}
#echo LPFC6=${LPFC6}
#echo LPFC7=${LPFC7}

WWN2=${framehead}${LPFC2}
WWN3=${framehead}${LPFC3}
WWN4=${framehead}${LPFC4}
WWN5=${framehead}${LPFC5}
WWN6=${framehead}${LPFC6}
WWN7=${framehead}${LPFC7}
#echo WWN2=${WWN2}
#echo WWN3=${WWN3}
#echo WWN4=${WWN4}
#echo WWN5=${WWN5}
#echo WWN6=${WWN6}
#echo WWN7=${WWN7}

confirmation
}

checksg () {
clear
${PBRUN} symaccess -sid ${SID} list -name ${SG} -type stor | grep  ${SG} > ${TMPDIR}/sg.txt
LINES=`wc -l ${TMPDIR}/sg.txt | awk '{print $1}'`
if [ ${LINES} -eq 0 ]
then
	HOST=`echo ${HOSTNAME} | cut -c1-9`
	${PBRUN} symaccess -sid ${SID} list -type stor | grep ${HOST} > ${TMPDIR}/sg.txt
	LINES=`wc -l ${TMPDIR}/sg.txt | awk '{print $1}'`
fi

if [ ${LINES} -eq 0 ]
then
	print "Couldn't find any Storage Groups to match against \"${HOST}\""
	print "Exiting"
	sleep 2
	REASON="SG not found"
	outro
elif [ ${LINES} -gt 1 ]
then
	print "Found multiple Storage groups that match \"${HOST}\""
	print
	cat ${TMPDIR}/sg.txt | awk '{print $1}'
	print
	print -n "Please type the name of the correct Storage Group: "
	read SG
	${PBRUN} symaccess -sid ${SID} list -name ${SG} -type stor | grep  ${SG} > ${TMPDIR}/sg.txt
fi
	LINES=`wc -l ${TMPDIR}/sg.txt | awk '{print $1}'`

if [ ${LINES} -eq 1 ]
then
	SG=`awk '{print $1}' ${TMPDIR}/sg.txt`
	HOSTNAME=${SG}
else
	print "Couldn't find any Storage Groups to match against"
	print "Exiting"
        sleep 2
        REASON="SG not found"
        outro
fi

if [ "${ADD2SG}" = "YES" ]
then
	choosedevs
elif [ "${FASTPOLICY}" = "YES" ]
then
	fastpolicy
fi
}

choosedevs () {
clear
typeset -i NUMDEVS=0
typeset -i CHKDEV=0
typeset -i CAPACITY=0

print -n "Please enter the number of 34GB LUNS you require or 0 to exit: "
read NUMDEVS

if [ ${NUMDEVS} -eq 0 ]
then
        print "Exiting..."
        sleep 2
	REASON="user selected 0 devices to add"
        outro
fi

let CAPACITY=NUMDEVS*34

typeset -l REPLY
print "That will add approximately ${CAPACITY}GB of storage"
print -n "Is that correct? [ y/n/q ]: "
read REPLY

case ${REPLY} in
        y) continue;;
        n) choosedevs;;
        q) REASON="user selected quit"
	   outro;;
        *) print "Invalid selection"
           sleep 2
           choosedevs;;
esac

typeset -u -Z4 DEV1
typeset -u -Z4 DEV2

if [ ${NUMDEVS} -eq 1 ]
then
        print -n "Please enter the device number: "
	read DEV1
	DEV1TMP=0`echo ${DEV1}`
	DEV1=${DEV1TMP}
	if grep ^`echo ${DEV1}` ${NPLIST}
        then
                continue
        else
                print "${DEV1} is not in the noport list"
                sleep 3
		choosedevs
        fi

else
        print -n "Please enter the first device number in the range: "
	read DEV1
        print -n "Please enter the last device number in the range: "
	read DEV2
	DEV1TMP=0`echo ${DEV1}`
	DEV1=${DEV1TMP}
	DEV2TMP=0`echo ${DEV2}`
	DEV2=${DEV2TMP}
        DDEV1=$((16#${DEV1}))
        DDEV2=$((16#${DEV2}))
        let CHKDEV=DDEV2-DDEV1+1
        if [ ${CHKDEV} -ne ${NUMDEVS} ]
        then
                clear
                print "Device range ${DEV1}:${DEV2} is not a range of ${NUMDEVS} devices"
                sleep 5
		choosedevs
        fi
	if grep ^`echo ${DEV1}` ${NPLIST}
        then
                continue
        else
                print "${DEV1} is not in the noport list"
                sleep 3
		choosedevs
        fi
	if grep ^`echo ${DEV2}` ${NPLIST}
        then
                continue
        else
                print "${DEV2} is not in the noport list"
                sleep 3
		choosedevs
        fi

	typeset -i CHKNUM
	CHKNUM=`awk '/^'${DEV1}'/, /^'${DEV2}'/' ${NPLIST} | wc -l`
	print ${CHKNUM}

	if [ ${CHKNUM} -ne ${NUMDEVS} ]
	then
		print "There is a gap in the range ${DEV1}:${DEV2}"
		print "Please allocate this request manually"
                sleep 5
		REASON="device range selected is not contiguous"
                outro
	fi
fi

confirmation
}

enteros () {
clear
print
print "Which Operating System does the host run?"
print "(This will determine port flag settings for the host)"
print
print "     1) AIX"
print "     2) Windows"
print "     3) Solaris"
print "     4) RedHat"
print "     5) HP-UX"
print
print -n "Please select a number from 1 to 5 or q to quit : "
read OS

case ${OS} in
        1) OS=AIX
           continue ;;
        2) OS=Windows
           continue ;;
        3) OS=Solaris
           SETDBIT=YES ;;
        4) OS=RedHat
           SETDBIT=YES ;;
        5) OS=HP-UX
           SETVBIT=YES ;;
        q|Q) REASON="USER selected quit"
           outro ;;
        *) print "Invalid selection"
           sleep 2
           enteros ;;
esac

confirmation
}

confirmation () {
clear
if [ "${ADD2IG}" = "YES" ] 
then
	print "The following HBAs will be added to Initiator Group ${IG}"
	print "WWPN ${LPFC0} with alias ${HOSTNAME}/${ALIAS0}"
	print "WWPN ${LPFC1} with alias ${HOSTNAME}/${ALIAS1}"
elif [ "${ADD2SG}" = "YES" ]
then
	if [ ${NUMDEVS} -eq 1 ]
	then
		print "Device ${DEV1} will be added to Storage Group ${SG}"
	else
		print "Devices ${DEV1}:${DEV2} will be added to Storage Group ${SG}"
	fi
elif [ "${SETFLAGS}" = "YES" ]
then
	print "Port flags for ${OS} will be set"
elif [ "${ADDNPIV2IG}" = "YES" ]
then
	print "The following HBA's will be added to the Initiator Group ${IG}"
	print "WWPN ${WWN2} with alias ${HOSTNAME}/lpfc2"
	print "WWPN ${WWN3} with alias ${HOSTNAME}/lpfc3"
	print "WWPN ${WWN4} with alias ${HOSTNAME}/lpfc4"
	print "WWPN ${WWN5} with alias ${HOSTNAME}/lpfc5"
	print "WWPN ${WWN6} with alias ${HOSTNAME}/lpfc6"
	print "WWPN ${WWN7} with alias ${HOSTNAME}/lpfc7"
fi

typeset -l CONFIRM
print
print -n "Is this correct? [ y/n/q ] : "
read CONFIRM

case ${CONFIRM} in
	y) ALLDONE=Y
	   continue;;
	n) ALLDONE=N
	   makechanges;;
	q) REASON="user selected quit"
	   outro;;
	*) print "Invalid selection"
	   sleep 2
	   clear
	   confirmation;;
esac 

doit
}

fastpolicy () {
let ATTEMPT=ATTEMPT+1
print
print "Associating SG ${HOSTNAME} with FAST policy \"Production\" (Attempt ${ATTEMPT})"
COMMAND="symfast -sid ${SID} -fp_name Production associate -sg ${HOSTNAME} -priority 2"
DATE=`date +'%b%d %H:%M:%S'`
print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
${PBRUN} ${COMMAND}
ERRCODE=$?
errchk
print "SG ${HOSTNAME} associated with FAST policy \"Production\""
}

makechanges () {
clear
if [ "${ADD2IG}" = "YES" ]
then
	listlogins0
elif [ "${ADD2SG}" = "YES" ]
then
	choosedevs
elif [ "${SETFLAGS}" = "YES" ]
then
	enteros
elif [ "${ADDNPIV2IG}" = "YES" ]
then
	print "You can't make changes to this!!!"
	sleep 2
	confirmation
fi
}

doit () {
clear
if [ "${ADD2IG}" = "YES" ]
then
	print "Adding HBAs to Initiator Group ${IG}..."
	COMMAND="symaccess -sid ${SID} add -name ${IG} -type init -wwn ${LPFC0}"
	DATE=`date +'%b%d %H:%M:%S'`
	print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
	${PBRUN} ${COMMAND}
	ERRCODE=$?
	errchk
	COMMAND="symaccess -sid ${SID} add -name ${IG} -type init -wwn ${LPFC1}"
	DATE=`date +'%b%d %H:%M:%S'`
	print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
	${PBRUN} ${COMMAND}
	ERRCODE=$?
	errchk
	print "Initiator Group ${IG} successfully modified"

	print
	print "Creating HBA alias for ${HOSTNAME}/${ALIAS0}..."
	COMMAND="symaccess -sid ${SID} rename -wwn ${LPFC0} -alias ${HOSTNAME}/${ALIAS0}"
	DATE=`date +'%b%d %H:%M:%S'`
	print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
	print ${COMMAND} >> ${ALIASLOG}
	${PBRUN} ${COMMAND}
	ERRCODE=$?
	errchk
	print "HBA alias for ${HOSTNAME}/${ALIAS0} successfully created"

	print
	print "Creating HBA alias for ${HOSTNAME}/${ALIAS1}..."
	COMMAND="symaccess -sid ${SID} rename -wwn ${LPFC1} -alias ${HOSTNAME}/${ALIAS1}"
	DATE=`date +'%b%d %H:%M:%S'`
	print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
	print ${COMMAND} >> ${ALIASLOG}
	${PBRUN} ${COMMAND}
	ERRCODE=$?
	errchk
	print "HBA alias for ${HOSTNAME}/${ALIAS1} successfully created"
	${PBRUN} symaccess -sid ${SID} show ${IG} -type init -detail
        print -n "Press enter to continue..."
        read ENTER
	sleep 2
	REASON="script has completed successfully"
	outro
elif [ "${ADD2SG}" = "YES" ]
then
	print
	print "Adding devices to Storage Group ${SG}..."
	if [ ${NUMDEVS} -eq 1 ]
	then
		DATE=`date +'%b%d %H:%M:%S'`
		COMMAND="symaccess -sid ${SID} add -name ${SG} -type stor -dev ${DEV1}"
		print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
		${PBRUN} ${COMMAND}
		ERRCODE=$?
		errchk
	else
		DATE=`date +'%b%d %H:%M:%S'`
		COMMAND="symaccess -sid ${SID} add -name ${SG} -type stor -dev ${DEV1}:${DEV2}"
		print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
		${PBRUN} ${COMMAND}
		ERRCODE=$?
		errchk
	fi
	print "Storage Group ${SG} successfully modified"
	sleep 2
	${PBRUN} symaccess -sid ${SID} show ${SG} -type stor
        print -n "Press enter to continue..."
	read ENTER
	clear
	if [ ${NUMDEVS} -eq 1 ]
        then
             DEV2=${DEV1}
        fi
        ${PBRUN} symaccess -sid ${SID} list assign -dev ${DEV1}:${DEV2}
        print
        print "If you see any WWN's above as well as ${HOSTNAME}'s please recheck storage assignments"
        print -n "Press enter to continue..."
        read ENTER
	REASON="script has completed successfully"
	outro
elif [ "${SETFLAGS}" = "YES" ]
then
	print
	print "Setting SPC2 flag on IG ${HOSTNAME}..."
	COMMAND="symaccess -sid ${SID} -name ${HOSTNAME} -type init set ig_flags on spc2 -enable"
	DATE=`date +'%b%d %H:%M:%S'`
	print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
	${PBRUN} ${COMMAND}
	ERRCODE=$?
	errchk
	print "SPC2 flag set on IG ${HOSTNAME}"
	print
	print "Setting OS2007 flag on IG ${HOSTNAME}..."
	COMMAND="symaccess -sid ${SID} -name ${HOSTNAME} -type init set ig_flags on os2007 -enable"
	DATE=`date +'%b%d %H:%M:%S'`
	print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
	${PBRUN} ${COMMAND}
	ERRCODE=$?
	errchk
	print "OS2007 flag set on IG ${HOSTNAME}"
	
	if [ "${SETDBIT}" = "YES" ]
	then
        	print "Setting D bit flag on IG ${HOSTNAME}..."
        	COMMAND="symaccess -sid ${SID} -name ${HOSTNAME} -type init set ig_flags on d -enable"
        	DATE=`date +'%b%d %H:%M:%S'`
        	print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        	${PBRUN} ${COMMAND}
        	ERRCODE=$?
        	errchk
        	print "D bit flag set on IG ${HOSTNAME}"
	fi

	if [ "${SETVBIT}" = "YES" ]
	then
        	print "Setting V bit flag on IG ${HOSTNAME}..."
        	COMMAND="symaccess -sid ${SID} -name ${HOSTNAME} -type init set ig_flags on v -enable"
        	DATE=`date +'%b%d %H:%M:%S'`
        	print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        	${PBRUN} ${COMMAND}
        	ERRCODE=$?
        	errchk
        	print "V bit flag set on IG ${HOSTNAME}"
	fi

	sleep 2
	clear
	${PBRUN} symaccess -sid ${SID} show ${HOSTNAME} -type init -detail
	print
        print -n "Press enter to continue..."
        read ENTER
        REASON="script has completed successfully"
        outro
elif [ "${ADDNPIV2IG}" = "YES" ]
then
        print "Adding HBAs to Initiator Group ${IG}..."
        COMMAND="symaccess -sid ${SID} add -name ${IG} -type init -wwn ${WWN2}"
        DATE=`date +'%b%d %H:%M:%S'`
        print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        ${PBRUN} ${COMMAND}
        ERRCODE=$?
        errchk
        COMMAND="symaccess -sid ${SID} add -name ${IG} -type init -wwn ${WWN3}"
        DATE=`date +'%b%d %H:%M:%S'`
        print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        ${PBRUN} ${COMMAND}
        ERRCODE=$?
        errchk
        COMMAND="symaccess -sid ${SID} add -name ${IG} -type init -wwn ${WWN4}"
        DATE=`date +'%b%d %H:%M:%S'`
        print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        ${PBRUN} ${COMMAND}
        ERRCODE=$?
        errchk
        COMMAND="symaccess -sid ${SID} add -name ${IG} -type init -wwn ${WWN5}"
        DATE=`date +'%b%d %H:%M:%S'`
        print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        ${PBRUN} ${COMMAND}
        ERRCODE=$?
        errchk
        COMMAND="symaccess -sid ${SID} add -name ${IG} -type init -wwn ${WWN6}"
        DATE=`date +'%b%d %H:%M:%S'`
        print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        ${PBRUN} ${COMMAND}
        ERRCODE=$?
        errchk
        COMMAND="symaccess -sid ${SID} add -name ${IG} -type init -wwn ${WWN7}"
        DATE=`date +'%b%d %H:%M:%S'`
        print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        ${PBRUN} ${COMMAND}
        ERRCODE=$?
        errchk
        print "Initiator Group ${IG} successfully modified"

        print
        print "Creating HBA alias for ${HOSTNAME}/lpfc2..."
        COMMAND="symaccess -sid ${SID} rename -wwn ${WWN2} -alias ${HOSTNAME}/lpfc2"
        DATE=`date +'%b%d %H:%M:%S'`
        print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        print ${COMMAND} >> ${ALIASLOG}
        ${PBRUN} ${COMMAND}
        ERRCODE=$?
        errchk
        print "HBA alias for ${HOSTNAME}/lpfc2 successfully created"
        print
        print "Creating HBA alias for ${HOSTNAME}/lpfc3..."
        COMMAND="symaccess -sid ${SID} rename -wwn ${WWN3} -alias ${HOSTNAME}/lpfc3"
        DATE=`date +'%b%d %H:%M:%S'`
        print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        print ${COMMAND} >> ${ALIASLOG}
        ${PBRUN} ${COMMAND}
        ERRCODE=$?
        errchk
        print "HBA alias for ${HOSTNAME}/lpfc3 successfully created"
        print
        print "Creating HBA alias for ${HOSTNAME}/lpfc4..."
        COMMAND="symaccess -sid ${SID} rename -wwn ${WWN4} -alias ${HOSTNAME}/lpfc4"
        DATE=`date +'%b%d %H:%M:%S'`
        print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        print ${COMMAND} >> ${ALIASLOG}
        ${PBRUN} ${COMMAND}
        ERRCODE=$?
        errchk
        print "HBA alias for ${HOSTNAME}/lpfc4 successfully created"
        print
        print "Creating HBA alias for ${HOSTNAME}/lpfc5..."
        COMMAND="symaccess -sid ${SID} rename -wwn ${WWN5} -alias ${HOSTNAME}/lpfc5"
        DATE=`date +'%b%d %H:%M:%S'`
        print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        print ${COMMAND} >> ${ALIASLOG}
        ${PBRUN} ${COMMAND}
        ERRCODE=$?
        errchk
        print "HBA alias for ${HOSTNAME}/lpfc5 successfully created"
        print
        print "Creating HBA alias for ${HOSTNAME}/lpfc6..."
        COMMAND="symaccess -sid ${SID} rename -wwn ${WWN6} -alias ${HOSTNAME}/lpfc6"
        DATE=`date +'%b%d %H:%M:%S'`
        print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        print ${COMMAND} >> ${ALIASLOG}
        ${PBRUN} ${COMMAND}
        ERRCODE=$?
        errchk
        print "HBA alias for ${HOSTNAME}/lpfc6 successfully created"
        print
        print "Creating HBA alias for ${HOSTNAME}/lpfc7..."
        COMMAND="symaccess -sid ${SID} rename -wwn ${WWN7} -alias ${HOSTNAME}/lpfc7"
        DATE=`date +'%b%d %H:%M:%S'`
        print "${DATE} ${SOEID} Running command \"${COMMAND}\"" >> ${LOGFILE}
        print ${COMMAND} >> ${ALIASLOG}
        ${PBRUN} ${COMMAND}
        ERRCODE=$?
        errchk
        print "HBA alias for ${HOSTNAME}/lpfc7 successfully created"
	${PBRUN} symaccess -sid ${SID} show ${IG} -type init -detail
        print -n "Press enter to continue..."
        read ENTER
	sleep 2
	REASON="script has completed successfully"
	outro
fi
}

cleanup ()
{
if [ -f ${NPLIST} ]
then
	rm ${NPLIST}
fi

if [ -f ${TMPDIR}/sg.txt ] 
then
	rm ${TMPDIR}/sg.txt
fi

if [ -f ${TMPDIR}/mv.txt ] 
then
	rm ${TMPDIR}/mv.txt
fi

if [ -f ${TMPDIR}/logins0 ]
then
	rm ${TMPDIR}/logins0
fi

if [ -f ${TMPDIR}/logins1 ]
then
	rm ${TMPDIR}/logins1
fi
}

setsid
