Skip to content

Instantly share code, notes, and snippets.

@Will-Beninger
Created May 15, 2023 17:21
Show Gist options
  • Save Will-Beninger/0c817432c3970ffdd2c45b0c8631fe0f to your computer and use it in GitHub Desktop.
Save Will-Beninger/0c817432c3970ffdd2c45b0c8631fe0f to your computer and use it in GitHub Desktop.
Script to update pihole gravity list from firebog.net and automatically add/remove entries. Runs on cronjob weekly without additional addons. Based on a Reddit comment with small tweaks, source: https://www.reddit.com/r/pihole/comments/mxf6rp/comment/gvq1rn3/
#!/bin/bash
#This will pull the list of ticked from firebog, removes outdates lists, and then updates the sqlite db before updating gravity
#Based on this Reddit Comment with a slight fix to the if logic as default behaviour was space breaking:
#https://www.reddit.com/r/pihole/comments/mxf6rp/comment/gvq1rn3/
#
#This is being run from crontab by root (required for pihole command)
#Command: crontab -u root -e
#Runs on Satuday morning at 3:34am
#34 3 * * 6 /opt/pihole-custom/update-lists.sh > /opt/pihole-custom/updatelist.log 2>&1
sqlite3 /etc/pihole/gravity.db "SELECT Address FROM adlist" |sort -u > ./pihole.list
wget -qO - https://v.firebog.net/hosts/lists.php?type=tick |sort -u > ./src.list
diff -q ./pihole.list ./src.list 1>/dev/null 2>&1
if [ $? == "1" ]; then
comm -23 ./pihole.list ./src.list | xargs -I{} sudo sqlite3 /etc/pihole/gravity.db "DELETE FROM adlist WHERE Address='{}';"
comm -13 ./pihole.list ./src.list |xargs -I{} sudo sqlite3 /etc/pihole/gravity.db "INSERT INTO adlist (Address,Comment,Enabled) VALUES ('{}','Scrip$ pihole restartdns reload-lists
pihole -g
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment