45 lines
928 B
Django/Jinja
45 lines
928 B
Django/Jinja
#!/usr/bin/env python3
|
|
|
|
import subprocess
|
|
import sys
|
|
import json
|
|
|
|
def main():
|
|
try:
|
|
fqdn = sys.argv[1]
|
|
except IndexError:
|
|
print(f"usage: {sys.argv[0]} <fqdn>")
|
|
sys.exit(1)
|
|
|
|
return certbot_new(fqdn)
|
|
|
|
def certbot_new(fqdn):
|
|
dns_file = "dns-provider-domains.json"
|
|
with open(f'/usr/local/etc/letsencrypt/{dns_file}', 'r') as f:
|
|
domains = json.load(f)
|
|
|
|
dotted = fqdn.split('.')
|
|
domain = ".".join(dotted[1:])
|
|
|
|
try:
|
|
dns_provider = domains[domain]
|
|
except KeyError:
|
|
print(f"domain '{domain}' not found in '{dns_file}'!")
|
|
sys.exit(2)
|
|
|
|
dns_flag = f"--dns-{dns_provider}"
|
|
certbot_cmd = [
|
|
"/usr/local/bin/certbot",
|
|
"certonly",
|
|
"-d", fqdn,
|
|
dns_flag
|
|
]
|
|
|
|
print(" ".join(certbot_cmd))
|
|
|
|
p = subprocess.run(certbot_cmd, check=True)
|
|
return p.returncode
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|