From 84e9a378b3ac00730c7f96495b43f4ef1f8265f7 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 17 Jan 2021 19:42:17 +0100 Subject: [PATCH] create-unbound.sh and create-unbound.sh will now ignore empty entries, which may result into corrupt config files causing at least unbound (and probably also dnsmasq) to fail starting up https://github.com/uklans/cache-domains/issues/157 --- scripts/create-dnsmasq.sh | 4 ++++ scripts/create-unbound.sh | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/scripts/create-dnsmasq.sh b/scripts/create-dnsmasq.sh index b3e054d..8fe1e66 100755 --- a/scripts/create-dnsmasq.sh +++ b/scripts/create-dnsmasq.sh @@ -69,6 +69,10 @@ while read -r entry; do continue fi parsed=$(echo $fileentry) + # Ignore empty lines + if [[ -z "$parsed" ]]; then + continue + fi if grep -qx "$parsed" "$outputfile"; then continue fi diff --git a/scripts/create-unbound.sh b/scripts/create-unbound.sh index 32f64c3..3507167 100755 --- a/scripts/create-unbound.sh +++ b/scripts/create-unbound.sh @@ -42,6 +42,7 @@ while read entry; do cacheip=$(jq -r 'if type == "array" then .[] else . end' <<< ${!cacheipname} | xargs) while read fileid; do while read filename; do + isvalid=false destfilename=$(echo $filename | sed -e 's/txt/conf/') outputfile=${outputdir}/${destfilename} touch $outputfile @@ -52,14 +53,23 @@ while read entry; do continue fi parsed=$(echo $fileentry | sed -e "s/^\*\.//") + # Ignore empty lines + if [[ -z "$parsed" ]]; then + continue + fi if grep -qx "$parsed" $outputfile; then continue fi + isvalid=true echo " local-zone: \"${parsed}\" redirect" >> $outputfile for i in ${cacheip}; do echo " local-data: \"${parsed} 30 IN A ${i}\"" >> $outputfile done done <<< $(cat ${basedir}/$filename | sort); + # Delete files with no entries + if [[ $isvalid == false ]]; then + rm $outputfile + fi done <<< $(jq -r ".cache_domains[$entry].domain_files[$fileid]" $path) done <<< $(jq -r ".cache_domains[$entry].domain_files | to_entries[] | .key" $path) done <<< $(jq -r '.cache_domains | to_entries[] | .key' $path)