#!/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=01

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


undo_vector_ppp() {
fname=asppp
cat >/tmp/$fname.$$ <<\EOF
#!/sbin/sh
#
# Copyright (c) 1993, 1997 by Sun Microsystems, Inc.
# All rights reserved.
#
#ident	"@(#)asppp	1.18	98/01/28 SMI"

PATH=/sbin:/usr/bin:/usr/sbin; export PATH

case "$1" in
'start')
	if [ -f /etc/asppp.cf ]; then
		# If the configuration file is empty (consists of lines which
		# contain only blanks, or have a leading '#') then exit
		egrep -v '^[ 	]*(#|$)' /etc/asppp.cf >/dev/null 2>&1 || exit 0

		# Check for required files
		for file in /usr/sbin/aspppd /usr/sbin/aspppls; do

			[ -f $file ] && continue

			echo "$0: Asynchronous PPP has been installed but"
			echo "not configured correctly"
			echo "$0: $file not found"
			echo "$0: Please refer to the PPP documentation"

			exit 1
		done

		# Execute the ifconfig lines
        	nawk '/^[ \t]*ifconfig/ { system($0) }' < /etc/asppp.cf

		# Start the aspppd daemon
		/usr/sbin/aspppd -d 1 || \
			echo "aspppd not started, see /var/adm/log/asppp.log"
	fi
       	;; 
           
'stop')
	if [ -f /etc/asppp.cf ]; then

		# Stop the aspppd daemon if it's running

		/usr/bin/pkill -x -u 0 aspppd

		# Use ifconfig to make the interfaces down just in case

        	nawk '/^[ \t]*ifconfig/ { \
			system("ifconfig " $2 " down"); \
			system("ifconfig " $2 " unplumb")
				}' < /etc/asppp.cf
	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 111300 is on
# the system.


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

undo_vector_ppp && exit

exit 0
