2017-10-31 10:38:09 +00:00
|
|
|
set_dns() {
|
|
|
|
[[ ${#DNS[@]} -gt 0 ]] || return 0
|
|
|
|
|
|
|
|
if [[ $(resolvconf --version 2>/dev/null) == openresolv\ * ]]; then
|
2020-05-09 05:15:50 +00:00
|
|
|
{ printf 'nameserver %s\n' "${DNS[@]}"
|
|
|
|
[[ ${#DNS_SEARCH[@]} -eq 0 ]] || printf 'search %s\n' "${DNS_SEARCH[*]}"
|
|
|
|
} | cmd resolvconf -a "$INTERFACE" -m 0 -x
|
2017-10-31 10:38:09 +00:00
|
|
|
else
|
|
|
|
echo "[#] mount \`${DNS[*]}' /etc/resolv.conf" >&2
|
|
|
|
[[ -e /etc/resolv.conf ]] || touch /etc/resolv.conf
|
|
|
|
{ cat <<-_EOF
|
|
|
|
# This file was generated by wg-quick(8) for use with
|
|
|
|
# the WireGuard interface $INTERFACE. It cannot be
|
|
|
|
# removed or altered directly. You may remove this file
|
|
|
|
# by running \`wg-quick down $INTERFACE', or if that
|
|
|
|
# poses problems, run \`umount /etc/resolv.conf'.
|
|
|
|
|
|
|
|
_EOF
|
|
|
|
printf 'nameserver %s\n' "${DNS[@]}"
|
2020-05-09 05:15:50 +00:00
|
|
|
[[ ${#DNS_SEARCH[@]} -eq 0 ]] || printf 'search %s\n' "${DNS_SEARCH[*]}"
|
2017-10-31 10:38:09 +00:00
|
|
|
} | unshare -m --propagation shared bash -c "$(cat <<-_EOF
|
|
|
|
set -e
|
2018-06-16 22:06:58 +00:00
|
|
|
context="\$(stat -c %C /etc/resolv.conf 2>/dev/null)" || unset context
|
2017-10-31 10:38:09 +00:00
|
|
|
mount --make-private /dev/shm
|
|
|
|
mount -t tmpfs none /dev/shm
|
|
|
|
cat > /dev/shm/resolv.conf
|
2018-06-16 22:06:58 +00:00
|
|
|
[[ -z \$context || \$context == "?" ]] || chcon "\$context" /dev/shm/resolv.conf 2>/dev/null || true
|
2017-10-31 10:38:09 +00:00
|
|
|
mount -o remount,ro /dev/shm
|
|
|
|
mount -o bind,ro /dev/shm/resolv.conf /etc/resolv.conf
|
|
|
|
_EOF
|
|
|
|
)"
|
|
|
|
fi
|
|
|
|
HAVE_SET_DNS=1
|
|
|
|
}
|
|
|
|
|
|
|
|
unset_dns() {
|
|
|
|
[[ ${#DNS[@]} -gt 0 ]] || return 0
|
|
|
|
|
|
|
|
if [[ $(resolvconf --version 2>/dev/null) == openresolv\ * ]]; then
|
|
|
|
cmd resolvconf -d "$INTERFACE"
|
|
|
|
else
|
|
|
|
cmd umount /etc/resolv.conf
|
|
|
|
fi
|
|
|
|
}
|