Code format cleanups

This commit is contained in:
Dan Schaper 2015-11-26 15:56:37 -08:00
parent d1e475da89
commit 9892d06c0d

View file

@ -51,7 +51,7 @@ fi
########################### ###########################
# collapse - begin formation of pihole # collapse - begin formation of pihole
function gravity_collapse() { function gravity_collapse() {
echo "** Neutrino emissions detected..." echo "** Neutrino emissions detected..."
# Create the pihole resource directory if it doesn't exist. Future files will be stored here # Create the pihole resource directory if it doesn't exist. Future files will be stored here
if [[ -d $piholeDir ]];then if [[ -d $piholeDir ]];then
@ -66,8 +66,7 @@ echo "** Neutrino emissions detected..."
fi fi
} }
# patternCheck - check to see if curl downloaded any new files, and then process those # patternCheck - check to see if curl downloaded any new files.
# files so they are in host format.
function gravity_patternCheck() { function gravity_patternCheck() {
patternBuffer=$1 patternBuffer=$1
# check if the patternbuffer is a non-zero length file # check if the patternbuffer is a non-zero length file
@ -83,7 +82,7 @@ function gravity_patternCheck() {
fi fi
} }
# transport - curl the specified url with any needed command extentions, then patternCheck # transport - curl the specified url with any needed command extentions
function gravity_transport() { function gravity_transport() {
url=$1 url=$1
cmd_ext=$2 cmd_ext=$2
@ -109,9 +108,9 @@ function gravity_transport() {
# spinup - main gravity function # spinup - main gravity function
function gravity_spinup() { function gravity_spinup() {
# Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and blank lines # Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and # blank lines
for ((i = 0; i < "${#sources[@]}"; i++)) for ((i = 0; i < "${#sources[@]}"; i++))
do do
url=${sources[$i]} url=${sources[$i]}
# Get just the domain from the URL # Get just the domain from the URL
domain=$(echo "$url" | cut -d'/' -f3) domain=$(echo "$url" | cut -d'/' -f3)
@ -140,7 +139,7 @@ do
*) cmd_ext="" *) cmd_ext=""
esac esac
gravity_transport $url $cmd_ext $agent gravity_transport $url $cmd_ext $agent
done done
} }
# Schwarzchild - aggregate domains to one list and add blacklisted domains # Schwarzchild - aggregate domains to one list and add blacklisted domains
@ -155,6 +154,7 @@ function gravity_Schwarzchild() {
done done
} }
# Pulsar - White/blacklist application
function gravity_pulsar() { function gravity_pulsar() {
# Append blacklist entries if they exist # Append blacklist entries if they exist
@ -192,25 +192,26 @@ function gravity_pulsar() {
} }
function gravity_unique() { function gravity_unique() {
# Sort and remove duplicates # Sort and remove duplicates
sort -u $piholeDir/$supernova > $piholeDir/$eventHorizon sort -u $piholeDir/$supernova > $piholeDir/$eventHorizon
numberOf=$(wc -l < $piholeDir/$eventHorizon) numberOf=$(wc -l < $piholeDir/$eventHorizon)
echo "** $numberOf unique domains trapped in the event horizon." echo "** $numberOf unique domains trapped in the event horizon."
} }
function gravity_hostFormat() { function gravity_hostFormat() {
# 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 $piholeDir/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP"' " $0}' > $piholeDir/$accretionDisc cat $piholeDir/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP"' " $0}' > $piholeDir/$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
cp $piholeDir/$accretionDisc $adList cp $piholeDir/$accretionDisc $adList
} }
# blackbody - remove any remnant files from script processes
function gravity_blackbody() { function gravity_blackbody() {
# Loop through list files # Loop through list files
for file in $piholeDir/*.$justDomainsExtension for file in $piholeDir/*.$justDomainsExtension
do do
# If list is active then leave it (noop) else rm the list # If list is in active array then leave it (noop) else rm the list
if [[ " ${activeDomains[@]} " =~ " ${file} " ]]; then if [[ " ${activeDomains[@]} " =~ " ${file} " ]]; then
: :
else else
@ -220,19 +221,19 @@ function gravity_blackbody() {
} }
function gravity_advanced() { function gravity_advanced() {
# Remove comments and print only the domain name
# Most of the lists downloaded are already in hosts file format but the spacing/formating is not contigious
# This helps with that and makes it easier to read
# It also helps with debugging so each stage of the script can be researched more in depth
awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' $piholeDir/$andLight | \
sed -nr -e 's/\.{2,}/./g' -e '/\./p' > $piholeDir/$supernova
# Remove comments and print only the domain name numberOf=$(wc -l < $piholeDir/$supernova)
# Most of the lists downloaded are already in hosts file format but the spacing/formating is not contigious echo "** $numberOf domains being pulled in by gravity..."
# This helps with that and makes it easier to read
# It also helps with debugging so each stage of the script can be researched more in depth
awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' $piholeDir/$andLight | \
sed -nr -e 's/\.{2,}/./g' -e '/\./p' > $piholeDir/$supernova
numberOf=$(wc -l < $piholeDir/$supernova) gravity_unique
echo "** $numberOf domains being pulled in by gravity..."
gravity_unique
sudo kill -HUP $(pidof dnsmasq) sudo kill -HUP $(pidof dnsmasq)
} }
gravity_collapse gravity_collapse