#!/bin/sh
set -eu

set -- $RENEWED_DOMAINS
[ "$1" = "$(hostname)".mail.dxld.at ] || exit 0

ln -sf "$RENEWED_LINEAGE" /etc/exim4/le-live

cp -a --remove-destination \
   "$RENEWED_LINEAGE"/fullchain.pem /etc/exim4/exim.crt.tmp
cp -a --remove-destination \
   "$RENEWED_LINEAGE"/privkey.pem   /etc/exim4/exim.key.tmp

chmod 755 /etc/exim4/exim.crt.tmp
chown root:root /etc/exim4/exim.crt.tmp

chmod 740 /etc/exim4/exim.key.tmp
chown root:Debian-exim /etc/exim4/exim.key.tmp

mv /etc/exim4/exim.crt.tmp /etc/exim4/exim.crt
mv /etc/exim4/exim.key.tmp /etc/exim4/exim.key
