Mercurial > hg > dhcpcd
annotate hooks/50-ypbind.in @ 5535:a0d828e25482 draft
Add --noconfigure option
With this set dhcpcd will not configure anything on the host.
The expectation is that a 3rd party script will instead.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Wed, 04 Nov 2020 14:18:48 +0000 |
| parents | 0b2abe4e9d2e |
| children |
| rev | line source |
|---|---|
| 3936 | 1 # Sample dhcpcd hook for ypbind |
| 2 # This script is only suitable for the BSD versions. | |
| 3 | |
| 4 : ${ypbind_restart_cmd:=service_command ypbind restart} | |
| 5 : ${ypbind_stop_cmd:=service_condcommand ypbind stop} | |
| 6 ypbind_dir="$state_dir/ypbind" | |
| 7 : ${ypdomain_dir:=@YPDOMAIN_DIR@} | |
| 8 : ${ypdomain_suffix:=@YPDOMAIN_SUFFIX@} | |
| 9 | |
| 10 | |
| 11 best_domain() | |
| 12 { | |
| 13 for i in "$ypbind_dir/$interface_order".*; do | |
| 14 if [ -f "$i" ]; then | |
| 15 cat "$i" | |
| 16 return 0 | |
| 17 fi | |
| 18 done | |
| 19 return 1 | |
| 20 } | |
| 21 | |
| 22 make_yp_binding() | |
| 23 { | |
| 24 [ -d "$ypbind_dir" ] || mkdir -p "$ypbind_dir" | |
| 25 echo "$new_nis_domain" >"$ypbind_dir/$ifname" | |
| 26 | |
| 27 if [ -z "$ypdomain_dir" ]; then | |
| 28 false | |
| 29 else | |
|
4215
e323d30f279e
dhcpcd-run-hooks: POSIX shell does not require the local builtin
Roy Marples <roy@marples.name>
parents:
3936
diff
changeset
|
30 cf="$ypdomain_dir/$new_nis_domain$ypdomain_suffix" |
| 3936 | 31 if [ -n "$new_nis_servers" ]; then |
|
4215
e323d30f279e
dhcpcd-run-hooks: POSIX shell does not require the local builtin
Roy Marples <roy@marples.name>
parents:
3936
diff
changeset
|
32 ncf="$cf.$ifname" |
| 3936 | 33 rm -f "$ncf" |
| 34 for x in $new_nis_servers; do | |
| 35 echo "$x" >>"$ncf" | |
| 36 done | |
| 37 change_file "$cf" "$ncf" | |
| 38 else | |
| 39 [ -e "$cf" ] && rm "$cf" | |
| 40 fi | |
| 41 fi | |
| 42 | |
|
4215
e323d30f279e
dhcpcd-run-hooks: POSIX shell does not require the local builtin
Roy Marples <roy@marples.name>
parents:
3936
diff
changeset
|
43 nd="$(best_domain)" |
|
4322
0b2abe4e9d2e
hooks: shell [ ] only supports 4 parameters
Roy Marples <roy@marples.name>
parents:
4215
diff
changeset
|
44 if [ $? = 0 ] && [ "$nd" != "$(domainname)" ]; then |
| 3936 | 45 domainname "$nd" |
| 46 if [ -n "$ypbind_restart_cmd" ]; then | |
| 47 eval $ypbind_restart_cmd | |
| 48 fi | |
| 49 fi | |
| 50 } | |
| 51 | |
| 52 restore_yp_binding() | |
| 53 { | |
| 54 rm -f "$ypbind_dir/$ifname" | |
|
4215
e323d30f279e
dhcpcd-run-hooks: POSIX shell does not require the local builtin
Roy Marples <roy@marples.name>
parents:
3936
diff
changeset
|
55 nd="$(best_domain)" |
| 3936 | 56 # We need to stop ypbind if there is no best domain |
| 57 # otherwise it will just stall as we cannot set domainname | |
| 58 # to blank :/ | |
| 59 if [ -z "$nd" ]; then | |
| 60 if [ -n "$ypbind_stop_cmd" ]; then | |
| 61 eval $ypbind_stop_cmd | |
| 62 fi | |
| 63 elif [ "$nd" != "$(domainname)" ]; then | |
| 64 domainname "$nd" | |
| 65 if [ -n "$ypbind_restart_cmd" ]; then | |
| 66 eval $ypbind_restart_cmd | |
| 67 fi | |
| 68 fi | |
| 69 } | |
| 70 | |
| 5535 | 71 if ! $if_configured; then |
| 72 ; | |
| 73 elif [ "$reason" = PREINIT ]; then | |
| 3936 | 74 rm -f "$ypbind_dir/$interface".* |
| 75 elif $if_up || $if_down; then | |
| 76 if [ -n "$new_nis_domain" ]; then | |
| 77 if valid_domainname "$new_nis_domain"; then | |
| 78 make_yp_binding | |
| 79 else | |
| 80 syslog err "Invalid NIS domain name: $new_nis_domain" | |
| 81 fi | |
| 82 elif [ -n "$old_nis_domain" ]; then | |
| 83 restore_yp_binding | |
| 84 fi | |
| 85 fi |
