Script de Renovação de certificados letsencrypt Email ZIMBRA
Renovação de certificados letsencrypt Email ZIMBRA:
#-----------DECLARACAO DE VARIAVEIS---------------------------------------------
CERTS_LETSENCRYPT=$(find /etc/letsencrypt/live/ -type d | grep exemplo.com.br) #DIRETORIO DE ARQUIVOS DO LETS ENCRYPT
ZIMBRA_LETSENCRYPT='/opt/zimbra/ssl/letsencrypt' #DIRETORIO DE ARQUIVOS ZIMBRA DO LETSENCRYPT
ZIMBRA_SSL_COMM='/opt/zimbra/ssl/zimbra/commercial' #DIRETORIO DE ARQUIVOS SSL ZIMBRA
ZIMBRA_BACKUP='/root/backup/zimbra' #DIREOTORIO DE BACKUP DESTINO
TIMESTAMP=$(date "+%Y%m%d") #VARIAVEL DE TEMPO PARA SCRIPT
BACKUP_FOLDER="/root/backup/zimbra/zimbra-$TIMESTAMP"
########################### ARMAZENAMENTO DE LOGS ############################
LOG="/root/backup/logs/rollover-certs-letsencrypts-$(date "+%Y%m%d").log"
exec 1>> >(tee -a "$LOG")
exec 2>&1
##############################################################################
echo -e "\n\n===== INICIANDO SCRIPT DE RENOVACAO DE CERTIFICADOS SSL LETSENCRYPT PARA ZIMBRA ====="
sleep 3
echo -e "==== ROTINAS DE BACKUP DOS ARQUIVOS SSL DE PRODUCAO EM: $TIMESTAMP\n"
echo -e "==== INICIANDO ROTINAS DE BACKUPS DE ARQUIVOS"
sleep 3
cd $ZIMBRA_BACKUP
mkdir -p $BACKUP_FOLDER
cd $BACKUP_FOLDER
echo -n "1) Criando backup dos arquivos letsencrypt atuais: " && sleep 1 && echo "OK"
cd $BACKUP_FOLDER
mkdir zimbra-letsencrypt
cd zimbra-letsencrypt
cp $ZIMBRA_LETSENCRYPT/* .
if [ $? -ne 0 ]; then { echo "Falha detectada, abortando..." ; exit 1; } fi
echo -n "2) Criando backup dos arquivos zimbra commercial atuais: " && sleep 1 && echo "OK"
cd $BACKUP_FOLDER
mkdir zimbra-commercial
cd zimbra-commercial
cp $ZIMBRA_SSL_COMM/* .
if [ $? -ne 0 ]; then { echo "Falha detectada, abortando..." ; exit 1; } fi
echo -n "3) Criando backup dos arquivos Lets encrypt LIVE: " && sleep 1 && echo "OK"
cd $BACKUP_FOLDER
mkdir letsencrypt-live
cd letsencrypt-live
cp $CERTS_LETSENCRYPT/* .
if [ $? -ne 0 ]; then { echo "Falha detectada, abortando..." ; exit 1; } fi
sleep 2
echo -e "\n==== os backups dos certificados foram feitos com sucesso ====\n"
sleep 3
echo "###########################################################################################"
echo "###### PARANDO OS SERVICOS DO ZMPROXY E ZMAILBOXD #####"
echo "###########################################################################################"
sleep 3
echo "++++++ PARANDOS OS SERVICOS NGINX E JETTY DO ZIMBRA SERVER COM O USER ZIMBRA +++++++"
su - zimbra -c "/opt/zimbra/bin/zmproxyctl stop"
echo "ZMPROXY PARADO"
sleep 15
su - zimbra -c "/opt/zimbra/bin/zmmailboxdctl stop"
echo "ZMMAILBOXD PARADO"
sleep 15
echo "==== SERVICOS ZIMBRA PARADOS COM SUCESSO!! ===="
exit
###########################################################################################
##### NESTA ETAPA IREMOS REALIZAR OS BACKUPS DOS CERTIFICADOS ATUAIS DE PRODUCAO #####
###########################################################################################
# REALIZAR BACKUP DA PASTA DO LETSENCRYPTY
tar -cvzf backup_certs_letsencrypt_$TIMESTAMP.tar.gz $ZIMBRA_LETSENCRYPT/*
echo "#====== COPIANDO OS ARQUIVOS DA PASTA LETS ENCRYPT PARA A PASTA $ZIMBRA_LETSENCRYPT ======="
sleep 5
# CRIAR NOVAS CHAVES LETSENCRYPT EMAIL.MA.GOV.BR
/root/letsencrypt/letsencrypt-auto certonly --standalone -d exemplo.com.br >> $LOG
# montar o arquivo chain do letsencrypt
cd $CERTS_LETSENCRYPT
cat chain.pem /root/scripts/cert-root-letsencrypt.crt > chain-new.pem
cp * $ZIMBRA_LETSENCRYPT
chown zimbra:zimbra $ZIMBRA_LETSENCRYPT/*
echo -n "COPIA DE ARQUIVOS LETSENCRYT CONCLUIDA: " && sleep 1 && echo "OK"
echo -n "PERMISSOES DE ARQUIVO ZIMBRA: " && sleep 1 && echo "OK"
su zimbra
cd $ZIMBRA_LETSENCRYPT
su - zimbra -c "/opt/zimbra/bin/zmcertmgr verifycrt comm privkey.pem cert.pem chain-new.pem | grep OK"
if [ $? -ne 0 ]; then { echo "Falha detectada, abortando..." ; exit 1; } fi
su - zimbra -c "/opt/zimbra/bin/zmcertmgr verifycrt comm privkey.pem cert.pem chain-new.pem" >> $LOG
echo "DEPLOY REALIZADO COM SUCESSO!!"
mkdir /opt/zimbra/ssl/zimbra.$TIMESTAMP
cp -a /opt/zimbra/ssl/zimbra /opt/zimbra/ssl/zimbra.$TIMESTAMP
echo -n "REALIZANDO BACKUP DOS CERTIFICADOS: " && sleep 1 && echo "OK"
cp /opt/zimbra/ssl/letsencrypt/privkey.pem /opt/zimbra/ssl/zimbra/commercial/commercial.key
sleep 10
su - zimbra -c "/opt/zimbra/bin/zmcertmgr deploycrt comm cert.pem chain-new.pem" >> $LOG
su - zimbra -c "/opt/zimbra/bin/zmcontrol restart"
echo "RENOVAÇÃO DE CERTIFICADOS REALIZADA COM SUCESSO!" >> $LOG
Comentários
Postar um comentário