Nico Huber | 804b41b | 2023-07-02 15:53:42 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | set -e |
| 4 | |
Nico Huber | b650ed4 | 2023-07-20 17:08:54 +0000 | [diff] [blame^] | 5 | # Add local containers as trusted for postfix relaying. |
| 6 | add_mynetworks_hosts() { |
| 7 | myhosts= |
| 8 | for host in mailserver "$@"; do |
| 9 | IP=$(host ${host} | sed -n 's/.*has address //p') |
| 10 | myhosts="${myhosts} ${IP}/32" |
| 11 | done |
| 12 | postconf "mynetworks =${myhosts}" |
| 13 | } |
| 14 | |
| 15 | # Create given users, requiring a plain-text password in `/tmp/passwd/`. |
| 16 | add_users_with_passwd() { |
| 17 | for user in "$@"; do |
| 18 | i=0 |
| 19 | while [ -z "$(cat /tmp/passwd/${user}/secret 2>/dev/null)" ]; do |
| 20 | if [ ${i} -eq 10 ]; then |
| 21 | echo "ERROR: No password file for '${user}' after ${i}s." |
| 22 | exit 1 |
| 23 | fi |
| 24 | sleep 1 |
| 25 | i=$((i+1)) |
| 26 | done |
| 27 | |
| 28 | if [ ! -d /var/mail/${HOSTNAME#mail.}/${user} ]; then |
| 29 | setup email add gerrit@${HOSTNAME#mail.} $(cat /tmp/passwd/${user}/secret) |
| 30 | else |
| 31 | setup email update gerrit@${HOSTNAME#mail.} $(cat /tmp/passwd/${user}/secret) |
| 32 | fi |
| 33 | done |
| 34 | } |
| 35 | |
Nico Huber | 804b41b | 2023-07-02 15:53:42 +0000 | [diff] [blame] | 36 | { |
Nico Huber | b650ed4 | 2023-07-20 17:08:54 +0000 | [diff] [blame^] | 37 | add_users_with_passwd gerrit |
| 38 | |
| 39 | # Restrict gerrit@ sending to local IP: |
| 40 | if ! grep -q gerrit /tmp/docker-mailserver/user.access 2>/dev/null; then |
| 41 | echo "gerrit@${HOSTNAME#mail.} gerrit_sender_check" >>/tmp/docker-mailserver/user.access |
| 42 | postmap /tmp/docker-mailserver/user.access |
| 43 | fi |
| 44 | IP=$(host gerrit | sed -n 's/.*has address //p') |
| 45 | echo "${IP} permit_sasl_authenticated" >/tmp/docker-mailserver/gerrit-client.access |
| 46 | postmap /tmp/docker-mailserver/gerrit-client.access |
Nico Huber | 804b41b | 2023-07-02 15:53:42 +0000 | [diff] [blame] | 47 | } |