blob: dc949878503b55f38e08afcb4ec7cceed1739991 [file] [log] [blame]
Nico Huber804b41b2023-07-02 15:53:42 +00001#!/bin/sh
2
3set -e
4
Nico Huber177e6102023-07-25 13:39:16 +00005secret() {
6 seed=$(cat /run/secrets/seed)
7 printf "%s:%40s" "${seed}" "$*" | sha256sum | sed 's/[[:space:]].*//'
8}
9
Nico Huberb650ed42023-07-20 17:08:54 +000010# Add local containers as trusted for postfix relaying.
11add_mynetworks_hosts() {
12 myhosts=
13 for host in mailserver "$@"; do
14 IP=$(host ${host} | sed -n 's/.*has address //p')
15 myhosts="${myhosts} ${IP}/32"
16 done
17 postconf "mynetworks =${myhosts}"
18}
19
Nico Huber177e6102023-07-25 13:39:16 +000020# Create given users, requires a seed file for secret()
Nico Huberb650ed42023-07-20 17:08:54 +000021add_users_with_passwd() {
22 for user in "$@"; do
Nico Huberb650ed42023-07-20 17:08:54 +000023 if [ ! -d /var/mail/${HOSTNAME#mail.}/${user} ]; then
Nico Huber177e6102023-07-25 13:39:16 +000024 setup email add ${user}@${HOSTNAME#mail.} $(secret mail:${user})
Nico Huberb650ed42023-07-20 17:08:54 +000025 else
Nico Huber177e6102023-07-25 13:39:16 +000026 setup email update ${user}@${HOSTNAME#mail.} $(secret mail:${user})
Nico Huberb650ed42023-07-20 17:08:54 +000027 fi
28 done
29}
30
Nico Huber804b41b2023-07-02 15:53:42 +000031{
Nico Huber7f8dc5b2023-07-25 16:48:01 +000032 add_users_with_passwd gerrit keycloak
Nico Huberb650ed42023-07-20 17:08:54 +000033
34 # Restrict gerrit@ sending to local IP:
35 if ! grep -q gerrit /tmp/docker-mailserver/user.access 2>/dev/null; then
36 echo "gerrit@${HOSTNAME#mail.} gerrit_sender_check" >>/tmp/docker-mailserver/user.access
37 postmap /tmp/docker-mailserver/user.access
38 fi
39 IP=$(host gerrit | sed -n 's/.*has address //p')
40 echo "${IP} permit_sasl_authenticated" >/tmp/docker-mailserver/gerrit-client.access
41 postmap /tmp/docker-mailserver/gerrit-client.access
Nico Huber804b41b2023-07-02 15:53:42 +000042}