added 486 characters in body
Source Link
jake
  • 1k
  • 7
  • 20
#!/bin/bash

installAB () {
  
  if [[ "$(crontab -l | grep adblocker.sh)" =~ adblocker.sh ]]; then
    echo "adblocker is already installed"
    echo exit
    exit 1
  fi

  crontab -l > mycron
  echo '@daily        SHELL=/bin/bash ~/adblocker.sh --update' >> mycron
  crontab mycron
  rm mycron
  backupFile="/etc/dnsmasq.conf.bak-$(date +%d%m%y%H%M)"
  sudo mv /etc/dnsmasq.conf "$backupFile"
  echo "conf-file=/etc/dnsmasq.domains.conf
  addn-hosts=/etc/dnsmasq.hostnames.conf
  $(egrep -v  '^#|^s*$' $backupFile)" | sudo tee /etc/dnsmasq.conf > /dev/null

}

updateAB () {

  wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/domains.txt https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt
  wgetreturn=$?

  sudo mv domains.txt /etc/dnsmasq.domains.conf
  sudo mv hostnames.txt /etc/dnsmasq.hostnames.conf

  if [ $wgetreturn -eq 0 ]; then
      echo "successfully updated: $(date)" >> /home/pi/update_adblocker.log 
  else
      echo "downloading domains and hostnames failed: $(date)" >> /home/pi/update_adblocker.log
  fi

}


activateAB () {

  sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*//g' /etc/dnsmasq.conf
  echo "adblocker activated"

}


deactivateAB () {

  sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*/#/g' /etc/dnsmasq.conf
  echo "adblocker deactivated"

}

case "$1" in
  install|--install) 
    updateAB
    installAB
    ;;
  start|--start)
    activateAB
    ;;
  stop|--stop)
    deactivateAB
    ;;
  update|--update) 
    updateAB
    ;;
  *) 
    echo "run the script with »--install«, »--start«, »--stop« or »--update«"
    echo "exit"
    exit 1
    ;;
esac

sudo service dnsmasq restart && echo "service restarted"
#!/bin/bash

installAB () {
  
  if [[ "$(crontab -l | grep adblocker.sh)" =~ adblocker.sh ]]; then
    echo "adblocker is already installed"
    echo exit
    exit 1
  fi

  crontab -l > mycron
  echo '@daily        SHELL=/bin/bash ~/adblocker.sh --update' >> mycron
  crontab mycron
  rm mycron
  backupFile="/etc/dnsmasq.conf.bak-$(date +%d%m%y%H%M)"
  sudo mv /etc/dnsmasq.conf "$backupFile"
  echo "conf-file=/etc/dnsmasq.domains.conf
  addn-hosts=/etc/dnsmasq.hostnames.conf
  $(egrep -v  '^#|^s*$' $backupFile)" | sudo tee /etc/dnsmasq.conf > /dev/null

}

updateAB () {

  wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/domains.txt https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt
  wgetreturn=$?

  sudo mv domains.txt /etc/dnsmasq.domains.conf
  sudo mv hostnames.txt /etc/dnsmasq.hostnames.conf

  if [ $wgetreturn -eq 0 ]; then
      echo "successfully updated: $(date)" >> /home/pi/update_adblocker.log 
  else
      echo "downloading domains and hostnames failed: $(date)" >> /home/pi/update_adblocker.log
  fi

}


activateAB () {

  sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*//g' /etc/dnsmasq.conf
  echo "adblocker activated"

}


deactivateAB () {

  sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*/#/g' /etc/dnsmasq.conf
  echo "adblocker deactivated"

}

case "$1" in
  install|--install) 
    updateAB
    installAB
    ;;
  start|--start)
    activateAB
    ;;
  stop|--stop)
    deactivateAB
    ;;
  update|--update) 
    updateAB
    ;;
  *) 
    echo "run the script with »--install«, »--start«, »--stop« or »--update«"
    echo "exit"
    exit 1
    ;;
esac

sudo service dnsmasq restart && echo "service restarted"
#!/bin/bash

