Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / bsd / dhcpcd / dist / dhcpcd-hooks / 50-ypbind
blob3d56946759f6cf6437a8d3eddf863cdd3c405008
1 # Sample dhcpcd hook for ypbind
2 # This script is only suitable for the Linux version.
4 # Distributions may want to just have their command here instead of this
5 if [ -x /etc/rc.d/ypbind ]; then
6         ypbind_restart_cmd="/etc/rc.d/ypbind restart"
7         ypbind_stop_cmd="/etc/rc.d/ypbind stop"
8 elif [ -x /usr/local/etc/rc.d/ypbind ]; then
9         ypbind_restart_cmd="/usr/local/etc/rc.d/ypbind restart"
10         ypbind_stop_cmd="/usr/local/etc/rc.d/ypbind stop"
13 ypbind_dir="$state_dir/ypbind"
15 best_domain()
17         local i=
19         for i in $interfaces; do
20                 if [ -e "$ypbind_dir/$i" ]; then
21                         cat "$ypbind_dir/$i"
22                 fi
23         done
24         return 1
27 make_yp_binding()
29         [ -d "$ypbind_dir" ] || mkdir -p "$ypbind_dir"
30         echo "$new_nis_domain" >"$ypbind_dir/$interface"
31         local nd="$(best_domain)"
33         local cf=/var/yp/binding/"$new_nis_domain".ypservers
34         if [ -n "$new_nis_servers" ]; then
35                 local ncf="$cf.$interface" x=
36                 rm -f "$ncf"
37                 for x in $new_nis_servers; do
38                         echo "$x" >>"$ncf"
39                 done
40                 change_file "$cf" "$ncf"
41         else
42                 # Because this is not an if .. fi then we can use $? below
43                 [ -e "$cf" ] && rm "$cf"
44         fi
46         if [ $? = 0 -o "$nd" != "$(domainname)" ]; then
47                 domainname "$nd"
48                 if [ -n "$ypbind_restart_cmd" ]; then
49                         eval $ypbind_restart_cmd
50                 fi
51         fi
54 restore_yp_binding()
56         rm -f "$ypbind_dir/$interface"
57         local nd="$(best_domain)"
58         # We need to stop ypbind if there is no best domain
59         # otherwise it will just stall as we cannot set domainname
60         # to blank :/
61         if [ -z "$nd" ]; then
62                 if [ -n "$ypbind_stop_cmd" ]; then
63                         eval $ypbind_stop_cmd
64                 fi
65         elif [ "$nd" != "$(domainname)" ]; then
66                 domainname "$nd"
67                 if [ -n "$ypbind_restart_cmd" ]; then
68                         eval $ypbind_restart_cmd
69                 fi
70         fi
73 case "$reason" in
74 PREINIT)
75         rm -f "$ypbind_dir/$interface"
76         ;;
77 TEST)
78         ;;
80         if [ -n "$new_nis_domain" ]; then
81                 make_yp_binding
82         elif [ -n "$old_nis_domain" ]; then
83                 restore_yp_binding
84         fi
85         ;;
86 esac