#!/bin/ksh -p
# $Id: //depot/stable/explorer/tools/t3#2 $
#
# Explorer Version:
EXP_VERSION=4.0
#

# Source tools functions
. ${EXP_LIB}/exp_tools

# Run if specified to do so
script=${0##*/}
which_gate_exit storage $script default all

CFILE=/tmp/cfile.$$

#
#  Function to create format command file
#
mkCfile () {
    # Create the format commands file
    cat >${CFILE} <<-EOF
scsi
inquiry
quit
quit
EOF
}

# Create format cfile
mkCfile

#
# Go through the list of disks via format
# and look for label SUN-T3
#
echo 0 | /usr/sbin/format 2>&1 | sed -e '/^Specify disk/,$d' |
while read line
do
    echo $line | egrep -s -e SUN-T3
    if [ $? = 0 ]; then
        LUN=`echo $line | awk '{ print $2 }'`

	# Expert SCSI inquiry
	get_cmd "/usr/sbin/format -e -f ${CFILE} -d ${LUN} 2>&1 | \
	    sed -n -e '/^Inquiry:/,/^scsi>/p' | \
	    sed    -e '/^scsi> quit/d'" \
	    disks/t3/${LUN}.scsiinfo
    fi
done

for i in `/usr/sbin/luxadm probe | nawk '/^  Node/,/Logical/' | nawk '{print $2}'`
do
    if [ "WWN" = `echo $i|sed s/:.*//` ]
    then
	LUN=`echo $i | sed 's/WWN://'`

	# Make sure LUN is a T3
	luxadm display ${LUN} | egrep -e "Product ID" | nawk -F: '{ print $2 }' | sed -e 's/[ 	]//g' | egrep -s -e "^T3" && {
	    sleep 1
	    get_cmd "/usr/sbin/luxadm display ${LUN}"     disks/t3/luxadm_display_${LUN}
	    sleep 1
	    get_cmd "/usr/sbin/luxadm -e dump_map ${LUN}" disks/t3/luxadm_-e_dump_map_${LUN}
	}
    fi
done

# Remove cfile
rm -f ${CFILE}
