#! /bin/sh
# 
# yppasswd changes pkgs and moves from SUNWcsu to SUNWnisu pkg.  
# Remove it from SUNWcsu pkg in the database.
#

PATID=108993
NUNDO_REV=14
CURRENT_REV=`expr //$PatchNum : '.*-\(.*\)'`

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

reset_db_csu () {

if [ "$ROOTDIR" != "" ]; then
        REMOVEF="removef -R ${ROOTDIR}"
else
        REMOVEF="removef"
fi

pkginfo -R $ROOTDIR -q  SUNWcsu
if [ $? -eq 0 ]
then
        ${REMOVEF} SUNWcsu /usr/bin/yppasswd
        ${REMOVEF} -f SUNWcsu || exit 2
fi

}

for i in `echo $pids`; do
        echo $i | egrep -s $PATID || continue
        rev=`expr //$i : '.*-\(.*\)'`
        #Don't do cleanup if there patch between revs 14 
        #and less than CURRENT_REV on the system. 
        [ $rev -ge $NUNDO_REV -a $rev -lt $CURRENT_REV ] && exit
done

reset_db_csu

exit 0

