1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-12-22 23:08:07 +00:00

Tidied up a couple of things

This commit is contained in:
Adam Warner 2016-01-15 15:54:00 +00:00
parent 89e3c25a90
commit f68cf10efa

View File

@ -9,10 +9,13 @@
if [[ $# = 0 ]]; then if [[ $# = 0 ]]; then
echo "Immediately whitelists one or more domains in the hosts file" echo "Immediately whitelists one or more domains in the hosts file"
echo " "
echo "Usage: whitelist.sh domain1 [domain2 ...]" echo "Usage: whitelist.sh domain1 [domain2 ...]"
echo " "
echo "Options:" echo "Options:"
echo " -d, --delmode Remove domains from the whitelist" echo " -d, --delmode Remove domains from the whitelist"
echo " -nr, --noreload Update Whitelist without refreshing dnsmasq echo " -nr, --noreload Update Whitelist without refreshing dnsmasq"
echo " -f, --force Force updating of the hosts files, even if there are no changes"
exit 1 exit 1
fi fi
@ -22,6 +25,8 @@ whitelist=/etc/pihole/whitelist.txt
adList=/etc/pihole/gravity.list adList=/etc/pihole/gravity.list
reload=true reload=true
addmode=true addmode=true
force=false
versbose=true
domList=() domList=()
domToRemoveList=() domToRemoveList=()
@ -74,11 +79,15 @@ function AddDomain(){
grep -Ex -q "$1" $whitelist || bool=true grep -Ex -q "$1" $whitelist || bool=true
if $bool; then if $bool; then
#domain not found in the whitelist file, add it! #domain not found in the whitelist file, add it!
if $versbose; then
echo "** Adding $1 to whitelist file" echo "** Adding $1 to whitelist file"
fi
echo $1 >> $whitelist echo $1 >> $whitelist
modifyHost=true modifyHost=true
else else
echo "** $1 already whitelisted! No need to add" if $versbose; then
echo "** $1 already whitelisted! No need to add"
fi
fi fi
} }
@ -88,10 +97,14 @@ function RemoveDomain(){
grep -Ex -q "$1" $whitelist || bool=true grep -Ex -q "$1" $whitelist || bool=true
if $bool; then if $bool; then
#Domain is not in the whitelist file, no need to Remove #Domain is not in the whitelist file, no need to Remove
if $versbose; then
echo "** $1 is NOT whitelisted! No need to remove" echo "** $1 is NOT whitelisted! No need to remove"
fi
else else
#Domain is in the whitelist file, add to a temporary array and remove from whitelist file #Domain is in the whitelist file, add to a temporary array and remove from whitelist file
if $versbose; then
echo "** Un-whitelisting $dom..." echo "** Un-whitelisting $dom..."
fi
domToRemoveList=("${domToRemoveList[@]}" $1) domToRemoveList=("${domToRemoveList[@]}" $1)
modifyHost=true modifyHost=true
fi fi
@ -144,19 +157,23 @@ for var in "$@"
do do
case "$var" in case "$var" in
"-nr"| "--noreload" ) reload=false;; "-nr"| "--noreload" ) reload=false;;
"-d" | "--delmode" ) addmode=false;; "-d" | "--delmode" ) addmode=false;;
"-f" | "--force" ) force=true;;
"-q" | "--quiet" ) versbose=false;;
* ) HandleOther $var;; * ) HandleOther $var;;
esac esac
done done
PopWhitelistFile PopWhitelistFile
if $modifyHost; then if $modifyHost || $force; then
echo "** Modifying Hosts File" echo "** Modifying Hosts File"
ModifyHostFile ModifyHostFile
else else
if $versbose; then
echo "** No changes need to be made" echo "** No changes need to be made"
exit 1 exit 1
fi
fi fi
if $reload; then if $reload; then