#!/bin/sh
#
# This sample code shows you one way to modify your setup to allow automatic
# configuration of your resolv.conf for peer supplied DNS addresses when using
# the `usepeerdns' option.
#
# In my case I just added this to my /etc/ppp/ip-up.local script. You may need to 
# create an executable script if one does not exist.
#
# Nick Walker (nickwalker@email.com)
#

# Yannis: 
# 1. This script is executed with a limited environment variable PATH, 
#    make sure that you use absolute file paths!
#    e.g. Use '/sbin/ifconfig ppp0' instead of 'ifconfig ppp0'
# 2. The output if this script is re-directed(to /dev/NULL maybe?),
#    In order to watch the output, you can re-direct the output to a tty.
#    e.g. echo "$0 is called" >/dev/tty0 2>&1
# 3. When this script is called, interface ppp0 is already up. 
#    And we need to add a default route for ppp0.

if [ -n "$USEPEERDNS" -a -f /etc/ppp/resolv.conf ]; then
	rm -f /etc/ppp/resolv.prev
	if [ -f /etc/resolv.conf ]; then
		cp /etc/resolv.conf /etc/ppp/resolv.prev
		grep domain /etc/ppp/resolv.prev > /etc/resolv.conf
		grep search /etc/ppp/resolv.prev >> /etc/resolv.conf
		cat /etc/ppp/resolv.conf >> /etc/resolv.conf
	else
		cp /etc/ppp/resolv.conf /etc
	fi
fi

/sbin/route add default dev ppp0 metric 0 #>/dev/tty0 2>&1
