#!/bin/sh
#
#       This script will remove, as necessary, the changes introduced by the
#       Taks, Projects and Accounting project.
#

# PATID_NEW is the base patchid that acc/obs'd PATID.

PATID_NEW=108994
NUNDO_REV_NEW=14

# PATID is the initial base patchid that had this fix.

PATID=111300
NUNDO_REV=01

INFO="$PKG_INSTALL_ROOT/var/sadm/pkg/SUNWcsr/pkginfo"
pids=`egrep '^PATCHLIST' $INFO | nawk -F= '{print $2}'`


rmv_attr=1

undo_attr() {
	sed -e '/asppp2pppd/d' $PKG_INSTALL_ROOT/etc/security/exec_attr > \
		/tmp/exec_attr.$$
	cp /tmp/exec_attr.$$ $PKG_INSTALL_ROOT/etc/security/exec_attr
	rm /tmp/exec_attr.$$
}

# First check to see if a version of the
# new patchid is still on the system.  Exit if
# rev 14 or greater is there.  If not, continue
# to check for 111300 in next section.
#

if echo "$pids" | grep 108994  > /dev/null 2>&1
then

  for i in `echo $pids`; do
        echo $i | egrep -s $PATID_NEW || continue
        rev_new=`expr //$i : '.*-\(.*\)'`
        #No edits for rev-01 or higher
        [ $rev_new -ge $NUNDO_REV_NEW ] && exit
  done

fi

# Continue to check if a version of 111300 is on
# the system.


for i in `echo $pids`; do
	echo $i | egrep -s $PATID || continue
	rev=`expr //$i : '.*-\(.*\)'`
	#No edits for rev-01 or higher
	[ $rev -ge $NUNDO_REV ] && exit
done


[ "$rmv_attr" ] && undo_attr

exit 0
