Nico Huber | 804b41b | 2023-07-02 15:53:42 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | set -e |
| 4 | |
Nico Huber | 177e610 | 2023-07-25 13:39:16 +0000 | [diff] [blame] | 5 | secret() { |
| 6 | seed=$(cat /run/secrets/seed) |
| 7 | printf "%s:%40s" "${seed}" "$*" | sha256sum | sed 's/[[:space:]].*//' |
| 8 | } |
| 9 | |
Nico Huber | b650ed4 | 2023-07-20 17:08:54 +0000 | [diff] [blame] | 10 | # Add local containers as trusted for postfix relaying. |
| 11 | add_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 Huber | 177e610 | 2023-07-25 13:39:16 +0000 | [diff] [blame] | 20 | # Create given users, requires a seed file for secret() |
Nico Huber | b650ed4 | 2023-07-20 17:08:54 +0000 | [diff] [blame] | 21 | add_users_with_passwd() { |
| 22 | for user in "$@"; do |
Nico Huber | b650ed4 | 2023-07-20 17:08:54 +0000 | [diff] [blame] | 23 | if [ ! -d /var/mail/${HOSTNAME#mail.}/${user} ]; then |
Nico Huber | 177e610 | 2023-07-25 13:39:16 +0000 | [diff] [blame] | 24 | setup email add ${user}@${HOSTNAME#mail.} $(secret mail:${user}) |
Nico Huber | b650ed4 | 2023-07-20 17:08:54 +0000 | [diff] [blame] | 25 | else |
Nico Huber | 177e610 | 2023-07-25 13:39:16 +0000 | [diff] [blame] | 26 | setup email update ${user}@${HOSTNAME#mail.} $(secret mail:${user}) |
Nico Huber | b650ed4 | 2023-07-20 17:08:54 +0000 | [diff] [blame] | 27 | fi |
| 28 | done |
| 29 | } |
| 30 | |
Nico Huber | 804b41b | 2023-07-02 15:53:42 +0000 | [diff] [blame] | 31 | { |
Nico Huber | 7f8dc5b | 2023-07-25 16:48:01 +0000 | [diff] [blame^] | 32 | add_users_with_passwd gerrit keycloak |
Nico Huber | b650ed4 | 2023-07-20 17:08:54 +0000 | [diff] [blame] | 33 | |
| 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 Huber | 804b41b | 2023-07-02 15:53:42 +0000 | [diff] [blame] | 42 | } |