Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

52 lines
1.4KB

  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. CONF_FILE=custom_dnsmasq.conf
  8. IP_LOOKUP="$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')" # May not work for VPN / tun0
  9. # read variables, for domain and host names
  10. source .env
  11. # global domain
  12. echo server=/${LDAP_DOMAIN}/${IP_LOOKUP} > /tmp/${CONF_FILE}
  13. # mail
  14. #echo address=/${MAIL_HOSTNAME}.${LDAP_DOMAIN}/${IP_LOOKUP} > /tmp/${CONF_FILE}
  15. # Nextcloud
  16. #echo address=/${NEXTCLOUD_SERVER_NAME}.${LDAP_DOMAIN}/${IP_LOOKUP} >> /tmp/${CONF_FILE}
  17. # gogs
  18. #echo address=/gogs.${LDAP_DOMAIN}/${IP_LOOKUP} >> /tmp/${CONF_FILE}
  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. container=$(ssh $host 'docker ps | grep pihole | cut -f1 -d" "')
  27. #echo Container=$container
  28. if [ -z $container ]; then
  29. echo "Qué me estás container?!";
  30. exit 1;
  31. fi
  32. echo Copying user files to Host $host
  33. scp -r /tmp/${CONF_FILE} $host:/tmp/
  34. echo Copying user files to Container $container in Host $host
  35. ssh $host "docker cp /tmp/${CONF_FILE} $container:/etc/dnsmasq.d/99-local-addresses.conf"
  36. # restart dns
  37. ssh $host "docker exec ${container} pihole restartdns"
  38. echo Removing copied user files
  39. ssh $host "docker exec ${container} sh -c 'rm -Rf /tmp/${CONF_FILE}'"
  40. ssh $host "rm -Rf /tmp/${CONF_FILE}"