#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/samples/hbaapi/register_platform.sh 1.2 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2003,2007 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)59  1.2  src/bos/usr/samples/hbaapi/register_platform.sh, hbaapisamp, bos720 4/20/07 01:09:45
# ************************************************************************ 
# *  Program: register_platform                                          *
# *  Purpose: Checks for a Fibre Channel environment, if found, calls    *
# *           the platform registration executable.                      *
# ************************************************************************ 
GREP=/usr/bin/grep
AWK=/usr/bin/awk

/usr/bin/lslpp -l devices.common.IBM.fc.hba-api >/dev/null 2>&1
if [[ $? -eq 1 ]]; then
    echo "HBA API not installed"
    exit 1
fi
/usr/sbin/lsdev -Cc adapter -S 1 |$GREP "FC Adapter" > /dev/null
if [[ $? -eq 1 ]]; then
    echo "There are no Fibre Channel Adapters configured for this system"
    exit 1
fi
/usr/sbin/lsdev -Cc driver |$GREP fscsi | $AWK '{system("lsattr -a attach -F value -El" $1)}' | $GREP switch > /dev/null
if [[ $? -eq 1 ]]; then
    echo "No switches found, cannot perform Platform Registration"
    exit 1
fi
echo "Registering platform with fabric..."
/usr/samples/hbaapi/hba_reg_platform
exit 0
