#!/bin/bash

autocheck=$(/sbin/e-smith/config getprop letsencrypt autocheck || echo "enabled")

if [[ "$autocheck" == "enabled" ]]; then
    /etc/e-smith/events/actions/letsencrypt-setdomains "" "" enabled
fi

status=$(/sbin/e-smith/config getprop letsencrypt status || echo "disabled")
if [[ "$status" == "enabled" ]]; then
    # if enabled and we have a staging issuer, then delete the link to force renew
    openssl x509 -in `config getprop modSSL crt` -noout -issuer | grep -qi "staging" && unlink  `config getprop modSSL crt`
fi

/sbin/e-smith/expand-template /etc/dehydrated/config
/sbin/e-smith/expand-template /etc/dehydrated/domains.txt
exit 0
