-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtomav-renew-certs
More file actions
56 lines (53 loc) · 2.06 KB
/
tomav-renew-certs
File metadata and controls
56 lines (53 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
#script for tomav mailserver https://github.com/tomav/docker-mailserver/
# and https://github.com/docker-mailserver/docker-mailserver
# works fine for me on 2023-06
#script checks if new letsencrypt certificates are present in config dir.
#if so they are copied and daemons restarted
# script is kicked of by refreshpemsmail.sh, that fetches certbox certificates from another host
Currentcert=/etc/dms/tls/cert
#Currentcert=/etc/postfix/ssl/cert
CurrentcertD=/etc/postfix/ssl/cert #dovecot
Newcert=/tmp/ssl/fullchain.pem
Currentkey=/etc/dms/tls/key
#Currentkey=/etc/postfix/ssl/key
CurrentkeyD=/etc/postfix/ssl/key #dovecot
Newkey=/tmp/ssl/privkey.pem
Backupkey="$Newkey.backup"
Backupcert="$Newcert.backup"
#check if a new cert is present
echo "newcert is $Newcert"
if [ -f "$Newcert" ]
then
echo "new certificate detected"
#take fingerprints
FP_CurrentC=`openssl x509 -fingerprint -nocert -in $Currentcert`
FP_NewC=`openssl x509 -fingerprint -nocert -in $Newcert`
echo "FP Curry is $FP_CurrentC"
echo "FP New is $FP_NewC"
#check sanity pemfile
stringlenght=${#FP_NewC} #fingerprint should be a long string
echo " length is $stringlenght"
if [ $stringlenght -gt 50 ]
then
echo sane
#test if FP are different, if yes let take actions
if [ "$FP_NewC" = "$FP_CurrentC" ]
then
echo " FPs match, do nothing"
logger "Cert update: certificate update started, but something went wrong, check newcerts perhaps"
else
cp $Newcert $Currentcert
cp $Newkey $Currentkey
chmod 600 $Currentcert
chmod 600 $Currentkey
logger "Cert update: new certificates have been copied into container"
logger "Cert update: restarting daemons Postfix and Dovecot"
supervisorctl restart postfix
supervisorctl restart dovecot
mv $Newkey $Backupkey
mv $Newcert $Backupcert
fi
fi
logger "Cert update: Newcert script exited fine"
fi