#! /bin/sh 
#
#       This script checks for the revision of the patch 
#       installed and takes the necessary action.
#       Updated script so it works with more than one
#       rev of this patch installed on the system.

PATID=109923
NOUNDO_PCELX=03      # rev when this postbackout was introduced
rmv_pcelx=1

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

PKG_INSTALL_ROOT=$ROOTDIR
INFO="$PKG_INSTALL_ROOT/var/sadm/pkg/SUNWpcelx/pkginfo"

# Cleanup function.

remove_entries()
{

if grep '^pcelx\>' ${PKG_INSTALL_ROOT}/etc/name_to_major > /dev/null 2> /dev/null 
then
   if grep '^pcelx "pccard101,574"' ${PKG_INSTALL_ROOT}/etc/driver_aliases > /dev/null
   then
         rem_drv -b ${PKG_INSTALL_ROOT} pcelx
         add_drv -b ${PKG_INSTALL_ROOT} -n \
         -i  '"pccard101,589" "pccard101,562,0"' pcelx || EXIT=1
   fi
fi

}

# Go through list of patches and find highest rev of this
# patch on the system after this patch has been removed.
# If patch rev is 03 or higher, do not do cleanup. 
#Find highest rev on the system

pids=`egrep '^PATCHLIST' $INFO 2> /dev/null | nawk -F= '{print $2}'` 
for i in `echo $pids`; do
        echo $i | egrep -s $PATID || continue
        rev=`expr //$i : '.*-\(.*\)'`
        #No undo edits for rev-03 or higher
        [ $rev -ge $NOUNDO_PCELX ] && exit 
done
   [ $rmv_pcelx ] && remove_entries
exit ${EXIT}
