File: 50-ypbind.in

package info (click to toggle)
dhcpcd 1%3A10.2.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,988 kB
  • sloc: ansic: 39,785; sh: 2,374; makefile: 380
file content (84 lines) | stat: -rw-r--r-- 1,829 bytes parent folder | download | duplicates (6)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Sample dhcpcd hook for ypbind
# This script is only suitable for the BSD versions.

: ${ypbind_restart_cmd:=service_command ypbind restart}
: ${ypbind_stop_cmd:=service_condcommand ypbind stop}
ypbind_dir="$state_dir/ypbind"
: ${ypdomain_dir:=@YPDOMAIN_DIR@}
: ${ypdomain_suffix:=@YPDOMAIN_SUFFIX@}

best_domain()
{
	for i in "$ypbind_dir/$interface_order".*; do
		if [ -f "$i" ]; then
			cat "$i"
			return 0
		fi
	done
	return 1
}

make_yp_binding()
{
	[ -d "$ypbind_dir" ] || mkdir -p "$ypbind_dir"
	echo "$new_nis_domain" >"$ypbind_dir/$ifname"

	if [ -z "$ypdomain_dir" ]; then
		false
	else
		cf="$ypdomain_dir/$new_nis_domain$ypdomain_suffix"
		if [ -n "$new_nis_servers" ]; then
			ncf="$cf.$ifname"
			rm -f "$ncf"
			for x in $new_nis_servers; do
				echo "$x" >>"$ncf"
			done
			change_file "$cf" "$ncf"
		else
			[ -e "$cf" ] && rm "$cf"
		fi
	fi

	nd="$(best_domain)"
	if [ $? = 0 ] && [ "$nd" != "$(domainname)" ]; then
		domainname "$nd"
		if [ -n "$ypbind_restart_cmd" ]; then
			eval $ypbind_restart_cmd
		fi
	fi
}

restore_yp_binding()
{
	rm -f "$ypbind_dir/$ifname"
	nd="$(best_domain)"
	# We need to stop ypbind if there is no best domain
	# otherwise it will just stall as we cannot set domainname
	# to blank :/
	if [ -z "$nd" ]; then
		if [ -n "$ypbind_stop_cmd" ]; then
			eval $ypbind_stop_cmd
		fi
	elif [ "$nd" != "$(domainname)" ]; then
		domainname "$nd"
		if [ -n "$ypbind_restart_cmd" ]; then
			eval $ypbind_restart_cmd
		fi
	fi
}

if ! $if_configured; then
	;
elif [ "$reason" = PREINIT ]; then
	rm -f "$ypbind_dir/$interface".*
elif $if_up || $if_down; then
	if [ -n "$new_nis_domain" ]; then
		if valid_domainname "$new_nis_domain"; then
			make_yp_binding
		else
			syslog err "Invalid NIS domain name: $new_nis_domain"
		fi
	elif [ -n "$old_nis_domain" ]; then
		restore_yp_binding
	fi
fi