#!/bin/sh

# Copyright (c) 2010-2011, by Broadcom, Inc.
# All Rights Reserved.

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

DRV=bge
DRVPERM="* 0666 root sys"

ADD_DRV=/usr/sbin/add_drv

devices="SUNW,bge
         pci108e,1647
         pci108e,1648
         pci108e,16a7
         pci108e,16a8
         pci14e4,1600
         pci14e4,1601
         pci14e4,1644
         pci14e4,1645
         pci14e4,1647
         pci14e4,1648
         pci14e4,1649
         pci14e4,1653
         pci14e4,1654
         pci14e4,1659
         pci14e4,165d
         pci14e4,165e
         pci14e4,1668
         pci14e4,1669
         pci14e4,166a
         pci14e4,166e
         pci14e4,1677
         pci14e4,1678
         pci14e4,1679
         pci14e4,167d
         pci14e4,1693
         pci14e4,1696
         pci14e4,1699
         pci14e4,169b
         pci14e4,169c
         pci14e4,16a6
         pci14e4,16a7
         pci14e4,16a8
         pci14e4,16c7
         pciex14e4,1655
         pciex14e4,1656
         pciex14e4,1659
         pciex14e4,165c
         pciex14e4,165a
         pciex14e4,165b
         pciex14e4,1673
         pciex14e4,1674
         pciex14e4,1677
         pciex14e4,167a
         pciex14e4,167b
         pciex14e4,1680
         pciex14e4,1681
         pciex14e4,1684
         pciex14e4,169d
         pciex14e4,16fd
         pciex14e4,1713"

unset devlist
for device in $devices; do
	devlist="$devlist \"$device\""
done

# Select the correct add_drv options to execute.
# add_drv touches /reconfigure to cause the next
# boot to be a reconfigure boot.

if [ "${BASEDIR}" = "" -o "${BASEDIR}" = "/" ]; then
    # On a running system, modify the system files and attach the driver.
    ADD_DRV_FLAGS=""
else
    # On a client, modify the system files relative to BASEDIR.
    ADD_DRV_FLAGS="-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} ${ADD_DRV_FLAGS} -v -m '* 0666 bin bin' -i "$devlist" ${DRV}
    if [ $? -ne 0 ]; then
       echo "postinstall: add_drv $DRV failed\n" >&2
       exit 1
    fi
fi

exit 0

