mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-05-31 04:44:05 +02:00
Apply dns servers only if no vpn option is true
https://github.com/alexbelgium/hassio-addons/issues/2449
This commit is contained in:
@@ -9,35 +9,38 @@ set -e
|
|||||||
# Avoid usage of local dns such as adguard home or pihole\n"
|
# Avoid usage of local dns such as adguard home or pihole\n"
|
||||||
|
|
||||||
if bashio::config.has_value 'DNS_server'; then
|
if bashio::config.has_value 'DNS_server'; then
|
||||||
# Define variables
|
if ! bashio::config.is_true "openvpn_enabled" && ! bashio::config.is_true "wireguard_enabled"; then
|
||||||
DNSSERVER=$(bashio::config 'DNS_server')
|
# Define variables
|
||||||
DNS=""
|
DNSSERVER=$(bashio::config 'DNS_server')
|
||||||
DNSLIST=""
|
DNS=""
|
||||||
|
DNSLIST=""
|
||||||
# Get DNS servers
|
|
||||||
# shellcheck disable=SC2086
|
# Get DNS servers
|
||||||
for server in ${DNSSERVER//,/ }; do # Separate comma separated values
|
# shellcheck disable=SC2086
|
||||||
# Only add DNS if successful
|
for server in ${DNSSERVER//,/ }; do # Separate comma separated values
|
||||||
if ping -c 1 "$server" &> /dev/null; then
|
# Only add DNS if successful
|
||||||
DNS="${DNS}nameserver $server\n"
|
if ping -c 1 "$server" &> /dev/null; then
|
||||||
DNSLIST="$server $DNSLIST"
|
DNS="${DNS}nameserver $server\n"
|
||||||
|
DNSLIST="$server $DNSLIST"
|
||||||
|
else
|
||||||
|
bashio::log.warning "DNS $server was requested but can't be pinged. It won't be used"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Only add DNS if there are DNS set
|
||||||
|
# shellcheck disable=SC2236
|
||||||
|
if [[ -n "${DNS:-}" ]]; then
|
||||||
|
# Write resolv.conf
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
printf "${DNS}" > /etc/resolv.conf
|
||||||
|
chmod 644 /etc/resolv.conf
|
||||||
|
bashio::log.info "DNS SERVERS set to $DNSLIST"
|
||||||
else
|
else
|
||||||
bashio::log.warning "DNS $server was requested but can't be pinged. It won't be used"
|
bashio::log.warning "No valid DNS were found. Using default router (or HA) dns servers."
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
# Only add DNS if there are DNS set
|
|
||||||
# shellcheck disable=SC2236
|
|
||||||
if [[ -n "${DNS:-}" ]]; then
|
|
||||||
# Write resolv.conf
|
|
||||||
# shellcheck disable=SC2059
|
|
||||||
printf "${DNS}" > /etc/resolv.conf
|
|
||||||
chmod 644 /etc/resolv.conf
|
|
||||||
bashio::log.info "DNS SERVERS set to $DNSLIST"
|
|
||||||
else
|
else
|
||||||
bashio::log.warning "No valid DNS were found. Using default router (or HA) dns servers."
|
bashio::log.warning "DNS servers are enabled but a vpn is enabled. Resolv will be handled through the vpn script"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
bashio::log.info "DNS Servers option empty. Using default router (or HA) dns servers."
|
bashio::log.info "DNS Servers option empty. Using default router (or HA) dns servers."
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user