/ppp/ip-up.d/0000usepeerdns

http://github.com/brinkman83/bashrc · Shell · 33 lines · 16 code · 9 blank · 8 comment · 6 complexity · 47b1eee2bd4e9e492ad5a9f5870ca272 MD5 · raw file

  1. #!/bin/sh -e
  2. # this variable is only set if the usepeerdns pppd option is being used
  3. [ "$USEPEERDNS" ] || exit 0
  4. # exit if the resolvconf package is installed
  5. [ -x /sbin/resolvconf ] && exit 0
  6. # create the file if it does not exist
  7. if [ ! -e /etc/resolv.conf ]; then
  8. : > /etc/resolv.conf
  9. fi
  10. # follow any symlink to find the real file
  11. REALRESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)
  12. # merge the new nameservers with the other options from the old configuration
  13. {
  14. cat /etc/ppp/resolv.conf
  15. grep --invert-match '^nameserver[[:space:]]' "$REALRESOLVCONF" || true
  16. } > "$REALRESOLVCONF.tmp"
  17. # backup the old configuration and install the new one
  18. cp -a "$REALRESOLVCONF" "$REALRESOLVCONF.pppd-backup"
  19. mv -f "$REALRESOLVCONF.tmp" "$REALRESOLVCONF"
  20. # restart nscd because resolv.conf has changed
  21. if [ -e /var/run/nscd.pid ]; then
  22. /etc/init.d/nscd restart || true
  23. fi
  24. exit 0