2016-04-12 19:40:28 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
RENEW_BEFORE={{ letsencrypt_renew_before }}
|
|
|
|
LETSENCRYPT_BIN={{ letsencrypt_auto }}
|
|
|
|
LE_CERT_DIR={{ letsencrypt_certs_dir }}
|
|
|
|
LE_SERVICES_SCRIPT_DIR={{ letsencrypt_services_scripts_dir }}
|
|
|
|
LOG_DIR={{ letsencrypt_logdir }}
|
|
|
|
VALIDITY_RETVAL=0
|
2016-04-13 17:02:04 +02:00
|
|
|
DOMAINS="{{ letsencrypt_domains }}"
|
|
|
|
CERT_DOMAINS_LIST=
|
|
|
|
ACTION=certonly
|
2016-04-12 19:40:28 +02:00
|
|
|
RETVAL=0
|
|
|
|
|
|
|
|
# Check if the cert file exists. If not, it is a certificate request and not a renewal.
|
|
|
|
if [ -f $LE_CERT_DIR/cert.pem ] ; then
|
|
|
|
VALIDITY_CHECK=$( openssl x509 -checkend $RENEW_BEFORE -noout -in $LE_CERT_DIR/cert.pem )
|
|
|
|
VALIDITY_RETVAL=$?
|
|
|
|
if [ $VALIDITY_RETVAL -eq 0 ] ; then
|
|
|
|
echo "The certificate is still valid" >> $LOG_DIR/letsencrypt_request.log
|
|
|
|
exit 0
|
2016-04-13 17:02:04 +02:00
|
|
|
else
|
|
|
|
ACTION=renew
|
2016-04-12 19:40:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-04-13 17:02:04 +02:00
|
|
|
if [ "$ACTION" === "certonly" ] ; then
|
|
|
|
for dom in $DOMAINS ; do
|
|
|
|
CERT_DOMAINS_LIST+=" -d $dom"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2016-04-12 19:40:28 +02:00
|
|
|
# Ask for a new certificate. First request or renewal are the same. We only support the standalone method right now
|
2016-04-13 17:02:04 +02:00
|
|
|
$LETSENCRYPT_BIN $ACTION $CERT_DOMAINS_LIST --http-01-port {{ letsencrypt_standalone_port }} --config /etc/letsencrypt/cli.ini >> $LOG_DIR/letsencrypt_request.log 2>&1
|
2016-04-12 19:40:28 +02:00
|
|
|
RETVAL=$?
|
|
|
|
|
|
|
|
# Run the reconfiguration scripts to make the involved services load the new certificate
|
|
|
|
for f in $( /bin/ls -1 $LE_SERVICES_SCRIPT_DIR ) ; do
|
2016-04-13 17:02:04 +02:00
|
|
|
if [ -x $LE_SERVICES_SCRIPT_DIR/$f ] ; then
|
|
|
|
echo "Running $LE_SERVICES_SCRIPT_DIR/$f" >> $LOG_DIR/letsencrypt_request.log
|
2016-04-13 19:52:10 +02:00
|
|
|
$LE_SERVICES_SCRIPT_DIR/$f >> $LOG_DIR/letsencrypt_request.log 2>&1
|
2016-04-12 19:40:28 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
|