#!/bin/sh

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

LOGDEVICE=$6
REALDEVICE=$1

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

# To resolve long-standing bug:
# This script can be executed in different contexts.
# 1st context: pppd run from command line with usepeerdns option.
# In this case we must add nameserver lines.
# 2nd context: pppd run by kppp with usepeerdns option. pppd will
# save nameserver lines in /etc/ppp/resolv.conf and kppp will
# modify /etc/resolv.conf itself. We must not touch resolv.conf.
# 3rd context: pppd run by ifup-ppp script (ppp-watch actually).
# The script may specify usepeerdns option (or may not). In this
# case we must not change resolv.conf again, because we have a
# ifcfg-ppp* config and ifup-post will do its job to modify
# resolv.conf.
#
# Let's have a quick global hack: handle RESOLV_MODS here like in
# ifup-post.

. /etc/init.d/functions
SourceIfNotEmpty /etc/sysconfig/network

if ! is_no "$RESOLV_MODS"; then
	# for dynamic DNS support with gnome-ppp and kppp and draknet (adsl)
	if grep -iqs '#.*ppp temp entry' /etc/resolv.conf; then
		PPP_TEMP_ENTRY=`grep '#.*ppp temp entry' /etc/resolv.conf | \
		tail -1 | sed 's/.*ppp temp entry/# ppp temp entry/' `
	else
		unset PPP_TEMP_ENTRY
	fi
	if [ -n "$PPP_TEMP_ENTRY" ]; then
		[ -n "$DNS1" ] && \
		echo -e "nameserver $DNS1 $PPP_TEMP_ENTRY" >> /etc/resolv.conf
		[ -n "$DNS2" ] && \
		echo -e "nameserver $DNS2 $PPP_TEMP_ENTRY" >> /etc/resolv.conf
	fi
fi
/etc/sysconfig/network-scripts/ifup-post "ifcfg-$LOGDEVICE"

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

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

	"$f" "$@"
done

IP_UP_LOCAL=/etc/ppp/ip-up.local
[ -x "$IP_UP_LOCAL" ] && "$IP_UP_LOCAL" "$@"

exit 0
