#!/bin/sh

#############################################################################
# Script for Installing Adaptec Cogent PCI Fast Ethernet Drivers for UnixWare
#############################################################################

echo ""
echo "---------------------------------------------------------------"
echo "Adaptec Cogent eMaster+ (10/100) PCI Fast Ethernet Installation" 
echo "---------------------------------------------------------------"
echo ""

set `/sbin/resmgr |sed -n '/0x10110009/p'`

if test $1
then

  echo "ADAPTEC: Pl. Enter the ADAPTER you want to INSTALL"
  echo ""
  echo "         1. Adaptec Cogent ANA-6911 PCI EM110"
  echo "         2. Adaptec Cogent ANA-6944 PCI EM440 (4 ports)"
  echo ""
  echo -n "Your Choice (1 or 2) : "

  read card 

  echo ""

  if test $card = "1"
  then 

# ------------------------- EM110 INSTALLATION ----------------------------

    echo "ADAPTEC: Installing Adaptec Cogent ANA-6911 PCI EM110 ..."

    cp Drvmap.110 Drvmap
    cp EMPCI.110.bcfg EMPCI.bcfg

    set `/sbin/resmgr | sed -n '/0x10110009/p'`

    echo "ADAPTEC: Running idinstall ..."
    /etc/conf/bin/idinstall -ka EMPCI

    ./S24EMPCI110
    /bin/cp ./S24EMPCI110 /etc/rc2.d/S24EMPCI110
    /bin/chmod 555 /etc/rc2.d/S24EMPCI110

    echo "ADAPTEC: Running idconfupdate ..."
    /etc/conf/bin/idconfupdate -f

    echo "ADAPTEC: Running idbuild ..."
    echo ""
    /etc/conf/bin/idbuild -M EMPCI
    echo ""

    echo "ADAPTEC: Running netinfo ..."
    /usr/sbin/netinfo -a -d EMPCI_0 -p inet

    /usr/sbin/netinfo -l dev

    if test ! -f "/etc/conf/mod.d/lsl"
    then
      if test -f "/etc/conf.unix.old/mod.d/lsl"
      then
        echo "ADAPTEC: copying module lsl from backup ..."
        /bin/cp /etc/conf.unix.old/mod.d/lsl /etc/conf/mod.d
      else
        echo "ADAPTEC: ERROR: module lsl missing from system"
        exit 0
      fi
    fi

    if test ! -f "/etc/conf/mod.d/msm"
    then
      if test -f "/etc/conf.unix.old/mod.d/msm"
      then
        echo "ADAPTEC: copying module msm from backup ..."
        /bin/cp /etc/conf.unix.old/mod.d/msm /etc/conf/mod.d
      else
        echo "ADAPTEC: ERROR: module msm missing from system"
        exit 0
      fi
    fi

    if test ! -f "/etc/conf/mod.d/ethtsm"
    then
      if test -f "/etc/conf.unix.old/mod.d/ethtsm"
      then
        echo "ADAPTEC: copying module ethtsm from backup ..."
        /bin/cp /etc/conf.unix.old/mod.d/ethtsm /etc/conf/mod.d
      else
        echo "ADAPTEC: ERROR: module ethtsm missing from system"
        exit 0
      fi
    fi

    echo "ADAPTEC: Running configure ..."
    /etc/confnet.d/configure -i

    fi

    if test $card = "2"
    then

# ------------------------- EM440 INSTALLATION ----------------------------

      echo "ADAPTEC: Installing Adaptec Cogent ANA-6944 PCI EM440"

      cp Drvmap.440 Drvmap
      cp EMPCI.440.bcfg EMPCI.bcfg

      echo "ADAPTEC: Running idinstall ..."
      /etc/conf/bin/idinstall -ka EMPCI

      ./S24EMPCI440
      /bin/cp ./S24EMPCI440 /etc/rc2.d/S24EMPCI440
      /bin/chmod 555 /etc/rc2.d/S24EMPCI440

      echo "ADAPTEC: Running idconfupdate ..."
      /etc/conf/bin/idconfupdate -f

      echo "ADAPTEC: Running idbuild ..."
      echo ""
      /etc/conf/bin/idbuild -M EMPCI
      echo ""

      echo "ADAPTEC: Running netinfo ..."
      /usr/sbin/netinfo -a -d EMPCI_0 -p inet
      /usr/sbin/netinfo -a -d EMPCI_1 -p inet
      /usr/sbin/netinfo -a -d EMPCI_2 -p inet
      /usr/sbin/netinfo -a -d EMPCI_3 -p inet

      /usr/sbin/netinfo -l dev

      if test ! -f "/etc/conf/mod.d/lsl"
      then
        if test -f "/etc/conf.unix.old/mod.d/lsl"
        then
          echo "ADAPTEC: copying module lsl from backup ..."
          /bin/cp /etc/conf.unix.old/mod.d/lsl /etc/conf/mod.d
        else
          echo "ADAPTEC: ERROR: module lsl missing from system"
          exit 0
        fi
      fi

      if test ! -f "/etc/conf/mod.d/msm"
      then
        if test -f "/etc/conf.unix.old/mod.d/msm"
        then
          echo "ADAPTEC: copying module msm from backup ..."
          /bin/cp /etc/conf.unix.old/mod.d/msm /etc/conf/mod.d
        else
          echo "ADAPTEC: ERROR: module msm missing from system"
          exit 0
        fi
      fi

      if test ! -f "/etc/conf/mod.d/ethtsm"
      then
        if test -f "/etc/conf.unix.old/mod.d/ethtsm"
        then
          echo "ADAPTEC: copying module ethtsm from backup ..."
          /bin/cp /etc/conf.unix.old/mod.d/ethtsm /etc/conf/mod.d
        else
          echo "ADAPTEC: ERROR: module ethtsm missing from system"
          exit 0
        fi
      fi

      echo "ADAPTEC: Running configure ..."
      /etc/confnet.d/configure -i

    fi

    if test $card -gt 2
    then
      echo "ADAPTEC: ERROR: Invalid choice, Try again"
      echo "ADAPTEC: ***  Installation Failed  ***"
      echo ""
      echo "---------------------------------------------------------------"
      echo ""
      exit 0
    else 
      echo ""
      echo "ADAPTEC: ***  INSTALLATION COMPLETE  ***"
      echo "ADAPTEC: ***  Pl. REBOOT the SYSTEM  ***"
      echo ""
      echo "---------------------------------------------------------------"
      echo ""
    fi
else 
  echo "ADPATEC: ERROR: Adaptec Cogent eMASTER+ PCI Adapter Not Found"
  echo "ADAPTEC: ***  Installation Failed  ***"
  echo ""
  echo "---------------------------------------------------------------"
  echo ""
  exit 0
fi

