mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-24 07:03:43 +00:00
Simplfy gravity_advanced.
Remove extraneous calls to several programs (cat, uniq).
This commit is contained in:
parent
e1b9ed450c
commit
2d92a0369f
1 changed files with 17 additions and 12 deletions
23
gravity.sh
23
gravity.sh
|
@ -135,24 +135,27 @@ if [[ -r $blacklist ]];then
|
||||||
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l)
|
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l)
|
||||||
echo "** Blacklisting $numberOf domain(s)..."
|
echo "** Blacklisting $numberOf domain(s)..."
|
||||||
cat $blacklist >> $origin/$matter
|
cat $blacklist >> $origin/$matter
|
||||||
else
|
|
||||||
:
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function gravity_advanced()
|
|
||||||
###########################
|
###########################
|
||||||
{
|
function gravity_advanced() {
|
||||||
numberOf=$(cat $origin/$andLight | sed '/^\s*$/d' | wc -l)
|
|
||||||
|
numberOf=$(wc -l $origin/$andLight)
|
||||||
echo "** $numberOf domains being pulled in by gravity..."
|
echo "** $numberOf domains being pulled in by gravity..."
|
||||||
|
|
||||||
# Remove carriage returns and preceding whitespace
|
# Remove carriage returns and preceding whitespace
|
||||||
cat $origin/$andLight | sed $'s/\r$//' | sed '/^\s*$/d' > $origin/$supernova
|
# not really needed anymore?
|
||||||
|
cp $origin/$andLight $origin/$supernova
|
||||||
|
|
||||||
# Sort and remove duplicates
|
# Sort and remove duplicates
|
||||||
cat $origin/$supernova | sort | uniq > $origin/$eventHorizon
|
sort -u $origin/$supernova > $origin/$eventHorizon
|
||||||
numberOf=$(cat $origin/$eventHorizon | sed '/^\s*$/d' | wc -l)
|
numberOf=$(wc -l $origin/$eventHorizon)
|
||||||
echo "** $numberOf unique domains trapped in the event horizon."
|
echo "** $numberOf unique domains trapped in the event horizon."
|
||||||
|
|
||||||
# Format domain list as "192.168.x.x domain.com"
|
# Format domain list as "192.168.x.x domain.com"
|
||||||
echo "** Formatting domains into a HOSTS file..."
|
echo "** Formatting domains into a HOSTS file..."
|
||||||
cat $origin/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP"'" $0}' > $origin/$accretionDisc
|
awk '{print "'"$piholeIP"'" $1}' $origin/$eventHorizon > $origin/$accretionDisc
|
||||||
|
|
||||||
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
|
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
|
||||||
sudo cp $origin/$accretionDisc $adList
|
sudo cp $origin/$accretionDisc $adList
|
||||||
kill -HUP $(pidof dnsmasq)
|
kill -HUP $(pidof dnsmasq)
|
||||||
|
@ -164,6 +167,7 @@ if [[ -r $whitelist ]];then
|
||||||
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l)
|
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l)
|
||||||
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||||
echo "** Whitelisting $numberOf domain${plural}..."
|
echo "** Whitelisting $numberOf domain${plural}..."
|
||||||
|
|
||||||
# Append a "$" to the end, prepend a "^" to the beginning, and
|
# Append a "$" to the end, prepend a "^" to the beginning, and
|
||||||
# replace "." with "\." of each line to turn each entry into a
|
# replace "." with "\." of each line to turn each entry into a
|
||||||
# regexp so it can be parsed out with grep -x
|
# regexp so it can be parsed out with grep -x
|
||||||
|
@ -180,6 +184,7 @@ do
|
||||||
echo "$url" | awk -F '/' '{print "^"$3"$"}' | sed 's/\./\\./g' >> $latentWhitelist
|
echo "$url" | awk -F '/' '{print "^"$3"$"}' | sed 's/\./\\./g' >> $latentWhitelist
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Remove whitelist entries from deduped list
|
||||||
grep -vxf $latentWhitelist $origin/$matter > $origin/$andLight
|
grep -vxf $latentWhitelist $origin/$matter > $origin/$andLight
|
||||||
|
|
||||||
gravity_advanced
|
gravity_advanced
|
||||||
|
|
Loading…
Reference in a new issue