summaryrefslogtreecommitdiffstats
path: root/modules/certbot/templates/certbot-tozt
blob: bdf1201a608cb1782cf9fef21a8c7f7c61f91109 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
set -eu
set -o pipefail

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 <%= @primary_domain %>;
        location / {
            root /tmp;
        }
    }
<%- @secondary_domains.each do |domain| -%>
    server {
        listen 80;
        server_name <%= domain %>;
        location / {
            root /tmp;
        }
    }
<%- end -%>
}
EOF

if [ -z "$is_running" ]; then
    systemctl start nginx
fi

if [ -z "$config_dir" ]; then
    /usr/bin/certbot run \
        -n \
        --agree-tos \
        -m doy@tozt.net \
        --cert-name <%= @primary_domain %> \
        -d <%= @primary_domain %> \
<%- @secondary_domains.each do |domain| -%>
        -d <%= domain %> \
<%- end -%>
        --nginx
else
    /usr/bin/certbot run \
        -n \
        --agree-tos \
        -m doy@tozt.net \
        --config-dir "$config_dir" \
        --cert-name <%= @primary_domain %> \
        -d <%= @primary_domain %> \
<%- @secondary_domains.each do |domain| -%>
        -d <%= domain %> \
<%- end -%>
        --nginx
fi