Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to create Unbound forwarding configs. #187

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletions scripts/create-unbound.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@ if [ $out -gt 0 ] ; then
exit 1
fi

forward=false
if [ ${1} == --forward ]; then
forward=true
fi

cachenamedefault="disabled"

while read line; do
while read line; do
ip=$(jq ".ips[\"${line}\"]" config.json)
declare "cacheip$line"="$ip"
done <<< $(jq -r '.ips | to_entries[] | .key' config.json)

while read line; do
while read line; do
name=$(jq -r ".cache_domains[\"${line}\"]" config.json)
declare "cachename$line"="$name"
done <<< $(jq -r '.cache_domains | to_entries[] | .key' config.json)

rm -rf ${outputdir}
mkdir -p ${outputdir}
while read entry; do
while read entry; do
unset cacheip
unset cachename
key=$(jq -r ".cache_domains[$entry].name" $path)
Expand All @@ -45,22 +50,47 @@ while read entry; do
destfilename=$(echo $filename | sed -e 's/txt/conf/')
outputfile=${outputdir}/${destfilename}
touch $outputfile

if $forward; then
echo 'forward-zone:' > $outputfile
echo " name: \"${key}.cache.lancache.net.\"" >> $outputfile
for i in ${cacheip}; do
echo " forward-addr: \"${i}\"" >> $outputfile
done
echo " forward-first: yes" >> $outputfile
echo " forward-no-cache: yes" >> $outputfile
fi

while read fileentry; do
# Ignore comments and newlines
if [[ $fileentry == \#* ]] || [[ -z $fileentry ]]; then
continue
fi
parsed=$(echo $fileentry | sed -e "s/^\*\.//")
if grep -qx " local-zone: \"${parsed}\" redirect" $outputfile; then
continue

if $forward; then
if grep -qx " name: \"${parsed}\"" $outputfile; then
continue
fi
echo 'forward-zone:' >> $outputfile
echo " name: \"${parsed}.\"" >> $outputfile
for i in ${cacheip}; do
echo " forward-addr: \"${i}\"" >> $outputfile
done
echo " forward-first: yes" >> $outputfile
echo " forward-no-cache: yes" >> $outputfile
else
if grep -qx " local-zone: \"${parsed}\" redirect" $outputfile; then
continue
fi
if [[ $(head -n 1 $outputfile) != "server:" ]]; then
echo "server:" >> $outputfile
fi
echo " local-zone: \"${parsed}\" redirect" >> $outputfile
for i in ${cacheip}; do
echo " local-data: \"${parsed} 30 IN A ${i}\"" >> $outputfile
done
fi
if [[ $(head -n 1 $outputfile) != "server:" ]]; then
echo "server:" >> $outputfile
fi
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);
done <<< $(jq -r ".cache_domains[$entry].domain_files[$fileid]" $path)
done <<< $(jq -r ".cache_domains[$entry].domain_files | to_entries[] | .key" $path)
Expand Down