10a68f8d2SRoy Marples# Sample dhcpcd hook for ypbind 20a68f8d2SRoy Marples# This script is only suitable for the BSD versions. 30a68f8d2SRoy Marples 40a68f8d2SRoy Marples: ${ypbind_restart_cmd:=service_command ypbind restart} 50a68f8d2SRoy Marples: ${ypbind_stop_cmd:=service_condcommand ypbind stop} 60a68f8d2SRoy Marplesypbind_dir="$state_dir/ypbind" 70a68f8d2SRoy Marples: ${ypdomain_dir:=} 80a68f8d2SRoy Marples: ${ypdomain_suffix:=} 90a68f8d2SRoy Marples 100a68f8d2SRoy Marplesbest_domain() 110a68f8d2SRoy Marples{ 120a68f8d2SRoy Marples for i in "$ypbind_dir/$interface_order".*; do 130a68f8d2SRoy Marples if [ -f "$i" ]; then 140a68f8d2SRoy Marples cat "$i" 150a68f8d2SRoy Marples return 0 160a68f8d2SRoy Marples fi 170a68f8d2SRoy Marples done 180a68f8d2SRoy Marples return 1 190a68f8d2SRoy Marples} 200a68f8d2SRoy Marples 210a68f8d2SRoy Marplesmake_yp_binding() 220a68f8d2SRoy Marples{ 230a68f8d2SRoy Marples [ -d "$ypbind_dir" ] || mkdir -p "$ypbind_dir" 240a68f8d2SRoy Marples echo "$new_nis_domain" >"$ypbind_dir/$ifname" 250a68f8d2SRoy Marples 260a68f8d2SRoy Marples if [ -z "$ypdomain_dir" ]; then 270a68f8d2SRoy Marples false 280a68f8d2SRoy Marples else 290a68f8d2SRoy Marples cf="$ypdomain_dir/$new_nis_domain$ypdomain_suffix" 300a68f8d2SRoy Marples if [ -n "$new_nis_servers" ]; then 310a68f8d2SRoy Marples ncf="$cf.$ifname" 320a68f8d2SRoy Marples rm -f "$ncf" 330a68f8d2SRoy Marples for x in $new_nis_servers; do 340a68f8d2SRoy Marples echo "$x" >>"$ncf" 350a68f8d2SRoy Marples done 360a68f8d2SRoy Marples change_file "$cf" "$ncf" 370a68f8d2SRoy Marples else 380a68f8d2SRoy Marples [ -e "$cf" ] && rm "$cf" 390a68f8d2SRoy Marples fi 400a68f8d2SRoy Marples fi 410a68f8d2SRoy Marples 420a68f8d2SRoy Marples nd="$(best_domain)" 430a68f8d2SRoy Marples if [ $? = 0 ] && [ "$nd" != "$(domainname)" ]; then 440a68f8d2SRoy Marples domainname "$nd" 450a68f8d2SRoy Marples if [ -n "$ypbind_restart_cmd" ]; then 460a68f8d2SRoy Marples eval $ypbind_restart_cmd 470a68f8d2SRoy Marples fi 480a68f8d2SRoy Marples fi 490a68f8d2SRoy Marples} 500a68f8d2SRoy Marples 510a68f8d2SRoy Marplesrestore_yp_binding() 520a68f8d2SRoy Marples{ 530a68f8d2SRoy Marples rm -f "$ypbind_dir/$ifname" 540a68f8d2SRoy Marples nd="$(best_domain)" 550a68f8d2SRoy Marples # We need to stop ypbind if there is no best domain 560a68f8d2SRoy Marples # otherwise it will just stall as we cannot set domainname 570a68f8d2SRoy Marples # to blank :/ 580a68f8d2SRoy Marples if [ -z "$nd" ]; then 590a68f8d2SRoy Marples if [ -n "$ypbind_stop_cmd" ]; then 600a68f8d2SRoy Marples eval $ypbind_stop_cmd 610a68f8d2SRoy Marples fi 620a68f8d2SRoy Marples elif [ "$nd" != "$(domainname)" ]; then 630a68f8d2SRoy Marples domainname "$nd" 640a68f8d2SRoy Marples if [ -n "$ypbind_restart_cmd" ]; then 650a68f8d2SRoy Marples eval $ypbind_restart_cmd 660a68f8d2SRoy Marples fi 670a68f8d2SRoy Marples fi 680a68f8d2SRoy Marples} 690a68f8d2SRoy Marples 700a68f8d2SRoy Marplesif ! $if_configured; then 710a68f8d2SRoy Marples ; 720a68f8d2SRoy Marpleselif [ "$reason" = PREINIT ]; then 730a68f8d2SRoy Marples rm -f "$ypbind_dir/$interface".* 740a68f8d2SRoy Marpleselif $if_up || $if_down; then 750a68f8d2SRoy Marples if [ -n "$new_nis_domain" ]; then 760a68f8d2SRoy Marples if valid_domainname "$new_nis_domain"; then 770a68f8d2SRoy Marples make_yp_binding 780a68f8d2SRoy Marples else 790a68f8d2SRoy Marples syslog err "Invalid NIS domain name: $new_nis_domain" 800a68f8d2SRoy Marples fi 810a68f8d2SRoy Marples elif [ -n "$old_nis_domain" ]; then 820a68f8d2SRoy Marples restore_yp_binding 830a68f8d2SRoy Marples fi 840a68f8d2SRoy Marplesfi 85