installAB () {
  
  if [[ "$(crontab -l | grep adblocker.sh)" =~ adblocker.sh ]]; then
    echo "adblocker is already installed"
    echo exit
    exit 1
  fi

  crontab -l > mycron
  echo '@daily        SHELL=/bin/bash ~/adblocker.sh --update' >> mycron
  crontab mycron
  rm mycron
  backupFile="/etc/dnsmasq.conf.bak-$(date +%d%m%y%H%M)"
  sudo mv /etc/dnsmasq.conf "$backupFile"
  echo "conf-file=/etc/dnsmasq.domains.conf
addn-hosts=/etc/dnsmasq.hostnames.conf
$(egrep -v  '^#|^s*$' $backupFile)" | sudo tee /etc/dnsmasq.conf > /dev/null

}

updateAB () {

  wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/domains.txt https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt
  wgetreturn=$?

  sudo mv domains.txt /etc/dnsmasq.domains.conf
  sudo mv hostnames.txt /etc/dnsmasq.hostnames.conf

  if [ $wgetreturn -eq 0 ]; then
      echo "successfully updated: $(date)" >> /home/pi/update_adblocker.log 
  else
      echo "downloading domains and hostnames failed: $(date)" >> /home/pi/update_adblocker.log
  fi

}


activateAB () {

  sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*//g' /etc/dnsmasq.conf
  echo "adblocker activated"

}


deactivateAB () {

  sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*/#/g' /etc/dnsmasq.conf
  echo "adblocker deactivated"

}

case "$1" in
  install|--install) 
    updateAB
    installAB
    ;;
  start|--start)
    activateAB
    ;;
  stop|--stop)
    deactivateAB
    ;;
  update|--update) 
    updateAB
    ;;
  *) 
    echo "run the script with »--install«, »--start«, »--stop« or »--update«"
    echo "exit"
    exit 1
    ;;
esac

sudo service dnsmasq restart && echo "service restarted"
added 486 characters in body
Source Link
jake
  • 1k
  • 7
  • 20

I've found a solution: I wrote this script and addedcreated a daily cronjob forscript to share it:

. This script will download a list of known domains and block them by using crontab -ednsmasq

add:

. Those lists will be updated daily. Run @daily SHELL=/bin/bash /home/pi./adblocker.sh --updateinstall|--start|--stop to install, start or stop it.

The script:The script:

#!/bin/bash

installAB () {
  
  if [[ "$(crontab -l | grep adblocker.sh)" =~ adblocker.sh ]]; then
    echo "adblocker is already installed"
    echo exit
    exit 1
  fi

  crontab -l > mycron
  echo '@daily        SHELL=/bin/bash ~/adblocker.sh --update' >> mycron
  crontab mycron
  rm mycron
  backupFile="/etc/dnsmasq.conf.bak-$(date +%d%m%y%H%M)"
  sudo mv /etc/dnsmasq.conf "$backupFile"
  echo "conf-file=/etc/dnsmasq.domains.conf
  addn-hosts=/etc/dnsmasq.hostnames.conf
  $(egrep -v  '^#|^s*$' $backupFile)" | sudo tee /etc/dnsmasq.conf > /dev/null

}

updateAB () { 

  wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/domains.txt https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt
  wgetreturn=$?

  sudo mv domains.txt /etc/dnsmasq.domains.conf
  sudo mv hostnames.txt /etc/dnsmasq.hostnames.conf

  if [ $wgetreturn -eq 0 ]; then
   cat >> /home/pi/update_adblocker.log <<EOF
successfullyecho "successfully updated: $(date)
EOF
   else
    cat" >> /home/pi/update_adblocker.log <<EOF
downloading  else
      echo "downloading domains and hostnames failed: $(date)
EOF" >> /home/pi/update_adblocker.log
  fi 

}


activateAB () { 

  sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*//g' /etc/dnsmasq.conf
sudo service apache2 restart
sudo systemctl enable apache2
echo "adblocker activated" 

}


deactivateAB () {
     
  sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*/#/g' /etc/dnsmasq.conf
      sudo service apache2 stop
      sudo systemctl disable apache2
      echo "adblocker deactivated" 

}

case "$1" in
        install|--startinstall)  activateAB
    updateAB
    installAB
    ;;
        start|--stopstart) deactivateAB
    activateAB
    ;;
  stop|--stop)
  ;;
  deactivateAB
    ;;
  update|--update) updateAB
        updateAB
    ;;
        *)  
   *) echo "run the script with »--install«, »--start«, »--stop« or »--update«"
               echo "exit"
               exit 1
            ;;
