#! /usr/bin/sh
#
# ident "@(#)postpatch 1.2     03/04/24 SMI"
#
# Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#       Defining convenient variables for later
#
PKG_INSTALL_ROOT=$ROOTDIR
ADD_DRV=add_drv
REM_DRV="rem_drv -b ${PKG_INSTALL_ROOT}"
DRV=grbeep
DRV_ALIAS="SUNW,smbus-beep"
DRVPERM='* 0666 root sys'

#
# There won't be an /etc/driver_aliases on the service
# (/export/Solaris_8), so check for its existence before
# trying to access it.
#

if [ -f ${PKG_INSTALL_ROOT}/etc/driver_aliases ] ; then

    nodes_found=`grep ${DRV_ALIAS} ${PKG_INSTALL_ROOT}/etc/driver_aliases`

    if [ "${PKG_INSTALL_ROOT}" = "/" ]; then
        case ${nodes_found} in
                #
                # On a running system with hardware,
                # modify the system files and attach the driver
                #
                1 )
                        ADD_DRV="${ADD_DRV} -b ${PKG_INSTALL_ROOT}"
                        ;;
                #
                # On a running system of the relevant arch with *no* hardware,
                # modify the system files only; i.e. don't try to "attach"
                #
                * )
                        ADD_DRV="${ADD_DRV} -b ${PKG_INSTALL_ROOT} -n"
                        ;;
        esac
    else
        #
        # On a client,
        # modify the system files and touch /reconfigure ??
        # for reconfigure reboot ??
        #
        ADD_DRV="${ADD_DRV} -b ${PKG_INSTALL_ROOT} -n"
    fi

    grep -s "^(${DRV}) " ${PKG_INSTALL_ROOT}/etc/driver_aliases 2> /dev/null || {


#       Remove the driver first

	${REM_DRV} ${DRV}
	
        ${ADD_DRV} -m "${DRVPERM}" -i '"'"${DRV_ALIAS}"'"' ${DRV} || { echo "\n${PKGINST}: Failed ${ADD_DRV} -m "'"'"${DRVPERM}"'" -i " '"${DRV_ALIAS}"'"'" ${DRV}\n" >&2
        exit 1
        }
}
fi

exit 0

