| 1 | #!/bin/sh -e |
| 2 | |
| 3 | # this variable is only set if the usepeerdns pppd option is being used |
| 4 | [ "$USEPEERDNS" ] || exit 0 |
| 5 | |
| 6 | # exit if the resolvconf package is installed |
| 7 | [ -x /sbin/resolvconf ] && exit 0 |
| 8 | |
| 9 | # exit if systemd-resolved is running |
| 10 | [ -e /run/systemd/system ] && \ |
| 11 | systemctl is-active --quiet systemd-resolved.service && |
| 12 | exit 0 |
| 13 | |
| 14 | case "$6" in |
| 15 | nm-*-service-*|/org/freedesktop/NetworkManager/PPP/*) |
| 16 | # NetworkManager handles it |
| 17 | exit 0 |
| 18 | ;; |
| 19 | esac |
| 20 | |
| 21 | # create the file if it does not exist |
| 22 | if [ ! -e /etc/resolv.conf ]; then |
| 23 | : > /etc/resolv.conf |
| 24 | fi |
| 25 | |
| 26 | # follow any symlink to find the real file |
| 27 | REALRESOLVCONF=$(readlink --canonicalize /etc/resolv.conf) |
| 28 | |
| 29 | # merge the new nameservers with the other options from the old configuration |
| 30 | { |
| 31 | echo '# PPP: This file was written by /etc/ppp/ip-up.d/0000usepeerdns.' |
| 32 | echo '# PPP: The following entries were obtained using PPP:' |
| 33 | cat /etc/ppp/resolv.conf |
| 34 | echo '# PPP: End of section rewritten by 0000usepeerdns.' |
| 35 | grep -vE "^(nameserver[[:space:]]|# PPP: )" "$REALRESOLVCONF" || true |
| 36 | } > "$REALRESOLVCONF.tmp" |
| 37 | |
| 38 | # backup the old configuration and install the new one |
| 39 | cp -a "$REALRESOLVCONF" "$REALRESOLVCONF.pppd-backup.$PPP_IFACE" |
| 40 | mv -f "$REALRESOLVCONF.tmp" "$REALRESOLVCONF" |
| 41 | |
| 42 | # restart nscd because resolv.conf has changed |
| 43 | if [ -e /var/run/nscd.pid ]; then |
| 44 | /etc/init.d/nscd restart || true |
| 45 | fi |
| 46 | |
| 47 | exit 0 |