blob: 5a10bbdd4e60ffc67ebacc9f228cf282e21fc859 [file] [log] [blame]
Nico Huber804b41b2023-07-02 15:53:42 +00001#!/bin/sh
2
3set -e
4
Nico Huberb650ed42023-07-20 17:08:54 +00005# Add local containers as trusted for postfix relaying.
6add_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/`.
16add_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 Huber804b41b2023-07-02 15:53:42 +000036{
Nico Huberb650ed42023-07-20 17:08:54 +000037 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 Huber804b41b2023-07-02 15:53:42 +000047}