From 3fd9dd1b89f3372b65871f99cfe66e1be9b1e9cf Mon Sep 17 00:00:00 2001
From: Jesse Norell <jesse@kci.net>
Date: Tue, 16 Nov 2021 11:59:37 -0700
Subject: [PATCH] fix certbot symlink creation when certificate files exist

---
 install/lib/installer_base.lib.php | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index bc6306d697..af4132a5e3 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -3133,6 +3133,12 @@ class installer_base {
 						// certbot returns with 0 on issue for already existing certificate
 
 						$acme_cert_dir = '/etc/letsencrypt/live/' . $hostname;
+						foreach (array( 'fullchain.pem', 'privkey.pem' ) as $f) {
+							$f = $acme_cert_dir . '/' . $f;
+							if (file_exists($f) && ! is_link($f)) {
+								unlink($f);
+							}
+						}
 						symlink($acme_cert_dir . '/fullchain.pem', $ssl_crt_file);
 						symlink($acme_cert_dir . '/privkey.pem', $ssl_key_file);
 
-- 
GitLab