#!/bin/ksh -p
# $Id: //depot/stable/explorer/tools/photon#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

# Test for existance of photon
#
TEXT=`gettext "No photons installed"`
require "test -d /dev/es" "${TEXT}"
TEXT=`gettext "Luxadm not installed"`
require "test -x /usr/sbin/luxadm" "${TEXT}"
cnt=`/usr/sbin/luxadm probe | egrep -e "No Network Array enclosures found" | wc -l`
TEXT=`gettext "No photons installed"`
require 'test "$cnt" -eq 0' "${TEXT}"

# List all photons connected to the system
get_cmd "/usr/sbin/luxadm probe"    disks/photon/luxadm_probe
sleep 1
get_cmd "/usr/sbin/luxadm probe -p" disks/photon/luxadm_probe-p
get_cmd "/usr/bin/ls -l /dev/es"    disks/photon/ls-l_dev.es!

# get info for each photon using boxname. However, for compatibility
# with explorer pre 3.0 release, create a ses link to each boxname dir.
# This is why we are grabing boxname and Logical path for each photon.

BOX_DIR=disks/photon/boxnames

for i in `/usr/sbin/luxadm probe | nawk '/SENA/,/Logical/' | nawk '{print $2}'`
do
    if [ "Name" = `echo $i|sed s/:.*//` ]
    then
        # Get the photon name
	BOXNAME=`echo $i|sed s/Name://`

	# run all of the luxadm commands
        get_cmd "/usr/sbin/luxadm display $BOXNAME"     $BOX_DIR/$BOXNAME/luxadm_display
        sleep 1
        get_cmd "/usr/sbin/luxadm -v display $BOXNAME"  $BOX_DIR/$BOXNAME/luxadm-v_display
        sleep 1
        get_cmd "/usr/sbin/luxadm display -r $BOXNAME"  $BOX_DIR/$BOXNAME/luxadm_display-r
        sleep 1
        get_cmd "/usr/sbin/luxadm -e dump_map $BOXNAME" $BOX_DIR/$BOXNAME/luxadm_-e_dump_map
    else
	# for compatibility with explorer pre 3.0 release create links
	# into the BOXNAME dirs so older tools don't break.
        SES=`echo $i|sed s/Path:.dev.es.//`
	symlink disks/photon boxnames/$BOXNAME $SES
    fi
done
