#!/bin/bash

if [[ "$(CreoleGet cert_type)" == "letsencrypt" ]]
then
    LE_CERT="$(CreoleGet le_ssl_pem)"
    ZEPHIR_CERT="/etc/zephir/ssl/certs/zephir.pem"
    LE_KEY="$(CreoleGet le_ssl_key)"
    ZEPHIR_KEY="/etc/zephir/ssl/private/zephir.key"
    cmp -s "$LE_CERT" "$ZEPHIR_CERT" && cmp -s "$LE_KEY" "$ZEPHIR_KEY" && exit 0
    cp -f "$LE_CERT" "$ZEPHIR_CERT"
    chmod 0644 "$ZEPHIR_CERT"
    cp -f "$LE_KEY" "$ZEPHIR_KEY"
    chmod 0600 "$ZEPHIR_KEY"
    chown -R nobody:nogroup /etc/zephir/ssl
    systemctl restart zephir_web
fi

exit 0
