aboutsummaryrefslogtreecommitdiff
path: root/files/run_certbot.py
blob: 8b4dc208e358814f888f895c5710149b2998f858 (plain)
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
#!/usr/bin/env python3

"""
Exec certbot with flags.

Gathers domain names to give to certbot, and then execs
certbot. "Required" to send multiple domain names

File managed by Puppet
"""

# Script should be compatible with both Python2 and Python3

from __future__ import print_function
import sys
import os.path

if len(sys.argv) != 2:
    print('Takes exactly one argument: the certificates name',
          file=sys.stderr)
    sys.exit(1)


cert_name = sys.argv[1]
here = os.path.dirname(sys.argv[0])

cmdline = ['certbot', '--config', os.path.join(here, cert_name + ".ini")]

domainlist_file = os.path.join(here, cert_name + '.domains')

with open(domainlist_file) as f:
    domains = [line.strip() for line in f
               if line and line[0] != '#']

if not domains:
    print('No domains configured. Check {}'.format(domainlist_file))
    sys.exit(1)

for domain in domains:
    cmdline += ['-d', domain]

cmdline += ['certonly']

os.execvp('certbot', cmdline)