#!/bin/sh

# This file should not be modified -- make local changes to
# /etc/ppp/ip-down.local instead

# From pppd manpage:

#       /etc/ppp/ip-down
#              A program or script which is executed when the link is no longer
#              available for sending and receiving IP packets.  This script can
#              be  used  for  undoing the effects of the /etc/ppp/ip-up script.
#              It is invoked in the same manner and with the same parameters as
#              the ip-up script.

LOGDEVICE=$6
REALDEVICE=$1
RESOLVCONF=/sbin/resolvconf

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

if [ -f /etc/resolv.conf.save.$REALDEVICE ]; then
	cat /etc/resolv.conf.save.$REALDEVICE >/etc/resolv.conf
	rm -f /etc/resolv.conf.save.$REALDEVICE
	UC=/usr/sbin/update_chrooted
	[ -x $UC ] && $UC conf
else
	[ -x "$RESOLVCONF" ] && $RESOLVCONF -fd $REALDEVICE
fi

for f in /etc/ppp/ip-down.d/*; do
	[ -x "$f" ] || continue

	# Don't run *.rpm* and *~ scripts
	[ "${f%.rpm*}" = "$f" -a "${f%\~}" = "$f" ] || continue

	"$f" "$@"
done

IP_DOWN_LOCAL=/etc/ppp/ip-down.local
[ -x "$IP_DOWN_LOCAL" ] && "$IP_DOWN_LOCAL" "$@"

ETCNET_IFDOWN=/etc/net/scripts/ifdown-ppp
NS_IFDOWN=/etc/sysconfig/network-scripts/ifdown-post
N_C_S_CONFIG=/etc/sysconfig/network

. $N_C_S_CONFIG

case $CONFMETHOD in
	etcnet)
		exec $ETCNET_IFDOWN $REALDEVICE
	;;
	net-scripts)
		exec $NS_IFDOWN "ifcfg-$LOGDEVICE"
	;;
	*)
	;;
esac

exit 0