esac
 

sudo service dnsmasq restart && echo "service restarted"

Then I added conf-file=/etc/dnsmasq.domains.conf and addn-hosts=/etc/dnsmasq.hostnames.conf to /etc/dnsmasq.conf and restarted the service sudo service dnsmasq restart.

I've found a solution: I wrote this script and added a daily cronjob for it:

crontab -e

add:

@daily SHELL=/bin/bash /home/pi/adblocker.sh --update

The script:

#!/bin/bash

updateAB () {
wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/domains.txt https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt
wgetreturn=$?

sudo mv domains.txt /etc/dnsmasq.domains.conf
sudo mv hostnames.txt /etc/dnsmasq.hostnames.conf

if [ $wgetreturn -eq 0 ]; then
   cat >> /home/pi/update_adblocker.log <<EOF
successfully updated: $(date)
EOF
   else
    cat >> /home/pi/update_adblocker.log <<EOF
downloading domains and hostnames failed: $(date)
EOF
fi
}


activateAB () {
sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*//g' /etc/dnsmasq.conf
sudo service apache2 restart
sudo systemctl enable apache2
echo "adblocker activated"
}


deactivateAB () {
      sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*/#/g' /etc/dnsmasq.conf
      sudo service apache2 stop
      sudo systemctl disable apache2
      echo "adblocker deactivated"
}

case "$1" in
        --start)  activateAB
            ;;
        --stop) deactivateAB
            ;;
        --update) updateAB
            ;;
            *) echo "run the script with »--start«, »--stop« or »--update«"
               echo "exit"
               exit 1
            ;;
esac
 

sudo service dnsmasq restart && echo "service restarted"

Then I added conf-file=/etc/dnsmasq.domains.conf and addn-hosts=/etc/dnsmasq.hostnames.conf to /etc/dnsmasq.conf and restarted the service sudo service dnsmasq restart.

I've found a solution and created a script to share it. This script will download a list of known domains and block them by using dnsmasq. Those lists will be updated daily. Run ./adblocker.sh --install|--start|--stop to install, start or stop it.

The script:

#!/bin/bash

installAB () {
  
  if [[ "$(crontab -l | grep adblocker.sh)" =~ adblocker.sh ]]; then
    echo "adblocker is already installed"
    echo exit
    exit 1
  fi

  crontab -l > mycron
  echo '@daily        SHELL=/bin/bash ~/adblocker.sh --update' >> mycron
  crontab mycron
  rm mycron
  backupFile="/etc/dnsmasq.conf.bak-$(date +%d%m%y%H%M)"
  sudo mv /etc/dnsmasq.conf "$backupFile"
  echo "conf-file=/etc/dnsmasq.domains.conf
  addn-hosts=/etc/dnsmasq.hostnames.conf
  $(egrep -v  '^#|^s*$' $backupFile)" | sudo tee /etc/dnsmasq.conf > /dev/null

}

updateAB () { 

  wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/domains.txt https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt
  wgetreturn=$?

  sudo mv domains.txt /etc/dnsmasq.domains.conf
  sudo mv hostnames.txt /etc/dnsmasq.hostnames.conf

  if [ $wgetreturn -eq 0 ]; then
      echo "successfully updated: $(date)" >> /home/pi/update_adblocker.log 
  else
      echo "downloading domains and hostnames failed: $(date)" >> /home/pi/update_adblocker.log
  fi 

}


activateAB () { 

  sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*//g' /etc/dnsmasq.conf
  echo "adblocker activated" 

}


deactivateAB () {
 
  sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*/#/g' /etc/dnsmasq.conf
  echo "adblocker deactivated" 

}

case "$1" in
  install|--install) 
    updateAB
    installAB
    ;;
  start|--start)
    activateAB
    ;;
  stop|--stop)
    deactivateAB
    ;;
  update|--update) 
    updateAB
    ;;
  *)  
    echo "run the script with »--install«, »--start«, »--stop« or »--update«"
    echo "exit"
    exit 1
    ;;
esac

sudo service dnsmasq restart && echo "service restarted"
Improved the update script
Source Link
jake
  • 1k
  • 7
  • 20

