summaryrefslogtreecommitdiffstats
path: root/postfix/entrypoint.sh
blob: afea241990507489780255fca12841d8ae17c673 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh

users() {
    sed 's/:.*$//g' /etc/userconfig/passwd
}

## Generate virtual mappings from user password file
# Incoming mail: "user@domain domain/user/" >vmailbox
# Outgoing mail: "user@domain user@domain"  >vaddress
users | awk -F '@' '{printf "%s %s/%s/\n", $0, $2, $1}' >/etc/postfix/vmailbox
users | awk '{printf "%s %s\n", $0, $0}' >/etc/postfix/vaddress

## Synchronize mailing list configuration directories
eul=$(ls /etc/userconfig/lists | sed '/ /d') # Ignore spaces and dotfiles
vsl=$(ls -A /var/spool/mlmmj)
added=$(printf '%s\n' "$vsl" "$vsl" "$eul" | sort | uniq -u)
removed=$(printf '%s\n' "$eul" "$eul" "$vsl" | sort | uniq -u)

for list in $added; do
    sudo -u mlmmj /etc/postfix/make_list.sh "$list"
done
for list in $removed; do
    listdir="/var/spool/mlmmj/$list"
    rm -rf "$listdir"
    printf 'Deleted list directory: %s\n' "$listdir"
done

## Generate virtual mappings from mailing list addresses
# "address@domain list@localhost.mlmmj" >mlvirtual
# "list@localhost.mlmmj mlmmj:list"     >mltransport
touch /etc/postfix/mlvirtual
touch /etc/postfix/mltransport
for list in $(ls -A /var/spool/mlmmj); do
    address="/var/spool/mlmmj/$list/control/listaddress" # there could be multiple
    sed "s/$/ $list@localhost.mlmmj/g" <$address >>/etc/postfix/mlvirtual
    echo "$list@localhost.mlmmj mlmmj:$list" >>/etc/postfix/mltransport
done

## Generate Berkeley DB files
postmap /etc/postfix/mltransport
postmap /etc/postfix/mlvirtual
postmap /etc/postfix/vaddress
postmap /etc/postfix/vmailbox
postmap /etc/userconfig/aliases

## Execute postfix daemons
exec /usr/sbin/postfix start-fg