entrypoint.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. set -x
  3. touch /etc/passwd
  4. adduser nobody
  5. adduser postfix
  6. adduser dovecot
  7. adduser opendkim
  8. addgroup dovecot postfix
  9. addgroup opendkim postfix
  10. chown postfix:postfix "/var/mail/${MAIL_DOMAIN}"
  11. mkdir -p "/var/opendkim/keys/"
  12. chown opendkim:opendkim "/var/opendkim/keys/"
  13. chmod +x "/etc/service/postfix/run"
  14. chmod +x "/etc/service/dovecot/run"
  15. chmod +x "/etc/service/opendkim/run"
  16. chmod +x "/etc/service/rsyslog/run"
  17. chmod +x "/usr/bin/entrypoint.sh"
  18. mkdir -p "/var/mail/${MAIL_DOMAIN}/${MAIL_USER}"
  19. # Config postfix
  20. sed -ri \
  21. -e "s,%hostname%,${MAIL_DOMAIN}," \
  22. -e "s,%domain_root%,${MAIL_DOMAIN_ROOT}," \
  23. -e "s,%cert_file%,${SSL_CERT}," \
  24. -e "s,%key_file%,${SSL_KEY}," \
  25. -e "s,%postmaster_address%,${MAIL_ADDRESS}," \
  26. /etc/postfix/main.cf /etc/dovecot/dovecot.conf /etc/mail/opendkim/TrustedHosts
  27. # Prepare mail user
  28. touch /etc/mail/aliases /etc/mail/domains /etc/mail/mailboxes /etc/mail/passwd
  29. echo "${MAIL_DOMAIN} #OK" > /etc/mail/domains
  30. if ! grep -Fq 'root:' /etc/mail/aliases; then echo "root: ${MAIL_USER}" >> /etc/mail/aliases; fi
  31. echo "${MAIL_USER} ${MAIL_DOMAIN}/${MAIL_USER}/" > /etc/mail/mailboxes
  32. echo "${MAIL_USER}:${HASHED_PASSWORD}" > /etc/mail/passwd
  33. # Run opendkim
  34. if [ ! -e "/var/opendkim/keys/default.private" ]
  35. then
  36. opendkim-genkey -d "${MAIL_DOMAIN}" -D "/var/opendkim/keys/"
  37. fi
  38. newaliases
  39. postmap /etc/mail/aliases /etc/mail/domains /etc/mail/mailboxes /etc/mail/passwd
  40. postfix reload
  41. dovecot
  42. # # Run services
  43. # s6-svscan /etc/service