build-postfix.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. . mailcow.conf
  3. NAME="postfix-mailcow"
  4. PDNS_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' pdns-mailcow 2> /dev/null)
  5. if [[ ! ${PDNS_IP} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  6. echo "Cannot determine Powerdns Recursor ip address. Is the container running?"
  7. exit 1
  8. fi
  9. build() {
  10. docker build --no-cache -t postfix data/Dockerfiles/postfix/.
  11. }
  12. if [[ ${1} == "--reconf" ]]; then
  13. reconf
  14. exit 0
  15. fi
  16. echo "Stopping and removing containers with name tag ${NAME}..."
  17. if [[ ! -z $(docker ps -af "name=${NAME}" -q) ]]; then
  18. docker stop $(docker ps -af "name=${NAME}" -q)
  19. docker rm $(docker ps -af "name=${NAME}" -q)
  20. fi
  21. if [[ ! -z "$(docker images -q postfix)" ]]; then
  22. read -r -p "Found image locally. Delete local and rebuild without cache anyway? [y/N] " response
  23. response=${response,,}
  24. if [[ $response =~ ^(yes|y)$ ]]; then
  25. docker rmi postfix
  26. build
  27. fi
  28. else
  29. build
  30. fi
  31. sed -i "/^user/c\user = ${DBUSER}" data/conf/postfix/sql/*
  32. sed -i "/^password/c\password = ${DBPASS}" data/conf/postfix/sql/*
  33. sed -i "/^dbname/c\dbname = ${DBNAME}" data/conf/postfix/sql/*
  34. docker run \
  35. -p ${SMTP_PORT}:25 \
  36. -p ${SMTPS_PORT}:465 \
  37. -p ${SUBMISSION_PORT}:587 \
  38. -v ${PWD}/data/conf/postfix:/opt/postfix/conf:ro \
  39. -v ${PWD}/data/assets/ssl:/etc/ssl/mail/:ro \
  40. --dns=${PDNS_IP} \
  41. --dns-search=${DOCKER_NETWORK} \
  42. --name ${NAME} \
  43. --network=${DOCKER_NETWORK} \
  44. --network-alias postfix \
  45. -h ${MAILCOW_HOSTNAME} \
  46. -d postfix