Skip to content

Instantly share code, notes, and snippets.

@JosepOli
Created November 8, 2023 15:58
Show Gist options
  • Save JosepOli/0725bac0018cdeb8d376814d5493febf to your computer and use it in GitHub Desktop.
Save JosepOli/0725bac0018cdeb8d376814d5493febf to your computer and use it in GitHub Desktop.
Codigo para añadir enlaces a la whitelist de pihole
#!/bin/bash
# Set the name of your Pi-hole Docker container
PIHOLE_CONTAINER_NAME='pihole-unbound'
# Set the name of your txt file with the domains to whitelist
WHITELIST_FILE_NAME='lista.txt'
# Check if the file exists
if [ ! -f "$WHITELIST_FILE_NAME" ]; then
echo "File $WHITELIST_FILE_NAME not found!"
exit 1
fi
# Convert Windows line endings to Unix line endings
dos2unix $WHITELIST_FILE_NAME
# Loop through each line in yout txt file and add it to the Pi-hole whitelist
while IFS= read -r url; do
# Trim the URL to remove possible white spaces and extract the domain
trimmed_url=$(echo "$url" | xargs)
# Use awk to extract the domain from a full URL
domain=$(echo "$trimmed_url" | awk -F/ '{print $3}')
# Check if the domain variable is not empty
if [ -n "$domain" ]; then
echo "Adding domain: $domain to the whitelist"
docker exec "$PIHOLE_CONTAINER_NAME" pihole -w "$domain"
fi
done < "$WHITELIST_FILE_NAME"
echo "All domains have been added to the whitelist."
@JosepOli
Copy link
Author

Hey, this was one of my first approaches to docker. Hence the overkill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment