Additionally, exit script if 0 valid entries are detected

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
Adam Warner 2021-04-16 23:19:58 +01:00
parent 14e3bcb480
commit f6b9716a75
No known key found for this signature in database
GPG Key ID: 872950F3ECF2B173
1 changed files with 7 additions and 0 deletions

View File

@ -99,14 +99,21 @@ if [ -n "${PIHOLE_DNS_}" ]; then
# Split into an array (delimited by ;)
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))
else
echo "Invalid IP detected in PIHOLE_DNS_: ${i}"
fi
done
if [ $valid_entries -eq 0 ]; then
echo "No Valid IPs dectected 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
# if this is the case, we do not want to overwrite these with the defaults of 8.8.8.8 and 8.8.4.4