mirror of
				https://github.com/uklans/cache-domains
				synced 2025-11-04 13:08:53 +01:00 
			
		
		
		
	Merge branch 'master' of github.com:uklans/cache-domains
This commit is contained in:
		
						commit
						7309c7d057
					
				@ -39,11 +39,4 @@ configuration which can be utilised with:
 | 
			
		||||
 | 
			
		||||
**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.
 | 
			
		||||
 | 
			
		||||
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`
 | 
			
		||||
Multi-IP Lancache setups are only supported with Dnsmasq or Pi-hole versions >= 2.86 or 2021.09 respectively.
 | 
			
		||||
@ -17,17 +17,16 @@ cachenamedefault="disabled"
 | 
			
		||||
 | 
			
		||||
while read -r line; do
 | 
			
		||||
        ip=$(jq ".ips[\"${line}\"]" config.json)
 | 
			
		||||
        declare "cacheip$line"="$ip"
 | 
			
		||||
        declare "cacheip${line}"="${ip}"
 | 
			
		||||
done <<< $(jq -r '.ips | to_entries[] | .key' config.json)
 | 
			
		||||
 | 
			
		||||
while read -r line; do
 | 
			
		||||
        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)
 | 
			
		||||
 | 
			
		||||
rm -rf ${outputdir}
 | 
			
		||||
mkdir -p ${outputdir}/hosts
 | 
			
		||||
touch ${outputdir}/lancache.conf
 | 
			
		||||
mkdir -p ${outputdir}
 | 
			
		||||
while read -r entry; do
 | 
			
		||||
        unset cacheip
 | 
			
		||||
        unset cachename
 | 
			
		||||
@ -43,47 +42,29 @@ while read -r entry; do
 | 
			
		||||
        cacheip=$(jq -r 'if type == "array" then .[] else . end' <<< ${!cacheipname} | xargs)
 | 
			
		||||
        while read -r fileid; do
 | 
			
		||||
                while read -r filename; do
 | 
			
		||||
                        destfilename=$(echo $filename | sed -e 's/txt/hosts/')
 | 
			
		||||
                        lancacheconf=${outputdir}/lancache.conf
 | 
			
		||||
                        outputfile=${outputdir}/hosts/${destfilename}
 | 
			
		||||
                        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
 | 
			
		||||
                        destfilename=$(echo $filename | sed -e 's/txt/conf/')
 | 
			
		||||
                        outputfile=${outputdir}/${destfilename}
 | 
			
		||||
                        touch ${outputfile}
 | 
			
		||||
                        while read -r fileentry; do
 | 
			
		||||
                                # Ignore comments, newlines and wildcards
 | 
			
		||||
                                if [[ $fileentry =~ ^(\#|\*\.) ]] || [[ -z $fileentry ]]; then
 | 
			
		||||
                                        continue
 | 
			
		||||
                                fi
 | 
			
		||||
                                parsed=$(echo $fileentry)
 | 
			
		||||
                                if grep -qx "$parsed" "$outputfile"; then
 | 
			
		||||
                                if [[ ${fileentry} == \#* ]] || [[ -z ${fileentry} ]]; then
 | 
			
		||||
                                        continue
 | 
			
		||||
                                fi
 | 
			
		||||
                                parsed=$(echo ${fileentry} | sed -e "s/^\*\.//")
 | 
			
		||||
                                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 <<< $(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)
 | 
			
		||||
done <<< $(jq -r '.cache_domains | to_entries[] | .key' $path)
 | 
			
		||||
                        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})
 | 
			
		||||
done <<< $(jq -r '.cache_domains | to_entries[] | .key' ${path})
 | 
			
		||||
 | 
			
		||||
cat << EOF
 | 
			
		||||
Configuration generation completed.
 | 
			
		||||
 | 
			
		||||
Please copy the following files:
 | 
			
		||||
- ./${outputdir}/lancache.conf to /etc/dnsmasq/dnsmasq.d/
 | 
			
		||||
- ./${outputdir}/hosts to /etc/dnsmasq/
 | 
			
		||||
- ./${outputdir}/*.conf to /etc/dnsmasq/dnsmasq.d/
 | 
			
		||||
EOF
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user