-
Notifications
You must be signed in to change notification settings - Fork 0
/
cert_deploy.sh
66 lines (53 loc) · 2.67 KB
/
cert_deploy.sh
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
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
servername=$(hostname -f)
getdomains="-d $servername -d mail.domain.com"
getemail="[email protected]"
yum install certbot -y
##########################
/sbin/runuser -l zimbra -c '/opt/zimbra/bin/zmproxyctl stop'
/sbin/runuser -l zimbra -c '/opt/zimbra/bin/zmmailboxdctl stop'
/usr/bin/certbot certonly --agree-tos --non-interactive --email $getemail --standalone $getdomains
##### fix directory issues #####
echo "fix directory issues"
rm -rf /opt/zimbra/ssl/letsencrypt/
mkdir /opt/zimbra/ssl/letsencrypt/
##### copy needed files to zimbra directory #####
echo "copy needed files to zimbra directory"
cp -nf /etc/letsencrypt/live/$servername/*.pem /opt/zimbra/ssl/letsencrypt/
##### modify chain.pem file #####
echo "modify chain.pem file"
/opt/zimbra/ssl/letsencrypt/chain.pem <<"EOF"
-----BEGIN CERTIFICATE-----
MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow
PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD
Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O
rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq
OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b
xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw
7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD
aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV
HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG
SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69
ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr
AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz
R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5
JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo
Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ
-----END CERTIFICATE-----
EOF
### Than to give zimbra rights to the directory ###
chown -R zimbra.zimbra /opt/zimbra/ssl/letsencrypt/*
### Now we have to verify the Certificate #####
echo "Now we have to verify the Certificate"
cd /opt/zimbra/ssl/letsencrypt/ && /opt/zimbra/bin/zmcertmgr verifycrt comm privkey.pem cert.pem chain.pem
cp -nf /opt/zimbra/ssl/letsencrypt/privkey.pem /opt/zimbra/ssl/zimbra/commercial/commercial.key
### Now let's install the Certificate #####
echo "we are installing the certificate"
cd /opt/zimbra/ssl/letsencrypt/ && /opt/zimbra/bin/zmcertmgr deploycrt comm cert.pem chain.pem
### Now let's Restart the Zimbra Server #####
echo "Server Restart"
/sbin/runuser -l zimbra -c '/opt/zimbra/bin/zmcontrol restart'
exit