#! /bin/sh 
#

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

ARCH="`uname -p`"

ADDDRV=/usr/sbin/add_drv
DEVLINKTB="${ROOTDIR}/etc/devlink.tab"

TMP=/tmp/$$

# This script is to force users to install patch 107172 rev 07 or newer if 
# either of rev 05 or rev 06 existed. 

patchrm_patch_rev=`/usr/sbin/patchadd -p -R $ROOTDIR | sed -e 's/^Patch: //' -e 's/ .*$//' -e '/107172/!d' -e 's/^107172-//' | sort | tail -1` 

if [ "${patchrm_patch_rev}" -lt 7 -a "${patchrm_patch_rev}" -gt 4 ]
then
   echo "Patchrm has detected patch 107172-${patchrm_patch_rev} as being \
installed. Please install"
   echo "107172-07 or newer before backing out ${PatchNum}."
   exit 1
fi

#
# add_devlink - adds an entry to ${DEVLINKTB}
#
add_devlink()
{
        PATTERN="$1"
        LINK="$2"

        grep -v "^$PATTERN      $LINK$" ${DEVLINKTB} >$TMP.devlink
        echo "$PATTERN\t$LINK" >>$TMP.devlink
        mv $TMP.devlink ${DEVLINKTB}
}

# Get all revs of patchid 106542 crrently installed, add a NO at the top
# of the queue and get the bottom(-1) rev.

patchrm_patch_rev=`/usr/sbin/patchadd -p -R $ROOTDIR | sed -e 's/^Patch: //' -e 's/ .*$//' -e '/106542/!d' -e 's/^106542-//' | sort | (echo NO; cat) | tail -2 | head -1`

if [ "${patchrm_patch_rev}" = "NO" -o "${patchrm_patch_rev}" -le 14 ]
then
   add_devlink 'type=ddi_nexus;minor=initpcmcia' 'pcmcia/\N0'
   add_devlink 'type=ddi_nexus;minor=probepcmcia' 'pcmcia/probe_\N0'
fi

exit 0

