ansible-role-spamassassin/templates/letsencrypt-spamassassin-ho...

36 lines
1.2 KiB
Django/Jinja

#!/bin/bash
LE_SERVICES_SCRIPT_DIR=/usr/lib/acme/hooks
LE_CERTS_DIR={{ letsencrypt_acme_certs_dir }}
LE_LOG_DIR=/var/log/acme
LE_LOG_FILE="$LE_LOG_DIR"/spamassassin.log
SPAMASSASSIN_CERTDIR={{ spamassassin_home }}
RETVAL=
DATE=$( date )
echo "$DATE" >> "$LE_LOG_FILE"
echo "Check if the certificate changed" >> "$LE_LOG_FILE"
diff "${LE_CERTS_DIR}/fullchain" "$SPAMASSASSIN_CERTDIR"/client-cert.pem > /dev/null
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
echo "Certificate did not change, exiting." >> "$LE_LOG_FILE"
exit 0
fi
echo "Copying the new certificate files" >> "$LE_LOG_FILE"
cp -u "${LE_CERTS_DIR}/fullchain" "$SPAMASSASSIN_CERTDIR"/client-cert.pem
cp -u "${LE_CERTS_DIR}/privkey" "$SPAMASSASSIN_CERTDIR"/client-key.pem
chmod 444 "$SPAMASSASSIN_CERTDIR"/client-cert.pem
chown {{ spamassassin_user }}:{{ spamassassin_group }} "$SPAMASSASSIN_CERTDIR"/client-cert.pem
chmod 400 "$SPAMASSASSIN_CERTDIR"/client-key.pem
chown {{ spamassassin_user }}:{{ spamassassin_group }} "$SPAMASSASSIN_CERTDIR"/client-key.pem
echo "Restart the spamassassin service" >> "$LE_LOG_FILE"
if [ -x /bin/systemctl ] ; then
systemctl restart spamassassin >> "$LE_LOG_FILE" 2>&1
else
service spamassassin restart >> "$LE_LOG_FILE" 2>&1
fi