From 23fe30c4e1134d67650ee0cce2acc350ed154644 Mon Sep 17 00:00:00 2001
From: Christian Hesse <mail@eworm.de>
Date: Thu, 6 Feb 2020 18:10:47 +0100
Subject: [PATCH] check-certificates: rename all certificates by their common
 names

---
 check-certificates | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/check-certificates b/check-certificates
index f378f01..e13e984 100644
--- a/check-certificates
+++ b/check-certificates
@@ -8,6 +8,7 @@
 :global CertRenewUrl;
 :global CertRenewPass;
 
+:global CertificateNameByCN;
 :global ParseKeyValueStore;
 :global SendNotification;
 :global UrlEncode;
@@ -37,6 +38,10 @@
           / certificate import file-name=$CertFileName passphrase=$PassPhrase;
         }
         / file remove [ find where name=$CertFileName ];
+
+        :foreach CertInChain in=[ / certificate find where name~("^" . $CertFileName . "_[0-9]+\$") common-name!=($CertVal->"common-name") ] do={
+          $CertificateNameByCN [ / certificate get $CertInChain common-name ];
+        }
       } on-error={
         :log debug ("Could not download certificate file " . $CertFileName);
       }