diff options
Diffstat (limited to 'modules/certbot/files/bootstrap-certbot')
-rwxr-xr-x | modules/certbot/files/bootstrap-certbot | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/modules/certbot/files/bootstrap-certbot b/modules/certbot/files/bootstrap-certbot new file mode 100755 index 0000000..cb496f8 --- /dev/null +++ b/modules/certbot/files/bootstrap-certbot @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +set -eu +set -o pipefail + +# XXX update to real domain name + +config_dir="$1" +if systemctl is-active -q nginx; then + is_running=1 +else + is_running= +fi + +cleanup() { + if [ -z "$is_running" ]; then + systemctl stop nginx + fi + + if [ -e /etc/nginx/nginx.conf.backup ]; then + mv /etc/nginx/nginx.conf.backup /etc/nginx.conf + fi +} +trap cleanup EXIT + +mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup +cat > /etc/nginx/nginx.conf <<EOF +worker_processes 1; +events { + worker_connections 1024; +} +http { + server { + listen 80 default; + server_name new.tozt.net; + location / { + root /tmp; + } + } +} +EOF + +if [ -z "$is_running" ]; then + systemctl start nginx +fi + +if [ -z "$config_dir" ]; then + /usr/bin/certbot -n --agree-tos -m doy@tozt.net --nginx -d new.tozt.net +else + /usr/bin/certbot -n --agree-tos -m doy@tozt.net --nginx -d new.tozt.net --config-dir "$config_dir" +fi |