Merge pull request #113 from neheb/h

create-dnsmasq: Run through shellcheck
This commit is contained in:
James Kinsman 2019-10-13 20:47:10 +01:00 committed by GitHub
commit 8006f08125
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,19 +15,19 @@ fi
cachenamedefault="disabled" cachenamedefault="disabled"
while read line; do while read -r line; do
ip=$(jq ".ips[\"${line}\"]" config.json) ip=$(jq ".ips[\"${line}\"]" config.json)
declare "cacheip$line"="$ip" declare "cacheip$line"="$ip"
done <<< $(jq -r '.ips | to_entries[] | .key' config.json) done <<< $(jq -r '.ips | to_entries[] | .key' config.json)
while read line; do while read -r line; do
name=$(jq -r ".cache_domains[\"${line}\"]" config.json) name=$(jq -r ".cache_domains[\"${line}\"]" config.json)
declare "cachename$line"="$name" declare "cachename$line"="$name"
done <<< $(jq -r '.cache_domains | to_entries[] | .key' config.json) done <<< $(jq -r '.cache_domains | to_entries[] | .key' config.json)
rm -rf ${outputdir} rm -rf ${outputdir}
mkdir -p ${outputdir} mkdir -p ${outputdir}
while read entry; do while read -r entry; do
unset cacheip unset cacheip
unset cachename unset cachename
key=$(jq -r ".cache_domains[$entry].name" $path) key=$(jq -r ".cache_domains[$entry].name" $path)
@ -40,22 +40,22 @@ while read entry; do
fi fi
cacheipname="cacheip${!cachename}" cacheipname="cacheip${!cachename}"
cacheip=$(jq -r 'if type == "array" then .[] else . end' <<< ${!cacheipname} | xargs) cacheip=$(jq -r 'if type == "array" then .[] else . end' <<< ${!cacheipname} | xargs)
while read fileid; do while read -r fileid; do
while read filename; do while read -r filename; do
destfilename=$(echo $filename | sed -e 's/txt/conf/') destfilename=$(echo $filename | sed -e 's/txt/conf/')
outputfile=${outputdir}/${destfilename} outputfile=${outputdir}/${destfilename}
touch $outputfile touch "$outputfile"
while read fileentry; do while read -r fileentry; do
# Ignore comments # Ignore comments
if [[ $fileentry == \#* ]]; then if [[ $fileentry == \#* ]]; then
continue continue
fi fi
parsed=$(echo $fileentry | sed -e "s/^\*\.//") parsed=$(echo $fileentry | sed -e "s/^\*\.//")
if grep -q "$parsed" $outputfile; then if grep -q "$parsed" "$outputfile"; then
continue continue
fi fi
for i in ${cacheip}; do for i in ${cacheip}; do
echo "address=/${parsed}/${i}" >> $outputfile echo "address=/${parsed}/${i}" >> "$outputfile"
done done
done <<< $(cat ${basedir}/$filename); done <<< $(cat ${basedir}/$filename);
done <<< $(jq -r ".cache_domains[$entry].domain_files[$fileid]" $path) done <<< $(jq -r ".cache_domains[$entry].domain_files[$fileid]" $path)