Mercurial > code > home > repos > infra
annotate mail/mail.py @ 326:5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
author | drewp@bigasterisk.com |
---|---|
date | Mon, 20 Jan 2025 21:55:08 -0800 |
parents | mail.py@99c81fa0f2fc |
children |
rev | line source |
---|---|
326
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
1 from pyinfra.context import host |
16 | 2 from pyinfra.operations import apt, files, server, systemd |
3 | |
326
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
4 # ditto (and others?) might also run postfix; not sure how |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
5 |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
6 |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
7 def dkim(): |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
8 if host.name != 'prime': |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
9 return |
324
99c81fa0f2fc
add chat.bigasterisk.com dns and dkim
drewp@bigasterisk.com
parents:
311
diff
changeset
|
10 ''' |
99c81fa0f2fc
add chat.bigasterisk.com dns and dkim
drewp@bigasterisk.com
parents:
311
diff
changeset
|
11 per domain keygen: |
99c81fa0f2fc
add chat.bigasterisk.com dns and dkim
drewp@bigasterisk.com
parents:
311
diff
changeset
|
12 prime(pts/4):~# mkdir /etc/opendkim/keys/chat.bigasterisk.com |
99c81fa0f2fc
add chat.bigasterisk.com dns and dkim
drewp@bigasterisk.com
parents:
311
diff
changeset
|
13 prime(pts/4):~# opendkim-genkey -b 1024 -d chat.bigasterisk.com -D /etc/opendkim/keys/chat.bigasterisk.com -s default -v |
99c81fa0f2fc
add chat.bigasterisk.com dns and dkim
drewp@bigasterisk.com
parents:
311
diff
changeset
|
14 opendkim-genkey: generating private key |
99c81fa0f2fc
add chat.bigasterisk.com dns and dkim
drewp@bigasterisk.com
parents:
311
diff
changeset
|
15 opendkim-genkey: private key written to default.private |
99c81fa0f2fc
add chat.bigasterisk.com dns and dkim
drewp@bigasterisk.com
parents:
311
diff
changeset
|
16 opendkim-genkey: extracting public key |
99c81fa0f2fc
add chat.bigasterisk.com dns and dkim
drewp@bigasterisk.com
parents:
311
diff
changeset
|
17 opendkim-genkey: DNS TXT record written to default.txt |
99c81fa0f2fc
add chat.bigasterisk.com dns and dkim
drewp@bigasterisk.com
parents:
311
diff
changeset
|
18 prime(pts/4):~# chown opendkim /etc/opendkim/keys/*/* |
99c81fa0f2fc
add chat.bigasterisk.com dns and dkim
drewp@bigasterisk.com
parents:
311
diff
changeset
|
19 ''' |
326
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
20 apt.packages(packages=['opendkim', 'opendkim-tools']) |
218 | 21 |
326
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
22 files.template(src='mail/dkim/opendkim-KeyTable', dest='/etc/opendkim/KeyTable') |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
23 files.template(src='mail/dkim/opendkim-SigningTable', dest='/etc/opendkim/SigningTable') |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
24 files.template(src='mail/dkim/opendkim-TrustedHosts', dest='/etc/opendkim/TrustedHosts') |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
25 files.template(src='mail/dkim/opendkim.conf', dest='/etc/opendkim.conf') |
218 | 26 |
326
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
27 for domain in ['bigasterisk.com', 'chat.bigasterisk.com']: |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
28 files.put(src=f'secrets/mail/{domain}-default.private', |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
29 dest=f'/etc/opendkim/keys/{domain}/default.private', |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
30 mode='0600', |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
31 user='opendkim') |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
32 |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
33 files.template(src='mail/opendkim.service', dest='/usr/lib/systemd/system/opendkim.service') |
311 | 34 systemd.service(service='opendkim.service', enabled=True, running=True, restarted=True, daemon_reload=True) |
218 | 35 |
326
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
36 |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
37 def postfix(): |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
38 if host.name != 'prime': |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
39 return |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
40 apt.packages(packages=['postfix', 'isync']) |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
41 |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
42 files.template(src='mail/main.cf.j2', dest='/etc/postfix/main.cf') |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
43 files.put(src='mail/mydestination', dest='/etc/postfix/mydestination') |
183 | 44 files.put(src='secrets/mail/aliases', dest='/etc/postfix/aliases') |
16 | 45 files.put(src='secrets/mail/sender_access', dest='/etc/postfix/sender_access') |
46 files.put(src='secrets/mail/virtual', dest='/etc/postfix/virtual') | |
47 | |
18
fb226978c4d7
fix prime postfix setup. forwards to gmail were piling up
drewp@bigasterisk.com
parents:
16
diff
changeset
|
48 server.shell(commands=[ |
fb226978c4d7
fix prime postfix setup. forwards to gmail were piling up
drewp@bigasterisk.com
parents:
16
diff
changeset
|
49 'postmap /etc/postfix/sender_access', |
fb226978c4d7
fix prime postfix setup. forwards to gmail were piling up
drewp@bigasterisk.com
parents:
16
diff
changeset
|
50 'postmap /etc/postfix/virtual', |
218 | 51 'postmap /etc/postfix/aliases', # broken |
18
fb226978c4d7
fix prime postfix setup. forwards to gmail were piling up
drewp@bigasterisk.com
parents:
16
diff
changeset
|
52 'postfix reload', |
fb226978c4d7
fix prime postfix setup. forwards to gmail were piling up
drewp@bigasterisk.com
parents:
16
diff
changeset
|
53 ]) |
184
53b6457f75f3
also config postfix on bang (others, soon)
drewp@bigasterisk.com
parents:
183
diff
changeset
|
54 systemd.service(service='postfix@-.service', enabled=True, running=True) |
16 | 55 |
326
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
56 |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
57 def mbsync(): |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
58 if host.name != 'prime': |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
59 return |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
60 |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
61 # todo: something to run ~drewp/mbsync/go at startup |
16 | 62 |
41 | 63 server.shell(commands=[ |
64 "cd /home/drewp/mbsync; /usr/bin/mbsync-get-cert 10.5.0.1 > servercert", | |
65 ]) | |
16 | 66 |
326
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
67 files.put(src='mail/file-count/file_count.py', dest='/opt/file_count.py') |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
68 files.put(src='mail/file-count/file-count.service', dest='/etc/systemd/system/maildir-count.service') |
253 | 69 systemd.service(service='maildir-count.service', enabled=True, running=True, daemon_reload=True) |
70 | |
71 | |
16 | 72 # other machines, route mail to bang or prime for delivery |
41 | 73 |
326
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
74 # if host.name == 'bang': |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
75 # apt.packages(packages=['postfix']) |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
76 # files.template(src='templates/mail/main.cf.j2', dest='/etc/postfix/main.cf') |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
77 # files.template(src='templates/mail/mydestination.j2', dest='/etc/postfix/mydestination') |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
78 # files.put(src='secrets/mail/aliases', dest='/etc/postfix/aliases') |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
79 # files.put(src='secrets/mail/sender_access', dest='/etc/postfix/sender_access') |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
80 # files.put(src='secrets/mail/virtual', dest='/etc/postfix/virtual') |
184
53b6457f75f3
also config postfix on bang (others, soon)
drewp@bigasterisk.com
parents:
183
diff
changeset
|
81 |
326
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
82 # server.shell(commands=[ |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
83 # 'postmap /etc/postfix/sender_access', |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
84 # 'postmap /etc/postfix/virtual', |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
85 # 'postmap /etc/postfix/aliases', |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
86 # 'postfix reload', |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
87 # ]) |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
88 # systemd.service(service='postfix@-.service', enabled=True, running=True) |
184
53b6457f75f3
also config postfix on bang (others, soon)
drewp@bigasterisk.com
parents:
183
diff
changeset
|
89 |
326
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
90 # # server.shell(commands=[ |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
91 # # # not working |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
92 # # "cd /my/serv/dovecot; runuser -u drewp -- invoke certs", |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
93 # # ]) |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
94 |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
95 operations = [ |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
96 dkim, |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
97 postfix, |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
98 mbsync, |
5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents:
324
diff
changeset
|
99 ] |