mirror of
https://github.com/uklans/cache-domains
synced 2024-11-24 20:33:03 +00:00
Merge pull request #174 from nightah/update-dnsmasq-roundrobin
Simplify Dnsmasq script
This commit is contained in:
commit
cfcdf1b7c5
2 changed files with 18 additions and 44 deletions
|
@ -39,11 +39,4 @@ configuration which can be utilised with:
|
||||||
|
|
||||||
**This also applies to users utilising the script alongside Pi-hole.**
|
**This also applies to users utilising the script alongside Pi-hole.**
|
||||||
|
|
||||||
If utilising the `create-dnsmasq.sh` the generation script will create a `lancache.conf` which also loads in the respective `*.hosts` files.
|
Multi-IP Lancache setups are only supported with Dnsmasq or Pi-hole versions >= 2.86 or 2021.09 respectively.
|
||||||
|
|
||||||
The `lancache.conf` should be copied into the `/etc/dnsmasq.d/` location but also will need to be modified to point to the respective location of the `*.hosts` files.
|
|
||||||
|
|
||||||
You can copy the `*.hosts` file to any location other than `/etc/dnsmasq.d/` as this location is utilised only for `*.conf` files.
|
|
||||||
|
|
||||||
For example if utilising Pi-hole a user can copy the `*.hosts` files to `/etc/pihole/` and modify the `lancache.conf` with the following command, prior to copying it to `/etc/dnsmasq.d/`:
|
|
||||||
`sed -i 's/dnsmasq\/hosts/pihole/g' output/dnsmasq/lancache.conf`
|
|
|
@ -17,17 +17,16 @@ cachenamedefault="disabled"
|
||||||
|
|
||||||
while read -r 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 -r 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}/hosts
|
mkdir -p ${outputdir}
|
||||||
touch ${outputdir}/lancache.conf
|
|
||||||
while read -r entry; do
|
while read -r entry; do
|
||||||
unset cacheip
|
unset cacheip
|
||||||
unset cachename
|
unset cachename
|
||||||
|
@ -43,47 +42,29 @@ while read -r entry; do
|
||||||
cacheip=$(jq -r 'if type == "array" then .[] else . end' <<< ${!cacheipname} | xargs)
|
cacheip=$(jq -r 'if type == "array" then .[] else . end' <<< ${!cacheipname} | xargs)
|
||||||
while read -r fileid; do
|
while read -r fileid; do
|
||||||
while read -r filename; do
|
while read -r filename; do
|
||||||
destfilename=$(echo $filename | sed -e 's/txt/hosts/')
|
destfilename=$(echo $filename | sed -e 's/txt/conf/')
|
||||||
lancacheconf=${outputdir}/lancache.conf
|
outputfile=${outputdir}/${destfilename}
|
||||||
outputfile=${outputdir}/hosts/${destfilename}
|
touch ${outputfile}
|
||||||
echo "addn-hosts=/etc/dnsmasq/hosts/${destfilename}" >> ${lancacheconf}
|
|
||||||
touch "$outputfile"
|
|
||||||
# Wildcard entries
|
|
||||||
while read -r fileentry; do
|
|
||||||
# Ignore comments and non-wildcards
|
|
||||||
if [[ $fileentry == \#* ]] || [[ ! $fileentry =~ ^\*\. ]]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
wildcard=$(echo $fileentry | sed -e "s/^\*\.//")
|
|
||||||
if grep -qx "$wildcard" "$lancacheconf"; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
for i in ${cacheip}; do
|
|
||||||
echo "address=/${wildcard}/${i}" >> "$lancacheconf"
|
|
||||||
done
|
|
||||||
done <<< $(cat ${basedir}/$filename | sort);
|
|
||||||
# All other entries
|
|
||||||
while read -r fileentry; do
|
while read -r fileentry; do
|
||||||
# Ignore comments, newlines and wildcards
|
# Ignore comments, newlines and wildcards
|
||||||
if [[ $fileentry =~ ^(\#|\*\.) ]] || [[ -z $fileentry ]]; then
|
if [[ ${fileentry} == \#* ]] || [[ -z ${fileentry} ]]; then
|
||||||
continue
|
|
||||||
fi
|
|
||||||
parsed=$(echo $fileentry)
|
|
||||||
if grep -qx "$parsed" "$outputfile"; then
|
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
parsed=$(echo ${fileentry} | sed -e "s/^\*\.//")
|
||||||
for i in ${cacheip}; do
|
for i in ${cacheip}; do
|
||||||
echo "${i} ${parsed}" >> "$outputfile"
|
if grep -qx "address=/${parsed}/${i}" "${outputfile}"; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
echo "address=/${parsed}/${i}" >> "${outputfile}"
|
||||||
done
|
done
|
||||||
done <<< $(cat ${basedir}/$filename | sort);
|
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})
|
||||||
|
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Configuration generation completed.
|
Configuration generation completed.
|
||||||
|
|
||||||
Please copy the following files:
|
Please copy the following files:
|
||||||
- ./${outputdir}/lancache.conf to /etc/dnsmasq/dnsmasq.d/
|
- ./${outputdir}/*.conf to /etc/dnsmasq/dnsmasq.d/
|
||||||
- ./${outputdir}/hosts to /etc/dnsmasq/
|
|
||||||
EOF
|
EOF
|
||||||
|
|
Loading…
Reference in a new issue