#!/bin/sh

PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH

#
# Driver info
#
DRV=o1k

DRVALIAS="pci1061,3"
DRVPERM='* 0666 root sys'

DRVALIAS_PRE7="pci1061,3"
DRVALIAS_REV7_SVP="pci1576,3"
DRVALIAS_REV7_1500="pci1576,5"

#
# Is the hardware there?
#
hw_exists=0
prtconf -pv |  egrep compatible | egrep "${DRVALIAS_PRE7}"
if [ $? -eq 0 ]; then
  echo "Found o1k Based Hardware"
  hw_exists=1
fi
prtconf -pv |  egrep compatible | egrep "${DRVALIAS_REV7_SVP}"
if [ $? -eq 0 ]; then
  echo "Found SVP Version-7"
  hw_exists=1
fi
prtconf -pv |  egrep compatible | egrep "${DRVALIAS_REV7_1500}"
if [ $? -eq 0 ]; then
  echo "Found 1500 Version-7"
  hw_exists=1
fi

#
# Select the correct add_drv options to execute.
# Only attempt to attach the driver
# on a running system with the hardware present.
#
if [ "${BASEDIR}" = "/" ]; then

        #
        # No need to add_drv if the running system is of a different arch
        # than the package
        #
        karch=sparc.`uname -m`
        if [ "${karch}" != "${ARCH}" ]; then
                exit 0
        fi

        case ${hw_exists} in
                #
                # On a running system with *no* hardware,
                # modify the system files only
                #
                0 )
                        ADD_DRV="add_drv -n"
                        ;;
                #
                # On a running system with hardware,
                # modify the system files and attach the driver
                #
                1 )
			echo "Adding driver now..."
                        ADD_DRV="add_drv"
                        ;;
         esac
else
        #
        # On a client,
        # modify the system files and touch /reconfigure
        # for reconfigure reboot
        #
        ADD_DRV="add_drv -b ${BASEDIR}"
fi

#
# Make sure add_drv has *not* been previously executed
# before attempting to add the driver.
#
grep "^${DRV} " $BASEDIR/etc/name_to_major > /dev/null 2>&1
if [ $? -ne 0 ]; then
        ${ADD_DRV} -m "${DRVPERM}" -i '"pci1061,3" "pci1576,3" "pci1576,5"' ${DRV}
        if [ $? -ne 0 ]; then
                echo "\nFailed add_drv!\n" >&2
                exit 1
        fi
fi

exit 0