I've found a solution: I wrote this script and added a daily cronjob for it:

@daily crontab -e

add:

@daily SHELL=/bin/bash /home/pi/update_adblockeradblocker.sh --update for it

The script:

#!/bin/bash 

updateAB () {
wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/domains.txt
wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt
wgetreturn=$?

sudo mv domains.txt /etc/dnsmasq.domains.conf
sudo mv hostnames.txt /etc/dnsmasq.hostnames.conf

if [ $wgetreturn -eq 0 ]; then
   cat >> /home/pi/update_adblocker.log <<EOF
successfully updated: $(date)
EOF
   else
    cat >> /home/pi/update_adblocker.log <<EOF
downloading domains and hostnames failed: $(date)
EOF
fi
}


activateAB () {
sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*//g' /etc/dnsmasq.conf
sudo service apache2 restart
sudo systemctl enable apache2
echo "adblocker activated"
}


deactivateAB () {
      sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*/#/g' /etc/dnsmasq.conf
      sudo service apache2 stop
      sudo systemctl disable apache2
      echo "adblocker deactivated"
}

case "$1" in
        --start)  activateAB
            ;;
        --stop) deactivateAB
            ;;
        --update) updateAB
            ;;
            *) echo "run the script with »--start«, »--stop« or »--update«"
               echo "exit"
               exit 1
            ;;
esac


sudo service dnsmasq restart && echo "service restarted"

Then I added conf-file=/etc/dnsmasq.domains.conf and addn-hosts=/etc/dnsmasq.hostnames.conf to /etc/dnsmasq.conf and restarted the service sudo service dnsmasq restart.

I've found a solution: I wrote this script and added a daily cronjob @daily SHELL=/bin/bash /home/pi/update_adblocker.sh for it:

#!/bin/bash

wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/domains.txt
wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt

sudo mv domains.txt /etc/dnsmasq.domains.conf
sudo mv hostnames.txt /etc/dnsmasq.hostnames.conf

sudo service dnsmasq restart

Then I added conf-file=/etc/dnsmasq.domains.conf and addn-hosts=/etc/dnsmasq.hostnames.conf to /etc/dnsmasq.conf and restarted the service sudo service dnsmasq restart.

I've found a solution: I wrote this script and added a daily cronjob for it:

crontab -e

add:

@daily SHELL=/bin/bash /home/pi/adblocker.sh --update

The script:

#!/bin/bash 

updateAB () {
wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/domains.txt https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt
wgetreturn=$?

sudo mv domains.txt /etc/dnsmasq.domains.conf
sudo mv hostnames.txt /etc/dnsmasq.hostnames.conf

if [ $wgetreturn -eq 0 ]; then
   cat >> /home/pi/update_adblocker.log <<EOF
successfully updated: $(date)
EOF
   else
    cat >> /home/pi/update_adblocker.log <<EOF
downloading domains and hostnames failed: $(date)
EOF
fi
}


activateAB () {
sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*//g' /etc/dnsmasq.conf
sudo service apache2 restart
sudo systemctl enable apache2
echo "adblocker activated"
}


deactivateAB () {
      sudo sed -i '/dnsmasq.domains.conf\|dnsmasq.hostnames.conf/s/^#*/#/g' /etc/dnsmasq.conf
      sudo service apache2 stop
      sudo systemctl disable apache2
      echo "adblocker deactivated"
}

case "$1" in
        --start)  activateAB
            ;;
        --stop) deactivateAB
            ;;
        --update) updateAB
            ;;
            *) echo "run the script with »--start«, »--stop« or »--update«"
               echo "exit"
               exit 1
            ;;
esac


sudo service dnsmasq restart && echo "service restarted"

Then I added conf-file=/etc/dnsmasq.domains.conf and addn-hosts=/etc/dnsmasq.hostnames.conf to /etc/dnsmasq.conf and restarted the service sudo service dnsmasq restart.

added 54 characters in body
Source Link
jake
  • 1k
  • 7
  • 20
Loading
added 12 characters in body
Source Link
jake
  • 1k
  • 7
  • 20
Loading
added 305 characters in body
Source Link
jake
  • 1k
  • 7
  • 20
Loading
Source Link
jake
  • 1k
  • 7
  • 20
Loading