#!/bin/sh

# Copyright 2014 QLogic Corporation
# The contents of this file are subject to the terms of the
# QLogic End User License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the License at
# http://www.qlogic.com/Resources/Documents/DriverDownloadHelp/
# QLogic_End_User_Software_License.txt
# See the License for the specific language governing permissions
# and limitations under the License.

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

DRV=bnx
DRVPERM="* 0666 root sys"

ADD_DRV=/usr/sbin/add_drv

devices="pci14e4,164a
         pci14e4,164c
         pci14e4,16aa
         pci14e4,16ac
         pci14e4,1639
         pci14e4,163a
         pci14e4,163b
         pci14e4,163c
         pciex14e4,164a
         pciex14e4,164c
         pciex14e4,16aa
         pciex14e4,16ac
         pciex14e4,1639
         pciex14e4,163a
         pciex14e4,163b
         pciex14e4,163c"

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 [ "${PKG_INSTALL_ROOT}" = "" -o "${PKG_INSTALL_ROOT}" = "/" ]; 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 PKG_INSTALL_ROOT
    ADD_DRV_FLAGS="-b ${PKG_INSTALL_ROOT}"
fi

# Make sure add_drv has not been previously executed
# before attempting to add the driver.
grep "^${DRV}[ 	]" $PKG_INSTALL_ROOT/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

