#!/sbin/sh
#############################################################################
#  Product: Networking
#  Fileset: LAN-KRN
#  configure
#  @(#) $Revision: 1.2.98.1 $
#############################################################################
# (c) Copyright Hewlett-Packard Company, 1994
#############################################################################

####### add our entry to the kernel config file only if on a client system
if [ -z "$SW_DEFERRED_KERNBLD" ] ; then
    # we are on a standalone or server; the postinstall script has already
    # updated the kernel config file
    exit 0
fi

####### setup environment 
UTILS="/usr/lbin/sw/control_utils"
if [ ! -f $UTILS ] ; then
    echo "ERROR:   Cannot find \"$UTILS\"."
    exit 1
fi
. $UTILS


####### remove old, on-longer-valid config file entries
mod_systemfile $SW_SYSTEM_FILE_PATH -d lan01
mod_systemfile $SW_SYSTEM_FILE_PATH -d lan


####### add our entry to the kernel config file
LAN0=0
LAN1=0
LAN2=0
LAN3=0
for LINE in `ioscan -F | sed 's/ /~/g'` ; do
    SVERS_MODEL=`echo "$LINE" | awk -F':' '{ print $12 }' | sed 's/~/ /g' | \
	    awk '{printf("%02x%02x%02x\n",$5,$6,$7)}' | \
            awk '{ $1=substr($1,2,5); print $1 }'`
    case $SVERS_MODEL in
        00050)
            # 0x50 ---> LANbrusca old NIO LAN card
	    LAN1=1
            ;;
        00072 | 0008a)
            # 0x72 ---> s700 built-in LAN
            # 0x8a ---> LASI LAN
	    LAN2=1
            ;;
        00052 | 00060)
            # 0x52 ---> Miura NIO LAN card
            # 0x60 ---> Diablo or Countache NIO LAN/Console card
	    LAN3=1
            ;;
        *)
            if [ -n "`echo $LINE | grep eisa`" ] ; then
                EISA_ID=`echo $LINE | awk -F':' '{ print $12 }' | \
			sed 's/~/ /g' | \
                        awk '{printf("%02x%02x%02x%02x\n",$1,$2,$3,$4)}'`
		if [ "$EISA_ID" = "22f01850" ] ; then
		    # 0x22f01850==HWP1850 ---> Tornado EISA LAN card
		    LAN2=1
		fi
            elif [ -n "`echo $LINE | grep cio_ca0`" ] ; then
                CIO_ID=`echo $LINE | awk -F':' '{ print $12 }' | \
			sed 's/~/ /g' | \
                        awk '{printf("%02x%02x%02x%02x\n",$1,$2,$3,$4)}'`
		if [ "$CIO_ID" = "00000006" ] ; then
		    # 0x00000006 ---> CIO LAN card
		    LAN0=1
		fi
	    fi
            ;;
    esac
done

EXITVAL=0

####### if we didn't find any cards, tell the user and let the install go on
if [ $LAN0 -ne 1 -a $LAN1 -ne 1 -a $LAN2 -ne 1 -a $LAN3 -ne 1 ] ; then
    echo "WARNING: Cannot find any LAN cards installed in the system."
    echo "         No LAN drivers have been configured into the kernel."
    exit 2
fi

####### add the drivers to the kernel
RES0=0
RES1=0
RES2=0
RES3=0
RESD=0
if [ $LAN0 -eq 1 ] ; then
    mod_systemfile $SW_SYSTEM_FILE_PATH -a lan0
    RES0=$?
fi
if [ $LAN1 -eq 1 ] ; then
    mod_systemfile $SW_SYSTEM_FILE_PATH -a lan1
    RES1=$?
fi
if [ $LAN2 -eq 1 ] ; then
    mod_systemfile $SW_SYSTEM_FILE_PATH -a lan2
    RES2=$?
fi
if [ $LAN3 -eq 1 ] ; then
    mod_systemfile $SW_SYSTEM_FILE_PATH -a lan3
    RES3=$?
fi
mod_systemfile $SW_SYSTEM_FILE_PATH -a dlpi
RESD=$?

####### see if the mod_systemfiles worked
if [ $RES0 -ne 0 -o $RES1 -ne 0 -o $RES2 -ne 0 -o $RES3 -ne 0 -o $RESD -ne 0 ] ; then
    echo "ERROR:   Cannot modify the kernel configuration file.  The"
    echo "         appropriate LAN driver must be manually configured"
    echo "         into the kernel."
    EXITVAL=1
fi
#
# Export the master file to the LAN-RUN fileset.
#
file="${SW_LOCATION}usr/conf/master.d/lan"
if swlist -l file $PRODUCT.$FILESET 2>/dev/null | grep -q $file
then        # master file not yet exported
  export_master $file
  if [[ $? -ne 0 ]]
    then
      echo "WARNING: Cannot give the master file(s) \"$file\""
      echo "         to ${FILESET%%-KRN}-RUN.  If you delete this"
      echo "         fileset, SAM will not be able to handle your"
      echo "         device files"
      if [[ $EXITVAL -ne $FAILURE ]]
        then
          EXITVAL=$WARNING
      fi # [[ $EXITVAL -ne $FAILURE ]]
    fi # [[ $? -ne 0 ]]
fi # swlist -l file $PRODUCT.$FILESET


exit $EXITVAL

