____ ___ _ _ ___ _ _____
| _ \_ _| | | |/ _ \| | | ____|
| |_) | || |_| | | | | | | _|
| __/| || _ | |_| | |___| |___
|_| |___|_| |_|\___/|_____|_____|
This repository provides scripts and configuration files to automate PiHole updates, email notifications, and more, keeping your network secure and ad-free with minimal manual intervention.
- Automated Updates:
- Refreshes package lists
- Installs upgrades
- Removes unused dependencies
- Updates Pi-hole itself
- Updates gravity lists
- Restarts Raspberry Pi
- Informative Email Notifications:
- Pre-update email with uptime information (potentially additional metrics to be added)
- Post-update email with uptime information (potentially additional metrics to be added)
- Comprehensive Documentation:
- Clear setup instructions with links to external resources
- Helpful tips for SSH access, file transfer, and log monitoring
- Active Pi-hole installation
- Consider using the instructional written by CrossTalk Solutions for the initial setup. The YouTube video worked well for me.
- Basic knowledge of Linux terminal commands
- Clone this repository to your Raspberry Pi or server.
- Github:
git clone https://github.com/ZachEngstrom/pihole.git - Gitlab:
git clone https://gitlab.com/engza/pihole.git
- Github:
- Install Speedtest CLI
- run
pip install speedtest-cli
- run
- Follow the instructions below
- Run this command in the root of your Raspberry Pi or server:
cp pihole/{pihole_configs.example.json,pihole_email_before_restart.py,pihole_email_after_restart.py} ./ && mv pihole_configs.example.json pihole_configs.json - Create a new email account and an email app password by following these instructions: Send an Email using Python. You can stop when you get to "The Email-Sending Script".
- Edit the configs file -
sudo nano pihole_configs.json- Use your arrow keys to navigate to the 3 values, remove the
REPLACE_WITH_THE_...text and then fill in the appropriate values. - You created the
from_addrandfrom_passvalues when you followed the Send an Email using Python document. - For the
to_addrvalue, I get the email message as a text to my phone. Here are some examples of how to do with with major cellular providers. Remember to replace "REPLACE_WITH_YOUR_TEN_DIGIT_PHONE_NUMBER" with your cell phone number: - Once you have all 3 values filled in, you can press [^X], [y] and [return] to save your changes and exit the file.
- Use your arrow keys to navigate to the 3 values, remove the
- Test that the email files work by running
python pihole_email_before_restart.py
andpython pihole_email_after_restart.py
in your terminal and then either checking your inbox or watching your phone for a text (depending on the value you entered for theto_addr).
- Run
cp pihole/pihole_update.sh pihole_update.sh - Run
sudo chmod +x ./pihole_update.shto make the file executable.
You can now run this script any time by running ./pihole_update.sh in your terminal.
- Run
crontab -ein your terminal - Add the following code to the end of the file:
55 1 * * 6 python pihole_email_before_restart.py 0 2 * * 6 ./pihole_update.sh >> pihole.log 2>&1 30 2 * * 6 python pihole_email_after_restart.py
- The 1st line runs
pihole_email_before_restart.pyevery Saturday at 1:55 AM. - The 2nd line runs
pihole_update.shevery Saturday at 2:00 AM and captures the output in thepihole.logfile (it will automatically get created if it's not already there). - The 3rd line runs
pihole_email_after_restart.pyevery Saturday at 2:30 AM.
- The 1st line runs
- Now press [^X], [y] and [return] to save your changes and exit the file.
- Validate that the file saved by running
crontab -lin your terminal. You should see the lines that you added.
- SSH into your Rasberry Pi
ssh PI_USER_NAME@PI_IP_ADDRESS
- Copy files from your local machine to your Raspberry Pi via SSH
scp pihole_update.sh pihole_email_before_restart.py pihole_email_after_restart.py pihole_configs.example.json PI_USER_NAME@PI_IP_ADDRESS:~
- Copy files from your Raspberry Pi to your local machine via SSH
scp PI_USER_NAME@PI_IP_ADDRESS:pihole.log ./
- Watch the
pihole.login real time as the update script is running (typically used when manually intiating the update script)tail -f pihole.log
- Use crontab.guru if you'd like to adjust when your cron jobs run.
As recommended in the CrossTalk Solutions tutorial, I referenced The Firebog for a majority of the lists that I implemented.
Here is a complete list of the ad lists that I've implemented:
- https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
- https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt
- https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts
- https://adaway.org/hosts.txt
- https://v.firebog.net/hosts/AdguardDNS.txt
- https://v.firebog.net/hosts/Easyprivacy.txt
- https://v.firebog.net/hosts/Prigent-Ads.txt
- https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt
- https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt
- https://zerodot1.gitlab.io/CoinBlockerLists/hosts_browser
I did have to whitelist slackb.com to use slack on my network.
- Set the email app password as an environment variable instead of in the config file.
- Handle the uptime and speedtest in the python scripts instead of being passed as parameters from out side the file
- Email python files don't have a fall back for null/empty values. This should be addressed.
All contributions and suggestions are welcome! Please create an issue or pull request on GitHub or Gitlab.