├── pihole-led.sh ├── README.md └── startup.sh /pihole-led.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########### 3 | ### This pihole-led script is built for the odroid c1+ using wiringPi here: 4 | ### https://github.com/hardkernel/wiringPi 5 | ### Built for pihole log's however you can modify as needed of course. 6 | ### I use header pin 9 for the ground and pin 11 for gpio. 7 | ### header 11 is equal to export gpio=88 or wiringPi pin=0 as used below. 8 | ########### 9 | ### Version: 0.1 10 | ### Author: Daniel Stinebaugh 11 | ### Attribution: http://www.stinebaugh.info/get-led-alerts-for-each-blocked-ad-using-pi-hole/ 12 | ### Date: 03/19/2016 13 | ### License: Copyleft. Enjoy! 14 | ########### 15 | pin=0 16 | gpio mode $pin out 17 | # Defaults the pin to low when starting 18 | gpio write $pin 0 19 | tailf /var/log/pihole.log | while read INPUT 20 | do 21 | if [[ "$INPUT" == *"/etc/pihole/gravity.list"* ]]; then 22 | gpio write $pin 1 23 | sleep 0.2 24 | gpio write $pin 0 25 | # echo "another ad bites the dust!" 26 | sleep 0.1 27 | fi 28 | done 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pihole-led 2 | ## Realtime LED alerts when an ad is blocked when using pi-hole. 3 | 4 | pihole-led.sh will parse /var/log/pihole.log for the string "/etc/pihole/gravity.list" and if found it will set gpio header pin 11 (wiringpi pin 0) to high (on) briefly then turn it back off making it blink once for each entry found in near realtime. 5 | 6 | *Requires ([wiringPi](http://wiringpi.com/)) to be installed* 7 | 8 | *wiringPi for the odroid here: https://github.com/hardkernel/wiringPi* 9 | 10 | Comment out the echo line 25 in the loop if you don't want textual updates to the terminal. 11 | 12 | I have now also included a startup script to launch the pihole-led.sh script on boot. Just edit the values in the Setting block and include it's location to your /etc/rc.local file. 13 | 14 | The startup script will launch a new screen session named "blink" so the screen package is also required to be installed. (It's in your repos most likely) 15 | 16 | Attribution and more info: http://www.stinebaugh.info/get-led-alerts-for-each-blocked-ad-using-pi-hole/ 17 | -------------------------------------------------------------------------------- /startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########### 3 | ### Provides an easy way to run my pihole-led.sh script on boot in it's own screen session. 4 | ### https://github.com/dstinebaugh/pihole-led 5 | ### Built for my script however you can modify as needed of course. 6 | ### Don't forget to change the Settings block below to match your locations! 7 | ### BLINKLOC should be the folder that has pihole-led.sh in it 8 | ### HISTORY is the number of scrollback lines in the screen session. Unless you have uncommented the echo line in the 9 | ### pihole script, there's not really any need for a scrollback so I've lowered it to keep memory use down on the pi. 10 | ########### 11 | ### Version: 0.1 12 | ### Author: Daniel Stinebaugh 13 | ### Attribution: http://www.stinebaugh.info/pihole-led-startup-script/ 14 | ### Date: 04/20/2016 15 | ### License: Copyleft. Enjoy! 16 | ########### 17 | 18 | #### Settings 19 | # Linux user to run as 20 | USERNAME='daniel' 21 | # folder holding the pihole-led.sh file 22 | BLINKLOC='/home/daniel/' 23 | # script name to run 24 | INVOCATION="pihole-led.sh" 25 | # history log of screen session keeping it small to save resources. 26 | HISTORY=10 27 | ### End Settings 28 | 29 | 30 | ME=`whoami` 31 | as_user() { 32 | if [ $ME == $USERNAME ] ; then 33 | bash -c "$1" 34 | else 35 | su - $USERNAME -c "$1" 36 | fi 37 | } 38 | 39 | 40 | if pgrep -u $USERNAME -f $INVOCATION > /dev/null 41 | then 42 | echo "pihole-led is already running!" 43 | echo " Check your screen sessions." 44 | exit 420 45 | else 46 | echo "Starting pihole-led.sh in a new screen session..." 47 | cd $BLINKLOC 48 | as_user "cd $BLINKLOC && screen -h $HISTORY -dmS blink $BLINKLOC$INVOCATION" 49 | sleep 5 50 | if pgrep -u $USERNAME -f $INVOCATION > /dev/null 51 | then 52 | logger -s "pihole-led.sh is now running." 53 | else 54 | logger -s "[ALERT] Couldn't Validate pihole-led.sh Started Properly!" 55 | fi 56 | fi 57 | echo "Startup Script complete." 58 | 59 | exit 0 60 | --------------------------------------------------------------------------------