OLD | NEW |
| (Empty) |
1 # Sample dhcpcd hook for ypbind | |
2 # This script is only suitable for the Linux version. | |
3 | |
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" | |
11 fi | |
12 | |
13 ypbind_dir="$state_dir/ypbind" | |
14 | |
15 best_domain() | |
16 { | |
17 local i= | |
18 | |
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 | |
25 } | |
26 | |
27 make_yp_binding() | |
28 { | |
29 [ -d "$ypbind_dir" ] || mkdir -p "$ypbind_dir" | |
30 echo "$new_nis_domain" >"$ypbind_dir/$interface" | |
31 local nd="$(best_domain)" | |
32 | |
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 | |
45 | |
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 | |
52 } | |
53 | |
54 restore_yp_binding() | |
55 { | |
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 | |
71 } | |
72 | |
73 case "$reason" in | |
74 PREINIT) | |
75 rm -f "$ypbind_dir/$interface" | |
76 ;; | |
77 TEST) | |
78 ;; | |
79 *) | |
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 | |
OLD | NEW |