Last active
May 14, 2020 15:48
-
-
Save RobFreiburger/fea17f1a957678e2b722207de9e496e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# As of Pi-hole v5.0, this script is no longer needed. | |
pihole_whitelist_string="" | |
if [[ $# -eq 0 ]]; then | |
echo "Please use one or more domains as arguments for this script:" | |
echo "./"`basename "$0"`" example.com foo.org" | |
exit 1 | |
fi | |
# Update gravity if it's over a hour old | |
if test `find "/etc/pihole/gravity.list" -mmin +60` | |
then | |
pihole -g | |
fi | |
while [[ $# > 0 ]] | |
do | |
# Whitelist requested domain/subdomain | |
pihole_whitelist_string="$pihole_whitelist_string $1" | |
# Create properly escaped string of input for grep | |
domain_grep="\.${1//./'\.'}$" | |
# Search gravity for input's subdomains and concatenate | |
pihole_whitelist_string="$pihole_whitelist_string $(cat /etc/pihole/gravity.list | grep "$domain_grep" | cut -d' ' -f2 | tr '\n' ' ')" | |
# Discard $1 to work on $#+1 | |
shift | |
done | |
pihole -w $pihole_whitelist_string | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment