-
Notifications
You must be signed in to change notification settings - Fork 41
/
Makefile
370 lines (326 loc) · 12.1 KB
/
Makefile
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# $OpenBSD$
# Put overrides in "Makefile.local"
PREFIX ?= /usr/local
GH_PROJECT ?= caesonia
BINDIR ?= ${PREFIX}/bin
BASESYSCONFDIR ?= /etc
VARBASE ?= /var
DOCDIR ?= ${PREFIX}/share/doc/${GH_PROJECT}
EXAMPLESDIR ?= ${PREFIX}/share/examples/${GH_PROJECT}
# Server
DOMAIN_NAME = example.com
VHOSTS_NAME = example.net \
example.org
PRIMARY = yes
PRIMARY_HOST = mercury
PRIMARY_IPv4 = 203.0.113.1
PRIMARY_IPv6 = 2001:0db8::1
BACKUP_HOST = hermes
BACKUP_IPv4 = 203.0.113.2
BACKUP_IPv6 = 2001:0db8::2
DKIM_SELECTOR = obsd
EGRESS = vio0
WHEEL_USER = puffy
REPLICATION_USER = dsync
VIRTUAL_USER = ${WHEEL_USER}
AUTOEXPUNGE = 30d
MAIL_QUOTA = 15G
MAX_MESSAGE_SIZE = 35M
FULL_SYNC_INTERVAL = 1h
UPGRADE = yes
CAESONIA = ${SCRIPT} ${SYSCONF} ${PFCONF} ${MAILCONF} ${SSHCONF} \
${MTREECONF} ${DKIMPROXYCONF} ${DOVECOTCONF} ${SIEVE} \
${RSPAMDCONF} ${WKD} ${TLSRPT} ${WWW} ${UNBOUNDCONF} \
${CRONALLOW} ${CRONTAB}
# Caesonia
SCRIPT = ${BINDIR:S|^/||}/dovecot-lda.sh \
${BINDIR:S|^/||}/learn_all_spam.sh \
${BINDIR:S|^/||}/learn_ham.sh \
${BINDIR:S|^/||}/learn_spam.sh \
${BINDIR:S|^/||}/quota-warning.sh \
${BINDIR:S|^/||}/rmchangelist.sh \
${BINDIR:S|^/||}/wks-server.sh
SYSCONF = ${BASESYSCONFDIR:S|^/||}/acme-client.conf \
${BASESYSCONFDIR:S|^/||}/changelist.local \
${BASESYSCONFDIR:S|^/||}/daily.local \
${BASESYSCONFDIR:S|^/||}/dhclient.conf \
${BASESYSCONFDIR:S|^/||}/doas.conf \
${BASESYSCONFDIR:S|^/||}/httpd.conf \
${BASESYSCONFDIR:S|^/||}/login.conf \
${BASESYSCONFDIR:S|^/||}/newsyslog.conf \
${BASESYSCONFDIR:S|^/||}/resolv.conf \
${BASESYSCONFDIR:S|^/||}/sysctl.conf
PFCONF = ${BASESYSCONFDIR:S|^/||}/pf.conf \
${BASESYSCONFDIR:S|^/||}/pf.conf.anchor.block \
${BASESYSCONFDIR:S|^/||}/pf.conf.anchor.icmp \
${BASESYSCONFDIR:S|^/||}/pf.conf.table.ban \
${BASESYSCONFDIR:S|^/||}/pf.conf.table.martians
MAILCONF = ${BASESYSCONFDIR:S|^/||}/mail/aliases \
${BASESYSCONFDIR:S|^/||}/mail/blacklist \
${BASESYSCONFDIR:S|^/||}/mail/mailname \
${BASESYSCONFDIR:S|^/||}/mail/passwd \
${BASESYSCONFDIR:S|^/||}/mail/relays \
${BASESYSCONFDIR:S|^/||}/mail/smtpd.conf \
${BASESYSCONFDIR:S|^/||}/mail/vdomains \
${BASESYSCONFDIR:S|^/||}/mail/virtual \
${BASESYSCONFDIR:S|^/||}/mail/whitelist
SSHCONF = ${BASESYSCONFDIR:S|^/||}/ssh/sshd_banner \
${BASESYSCONFDIR:S|^/||}/ssh/sshd_config
MTREECONF = ${BASESYSCONFDIR:S|^/||}/mtree/special.local
DKIMPROXYCONF = ${BASESYSCONFDIR:S|^/||}/dkimproxy_out.conf
DOVECOTCONF = ${BASESYSCONFDIR:S|^/||}/dovecot/dovecot-trash.conf.ext \
${BASESYSCONFDIR:S|^/||}/dovecot/local.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/10-auth.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/10-mail.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/10-master.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/10-ssl.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/15-lda.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/15-mailboxes.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/20-imap.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/20-lmtp.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/20-managesieve.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/90-plugin.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/90-quota.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/90-sieve-extprograms.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/90-sieve.conf \
${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/auth-passwdfile.conf.ext
SIEVE = ${VARBASE:S|^/||}/dovecot/imapsieve/before/report-ham.sieve \
${VARBASE:S|^/||}/dovecot/imapsieve/before/report-spam.sieve \
${VARBASE:S|^/||}/dovecot/sieve/before/00-wks.sieve \
${VARBASE:S|^/||}/dovecot/sieve/before/spamtest.sieve
RSPAMDCONF = ${BASESYSCONFDIR:S|^/||}/rspamd/local.d/antivirus.conf \
${BASESYSCONFDIR:S|^/||}/rspamd/local.d/classifier-bayes.conf \
${BASESYSCONFDIR:S|^/||}/rspamd/local.d/mime_types.conf \
${BASESYSCONFDIR:S|^/||}/rspamd/local.d/multimap.conf \
${BASESYSCONFDIR:S|^/||}/rspamd/local.d/options.inc \
${BASESYSCONFDIR:S|^/||}/rspamd/local.d/phishing.conf \
${BASESYSCONFDIR:S|^/||}/rspamd/local.d/rbl.conf.optional \
${BASESYSCONFDIR:S|^/||}/rspamd/local.d/replies.conf \
${BASESYSCONFDIR:S|^/||}/rspamd/local.d/surbl.conf \
${BASESYSCONFDIR:S|^/||}/rspamd/local.d/worker-controller.inc \
${BASESYSCONFDIR:S|^/||}/rspamd/local.d/worker-normal.inc \
${BASESYSCONFDIR:S|^/||}/rspamd/local.d/worker-proxy.inc \
${BASESYSCONFDIR:S|^/||}/rspamd/override.d/bad_emails.list \
${BASESYSCONFDIR:S|^/||}/rspamd/override.d/emails.conf.optional
UNBOUNDCONF = ${VARBASE:S|^/||}/unbound/etc/unbound.conf
WKD = ${VARBASE:S|^/||}/www/openpgpkey/policy \
${VARBASE:S|^/||}/www/openpgpkey/submission-address
TLSRPT = ${VARBASE:S|^/||}/www/mta-sts/mta-sts.txt
WWW = ${VARBASE:S|^/||}/www/htdocs/${HOSTNAME}/index.html \
${VARBASE:S|^/||}/www/htdocs/${HOSTNAME}/mail/config-v1.1.xml
CRONALLOW = ${VARBASE:S|^/||}/cron/cron.allow
CRONTAB = ${VARBASE:S|^/||}/cron/tabs/root
WRKSRC ?= ${HOSTNAME:S|^|${.CURDIR}/|}
RELEASE !!= uname -r
QUEUE !!= openssl rand -hex 16
PKG = dkimproxy \
dovecot \
dovecot-pigeonhole \
rspamd \
opensmtpd-extras \
gnupg-2.2.12
#-8<----------- [ cut here ] --------------------------------------------------^
.if exists(Makefile.local)
. include "Makefile.local"
.endif
.if empty(BACKUP_HOST)
DOVECOTCONF += ${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/90-replication.conf.optional
PRIMARY = yes
.else
DOVECOTCONF += ${BASESYSCONFDIR:S|^/||}/dovecot/conf.d/90-replication.conf
.endif
.if ${PRIMARY} == "yes"
HOSTNAME = ${PRIMARY_HOST}.${DOMAIN_NAME}
.else
HOSTNAME = ${BACKUP_HOST}.${DOMAIN_NAME}
.endif
# Specifications (target rules)
.if ${UPGRADE} == "yes"
upgrade: config .WAIT ${CAESONIA}
@echo Upgrade
.else
upgrade: config
@echo Fresh install
.endif
config:
mkdir -m750 ${WRKSRC}
(umask 077; cp -R ${.CURDIR}/src/* ${WRKSRC})
.if !empty(VHOSTS_NAME)
. for _VHOSTS_NAME in ${VHOSTS_NAME}
echo ${_VHOSTS_NAME} >> ${WRKSRC}/${MAILCONF:M*vdomains}
sed -i \
-e '/autoconfig.example.net/{p;s|.*| autoconfig.${_VHOSTS_NAME} \\|;}' \
-e '/mta-sts.example.net/{p;s|.*| mta-sts.${_VHOSTS_NAME} \\|;}' \
-e '/wkd.example.net/{p;s|.*| wkd.${_VHOSTS_NAME} \\|;}' \
${WRKSRC}/${SYSCONF:M*acme-client.conf}
sed -i \
-e '/^[email protected]/{p;s|.*|${VIRTUAL_USER}@${_VHOSTS_NAME} \
${VIRTUAL_USER}@${DOMAIN_NAME}|;}' \
${WRKSRC}/${MAILCONF:M*virtual}
echo @${_VHOSTS_NAME} >> ${WRKSRC}/${MAILCONF:M*whitelist}
sed -i \
-e '/^domain/ s|$$|,${_VHOSTS_NAME}|' \
${WRKSRC}/${DKIMPROXYCONF:M*dkimproxy_out.conf}
. endfor
.endif
sed -i \
-e '/^domain/s|,example.net||' \
${WRKSRC}/${DKIMPROXYCONF:M*dkimproxy_out.conf}
sed -i \
-e '/example.net/d' \
${WRKSRC}/${MAILCONF:M*vdomains} \
${WRKSRC}/${MAILCONF:M*whitelist} \
${WRKSRC}/${SYSCONF:M*acme-client.conf}
sed -i \
-e '/^[email protected]/d' \
${WRKSRC}/${MAILCONF:M*virtual}
sed -i \
-e 's|^puffy|${WHEEL_USER}|' \
${WRKSRC}/${MAILCONF:M*aliases}
sed -i \
-e "s/5101bef20f4d02c826bffc243e15a7c0/${QUEUE}/" \
${WRKSRC}/${MAILCONF:M*smtpd.conf}
find ${WRKSRC} -type f -exec sed -i \
-e 's|vio0|${EGRESS}|' \
-e 's|obsd|${DKIM_SELECTOR}|' \
-e 's|puffy|${VIRTUAL_USER}|' \
-e 's|example.com|${DOMAIN_NAME}|' \
-e 's|203.0.113.1|${PRIMARY_IPv4}|' \
-e 's|2001:0db8::1|${PRIMARY_IPv6}|' \
-e '/autoexpunge /s|30d|${AUTOEXPUNGE}|' \
-e '/storage=/s|15G|${MAIL_QUOTA}|' \
-e 's|35M|${MAX_MESSAGE_SIZE}|' \
-e '/full_sync_interval/s|1h|${FULL_SYNC_INTERVAL}|' \
{} +
.if empty(BACKUP_HOST)
sed -i \
-e 's/dsync\ //g' \
${WRKSRC}/${PFCONF:M*pf.conf}
sed -i \
-e '/203.0.113.2/d' \
-e '/2001:0db8::2/d' \
${WRKSRC}/${MAILCONF:M*relays}
sed -i \
-e '/hermes/d' \
${WRKSRC}/${TLSRPT:M*mta-sts.txt} \
${WRKSRC}/${SYSCONF:M*acme-client.conf}
find ${WRKSRC} -type f -exec sed -i \
-e 's|mercury|${PRIMARY_HOST}|' \
{} +
.else
find ${WRKSRC} -type f -exec sed -i \
-e 's|203.0.113.2|${BACKUP_IPv4}|' \
-e 's|2001:0db8::2|${BACKUP_IPv6}|' \
{} +
cp -p ${WRKSRC}${BASESYSCONFDIR}/dovecot/conf.d/90-replication.conf.optional \
${WRKSRC}${BASESYSCONFDIR}/dovecot/conf.d/90-replication.conf
. if ${PRIMARY} == "yes"
find ${WRKSRC} -type f -exec sed -i \
-e 's|mercury|${PRIMARY_HOST}|' \
-e 's|hermes|${BACKUP_HOST}|' \
{} +
@echo Primary MX
. else
find ${WRKSRC} -type f -exec sed -i \
-e 's|mercury|${BACKUP_HOST}|' \
-e 's|hermes|${PRIMARY_HOST}|' \
{} +
sed -i \
-e 's|action "mda"|action "backup"|' \
${WRKSRC}/${MAILCONF:M*smtpd.conf}
sed -i \
-e '/^[[:space:]]alternative/,/^[[:space:]]}/d' \
${WRKSRC}/${SYSCONF:M*acme-client.conf}
@echo Backup MX
. endif
.endif
mv ${WRKSRC}${VARBASE}/www/htdocs/mercury.example.com \
${WRKSRC}${VARBASE}/www/htdocs/${HOSTNAME}
@echo Configured
${CAESONIA}:
[[ -r ${DESTDIR}/$@ ]] \
&& (umask 077; diff -u ${DESTDIR}/$@ ${WRKSRC}/$@ >/dev/null \
|| sdiff -as -w $$(tput -T $${TERM:-vt100} cols) \
-o ${WRKSRC}/[email protected] \
${DESTDIR}/$@ \
${WRKSRC}/$@) \
|| [[ "$$?" -eq 1 ]]
clean:
@rm -r ${WRKSRC}
beforeinstall: upgrade
-rcctl stop smtpd httpd dkimproxy_out rspamd dovecot
.for _PKG in ${PKG}
env PKG_PATH= pkg_info ${_PKG} > /dev/null || pkg_add ${_PKG}
.endfor
.if ${UPGRADE} == "yes"
. for _CAESONIA in ${CAESONIA}
[[ -r ${_CAESONIA:S|^|${WRKSRC}/|:S|$|.merged|} ]] \
&& cp -p ${WRKSRC}/${_CAESONIA}.merged ${WRKSRC}/${_CAESONIA} \
|| [[ "$$?" -eq 1 ]]
. endfor
.endif
realinstall:
${INSTALL} -d ${VARBASE}/dovecot/imapsieve/{after,before}
${INSTALL} -d ${VARBASE}/dovecot/sieve/{after,before}
${INSTALL} -d ${BASESYSCONFDIR}/rspamd/{local.d,override.d}
${INSTALL} -d ${VARBASE}/www/openpgpkey/hu
${INSTALL} -d ${VARBASE}/www/mta-sts
${INSTALL} -d ${VARBASE}/www/htdocs/${HOSTNAME}/mail
${INSTALL} -d ${BASESYSCONFDIR}/ssl/dkim/private
.for _NAME in ${DOMAIN_NAME} ${VHOSTS_NAME}
${INSTALL} -d ${VARBASE}/lib/gnupg/wks/${_NAME}/pending
ln -sf ${VARBASE}/www/openpgpkey/hu \
${VARBASE}/lib/gnupg/wks/${_NAME}
ln -sf ${VARBASE}/www/openpgpkey/submission-address \
${VARBASE}/lib/gnupg/wks/${_NAME}
.endfor
.for _CAESONIA in ${CAESONIA:N*cron/tabs*}
${INSTALL} -S -o ${LOCALEOWN} -g ${LOCALEGRP} -m 440 \
${_CAESONIA:S|^|${WRKSRC}/|} \
${_CAESONIA:S|^|${DESTDIR}/|}
.endfor
afterinstall:
.if !empty(CRONTAB)
crontab -u root ${WRKSRC}/${CRONTAB}
.endif
user info -e vmail \
|| user add -u 2000 -g =uid -c "Virtual Mail" -s /sbin/nologin -b ${VARBASE} -m vmail
.if !empty(BACKUP_HOST)
user info -e dsync \
|| user add -u 2001 -g =uid -c "Dsync Replication" -s /bin/ksh -m dsync
.endif
[[ -r ${BASESYSCONFDIR}/changelist-${RELEASE} ]] \
|| cp ${BASESYSCONFDIR}/changelist ${BASESYSCONFDIR}/changelist-${RELEASE}
sed -i '/changelist.local/,$$d' ${BASESYSCONFDIR}/changelist
cat ${BASESYSCONFDIR}/changelist.local >> ${BASESYSCONFDIR}/changelist
.for _SIEVE in ${SIEVE}
sievec /${_SIEVE}
.endfor
doas -u vmail /usr/local/bin/gpg2 -K --with-wkd-hash key-submission@${DOMAIN_NAME} || \
doas -u vmail /usr/local/bin/gpg2 --batch --passphrase "" \
--quick-gen-key key-submission@${DOMAIN_NAME}
chown vmail ${VARBASE}/www/openpgpkey/hu
[[ -r ${VARBASE}/www/openpgpkey/hu/54f6ry7x1qqtpor16txw5gdmdbbh6a73 ]] || \
doas -u vmail /usr/local/bin/gpg2 \
-o ${VARBASE}/lib/gnupg/wks/${DOMAIN_NAME}/hu/54f6ry7x1qqtpor16txw5gdmdbbh6a73 \
--export-options export-minimal --export key-submission@${DOMAIN_NAME}
[[ -r ${BASESYSCONFDIR}/ssl/dkim/private/private.key ]] || (umask 077; \
openssl genrsa -out ${BASESYSCONFDIR}/ssl/dkim/private/private.key 2048; \
openssl rsa -in ${BASESYSCONFDIR}/ssl/dkim/private/private.key \
-pubout -out ${BASESYSCONFDIR}/ssl/dkim/public.key)
sed -i '/^console/s/ secure//' ${BASESYSCONFDIR}/ttys
mtree -qef ${BASESYSCONFDIR}/mtree/special -p / -U
mtree -qef ${BASESYSCONFDIR}/mtree/special.local -p / -U
pfctl -f /etc/pf.conf
rcctl disable check_quotas sndiod
-rcctl check sndiod && rcctl stop sndiod
rcctl enable unbound sshd httpd dkimproxy_out rspamd dovecot smtpd
rcctl restart unbound sshd httpd
ftp -o - https://${HOSTNAME}/index.html \
|| acme-client -ADv ${HOSTNAME}
ocspcheck -vNo ${BASESYSCONFDIR}/ssl/acme/${HOSTNAME}.ocsp.resp.der \
${BASESYSCONFDIR}/ssl/acme/${HOSTNAME}.fullchain.pem
rcctl restart httpd dkimproxy_out rspamd dovecot smtpd
.PHONY: upgrade
.USE: upgrade
.include <bsd.prog.mk>