You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 satır
1.5KB

  1. #!/bin/bash
  2. STACK_NAME=$1
  3. if [ $# -eq 0 ]; then
  4. echo "You must pass stack name as a parameter"
  5. exit 1
  6. fi
  7. echo ""
  8. echo "Adding DNS entries to PI-HOLE"
  9. CONF_FILE=custom_dnsmasq.conf
  10. IP_LOOKUP="$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')" # May not work for VPN / tun0
  11. # read variables, for domain and host names
  12. source .env
  13. # global domain with all subdomains
  14. echo address=/.${DOMAIN}/${IP_LOOKUP} > /tmp/${CONF_FILE}
  15. # virtual domains
  16. for domain in ${VIRTUAL_DOMAINS[@]}; do
  17. echo address=/.${domain}/${IP_LOOKUP} >> /tmp/${CONF_FILE}
  18. done;
  19. # ##### Add entries to PiHole ###### #
  20. host=$(docker stack ps ${STACK_NAME} | grep -v Shutdown | grep Running | grep pihole | awk '{ print $4 }')
  21. #echo Host=$host
  22. if [ -z $host ]; then
  23. echo "No host found!";
  24. exit 1;
  25. fi
  26. # add avahi suffix
  27. localhostname=$(cat /etc/hostname)
  28. if [ "${localhostname}" != "${host}" ]; then
  29. host=${host}.local
  30. fi
  31. container=$(ssh $host 'docker ps | grep pihole | cut -f1 -d" "')
  32. #echo Container=$container
  33. if [ -z $container ]; then
  34. echo "Qué me estás container?!";
  35. exit 1;
  36. fi
  37. echo Copying user files to Host $host
  38. scp -r /tmp/${CONF_FILE} $host:/tmp/
  39. echo Copying user files to Container $container in Host $host
  40. ssh $host "docker cp /tmp/${CONF_FILE} $container:/etc/dnsmasq.d/99-local-addresses.conf"
  41. # restart dns
  42. ssh $host "docker exec ${container} pihole restartdns"
  43. echo Removing copied user files
  44. ssh $host "docker exec ${container} sh -c 'rm -Rf /tmp/${CONF_FILE}'"
  45. ssh $host "rm -Rf /tmp/${CONF_FILE}"