Simplfy gravity_advanced.

Remove extraneous calls to several programs (cat, uniq).
This commit is contained in:
Jesse Becker 2015-09-12 00:26:29 -04:00
parent e1b9ed450c
commit 2d92a0369f

View file

@ -135,28 +135,31 @@ 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)
} }
# Whitelist (if applicable) then remove duplicates and format for dnsmasq # Whitelist (if applicable) then remove duplicates and format for dnsmasq
if [[ -r $whitelist ]];then if [[ -r $whitelist ]];then
@ -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