ansible-role-letsencrypt-ac.../files/acme-sh-request-cert

56 lines
1.4 KiB
Bash

#!/bin/bash
if [ $# -ne 1 ] ; then
ACME_SH_ENV_FILE="$1"
fi
if [ -f "/etc/default/acme_sh_request_env" ] ; then
. "/etc/default/acme_sh_request_env"
else
exit 1
fi
if [ -n "$ACME_SH_ENV_FILE" ] && [ -f "$ACME_SH_ENV_FILE" ] ; then
. "$ACME_SH_ENV_FILE"
else
exit 1
fi
RETVAL=
if [ ! -f "$ACME_SH_CONFIG_HOME/ok_certificate_issued" ] && [ "$ACME_SH_USE_DNS_PROVIDER" == "False" ] ; then
# First request. Try to shut down all the services running on port 80
if [ -x /bin/systemctl ] ; then
/bin/systemctl stop nginx >/dev/null 2>&1
/bin/systemctl stop apache2 >/dev/null 2>&1
/bin/systemctl stop httpd >/dev/null 2>&1
else
service nginx stop
service apache2 stop
service httpd stop
fi
$ACME_SH_BIN $ACME_SH_FIRST_CERT_REQUEST > "$ACME_SH_ISSUE_LOG_FILE" 2>&1
RETVAL=$?
if [ -x /bin/systemctl ] ; then
/bin/systemctl start nginx >/dev/null 2>&1
/bin/systemctl start apache2 >/dev/null 2>&1
/bin/systemctl start httpd >/dev/null 2>&1
else
service nginx start
service apache2 start
service httpd start
fi
else
$ACME_SH_BIN $ACME_SH_ISSUE_CERT_REQUEST > "$ACME_SH_ISSUE_LOG_FILE" 2>&1
RETVAL=$?
fi
if [ $RETVAL -eq 0 ] ; then
touch "$ACME_SH_CONFIG_HOME/ok_certificate_issued"
fi
if [ $RETVAL -eq 2 ] ; then
# There is a valid certificate already
exit 0
fi
exit $RETVAL