| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. -e |
| 2 | |
| 3 | # this variable is only set if the usepeerdns pppd option is being used |
| 4 | [scip-shell system . . `[`. "$USEPEERDNS" ] || exit 0 |
| 5 | |
| 6 | # exit if the resolvconf package is installed |
| 7 | [scip-shell system . . `[`. -x /sbin/resolvconfscip-shell filesystem . . `/sbin/resolvconf`. ] && exit 0 |
| 8 | |
| 9 | # exit if systemd-resolved is running |
| 10 | [scip-shell system . . `[`. -e /run/systemd/systemscip-shell filesystem . . `/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 [scip-shell system . . `[`. ! -e /etc/resolv.confscip-shell filesystem . . `/etc/resolv.conf`. ]; then |
| 23 | : > /etc/resolv.confscip-shell filesystem . . `/etc/resolv.conf`. |
| 24 | fi |
| 25 | |
| 26 | # follow any symlink to find the real file |
| 27 | REALRESOLVCONF=$(readlinkscip-shell system . . readlink. --canonicalize /etc/resolv.confscip-shell filesystem . . `/etc/resolv.conf`.) |
| 28 | |
| 29 | # merge the new nameservers with the other options from the old configuration |
| 30 | { |
| 31 | echoscip-shell system . . echo. '# PPP: This file was written by /etc/ppp/ip-up.d/0000usepeerdns.' |
| 32 | echoscip-shell system . . echo. '# PPP: The following entries were obtained using PPP:' |
| 33 | catscip-shell system . . cat. /etc/ppp/resolv.confscip-shell filesystem . . `/etc/ppp/resolv.conf`. |
| 34 | echoscip-shell system . . echo. '# PPP: End of section rewritten by 0000usepeerdns.' |
| 35 | grepscip-shell system . . grep. -vE "^(nameserver[[:space:]]|# PPP: )" "$REALRESOLVCONF" || truescip-shell system . . true. |
| 36 | } > "$REALRESOLVCONF.tmp" |
| 37 | |
| 38 | # backup the old configuration and install the new one |
| 39 | cpscip-shell system . . cp. -a "$REALRESOLVCONF" "$REALRESOLVCONF.pppd-backup.$PPP_IFACE" |
| 40 | mvscip-shell system . . mv. -f "$REALRESOLVCONF.tmp" "$REALRESOLVCONF" |
| 41 | |
| 42 | # restart nscd because resolv.conf has changed |
| 43 | if [scip-shell system . . `[`. -e /var/run/nscd.pidscip-shell filesystem . . `/var/run/nscd.pid`. ]; then |
| 44 | /etc/init.d/nscdscip-shell filesystem . . `/etc/init.d/nscd`. restart || truescip-shell system . . true. |
| 45 | fi |
| 46 | |
| 47 | exit 0 |