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
1 changed files with 22 additions and 5 deletions

View File

@ -9,10 +9,13 @@
if [[ $# = 0 ]]; then
echo "Immediately whitelists one or more domains in the hosts file"
echo " "
echo "Usage: whitelist.sh domain1 [domain2 ...]"
echo " "
echo "Options:"
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
fi
@ -22,6 +25,8 @@ whitelist=/etc/pihole/whitelist.txt
adList=/etc/pihole/gravity.list
reload=true
addmode=true
force=false
versbose=true
domList=()
domToRemoveList=()
@ -74,12 +79,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
echo "** Adding $1 to whitelist file"
fi
echo $1 >> $whitelist
modifyHost=true
else
if $versbose; then
echo "** $1 already whitelisted! No need to add"
fi
fi
}
function RemoveDomain(){
@ -88,10 +97,14 @@ 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
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
echo "** Un-whitelisting $dom..."
fi
domToRemoveList=("${domToRemoveList[@]}" $1)
modifyHost=true
fi
@ -145,18 +158,22 @@ do
case "$var" in
"-nr"| "--noreload" ) reload=false;;
"-d" | "--delmode" ) addmode=false;;
"-f" | "--force" ) force=true;;
"-q" | "--quiet" ) versbose=false;;
* ) HandleOther $var;;
esac
done
PopWhitelistFile
if $modifyHost; then
if $modifyHost || $force; then
echo "** Modifying Hosts File"
ModifyHostFile
else
if $versbose; then
echo "** No changes need to be made"
exit 1
fi
fi
if $reload; then