Files

40 lines
1.5 KiB
Bash

# emailwiz - Dovecot 2.4
# SPDX-License-Identifier: GPL-3.0-or-later
# shellcheck shell=sh
SIEVE_DIR=/var/lib/dovecot/sieve
# render_template FILE - substitute @VARS@ (values must not contain '|').
render_template() {
sed -e "s|@DOVECOT_CONFIG_VERSION@|$DOVECOT_CONFIG_VERSION|g" \
-e "s|@IMAP_PROTOCOLS@|$IMAP_PROTOCOLS|g" \
-e "s|@TLS_CERT@|$TLS_CERT|g" \
-e "s|@TLS_KEY@|$TLS_KEY|g" \
-e "s|@JUNK_AUTOEXPUNGE@|$JUNK_AUTOEXPUNGE|g" \
-e "s|@DOMAIN@|$DOMAIN|g" \
-e "s|@MAIL_HOSTNAME@|$MAIL_HOSTNAME|g" \
-e "s|@DKIM_DIR@|$DKIM_DIR|g" \
-e "s|@DKIM_PORT@|$DKIM_PORT|g" \
-e "s|@SPAMD_MAX_CHILDREN@|$SPAMD_MAX_CHILDREN|g" \
-e "s|@CERT_WARN_DAYS@|$CERT_WARN_DAYS|g" \
"$EMAILWIZ_ROOT/templates/$1"
}
dovecot_render() {
[ -n "$DOVECOT_CONFIG_VERSION" ] || die "cannot determine Dovecot version (is dovecot-core installed?)"
render_template dovecot.conf.in | stage_file /etc/dovecot/dovecot.conf 644 root root dovecot
# Validate the rendered file with the installed doveconf before anything
# touches the live config. doveconf resolves cert paths, so this also
# catches a missing certificate.
if ! _out=$(doveconf -c "$STAGE/etc/dovecot/dovecot.conf" -n 2>&1 >/dev/null); then
die "rendered dovecot.conf is invalid: $_out" "$EX_VALIDATION"
fi
render_template default.sieve | stage_file "$SIEVE_DIR/default.sieve" 644 root root sieve
}
# Compile the default sieve script after install (the .svbin is derived state).
dovecot_post_sieve() {
sievec "$SIEVE_DIR/default.sieve" || die "sievec failed for $SIEVE_DIR/default.sieve"
}