mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-03-30 20:20:17 +00:00
Space/Tab wildcard_regex_converter.sh
Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
This commit is contained in:
parent
b54e32f0ca
commit
c5091b0e49
1 changed files with 12 additions and 12 deletions
|
@ -13,16 +13,16 @@
|
||||||
wildcardFile="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
wildcardFile="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
||||||
|
|
||||||
convert_wildcard_to_regex() {
|
convert_wildcard_to_regex() {
|
||||||
if [ ! -f "${wildcardFile}" ]; then
|
if [ ! -f "${wildcardFile}" ]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
local addrlines domains uniquedomains
|
local addrlines domains uniquedomains
|
||||||
# Obtain wildcard domains from old file
|
# Obtain wildcard domains from old file
|
||||||
addrlines="$(grep -oE "/.*/" ${wildcardFile})"
|
addrlines="$(grep -oE "/.*/" ${wildcardFile})"
|
||||||
# Strip "/" from domain names and convert "." to regex-compatible "\."
|
# Strip "/" from domain names and convert "." to regex-compatible "\."
|
||||||
domains="$(sed 's/\///g;s/\./\\./g' <<< "${addrlines}")"
|
domains="$(sed 's/\///g;s/\./\\./g' <<< "${addrlines}")"
|
||||||
# Remove repeated domains (may have been inserted two times due to A and AAAA blocking)
|
# Remove repeated domains (may have been inserted two times due to A and AAAA blocking)
|
||||||
uniquedomains="$(uniq <<< "${domains}")"
|
uniquedomains="$(uniq <<< "${domains}")"
|
||||||
# Automatically generate regex filters and remove old wildcards file
|
# Automatically generate regex filters and remove old wildcards file
|
||||||
awk '{print "((^)|(\\.))"$0"$"}' <<< "${uniquedomains}" >> "${regexFile:?}" && rm "${wildcardFile}"
|
awk '{print "((^)|(\\.))"$0"$"}' <<< "${uniquedomains}" >> "${regexFile:?}" && rm "${wildcardFile}"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue