mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 23:08:07 +00:00
Fix gravity from only parsing one adlist URL
* Redirect `grep` correctly to $sources (instead of using `awk`) * Redirect $sourceDomains correctly * Replace use of ${COL_LIGHT_BLUE} * Add numeric count informing user of unique source domains being whitelisted
This commit is contained in:
parent
8d8482d60b
commit
a6f9272d4b
30
gravity.sh
30
gravity.sh
@ -128,25 +128,18 @@ gravity_Collapse() {
|
|||||||
echo -ne " ${INFO} ${str}..."
|
echo -ne " ${INFO} ${str}..."
|
||||||
|
|
||||||
# Retrieve source URLs from $adListFile
|
# Retrieve source URLs from $adListFile
|
||||||
mapfile -t sources < <(
|
# Logic: Remove comments and empty lines
|
||||||
# Logic: Remove comments (#@;![)
|
mapfile -t sources <<< "$(grep -v -E "^(#|$)" "${adListFile}" 2> /dev/null)"
|
||||||
awk '!/^[#@;!\[]/ {
|
|
||||||
# Remove windows CR line endings
|
|
||||||
gsub(/\r$/, "", $0)
|
|
||||||
# Print non-empty line
|
|
||||||
if ($1) { print $1 }
|
|
||||||
}' "${adListFile}" 2> /dev/null
|
|
||||||
)
|
|
||||||
|
|
||||||
# Parse source domains from $sources
|
# Parse source domains from $sources
|
||||||
mapfile -t sourceDomains < <(
|
mapfile -t sourceDomains <<< "$(
|
||||||
# Logic: Split by folder/port
|
# Logic: Split by folder/port
|
||||||
awk -F '[/:]' '{
|
awk -F '[/:]' '{
|
||||||
# Remove URL protocol & optional username:password@
|
# Remove URL protocol & optional username:password@
|
||||||
gsub(/(.*:\/\/|.*:.*@)/, "", $0)
|
gsub(/(.*:\/\/|.*:.*@)/, "", $0)
|
||||||
print $1
|
print $1
|
||||||
}' <<< "$(printf '%s\n' "${sources[@]}")" 2> /dev/null
|
}' <<< "$(printf '%s\n' "${sources[@]}")" 2> /dev/null
|
||||||
)
|
)"
|
||||||
|
|
||||||
if [[ -n "${sources[*]}" ]] && [[ -n "${sourceDomains[*]}" ]]; then
|
if [[ -n "${sources[*]}" ]] && [[ -n "${sourceDomains[*]}" ]]; then
|
||||||
echo -e "${OVER} ${TICK} ${str}"
|
echo -e "${OVER} ${TICK} ${str}"
|
||||||
@ -397,7 +390,7 @@ gravity_Filter() {
|
|||||||
# Format $parsedMatter line total as currency
|
# Format $parsedMatter line total as currency
|
||||||
num=$(printf "%'.0f" "$(wc -l < "${piholeDir}/${parsedMatter}")")
|
num=$(printf "%'.0f" "$(wc -l < "${piholeDir}/${parsedMatter}")")
|
||||||
echo -e "${OVER} ${TICK} ${str}
|
echo -e "${OVER} ${TICK} ${str}
|
||||||
${INFO} ${COL_LIGHT_BLUE}${num}${COL_NC} domains being pulled in by gravity"
|
${INFO} ${COL_BLUE}${num}${COL_NC} domains being pulled in by gravity"
|
||||||
|
|
||||||
str="Removing duplicate domains"
|
str="Removing duplicate domains"
|
||||||
echo -ne " ${INFO} ${str}..."
|
echo -ne " ${INFO} ${str}..."
|
||||||
@ -406,20 +399,21 @@ gravity_Filter() {
|
|||||||
|
|
||||||
# Format $preEventHorizon line total as currency
|
# Format $preEventHorizon line total as currency
|
||||||
num=$(printf "%'.0f" "$(wc -l < "${piholeDir}/${preEventHorizon}")")
|
num=$(printf "%'.0f" "$(wc -l < "${piholeDir}/${preEventHorizon}")")
|
||||||
echo -e " ${INFO} ${COL_LIGHT_BLUE}${num}${COL_NC} unique domains trapped in the Event Horizon"
|
echo -e " ${INFO} ${COL_BLUE}${num}${COL_NC} unique domains trapped in the Event Horizon"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Whitelist unique blocklist domain sources
|
# Whitelist unique blocklist domain sources
|
||||||
gravity_WhitelistBLD() {
|
gravity_WhitelistBLD() {
|
||||||
local plural="" str uniqDomains
|
local uniqDomains plural="" str
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
[[ "${#sources[@]}" -ne 1 ]] && plural="s"
|
|
||||||
str="Adding blocklist domain source${plural} to the whitelist"
|
|
||||||
echo -ne " ${INFO} ${str}..."
|
|
||||||
|
|
||||||
# Create array of unique $sourceDomains
|
# Create array of unique $sourceDomains
|
||||||
mapfile -t uniqDomains <<< "$(awk '{ if(!a[$1]++) { print $1 } }' <<< "$(printf '%s\n' "${sourceDomains[@]}")")"
|
mapfile -t uniqDomains <<< "$(awk '{ if(!a[$1]++) { print $1 } }' <<< "$(printf '%s\n' "${sourceDomains[@]}")")"
|
||||||
|
[[ "${#uniqDomains[@]}" -ne 1 ]] && plural="s"
|
||||||
|
|
||||||
|
str="Adding ${#uniqDomains[@]} blocklist source domain${plural} to the whitelist"
|
||||||
|
echo -ne " ${INFO} ${str}..."
|
||||||
|
|
||||||
# Whitelist $uniqDomains
|
# Whitelist $uniqDomains
|
||||||
"${PIHOLE_COMMAND}" -w -nr -q "${uniqDomains[*]}" &> /dev/null
|
"${PIHOLE_COMMAND}" -w -nr -q "${uniqDomains[*]}" &> /dev/null
|
||||||
@ -627,7 +621,7 @@ else
|
|||||||
# Gravity needs to modify Blacklist/Whitelist/Wildcards
|
# Gravity needs to modify Blacklist/Whitelist/Wildcards
|
||||||
echo -e " ${INFO} Using cached Event Horizon list..."
|
echo -e " ${INFO} Using cached Event Horizon list..."
|
||||||
numberOf=$(printf "%'.0f" "$(wc -l < "${piholeDir}/${preEventHorizon}")")
|
numberOf=$(printf "%'.0f" "$(wc -l < "${piholeDir}/${preEventHorizon}")")
|
||||||
echo -e " ${INFO} ${COL_LIGHT_BLUE}${numberOf}${COL_NC} unique domains trapped in the Event Horizon"
|
echo -e " ${INFO} ${COL_BLUE}${numberOf}${COL_NC} unique domains trapped in the Event Horizon"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Perform when downloading blocklists, or modifying the whitelist
|
# Perform when downloading blocklists, or modifying the whitelist
|
||||||
|
Loading…
Reference in New Issue
Block a user