diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-01-30 13:29:46 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-01-30 16:23:03 +0100 |
commit | f2ed769880271654297a4be420f26ab94d39666b (patch) | |
tree | 4cbfc23184993e8ef11bb1d60b307cbb3644a259 /dhcpcd/dhcpcd-hooks/50-ypbind | |
parent | arphole: New test (diff) | |
download | rtems-libbsd-f2ed769880271654297a4be420f26ab94d39666b.tar.bz2 |
DHCPCD(8): Import
Import DHCPCD(8) from:
http://roy.marples.name/projects/dhcpcd/
The upstream sources can be obtained via:
fossil clone http://roy.marples.name/projects/dhcpcd
The imported version is 2014-01-29 19:46:44 [6b209507bb].
Diffstat (limited to 'dhcpcd/dhcpcd-hooks/50-ypbind')
-rw-r--r-- | dhcpcd/dhcpcd-hooks/50-ypbind | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/dhcpcd/dhcpcd-hooks/50-ypbind b/dhcpcd/dhcpcd-hooks/50-ypbind new file mode 100644 index 00000000..25e009d7 --- /dev/null +++ b/dhcpcd/dhcpcd-hooks/50-ypbind @@ -0,0 +1,78 @@ +# Sample dhcpcd hook for ypbind +# This script is only suitable for the Linux version. + +: ${ypbind_restart_cmd:=service_command ypbind restart} +: ${ypbind_stop_cmd:=service_condcommand ypbind stop} +ypbind_dir="$state_dir/ypbind" + +best_domain() +{ + local i= + + for i in $interfaces; do + if [ -e "$ypbind_dir/$i" ]; then + cat "$ypbind_dir/$i" + fi + done + return 1 +} + +make_yp_binding() +{ + [ -d "$ypbind_dir" ] || mkdir -p "$ypbind_dir" + echo "$new_nis_domain" >"$ypbind_dir/$ifname" + local nd="$(best_domain)" + + local cf=/var/yp/binding/"$new_nis_domain".ypservers + if [ -n "$new_nis_servers" ]; then + local ncf="$cf.$ifname" x= + rm -f "$ncf" + for x in $new_nis_servers; do + echo "$x" >>"$ncf" + done + change_file "$cf" "$ncf" + else + # Because this is not an if .. fi then we can use $? below + [ -e "$cf" ] && rm "$cf" + fi + + if [ $? = 0 -o "$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" + local 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 [ "$reason" = PREINIT ]; then + rm -f "$ypbind_dir/$ifname" +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 |