| #!/bin/sh |
| |
| set -e |
| |
| # Add local containers as trusted for postfix relaying. |
| add_mynetworks_hosts() { |
| myhosts= |
| for host in mailserver "$@"; do |
| IP=$(host ${host} | sed -n 's/.*has address //p') |
| myhosts="${myhosts} ${IP}/32" |
| done |
| postconf "mynetworks =${myhosts}" |
| } |
| |
| # Create given users, requiring a plain-text password in `/tmp/passwd/`. |
| add_users_with_passwd() { |
| for user in "$@"; do |
| i=0 |
| while [ -z "$(cat /tmp/passwd/${user}/secret 2>/dev/null)" ]; do |
| if [ ${i} -eq 10 ]; then |
| echo "ERROR: No password file for '${user}' after ${i}s." |
| exit 1 |
| fi |
| sleep 1 |
| i=$((i+1)) |
| done |
| |
| if [ ! -d /var/mail/${HOSTNAME#mail.}/${user} ]; then |
| setup email add gerrit@${HOSTNAME#mail.} $(cat /tmp/passwd/${user}/secret) |
| else |
| setup email update gerrit@${HOSTNAME#mail.} $(cat /tmp/passwd/${user}/secret) |
| fi |
| done |
| } |
| |
| { |
| add_users_with_passwd gerrit |
| |
| # Restrict gerrit@ sending to local IP: |
| if ! grep -q gerrit /tmp/docker-mailserver/user.access 2>/dev/null; then |
| echo "gerrit@${HOSTNAME#mail.} gerrit_sender_check" >>/tmp/docker-mailserver/user.access |
| postmap /tmp/docker-mailserver/user.access |
| fi |
| IP=$(host gerrit | sed -n 's/.*has address //p') |
| echo "${IP} permit_sasl_authenticated" >/tmp/docker-mailserver/gerrit-client.access |
| postmap /tmp/docker-mailserver/gerrit-client.access |
| } |