1
0
mirror of https://github.com/pi-hole/pi-hole synced 2025-01-08 15:10:55 +00:00

output to match other scripts

This commit is contained in:
Promofaux 2016-01-24 17:18:37 +00:00
parent 3cd1a5b1d5
commit 8ecf8eb76c

View File

@ -81,13 +81,14 @@ function AddDomain(){
if $bool; then if $bool; then
#domain not found in the blacklist file, add it! #domain not found in the blacklist file, add it!
if $versbose; then if $versbose; then
echo "** Adding $1 to blacklist file" echo -n "::: Adding $1 to blacklist file..."
fi fi
echo $1 >> $blacklist echo $1 >> $blacklist
modifyHost=true modifyHost=true
echo " done!"
else else
if $versbose; then if $versbose; then
echo "** $1 already blacklisted! No need to add" echo "::: $1 already exists in blacklist.txt! No need to add"
fi fi
fi fi
} }
@ -99,12 +100,12 @@ function RemoveDomain(){
if $bool; then if $bool; then
#Domain is not in the blacklist file, no need to Remove #Domain is not in the blacklist file, no need to Remove
if $versbose; then if $versbose; then
echo "** $1 is NOT blacklisted! No need to remove" echo "::: $1 is NOT blacklisted! No need to remove"
fi fi
else else
#Domain is in the blacklist file, add to a temporary array #Domain is in the blacklist file, add to a temporary array
if $versbose; then if $versbose; then
echo "** Un-blacklisting $dom..." echo "::: Un-blacklisting $dom..."
fi fi
domToRemoveList=("${domToRemoveList[@]}" $1) domToRemoveList=("${domToRemoveList[@]}" $1)
modifyHost=true modifyHost=true
@ -117,7 +118,8 @@ function ModifyHostFile(){
if [[ -r $blacklist ]];then if [[ -r $blacklist ]];then
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l) numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l)
plural=; [[ "$numberOf" != "1" ]] && plural=s plural=; [[ "$numberOf" != "1" ]] && plural=s
echo "** blacklisting a total of $numberOf domain${plural}..." echo ":::"
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
if [[ -n $piholeIPv6 ]];then if [[ -n $piholeIPv6 ]];then
cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList
else else
@ -126,12 +128,18 @@ function ModifyHostFile(){
fi fi
else else
echo ":::"
for dom in "${domToRemoveList[@]}" for dom in "${domToRemoveList[@]}"
do do
#we need to remove the domains from the blacklist file and the host file #we need to remove the domains from the blacklist file and the host file
echo "::: $dom"
echo -n "::: removing from HOSTS file..."
echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList
echo " done!"
echo -n "::: removing from blackist.txt..."
echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist
echo " done!"
done done
fi fi
@ -139,7 +147,8 @@ function ModifyHostFile(){
function Reload() { function Reload() {
# Reload hosts file # Reload hosts file
echo "** Refresh lists in dnsmasq..." echo ":::"
echo -n "::: Refresh lists in dnsmasq..."
dnsmasqPid=$(pidof dnsmasq) dnsmasqPid=$(pidof dnsmasq)
@ -150,6 +159,7 @@ function Reload() {
# service not running, start it up # service not running, start it up
sudo service dnsmasq start sudo service dnsmasq start
fi fi
echo " done!"
} }
################################################### ###################################################
@ -167,12 +177,11 @@ done
PopBlacklistFile PopBlacklistFile
if $modifyHost || $force; then if $modifyHost || $force; then
echo "** Modifying Hosts File"
ModifyHostFile ModifyHostFile
else else
if $versbose; then if $versbose; then
echo "** No changes need to be made" echo "::: No changes need to be made"
fi fi
exit 1 exit 1
fi fi