Cleaned code and added prompt for purge on uninstall

This commit is contained in:
nate 2016-03-26 14:16:22 -05:00
parent 0b5f005a5d
commit 0b9e78df2c
6 changed files with 100 additions and 100 deletions

View file

@ -41,7 +41,7 @@ if [[ -f $piholeIPfile ]];then
else
# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}')
piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}')
piholeIP=${piholeIPCIDR%/*}
fi
@ -54,18 +54,19 @@ fi
# Variables for various stages of downloading and formatting the list
## Nate 3/26/2016 - Commented unused variables
basename=pihole
piholeDir=/etc/$basename
adList=$piholeDir/gravity.list
blacklist=$piholeDir/blacklist.txt
whitelist=$piholeDir/whitelist.txt
latentWhitelist=$piholeDir/latentWhitelist.txt
#blacklist=$piholeDir/blacklist.txt
#whitelist=$piholeDir/whitelist.txt
#latentWhitelist=$piholeDir/latentWhitelist.txt
justDomainsExtension=domains
matterandlight=$basename.0.matterandlight.txt
supernova=$basename.1.supernova.txt
eventHorizon=$basename.2.eventHorizon.txt
accretionDisc=$basename.3.accretionDisc.txt
eyeOfTheNeedle=$basename.4.wormhole.txt
#eyeOfTheNeedle=$basename.4.wormhole.txt
# After setting defaults, check if there's local overrides
if [[ -r $piholeDir/pihole.conf ]];then
@ -76,19 +77,18 @@ fi
spinner(){
local pid=$1
local delay=0.001
local spinstr='/-\|'
spin='-\|/'
i=0
while $SUDO kill -0 $pid 2>/dev/null
while $SUDO kill -0 "$pid" 2>/dev/null
do
i=$(( (i+1) %4 ))
printf "\b${spin:$i:1}"
printf "\b%s" "${spin:$i:1}"
sleep .1
done
printf "\b"
}
###########################
# collapse - begin formation of pihole
function gravity_collapse() {
@ -99,7 +99,7 @@ function gravity_collapse() {
#custom file found, use this instead of default
echo -n "::: Custom adList file detected. Reading..."
sources=()
while read -a line; do
while read -r line; do
#Do not read commented out or blank lines
if [[ $line = \#* ]] || [[ ! $line ]]; then
echo "" > /dev/null
@ -112,7 +112,7 @@ function gravity_collapse() {
#no custom file found, use defaults!
echo -n "::: No custom adlist file detected, reading from default file..."
sources=()
while read -a line; do
while read -r line; do
#Do not read commented out or blank lines
if [[ $line = \#* ]] || [[ ! $line ]]; then
echo "" > /dev/null
@ -146,7 +146,7 @@ function gravity_patternCheck() {
# Some of the blocklists are copyright, they need to be downloaded
# and stored as is. They can be processed for content after they
# have been saved.
cp $patternBuffer $saveLocation
cp "$patternBuffer" "$saveLocation"
echo " List updated, transport successful!"
else
# curl didn't download any host files, probably because of the date check
@ -169,12 +169,12 @@ function gravity_transport() {
fi
# Silently curl url
curl -s $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer
curl -s "$cmd_ext" "$heisenbergCompensator" -A "$agent" "$url" > "$patternBuffer"
# Check for list updates
gravity_patternCheck $patternBuffer
gravity_patternCheck "$patternBuffer"
# Cleanup
rm -f $patternBuffer
rm -f "$patternBuffer"
}
# spinup - main gravity function
@ -222,7 +222,7 @@ function gravity_Schwarzchild() {
truncate -s 0 $piholeDir/$matterandlight & spinner $!
for i in "${activeDomains[@]}"
do
cat $i |tr -d '\r' >> $piholeDir/$matterandlight
"$i" |tr -d '\r' >> $piholeDir/$matterandlight
done
echo " done!"
@ -249,7 +249,7 @@ function gravity_Whitelist() {
echo -n "::: Adding ${#sources[@]} ad list source${plural} to the whitelist..."
urls=()
for url in ${sources[@]}
for url in "${sources[@]}"
do
tmp=$(echo "$url" | awk -F '/' '{print $3}')
urls=("${urls[@]}" $tmp)
@ -257,7 +257,7 @@ function gravity_Whitelist() {
echo " done!"
echo -n "::: Running whitelist script to update HOSTS file...."
$whitelistScript -f -nr -q ${urls[@]} > /dev/null & spinner $!
$whitelistScript -f -nr -q "${urls[@]}" > /dev/null & spinner $!
numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt")
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
@ -283,13 +283,13 @@ function gravity_hostFormat() {
if [[ -n $piholeIPv6 ]];then
#Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain!
echo -e "$piholeIP Pi-Hole.IsWorking.OK \n$piholeIPv6 Pi-Hole.IsWorking.OK" > $piholeDir/$accretionDisc
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc
$piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc
else
# Otherwise, just create gravity.list as normal using IPv4
#Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain!
echo -e "$piholeIP Pi-Hole.IsWorking.OK" > $piholeDir/$accretionDisc
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $piholeDir/$accretionDisc
$piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $piholeDir/$accretionDisc
fi
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
cp $piholeDir/$accretionDisc $adList
@ -301,10 +301,10 @@ function gravity_blackbody() {
for file in $piholeDir/*.$justDomainsExtension
do
# If list is in active array then leave it (noop) else rm the list
if [[ " ${activeDomains[@]} " =~ " ${file} " ]]; then
if [[ " ${activeDomains[@]} " =~ ${file} ]]; then
:
else
rm -f $file
rm -f "$file"
fi
done
}
@ -343,7 +343,7 @@ function gravity_reload() {
if [[ $dnsmasqPid ]]; then
# service already running - reload config
$SUDO kill -HUP $dnsmasqPid & spinner $!
$SUDO kill -HUP "$dnsmasqPid" & spinner $!
else
# service not running, start it up
$SUDO service dnsmasq start & spinner $!