#!/bin/sh
#


# 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=02

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


undo_pppoe() {
fname=pppd
cat >/tmp/$fname.$$ <<\EOF
#!/sbin/sh
#
# Copyright (c) 2000 by Sun Microsystems, Inc.
# All rights reserved.
#
#ident	"@(#)pppd	1.1	01/01/24 SMI"

PATH=/sbin:/usr/bin:/usr/sbin; export PATH
PPPDIR=/etc/ppp; export PPPDIR

case "$1" in
'start')
	if [ ! -x /usr/bin/pppd -o ! -c /dev/sppp ]; then
		echo "$0: Solaris PPP has not been correctly installed on"
		echo "$0: this system.  Required files are missing."
		exit 1
	fi
	if [ -f $PPPDIR/ifconfig ]; then
		. $PPPDIR/ifconfig
	fi
	if [ -f $PPPDIR/demand ]; then
		. $PPPDIR/demand
	fi
       	;; 
           
'stop')
	/usr/bin/pkill -x pppd

	# Use ifconfig to make the interfaces down just in case
	if [ -f $PPPDIR/ifconfig ]; then
        	nawk '/ifconfig[	]*sppp/ { \
			system("ifconfig " $2 " down"); \
			system("ifconfig " $2 " unplumb"); \
			next; \
		} \
        	/ifconfig/ { \
			$3 = "removeif"; \
			NF = 4; \
			system($0); \
		}' < $PPPDIR/ifconfig
	fi
       	;; 

*)
        echo "Usage: $0 { start | stop }"
        exit 1
        ;;
esac
exit 0

EOF

cp /tmp/$fname.$$ $PKG_INSTALL_ROOT/etc/init.d/$fname
rm /tmp/$fname.$$

return 0

}

# 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 111299 is on
# the system.

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

undo_pppoe && exit

exit 0
