#!/bin/sh 
#
#
# 
if [ -f $ROOTDIR/kernel/drv/scsi_vhci ]; then 

# Ensures an entry is in /etc/name_to_major 
  grep scsi_vhci $ROOTDIR/etc/name_to_major >/dev/null 2>&1 
  if [ $? -eq 1 ]; then 
    $ROOTDIR/usr/sbin/add_drv -n -b $ROOTDIR scsi_vhci 
  fi 

# Update /kernel/drv/scsi__vhci.conf
  if [ -f $ROOTDIR/kernel/drv/scsi_vhci.conf ]; then 
    grep "^[ 	]*auto-failback" $ROOTDIR/kernel/drv/scsi_vhci.conf > \
	/dev/null 2>&1
    if [ $? -eq 1 ]; then

      cat <<AUTO_FAILBACK >> $ROOTDIR/kernel/drv/scsi_vhci.conf
# Automatic failback configuration
# possible values are auto-failback="enable" or auto-failback="disable"
#
# This functionality requires patch 113039-02 (or higher).
#
auto-failback="disable";
#
AUTO_FAILBACK

    fi  

    grep symmetric-option $ROOTDIR/kernel/drv/scsi_vhci.conf >/dev/null 2>&1
    if [ $? -eq 1 ]; then

      cat <<SYMMETRIC_OPT >> $ROOTDIR/kernel/drv/scsi_vhci.conf
# For enabling MPxIO support for 3rd party symmetric device need an
# entry similar to following in this file. Just replace the "SUN     SENA"
# part with the Vendor ID/Product ID for the device, exactly as reported by
# Inquiry cmd.
#
# This functionality requires patch 113039-02 (or higher).
#
# device-type-scsi-options-list =
# "SUN     SENA", "symmetric-option";
#
# symmetric-option = 0x1000000;
#
SYMMETRIC_OPT

    fi  
  fi    

# Updates /kernel/drv/ssd.conf with 
# name="ssd" parent="scsi_vhci" target=0; . 
# 
  if [ -f $ROOTDIR/kernel/drv/ssd.conf ] ; then 
    /usr/bin/grep \
	'^name="ssd"[ 	]*parent="scsi_vhci"[ 	]*target=0;' \
	$ROOTDIR/kernel/drv/ssd.conf > /dev/null 2>&1 
    if [ $? -eq 1 ] ; then 
      echo 'name="ssd" parent="scsi_vhci" target=0;' >> \
	$ROOTDIR/kernel/drv/ssd.conf 
    fi 
  fi 
fi 
###
#
#
#
#
# Update San_drivers

TMPF=/tmp/sand_$$
Dst=${ROOTDIR}/opt/SUNWsan/etc/san_drivers
Sav=${PKGDB}/SUNWsan/${PatchNum}.sav 
touch $Sav

idate=`date +%y/%m/%d`

while read driver dpkg desc ; do

   dfile=${ROOTDIR}${driver}

   if [ -f $dfile ] ; then

      siz=`ls -l ${dfile} | nawk '{print $5}'`
      cksum=`sum ${dfile} | nawk '{print $1}'`
   
      sd_line=`printf "%s:%s:%s:%s:%s:%s\n" \
      "$driver" "$desc" "$siz" "$cksum" "$idate" "$PatchNum"`

      osd_line=`grep \^${driver}\: $Dst`
   
      if [ -z "$osd_line" ] ; then
            echo $sd_line >> $Dst
      else
            echo "$osd_line" >> $Sav
            sed -e 's+^'$driver':.*+'$sd_line'+' $Dst > $TMPF
            mv $TMPF $Dst
      fi
   fi

done < ${patchdir}/san_drivers
 

# Archive this patch 
# 
# 
if [ -f $ROOTDIR/opt/SUNWsan/patches/patchconf ]; then 

 . $ROOTDIR/opt/SUNWsan/patches/patchconf 

 if [ $patch_archive = yes ] ; then 
   if [ ! -f $ROOTDIR/opt/SUNWsan/patches/${PatchNum}.tar.Z ]; then

     cd `dirname ${patchdir}`
     TMPF=/tmp/$$_${PatchNum}.tar

     tar cf $TMPF `basename ${patchdir}`
     compress $TMPF

     # Remove older versions
     for P in `ls $ROOTDIR/opt/SUNWsan/patches/${PatchBase}* 2> /dev/null`
     do
         rm -f $P
     done

     # check for space
     FreeSP=`df -b $ROOTDIR/opt/SUNWsan/patches | tail -1 | nawk '{print $2}'`
     TarSize=`du -k $TMPF.Z`

     if [ $FreeSP -gt $TarSize ]; then
        mv $TMPF.Z $ROOTDIR/opt/SUNWsan/patches/${PatchNum}.tar.Z
     else
        echo "Warning: Not enough space available in $ROOTDIR/opt/SUNWsan/patches to archive patch $PatchNum."
        echo "To avoid seeing this warning message in the future; either increase disk space or turn off patch archiving in $ROOTDIR/opt/SUNWsan/patches/patchconf"
        echo "Patch archiving is an optional service used for upgrade recovery"
     fi
   fi 
 fi
fi 

# Check for JFCA
[ -z "$ROOTDIR" ] && ROOTDIR=/

version=`/usr/sbin/patchadd -R $ROOTDIR -p | \
	nawk '$2 ~ /114878/{printf "%d\n", substr($2,8,2)}' | \
	sort | tail -1`

if [ -n "$version" ]; then
  # Patch 114878 is installed.

  # Check obsoleted field
  /usr/sbin/patchadd -R $ROOTDIR -p | \
	nawk -F: '{print $3}' | grep 114878 > /dev/null

  if [ $? -ne 0 ] ; then
    # Patch 114878 is not obsoleted by newer patch

    if [ $version -le 7 ] ; then
      echo 
      echo '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
      echo 
      echo "This patch, 113039, is not compatible with jfca driver patches" 
      echo "earlier than 114878-08."
      echo
      echo "It is strongly recommended that all systems with patch"
      echo "114878-07 (or earlier) be upgraded to 114878-08 (or later)."
      echo 
      echo '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
      echo 
    fi

  fi
fi

exit 0 

