1*0a68f8d2SRoy Marples# Sample dhcpcd hook for ypbind 2*0a68f8d2SRoy Marples# This script is only suitable for the BSD versions. 3*0a68f8d2SRoy Marples 4*0a68f8d2SRoy Marples: ${ypbind_restart_cmd:=service_command ypbind restart} 5*0a68f8d2SRoy Marples: ${ypbind_stop_cmd:=service_condcommand ypbind stop} 6*0a68f8d2SRoy Marplesypbind_dir="$state_dir/ypbind" 7*0a68f8d2SRoy Marples: ${ypdomain_dir:=} 8*0a68f8d2SRoy Marples: ${ypdomain_suffix:=} 9*0a68f8d2SRoy Marples 10*0a68f8d2SRoy Marplesbest_domain() 11*0a68f8d2SRoy Marples{ 12*0a68f8d2SRoy Marples for i in "$ypbind_dir/$interface_order".*; do 13*0a68f8d2SRoy Marples if [ -f "$i" ]; then 14*0a68f8d2SRoy Marples cat "$i" 15*0a68f8d2SRoy Marples return 0 16*0a68f8d2SRoy Marples fi 17*0a68f8d2SRoy Marples done 18*0a68f8d2SRoy Marples return 1 19*0a68f8d2SRoy Marples} 20*0a68f8d2SRoy Marples 21*0a68f8d2SRoy Marplesmake_yp_binding() 22*0a68f8d2SRoy Marples{ 23*0a68f8d2SRoy Marples [ -d "$ypbind_dir" ] || mkdir -p "$ypbind_dir" 24*0a68f8d2SRoy Marples echo "$new_nis_domain" >"$ypbind_dir/$ifname" 25*0a68f8d2SRoy Marples 26*0a68f8d2SRoy Marples if [ -z "$ypdomain_dir" ]; then 27*0a68f8d2SRoy Marples false 28*0a68f8d2SRoy Marples else 29*0a68f8d2SRoy Marples cf="$ypdomain_dir/$new_nis_domain$ypdomain_suffix" 30*0a68f8d2SRoy Marples if [ -n "$new_nis_servers" ]; then 31*0a68f8d2SRoy Marples ncf="$cf.$ifname" 32*0a68f8d2SRoy Marples rm -f "$ncf" 33*0a68f8d2SRoy Marples for x in $new_nis_servers; do 34*0a68f8d2SRoy Marples echo "$x" >>"$ncf" 35*0a68f8d2SRoy Marples done 36*0a68f8d2SRoy Marples change_file "$cf" "$ncf" 37*0a68f8d2SRoy Marples else 38*0a68f8d2SRoy Marples [ -e "$cf" ] && rm "$cf" 39*0a68f8d2SRoy Marples fi 40*0a68f8d2SRoy Marples fi 41*0a68f8d2SRoy Marples 42*0a68f8d2SRoy Marples nd="$(best_domain)" 43*0a68f8d2SRoy Marples if [ $? = 0 ] && [ "$nd" != "$(domainname)" ]; then 44*0a68f8d2SRoy Marples domainname "$nd" 45*0a68f8d2SRoy Marples if [ -n "$ypbind_restart_cmd" ]; then 46*0a68f8d2SRoy Marples eval $ypbind_restart_cmd 47*0a68f8d2SRoy Marples fi 48*0a68f8d2SRoy Marples fi 49*0a68f8d2SRoy Marples} 50*0a68f8d2SRoy Marples 51*0a68f8d2SRoy Marplesrestore_yp_binding() 52*0a68f8d2SRoy Marples{ 53*0a68f8d2SRoy Marples rm -f "$ypbind_dir/$ifname" 54*0a68f8d2SRoy Marples nd="$(best_domain)" 55*0a68f8d2SRoy Marples # We need to stop ypbind if there is no best domain 56*0a68f8d2SRoy Marples # otherwise it will just stall as we cannot set domainname 57*0a68f8d2SRoy Marples # to blank :/ 58*0a68f8d2SRoy Marples if [ -z "$nd" ]; then 59*0a68f8d2SRoy Marples if [ -n "$ypbind_stop_cmd" ]; then 60*0a68f8d2SRoy Marples eval $ypbind_stop_cmd 61*0a68f8d2SRoy Marples fi 62*0a68f8d2SRoy Marples elif [ "$nd" != "$(domainname)" ]; then 63*0a68f8d2SRoy Marples domainname "$nd" 64*0a68f8d2SRoy Marples if [ -n "$ypbind_restart_cmd" ]; then 65*0a68f8d2SRoy Marples eval $ypbind_restart_cmd 66*0a68f8d2SRoy Marples fi 67*0a68f8d2SRoy Marples fi 68*0a68f8d2SRoy Marples} 69*0a68f8d2SRoy Marples 70*0a68f8d2SRoy Marplesif ! $if_configured; then 71*0a68f8d2SRoy Marples ; 72*0a68f8d2SRoy Marpleselif [ "$reason" = PREINIT ]; then 73*0a68f8d2SRoy Marples rm -f "$ypbind_dir/$interface".* 74*0a68f8d2SRoy Marpleselif $if_up || $if_down; then 75*0a68f8d2SRoy Marples if [ -n "$new_nis_domain" ]; then 76*0a68f8d2SRoy Marples if valid_domainname "$new_nis_domain"; then 77*0a68f8d2SRoy Marples make_yp_binding 78*0a68f8d2SRoy Marples else 79*0a68f8d2SRoy Marples syslog err "Invalid NIS domain name: $new_nis_domain" 80*0a68f8d2SRoy Marples fi 81*0a68f8d2SRoy Marples elif [ -n "$old_nis_domain" ]; then 82*0a68f8d2SRoy Marples restore_yp_binding 83*0a68f8d2SRoy Marples fi 84*0a68f8d2SRoy Marplesfi 85