#
# Script fragment to make dhclient3 work with resolvconf
#
# Licensed under the GNU GPL.  See /usr/share/common-licenses/GPL.
#
# History
# June 2003: Written by Thomas Hood <jdthood@yahoo.co.uk>

# Be careful about changing the environment

if [ -x /sbin/resolvconf ] ; then
	# Do stuff now
	case "$reason" in
		EXPIRE|FAIL|RELEASE|STOP)   # and TIMEOUT too ??
			# Delete resolv.conf info 
			[ ! "$interface" ] || /sbin/resolvconf -d "$interface"
			;;
	esac
	# For safety, undefine the nasty default make_resolv_conf()
	make_resolv_conf() {
		true
	}
	# Define a resolvconf-compatible m_r_c() function which gets run later
	# (or, in the TIMEOUT case, MAY get run later)
	case "$reason" in
		BOUND|RENEW|REBIND|REBOOT|TIMEOUT)
			make_resolv_conf() {
				R=""
				if [ "$new_domain_name_servers" ] && [ "$new_domain_name" ] ; then
					R="${R}search $new_domain_name
"
				fi
				for nameserver in $new_domain_name_servers ; do
					R="${R}nameserver $nameserver
"
				done
				[ ! "$interface" ] || echo -n "$R" | /sbin/resolvconf -a "$interface"
			}
			;;
	esac
fi
