Last active
February 22, 2021 18:54
-
-
Save diamondo25/a07e5b8234ecc4496062ff76963cd785 to your computer and use it in GitHub Desktop.
Fix letsencrypt symlinks from /live to point to correct /archive entry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Just run this program. It'll find all 'archived' letsencrypt certs, | |
# and sets up the corresponding live/ entries. | |
# This solves the following error: | |
# CertStorageError: expected /etc/letsencrypt/live/example.com/cert.pem to be a symlink | |
import os | |
import re | |
maindir = "/etc/letsencrypt" | |
archived_entries = {} | |
for dirpath, dirnames, filepaths in os.walk(maindir + "/archive"): | |
if len(filepaths) == 0: continue | |
print("Found dir %s" % (dirpath)) | |
for filepath in filepaths: | |
m = re.search(r'([^0-9]+)(\d+)\.pem', filepath) | |
if not m: continue | |
entry = dirpath.replace("/archive", "/live") + '/' + m.group(1) + '.pem' | |
idx = int(m.group(2)) | |
if entry not in archived_entries: | |
archived_entries[entry] = { | |
'lastver': 0, | |
} | |
if archived_entries[entry]['lastver'] < idx: | |
archived_entries[entry]['lastver'] = idx | |
archived_entries[entry]['path'] = dirpath + '/' + filepath | |
for entry, data in archived_entries.items(): | |
print('%s (v%d) -> %s' % (entry, data['lastver'], data['path'])) | |
os.remove(entry) | |
os.symlink(data['path'], entry) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment