PageRenderTime 11ms CodeModel.GetById 9ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/dhcp3/dhclient-enter-hooks.d/resolvconf

http://github.com/brinkman83/bashrc
#! | 48 lines | 46 code | 2 blank | 0 comment | 0 complexity | 13b12445d1dd17c08b2cc941ef3d6eb8 MD5 | raw file
 1#
 2# Script fragment to make dhclient3 work with resolvconf
 3#
 4# Licensed under the GNU GPL.  See /usr/share/common-licenses/GPL.
 5#
 6
 7# Tips:
 8# * Be careful about changing the environment since this is sourced
 9# * This script fragment uses bash features
10
11if [ -x /sbin/resolvconf ] ; then
12	# Do stuff now
13	case "$reason" in
14		EXPIRE|FAIL|RELEASE|STOP)   # and TIMEOUT too ??
15			# Delete resolv.conf info 
16			[ ! "$interface" ] || /sbin/resolvconf -d "$interface"
17			;;
18	esac
19	# For safety, undefine the nasty default make_resolv_conf()
20	make_resolv_conf() {
21		true
22	}
23	# Define a resolvconf-compatible m_r_c() function which gets run later
24	# (or, in the TIMEOUT case, MAY get run later)
25	case "$reason" in
26		BOUND|RENEW|REBIND|REBOOT|TIMEOUT)
27			make_resolv_conf() {
28				R=""
29				if [ "$new_domain_name_servers" ] && [ "$new_domain_name" ] ; then
30					R="${R}domain $new_domain_name
31"
32				fi
33				if [ "$new_domain_name_servers" ] && [ "$new_domain_search" ] ; then
34					# The replacement below works around a bug with dhclient 3.1.0 which
35					# separates items with the four characters backslash-zero-three-two
36					# instead of with a space
37					R="${R}search ${new_domain_search//\\032/ }
38"
39				fi
40				for nameserver in $new_domain_name_servers ; do
41					R="${R}nameserver $nameserver
42"
43				done
44				[ ! "$interface" ] || echo -n "$R" | /sbin/resolvconf -a "$interface"
45			}
46			;;
47	esac
48fi