選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

61 行
1.6KB

  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
  14. echo server=/${LDAP_DOMAIN}/${IP_LOOKUP} > /tmp/${CONF_FILE}
  15. # mail
  16. #echo address=/${MAIL_HOSTNAME}.${LDAP_DOMAIN}/${IP_LOOKUP} > /tmp/${CONF_FILE}
  17. # Nextcloud
  18. #echo address=/${NEXTCLOUD_SERVER_NAME}.${LDAP_DOMAIN}/${IP_LOOKUP} >> /tmp/${CONF_FILE}
  19. # gogs
  20. #echo address=/gogs.${LDAP_DOMAIN}/${IP_LOOKUP} >> /tmp/${CONF_FILE}
  21. # ##### Add entries to PiHole ###### #
  22. host=$(docker stack ps ${STACK_NAME} | grep -v Shutdown | grep Running | grep pihole | awk '{ print $4 }')
  23. #echo Host=$host
  24. if [ -z $host ]; then
  25. echo "No host found!";
  26. exit 1;
  27. fi
  28. # add avahi suffix
  29. localhostname=$(cat /etc/hostname)
  30. if [ "${localhostname}" != "${host}" ]; then
  31. host=${host}.local
  32. fi
  33. container=$(ssh $host 'docker ps | grep pihole | cut -f1 -d" "')
  34. #echo Container=$container
  35. if [ -z $container ]; then
  36. echo "Qué me estás container?!";
  37. exit 1;
  38. fi
  39. echo Copying user files to Host $host
  40. scp -r /tmp/${CONF_FILE} $host:/tmp/
  41. echo Copying user files to Container $container in Host $host
  42. ssh $host "docker cp /tmp/${CONF_FILE} $container:/etc/dnsmasq.d/99-local-addresses.conf"
  43. # restart dns
  44. ssh $host "docker exec ${container} pihole restartdns"
  45. echo Removing copied user files
  46. ssh $host "docker exec ${container} sh -c 'rm -Rf /tmp/${CONF_FILE}'"
  47. ssh $host "rm -Rf /tmp/${CONF_FILE}"