Skip to content

Instantly share code, notes, and snippets.

@RobFreiburger
Last active May 14, 2020 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobFreiburger/fea17f1a957678e2b722207de9e496e0 to your computer and use it in GitHub Desktop.
Save RobFreiburger/fea17f1a957678e2b722207de9e496e0 to your computer and use it in GitHub Desktop.
#!/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