Fix generation scripts

This change leverages #130 and also applies this to the dnsmasq script.

As it currently stands both generation scripts (unbound and dnsmasq) have a condition where a domain will be skipped if it fuzzy matches a domain already parsed that is higher in the CDN domain list.

For example the latter of the below two samples would never be added.
8793ce1531/steam.txt (L20) 8793ce1531/steam.txt (L29)

I've also taken the liberty to sort the output of said scripts for readability and troubleshooting purposes.

Closes #130.
This commit is contained in:
Amir Zarrinkafsh 2020-10-29 23:05:45 +11:00
parent 8793ce1531
commit 74cab757af
No known key found for this signature in database
GPG Key ID: ECDB8EF9E77E4EBF
2 changed files with 12 additions and 12 deletions

View File

@ -50,32 +50,32 @@ while read -r entry; do
touch "$outputfile" touch "$outputfile"
# Wildcard entries # Wildcard entries
while read -r fileentry; do while read -r fileentry; do
# Ignore comments # Ignore comments and non-wildcards
if [[ $fileentry == \#* ]]; then if [[ $fileentry == \#* ]] || [[ ! $fileentry =~ ^\*\. ]]; then
continue continue
fi fi
wildcard=$(echo $fileentry | grep "*." | sed -e "s/^\*\.//") wildcard=$(echo $fileentry | sed -e "s/^\*\.//")
if grep -q "$wildcard" "$lancacheconf"; then if grep -qx "$wildcard" "$lancacheconf"; then
continue continue
fi fi
for i in ${cacheip}; do for i in ${cacheip}; do
echo "address=/${wildcard}/${i}" >> "$lancacheconf" echo "address=/${wildcard}/${i}" >> "$lancacheconf"
done done
done <<< $(cat ${basedir}/$filename); done <<< $(cat ${basedir}/$filename | sort);
# All other entries # All other entries
while read -r fileentry; do while read -r fileentry; do
# Ignore comments # Ignore comments and wildcards
if [[ $fileentry == \#* ]]; then if [[ $fileentry =~ ^(\#|\*\.) ]]; then
continue continue
fi fi
parsed=$(echo $fileentry | sed -e "s/^\*\.//") parsed=$(echo $fileentry)
if grep -q "$parsed" "$outputfile"; then if grep -qx "$parsed" "$outputfile"; then
continue continue
fi fi
for i in ${cacheip}; do for i in ${cacheip}; do
echo "${i} ${parsed}" >> "$outputfile" echo "${i} ${parsed}" >> "$outputfile"
done done
done <<< $(cat ${basedir}/$filename); done <<< $(cat ${basedir}/$filename | sort);
done <<< $(jq -r ".cache_domains[$entry].domain_files[$fileid]" $path) 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[$entry].domain_files | to_entries[] | .key" $path)
done <<< $(jq -r '.cache_domains | to_entries[] | .key' $path) done <<< $(jq -r '.cache_domains | to_entries[] | .key' $path)

View File

@ -52,14 +52,14 @@ while read entry; do
continue continue
fi fi
parsed=$(echo $fileentry | sed -e "s/^\*\.//") parsed=$(echo $fileentry | sed -e "s/^\*\.//")
if grep -q "$parsed" $outputfile; then if grep -qx "$parsed" $outputfile; then
continue continue
fi fi
echo " local-zone: \"${parsed}\" redirect" >> $outputfile echo " local-zone: \"${parsed}\" redirect" >> $outputfile
for i in ${cacheip}; do for i in ${cacheip}; do
echo " local-data: \"${parsed} 30 IN A ${i}\"" >> $outputfile echo " local-data: \"${parsed} 30 IN A ${i}\"" >> $outputfile
done done
done <<< $(cat ${basedir}/$filename); done <<< $(cat ${basedir}/$filename | sort);
done <<< $(jq -r ".cache_domains[$entry].domain_files[$fileid]" $path) 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[$entry].domain_files | to_entries[] | .key" $path)
done <<< $(jq -r '.cache_domains | to_entries[] | .key' $path) done <<< $(jq -r '.cache_domains | to_entries[] | .key' $path)