/dhcp3/dhclient-enter-hooks.d/resolvconf

http://github.com/brinkman83/bashrc · #! · 48 lines · 46 code · 2 blank · 0 comment · 0 complexity · 13b12445d1dd17c08b2cc941ef3d6eb8 MD5 · raw file

  1. #
  2. # Script fragment to make dhclient3 work with resolvconf
  3. #
  4. # Licensed under the GNU GPL. See /usr/share/common-licenses/GPL.
  5. #
  6. # Tips:
  7. # * Be careful about changing the environment since this is sourced
  8. # * This script fragment uses bash features
  9. if [ -x /sbin/resolvconf ] ; then
  10. # Do stuff now
  11. case "$reason" in
  12. EXPIRE|FAIL|RELEASE|STOP) # and TIMEOUT too ??
  13. # Delete resolv.conf info
  14. [ ! "$interface" ] || /sbin/resolvconf -d "$interface"
  15. ;;
  16. esac
  17. # For safety, undefine the nasty default make_resolv_conf()
  18. make_resolv_conf() {
  19. true
  20. }
  21. # Define a resolvconf-compatible m_r_c() function which gets run later
  22. # (or, in the TIMEOUT case, MAY get run later)
  23. case "$reason" in
  24. BOUND|RENEW|REBIND|REBOOT|TIMEOUT)
  25. make_resolv_conf() {
  26. R=""
  27. if [ "$new_domain_name_servers" ] && [ "$new_domain_name" ] ; then
  28. R="${R}domain $new_domain_name
  29. "
  30. fi
  31. if [ "$new_domain_name_servers" ] && [ "$new_domain_search" ] ; then
  32. # The replacement below works around a bug with dhclient 3.1.0 which
  33. # separates items with the four characters backslash-zero-three-two
  34. # instead of with a space
  35. R="${R}search ${new_domain_search//\\032/ }
  36. "
  37. fi
  38. for nameserver in $new_domain_name_servers ; do
  39. R="${R}nameserver $nameserver
  40. "
  41. done
  42. [ ! "$interface" ] || echo -n "$R" | /sbin/resolvconf -a "$interface"
  43. }
  44. ;;
  45. esac
  46. fi