#!/bin/sh
# os_type = String: "SunOS", "Linux"
[ -z "$AVBIN" ] && AVBIN="/tmp"
if [ -x /bin/uname ]; then 
    os_type=`/bin/uname -s`
elif [ -x /usr/bin/uname ]; then
    os_type=`/usr/bin/uname -s`
else
    echo "Cannot find uname in /bin or /usr/bin, exiting."
    os_type="unknown"
fi


DEVICE="esipw"
DEVLINK=${BASEDIR}/etc/devlink.tab

if [ $os_type = "SunOS" ]; then
    KERNELDIR=/usr/kernel/drv
    esipwid=`/sbin/modinfo 2>&1 | /bin/awk '/esipw / { print $1 } ' - 2>/dev/null`
    if [ -f ${BASEDIR}${KERNELDIR}/${DEVICE} ] ; then
	/bin/rm -f ${BASEDIR}${KERNELDIR}/${DEVICE}
	/bin/rm -f ${BASEDIR}${KERNELDIR}/${DEVICE}.conf
    fi
    if [ -f ${BASEDIR}${KERNELDIR}/sparcv9/${DEVICE} ] ; then
	/bin/rm -f ${BASEDIR}${KERNELDIR}/sparcv9/${DEVICE}
    fi
    if [ x${BASEDIR} = x -o x${BASEDIR} = x/ ] ; then
	    /usr/sbin/rem_drv ${DEVICE}
    else
	    /usr/sbin/rem_drv -b ${BASEDIR:-/} ${DEVICE}
    fi
    /bin/egrep -v 'name=esipw' ${DEVLINK} > ${DEVLINK}.new
    /bin/mv ${DEVLINK} ${DEVLINK}.bak
    /bin/cp -p ${DEVLINK}.bak ${DEVLINK}
    /bin/cp ${DEVLINK}.new ${DEVLINK}
    /bin/rm -f ${DEVLINK}.new
    /usr/sbin/devlinks -r ${BASEDIR:-/}
    if [ -d /usr/ucb -a -f /usr/ucb/ucblinks ] ; then
	/usr/ucb/ucblinks -r ${BASEDIR:-/}
    fi
    # Removing the link makes bad things happen at reboot if poliwall is still
    #   installed and tries to insert a kernel module.  Basically poliwall
    #   can't find the module even though it has actually been loaded. So,
    #   this means we can ONLY call this script and remove this /dev/ link
    #   if we are uninstalling poliwall.  Later installs will reinsert the
    #   link when the install occurs.
    /usr/bin/rm -f /dev/${DEVICE}
    [ -n "$esipwid" ] && /usr/sbin/modunload -i $esipwid

else
    if [ -x ${AVBIN}/pw_unload ]; then 
	${AVBIN}/pw_unload
    fi
fi
