cc63d139221ff84240aa8238034cb713b9d301ba
[dragonfly.git] / contrib / dhcpcd / hooks / 50-yp.conf
1 # Sample dhcpcd hook for ypbind
2 # This script is only suitable for the Linux version.
3
4 ypbind_pid()
5 {
6         [ -s /var/run/ypbind.pid ] && cat /var/run/ypbind.pid
7 }
8
9 make_yp_conf()
10 {
11         [ -z "$new_nis_domain" -a -z "$new_nis_servers" ] && return 0
12         cf=/etc/yp.conf."$ifname"
13         rm -f "$cf"
14         echo "$signature" > "$cf"
15         prefix=
16         if [ -n "$new_nis_domain" ]; then
17                 if ! valid_domainname "$new_nis_domain"; then
18                         syslog err "Invalid NIS domain name: $new_nis_domain"
19                         rm -f "$cf"
20                         return 1
21                 fi
22                 domainname "$new_nis_domain"
23                 if [ -n "$new_nis_servers" ]; then
24                         prefix="domain $new_nis_domain server "
25                 else
26                         echo "domain $new_nis_domain broadcast" >> "$cf"
27                 fi
28         else
29                 prefix="ypserver "
30         fi
31         for x in $new_nis_servers; do
32                 echo "$prefix$x" >> "$cf"
33         done
34         save_conf /etc/yp.conf
35         cat "$cf" > /etc/yp.conf
36         rm -f "$cf"
37         pid="$(ypbind_pid)"
38         if [ -n "$pid" ]; then
39                 kill -HUP "$pid"
40         fi
41 }
42
43 restore_yp_conf()
44 {
45         [ -n "$old_nis_domain" ] && domainname ""
46         restore_conf /etc/yp.conf || return 0
47         pid="$(ypbind_pid)"
48         if [ -n "$pid" ]; then
49                 kill -HUP "$pid"
50         fi
51 }
52
53 if $if_up; then
54         make_yp_conf
55 elif $if_down; then
56         restore_yp_conf
57 fi