ADMIN: dump-certs: don't update the file if it's up to date

Compare the fingerprint of the leaf certificate to the previous file to
check if it needs to be updated or not

Also skip the check if no file is on the disk.
This commit is contained in:
William Lallemand 2025-09-28 16:33:37 +02:00
parent 3a6ea8b959
commit 8781c65d8a

View File

@ -60,6 +60,21 @@ read_certificate() {
return 0 return 0
} }
cmp_certkey() {
prev=$1
new=$2
if [ ! -f "$prev" ]; then
return 1;
fi
if ! cmp -s <(openssl x509 -in "$prev" -noout -fingerprint -sha256) <(openssl x509 -in "$new" -noout -fingerprint -sha256); then
return 1
fi
return 0
}
dump_certificate() { dump_certificate() {
name=$1 name=$1
crt_filename=$2 crt_filename=$2
@ -82,6 +97,11 @@ dump_certificate() {
return 1 return 1
fi fi
if cmp_certkey "${crt_filename}" "${crt_filename}.${tmp}"; then
echo "notice: ${crt_filename} is already up to date"
return 0
fi
# move the current certificates to ".old.timestamp" # move the current certificates to ".old.timestamp"
mv "${crt_filename}" "${crt_filename}.${d}" mv "${crt_filename}" "${crt_filename}.${d}"
[ "${crt_filename}" != "${key_filename}" ] && mv "${key_filename}" "${key_filename}.${d}" [ "${crt_filename}" != "${key_filename}" ] && mv "${key_filename}" "${key_filename}.${d}"