Skip to content

Commit

Permalink
Space/Tab wildcard_regex_converter.sh
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Schaper <[email protected]>
  • Loading branch information
dschaper committed Jul 20, 2018
1 parent b54e32f commit c5091b0
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions advanced/Scripts/wildcard_regex_converter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
wildcardFile="/etc/dnsmasq.d/03-pihole-wildcard.conf"

convert_wildcard_to_regex() {
if [ ! -f "${wildcardFile}" ]; then
return
fi
local addrlines domains uniquedomains
# Obtain wildcard domains from old file
addrlines="$(grep -oE "/.*/" ${wildcardFile})"
# Strip "/" from domain names and convert "." to regex-compatible "\."
domains="$(sed 's/\///g;s/\./\\./g' <<< "${addrlines}")"
# Remove repeated domains (may have been inserted two times due to A and AAAA blocking)
uniquedomains="$(uniq <<< "${domains}")"
# Automatically generate regex filters and remove old wildcards file
awk '{print "((^)|(\\.))"$0"$"}' <<< "${uniquedomains}" >> "${regexFile:?}" && rm "${wildcardFile}"
if [ ! -f "${wildcardFile}" ]; then
return
fi
local addrlines domains uniquedomains
# Obtain wildcard domains from old file
addrlines="$(grep -oE "/.*/" ${wildcardFile})"
# Strip "/" from domain names and convert "." to regex-compatible "\."
domains="$(sed 's/\///g;s/\./\\./g' <<< "${addrlines}")"
# Remove repeated domains (may have been inserted two times due to A and AAAA blocking)
uniquedomains="$(uniq <<< "${domains}")"
# Automatically generate regex filters and remove old wildcards file
awk '{print "((^)|(\\.))"$0"$"}' <<< "${uniquedomains}" >> "${regexFile:?}" && rm "${wildcardFile}"
}

0 comments on commit c5091b0

Please sign in to comment.