#!/bin/sh
#
#       This script will remove, as necessary, the changes introduced by the
#       PM project.
#

PATID=108528
NUNDO_REV=03
NOUNDO_INVOL_PC=11
rmv_all=1

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


undo_remmedia() {
        sed -e '/^device-dependency-property removable-media/d' $PKG_INSTALL_ROOT/etc/power.conf > \
                /tmp/power.$$
        cp /tmp/power.$$ $PKG_INSTALL_ROOT/etc/power.conf
        rm /tmp/power.$$
}

undo_invol_pc () {
	cp $PKG_INSTALL_ROOT/etc/power.conf /tmp/involpower.$$
	echo "device-dependency /dev/fb /dev/kbd" >> /tmp/involpower.$$
	cp /tmp/involpower.$$ $PKG_INSTALL_ROOT/etc/power.conf
	rm /tmp/involpower.$$
}

for i in `echo $pids`; do
        echo $i | egrep -s $PATID || continue
        rev=`expr //$i : '.*-\(.*\)'`
	No undo edits for rev-11 or higher
	[ $rev -ge $NOUNDO_INVOL_PC ] && exit
	[ $rev -ge $NUNDO_REV ] && no_invol_pc=1 && continue
        [ $rev -le 02 ] && rmv_all=1 && continue
done

[ "$no_invol_pc" ] && undo_invol_pc && exit
[ "$rmv_all" ] && undo_invol_pc && undo_remmedia && exit

exit 0
