Merge pull request #451 from pi-hole/development
Development of Next release
This commit is contained in:
commit
3853997295
|
@ -22,7 +22,7 @@ blacklist=$piholeDir/blacklist.txt
|
|||
reload=true
|
||||
addmode=true
|
||||
force=false
|
||||
versbose=true
|
||||
verbose=true
|
||||
|
||||
domList=()
|
||||
domToRemoveList=()
|
||||
|
@ -51,17 +51,18 @@ fi
|
|||
|
||||
function helpFunc()
|
||||
{
|
||||
echo "::: Immediately blacklists one or more domains in the hosts file"
|
||||
echo ":::"
|
||||
echo "::: Usage: sudo pihole.sh -b domain1 [domain2 ...]"
|
||||
echo ":::"
|
||||
echo "::: Options:"
|
||||
echo "::: -d, --delmode Remove domains from the blacklist"
|
||||
echo "::: -nr, --noreload Update blacklist without refreshing dnsmasq"
|
||||
echo "::: -f, --force Force updating of the hosts files, even if there are no changes"
|
||||
echo "::: -q, --quiet output is less verbose"
|
||||
echo "::: -h, --help Show this help dialog"
|
||||
exit 1
|
||||
echo "::: Immediately blacklists one or more domains in the hosts file"
|
||||
echo ":::"
|
||||
echo ":::"
|
||||
echo "::: Usage: sudo pihole -b domain1 [domain2 ...]"
|
||||
echo "::: Options:"
|
||||
echo "::: -d, --delmode Remove domains from the blacklist"
|
||||
echo "::: -nr, --noreload Update blacklist without refreshing dnsmasq"
|
||||
echo "::: -f, --force Force updating of the hosts files, even if there are no changes"
|
||||
echo "::: -q, --quiet output is less verbose"
|
||||
echo "::: -h, --help Show this help dialog"
|
||||
echo "::: -l, --list Display your blacklisted domains"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function HandleOther(){
|
||||
|
@ -94,14 +95,14 @@ function AddDomain(){
|
|||
grep -Ex -q "$1" $blacklist || bool=true
|
||||
if $bool; then
|
||||
#domain not found in the blacklist file, add it!
|
||||
if $versbose; then
|
||||
if $verbose; then
|
||||
echo -n "::: Adding $1 to blacklist file..."
|
||||
fi
|
||||
echo "$1" >> $blacklist
|
||||
modifyHost=true
|
||||
echo " done!"
|
||||
else
|
||||
if $versbose; then
|
||||
if $verbose; then
|
||||
echo "::: $1 already exists in $blacklist! No need to add"
|
||||
fi
|
||||
fi
|
||||
|
@ -113,12 +114,12 @@ function RemoveDomain(){
|
|||
grep -Ex -q "$1" $blacklist || bool=true
|
||||
if $bool; then
|
||||
#Domain is not in the blacklist file, no need to Remove
|
||||
if $versbose; then
|
||||
if $verbose; then
|
||||
echo "::: $1 is NOT blacklisted! No need to remove"
|
||||
fi
|
||||
else
|
||||
#Domain is in the blacklist file, add to a temporary array
|
||||
if $versbose; then
|
||||
if $verbose; then
|
||||
echo "::: Un-blacklisting $dom..."
|
||||
fi
|
||||
domToRemoveList=("${domToRemoveList[@]}" $1)
|
||||
|
@ -173,6 +174,17 @@ function Reload() {
|
|||
echo " done!"
|
||||
}
|
||||
|
||||
function DisplayBlist() {
|
||||
verbose=false
|
||||
echo -e " Displaying Gravity Affected Domains \n"
|
||||
count=1
|
||||
while IFS= read -r AD
|
||||
do
|
||||
echo "${count}: $AD"
|
||||
count=$((count+1))
|
||||
done < "$blacklist"
|
||||
}
|
||||
|
||||
###################################################
|
||||
|
||||
for var in "$@"
|
||||
|
@ -181,8 +193,9 @@ do
|
|||
"-nr"| "--noreload" ) reload=false;;
|
||||
"-d" | "--delmode" ) addmode=false;;
|
||||
"-f" | "--force" ) force=true;;
|
||||
"-q" | "--quiet" ) versbose=false;;
|
||||
"-h" | "--help" ) helpFunc;;
|
||||
"-q" | "--quiet" ) verbose=false;;
|
||||
"-h" | "--help" ) helpFunc;;
|
||||
"-l" | "--list" ) DisplayBlist;;
|
||||
* ) HandleOther "$var";;
|
||||
esac
|
||||
done
|
||||
|
@ -192,8 +205,8 @@ PopBlacklistFile
|
|||
if $modifyHost || $force; then
|
||||
ModifyHostFile
|
||||
else
|
||||
if $versbose; then
|
||||
echo "::: No changes need to be made"
|
||||
if $verbose; then
|
||||
echo "::: No changes need to be made"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
@ -120,7 +120,7 @@ function normalChrono(){
|
|||
function displayHelp(){
|
||||
echo "::: Displays stats about your piHole!"
|
||||
echo ":::"
|
||||
echo "::: Usage: sudo pihole.sh -c [optional:-j]"
|
||||
echo "::: Usage: sudo pihole -c [optional:-j]"
|
||||
echo "::: Note: If no option is passed, then stats are displayed on screen, updated every 5 seconds"
|
||||
echo ":::"
|
||||
echo "::: Options:"
|
||||
|
|
|
@ -22,7 +22,7 @@ whitelist=$piholeDir/whitelist.txt
|
|||
reload=true
|
||||
addmode=true
|
||||
force=false
|
||||
versbose=true
|
||||
verbose=true
|
||||
|
||||
domList=()
|
||||
domToRemoveList=()
|
||||
|
@ -50,17 +50,18 @@ fi
|
|||
|
||||
function helpFunc()
|
||||
{
|
||||
echo "::: Immediately whitelists one or more domains in the hosts file"
|
||||
echo ":::"
|
||||
echo "::: Usage: sudo pihole.sh -w domain1 [domain2 ...]"
|
||||
echo ":::"
|
||||
echo "::: Options:"
|
||||
echo "::: -d, --delmode Remove domains from the whitelist"
|
||||
echo "::: -nr, --noreload Update Whitelist without refreshing dnsmasq"
|
||||
echo "::: -f, --force Force updating of the hosts files, even if there are no changes"
|
||||
echo "::: -q, --quiet output is less verbose"
|
||||
echo "::: -h, --help Show this help dialog"
|
||||
exit 1
|
||||
echo "::: Immediately whitelists one or more domains in the hosts file"
|
||||
echo ":::"
|
||||
echo "::: Usage: sudo pihole -w domain1 [domain2 ...]"
|
||||
echo ":::"
|
||||
echo "::: Options:"
|
||||
echo "::: -d, --delmode Remove domains from the whitelist"
|
||||
echo "::: -nr, --noreload Update Whitelist without refreshing dnsmasq"
|
||||
echo "::: -f, --force Force updating of the hosts files, even if there are no changes"
|
||||
echo "::: -q, --quiet output is less verbose"
|
||||
echo "::: -h, --help Show this help dialog"
|
||||
echo "::: -l, --list Display your whitelisted domains"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function HandleOther(){
|
||||
|
@ -95,16 +96,16 @@ function AddDomain(){
|
|||
grep -Ex -q "$1" $whitelist || bool=true
|
||||
if $bool; then
|
||||
#domain not found in the whitelist file, add it!
|
||||
if $versbose; then
|
||||
if $verbose; then
|
||||
echo -n "::: Adding $1 to $whitelist..."
|
||||
fi
|
||||
echo "$1" >> $whitelist
|
||||
modifyHost=true
|
||||
if $versbose; then
|
||||
if $verbose; then
|
||||
echo " done!"
|
||||
fi
|
||||
else
|
||||
if $versbose; then
|
||||
if $verbose; then
|
||||
echo "::: $1 already exists in $whitelist, no need to add!"
|
||||
fi
|
||||
fi
|
||||
|
@ -116,12 +117,12 @@ function RemoveDomain(){
|
|||
grep -Ex -q "$1" $whitelist || bool=true
|
||||
if $bool; then
|
||||
#Domain is not in the whitelist file, no need to Remove
|
||||
if $versbose; then
|
||||
if $verbose; then
|
||||
echo "::: $1 is NOT whitelisted! No need to remove"
|
||||
fi
|
||||
else
|
||||
#Domain is in the whitelist file, add to a temporary array and remove from whitelist file
|
||||
#if $versbose; then
|
||||
#if $verbose; then
|
||||
#echo "::: Un-whitelisting $dom..."
|
||||
#fi
|
||||
domToRemoveList=("${domToRemoveList[@]}" $1)
|
||||
|
@ -186,6 +187,17 @@ function Reload() {
|
|||
echo " done!"
|
||||
}
|
||||
|
||||
function DisplayWlist() {
|
||||
verbose=false
|
||||
echo -e " Displaying Gravity Resistant Domains \n"
|
||||
count=1
|
||||
while IFS= read -r RD
|
||||
do
|
||||
echo "${count}: $RD"
|
||||
count=$((count+1))
|
||||
done < "$whitelist"
|
||||
}
|
||||
|
||||
###################################################
|
||||
|
||||
for var in "$@"
|
||||
|
@ -194,8 +206,9 @@ do
|
|||
"-nr"| "--noreload" ) reload=false;;
|
||||
"-d" | "--delmode" ) addmode=false;;
|
||||
"-f" | "--force" ) force=true;;
|
||||
"-q" | "--quiet" ) versbose=false;;
|
||||
"-h" | "--help" ) helpFunc;;
|
||||
"-q" | "--quiet" ) verbose=false;;
|
||||
"-h" | "--help" ) helpFunc;;
|
||||
"-l" | "--list" ) DisplayWlist;;
|
||||
* ) HandleOther "$var";;
|
||||
esac
|
||||
done
|
||||
|
@ -205,11 +218,11 @@ PopWhitelistFile
|
|||
if $modifyHost || $force; then
|
||||
ModifyHostFile
|
||||
else
|
||||
if $versbose; then
|
||||
echo ":::"
|
||||
echo "::: No changes need to be made"
|
||||
exit 1
|
||||
if $verbose; then
|
||||
echo ":::"
|
||||
echo "::: No changes need to be made"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if $reload; then
|
||||
|
|
31
gravity.sh
31
gravity.sh
|
@ -12,6 +12,7 @@
|
|||
|
||||
# Run this script as root or under sudo
|
||||
echo ":::"
|
||||
|
||||
if [[ $EUID -eq 0 ]];then
|
||||
echo "::: You are root."
|
||||
else
|
||||
|
@ -71,20 +72,6 @@ if [[ -r $piholeDir/pihole.conf ]];then
|
|||
. $piholeDir/pihole.conf
|
||||
fi
|
||||
|
||||
spinner() {
|
||||
local pid=$1
|
||||
local delay=0.50
|
||||
local spinstr='/-|'
|
||||
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
|
||||
local temp=${spinstr#?}
|
||||
printf " [%c] " "$spinstr"
|
||||
local spinstr=$temp${spinstr%"$temp"}
|
||||
sleep $delay
|
||||
printf "\b\b\b\b\b\b"
|
||||
done
|
||||
printf " \b\b\b\b"
|
||||
}
|
||||
|
||||
###########################
|
||||
# collapse - begin formation of pihole
|
||||
function gravity_collapse() {
|
||||
|
@ -214,7 +201,7 @@ function gravity_Schwarzchild() {
|
|||
echo "::: "
|
||||
# Find all active domains and compile them into one file and remove CRs
|
||||
echo -n "::: Aggregating list of domains..."
|
||||
truncate -s 0 $piholeDir/$matterandlight & spinner $!
|
||||
truncate -s 0 $piholeDir/$matterandlight
|
||||
for i in "${activeDomains[@]}"
|
||||
do
|
||||
cat "$i" | tr -d '\r' >> $piholeDir/$matterandlight
|
||||
|
@ -225,7 +212,7 @@ function gravity_Schwarzchild() {
|
|||
function gravity_Blacklist(){
|
||||
# Append blacklist entries if they exist
|
||||
echo -n "::: Running blacklist script to update HOSTS file...."
|
||||
$blacklistScript -f -nr -q > /dev/null & spinner $!
|
||||
$blacklistScript -f -nr -q > /dev/null
|
||||
|
||||
numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt")
|
||||
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
|
||||
|
@ -247,7 +234,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
|
||||
numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt")
|
||||
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
|
||||
echo " $numWhitelisted domain${plural} whitelisted!"
|
||||
|
@ -256,7 +243,7 @@ function gravity_Whitelist() {
|
|||
function gravity_unique() {
|
||||
# Sort and remove duplicates
|
||||
echo -n "::: Removing duplicate domains...."
|
||||
sort -u $piholeDir/$supernova > $piholeDir/$eventHorizon & spinner $!
|
||||
sort -u $piholeDir/$supernova > $piholeDir/$eventHorizon
|
||||
echo " done!"
|
||||
numberOf=$(wc -l < $piholeDir/$eventHorizon)
|
||||
echo "::: $numberOf unique domains trapped in the event horizon."
|
||||
|
@ -302,7 +289,7 @@ function gravity_advanced() {
|
|||
# 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
|
||||
echo -n "::: Formatting list of domains to remove comments...."
|
||||
awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' $piholeDir/$matterandlight | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > $piholeDir/$supernova & spinner $!
|
||||
awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' $piholeDir/$matterandlight | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > $piholeDir/$supernova
|
||||
echo " done!"
|
||||
|
||||
numberOf=$(wc -l < $piholeDir/$supernova)
|
||||
|
@ -329,14 +316,14 @@ function gravity_reload() {
|
|||
$SUDO sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
|
||||
dnsmasqPid=$(pidof dnsmasq)
|
||||
|
||||
find "$piholeDir" -type f -exec $SUDO chmod 666 {} \; & spinner $!
|
||||
find "$piholeDir" -type f -exec $SUDO chmod 666 {} \;
|
||||
|
||||
if [[ $dnsmasqPid ]]; then
|
||||
# service already running - reload config
|
||||
$SUDO kill -HUP "$dnsmasqPid" & spinner $!
|
||||
$SUDO kill -HUP "$dnsmasqPid"
|
||||
else
|
||||
# service not running, start it up
|
||||
$SUDO service dnsmasq start & spinner $!
|
||||
$SUDO service dnsmasq start
|
||||
fi
|
||||
echo " done!"
|
||||
}
|
||||
|
|
32
pihole
32
pihole
|
@ -75,23 +75,23 @@ function uninstallFunc {
|
|||
}
|
||||
|
||||
function helpFunc {
|
||||
echo "::: Control all PiHole specific functions!"
|
||||
echo ":::"
|
||||
echo "::: Usage: pihole.sh [options]"
|
||||
printf ":::\tAdd -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage\n"
|
||||
echo ":::"
|
||||
echo "::: Options:"
|
||||
echo "::: -w, whitelist Whitelist domains"
|
||||
echo "::: -b, blacklist Blacklist domains"
|
||||
echo "::: -d, debug Start a debugging session if having trouble"
|
||||
echo "::: -f, flush Flush the pihole.log file"
|
||||
echo "::: -u, updateDashboard Update the web dashboard manually"
|
||||
echo "::: -g, updateGravity Update the list of ad-serving domains"
|
||||
echo "::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it"
|
||||
echo "::: -c, chronometer Calculates stats and displays to an LCD"
|
||||
echo "::: -h, help Show this help dialog"
|
||||
echo "::: Control all PiHole specific functions!"
|
||||
echo ":::"
|
||||
echo "::: Usage: pihole [options]"
|
||||
echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage"
|
||||
echo ":::"
|
||||
echo "::: Options:"
|
||||
echo "::: -w, whitelist Whitelist domains"
|
||||
echo "::: -b, blacklist Blacklist domains"
|
||||
echo "::: -d, debug Start a debugging session if having trouble"
|
||||
echo "::: -f, flush Flush the pihole.log file"
|
||||
echo "::: -u, updateDashboard Update the web dashboard manually"
|
||||
echo "::: -g, updateGravity Update the list of ad-serving domains"
|
||||
echo "::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it"
|
||||
echo "::: -c, chronometer Calculates stats and displays to an LCD"
|
||||
echo "::: -h, help Show this help dialog"
|
||||
echo "::: uninstall Uninstall Pi-Hole from your system!"
|
||||
exit 1
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [[ $# = 0 ]]; then
|
||||
|
|
Loading…
Reference in New Issue