summaryrefslogtreecommitdiffstats
path: root/dhcpcd-hooks/50-yp.conf
blob: 4bdd0623e7f465cf238cf1cdb49096fc94619a91 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Sample dhcpcd hook for ypbind
# This script is only suitable for the Linux version.

ypbind_pid()
{
	[ -s /var/run/ypbind.pid ] && cat /var/run/ypbind.pid
}

make_yp_conf()
{
	[ -z "$new_nis_domain" -a -z "$new_nis_servers" ] && return 0
	local cf=/etc/yp.conf."$interface" prefix= x= pid=
	rm -f "$cf"
	echo "$signature" > "$cf"
	if [ -n "$new_nis_domain" ]; then
		domainname "$new_nis_domain"
		if [ -n "$new_nis_servers" ]; then
			prefix="domain $new_nis_domain server "
		else
			echo "domain $new_nis_domain broadcast" >> "$cf"
		fi
	else
		prefix="ypserver "
	fi
	for x in $new_nis_servers; do
		echo "$prefix$x" >> "$cf"
	done
	save_conf /etc/yp.conf
	cat "$cf" > /etc/yp.conf
	rm -f "$cf"
	pid="$(ypbind_pid)"
	if [ -n "$pid" ]; then
		kill -HUP "$pid"
	fi
}

restore_yp_conf()
{
	[ -n "$old_nis_domain" ] && domainname ""
	restore_conf /etc/yp.conf || return 0
	local pid="$(ypbind_pid)"
	if [ -n "$pid" ]; then
		kill -HUP "$pid"
	fi
}

case "$reason" in
BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC)	make_yp_conf;;
EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP)		restore_yp_conf;;
esac