Test for empty values in the PIHOLE_DNS_ array, skip if it's empty
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
parent
1daeb117cb
commit
939a69b895
|
@ -267,39 +267,41 @@ setup_FTL_upstream_DNS(){
|
|||
# Split into an array (delimited by ;)
|
||||
# Loop through and add them one by one to setupVars.conf
|
||||
IFS=";" read -r -a PIHOLE_DNS_ARR <<< "${PIHOLE_DNS_}"
|
||||
# PIHOLE_DNS_ARR=(${PIHOLE_DNS_//;/ })
|
||||
count=1
|
||||
valid_entries=0
|
||||
for i in "${PIHOLE_DNS_ARR[@]}"; do
|
||||
if valid_ip "$i" || valid_ip6 "$i" ; then
|
||||
change_setting "PIHOLE_DNS_$count" "$i"
|
||||
((count=count+1))
|
||||
((valid_entries=valid_entries+1))
|
||||
continue
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
if [ -n "$(dig +short ${i//#*/})" ]; then
|
||||
# If the "address" is a domain (for example a docker link) then try to resolve it and add
|
||||
# the result as a DNS server in setupVars.conf.
|
||||
resolved_ip="$(dig +short ${i//#*/} | head -n 1)"
|
||||
if [ -n "${i//*#/}" ] && [ "${i//*#/}" != "${i//#*/}" ]; then
|
||||
resolved_ip="${resolved_ip}#${i//*#/}"
|
||||
fi
|
||||
echo "Resolved ${i} from PIHOLE_DNS_ as: ${resolved_ip}"
|
||||
if valid_ip "$resolved_ip" || valid_ip6 "$resolved_ip" ; then
|
||||
change_setting "PIHOLE_DNS_$count" "$resolved_ip"
|
||||
# Ensure we don't have an empty value first (see https://github.com/pi-hole/docker-pi-hole/issues/1174#issuecomment-1228763422 )
|
||||
if [ -n "$i" ]; then
|
||||
if valid_ip "$i" || valid_ip6 "$i" ; then
|
||||
change_setting "PIHOLE_DNS_$count" "$i"
|
||||
((count=count+1))
|
||||
((valid_entries=valid_entries+1))
|
||||
continue
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
if [ -n "$(dig +short ${i//#*/})" ]; then
|
||||
# If the "address" is a domain (for example a docker link) then try to resolve it and add
|
||||
# the result as a DNS server in setupVars.conf.
|
||||
resolved_ip="$(dig +short ${i//#*/} | head -n 1)"
|
||||
if [ -n "${i//*#/}" ] && [ "${i//*#/}" != "${i//#*/}" ]; then
|
||||
resolved_ip="${resolved_ip}#${i//*#/}"
|
||||
fi
|
||||
echo "Resolved ${i} from PIHOLE_DNS_ as: ${resolved_ip}"
|
||||
if valid_ip "$resolved_ip" || valid_ip6 "$resolved_ip" ; then
|
||||
change_setting "PIHOLE_DNS_$count" "$resolved_ip"
|
||||
((count=count+1))
|
||||
((valid_entries=valid_entries+1))
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
# If the above tests fail then this is an invalid DNS server
|
||||
echo "Invalid entry detected in PIHOLE_DNS_: ${i}"
|
||||
fi
|
||||
fi
|
||||
# If the above tests fail then this is an invalid DNS server
|
||||
echo "Invalid entry detected in PIHOLE_DNS_: ${i}"
|
||||
done
|
||||
|
||||
if [ $valid_entries -eq 0 ]; then
|
||||
echo "No Valid entries detected in PIHOLE_DNS_. Aborting"
|
||||
exit 1
|
||||
echo "No Valid entries detected in PIHOLE_DNS_. Aborting"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# Environment variable has not been set, but there may be existing values in an existing setupVars.conf
|
||||
|
|
Loading…
Reference in New Issue