aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-06-20 18:08:39 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-06-20 18:08:39 +0200
commit3672371d4153f3520c0c50f46085b29ba4580ece (patch)
tree22ea5c57f6b627f7f08318766f628f5996232c52
parentRemove invalid option from README. (diff)
downloadhugonikanor-letsencrypt-3672371d4153f3520c0c50f46085b29ba4580ece.tar.gz
hugonikanor-letsencrypt-3672371d4153f3520c0c50f46085b29ba4580ece.tar.xz
Repair python script.
-rw-r--r--files/run_certbot.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/files/run_certbot.py b/files/run_certbot.py
index f81f707..8b4dc20 100644
--- a/files/run_certbot.py
+++ b/files/run_certbot.py
@@ -1,6 +1,8 @@
-#!/usr/bin/env python
+#!/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
@@ -11,25 +13,32 @@ File managed by Puppet
from __future__ import print_function
import sys
-import os
+import os.path
if len(sys.argv) != 2:
print('Takes exactly one argument: the certificates name',
file=sys.stderr)
- os.exit(1)
+ 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")]
-with open(os.path.join(here, cert_name + '.domains')) as f:
- for line in f:
- if not line:
- continue
- if line[0] == '#':
- continue
- cmdline += ['-d', line.strip()]
+
+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)