renewal.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. git_dir="pki"
  3. branch="100883"
  4. log_file="/var/log/letsencrypt/letsencrypt.log"
  5. #git_url="git.sdsys.ru/sdsys/pki.git"
  6. [[ -z ${CERT_SUBDIR} ]] && exit 1
  7. function mail_send {
  8. echo "${message}"|mail -s "Attention! Certificate status!" \
  9. -S smtp=${SMTP_SERVER} \
  10. -S smtp-use-starttls \
  11. -S smtp-auth=login \
  12. -S ssl-verify=ignore \
  13. -S smtp-auth-user=${JENKINS_MAIL_USER} \
  14. -S smtp-auth-password=$(cat /run/secrets/jenkins-mail-pass) \
  15. -S nss-config-dir=/etc/pki/nssdb \
  16. -S from=${JENKINS_MAIL_USER} \
  17. -a ${log_file} \
  18. ${RECIPIENT_MAIL_BOX}
  19. }
  20. function git_config {
  21. cd /${git_dir}
  22. git config --global user.email "${JENKINS_MAIL_USER}"
  23. git config --global user.name "Jenkins"
  24. }
  25. function clear_log {
  26. echo -n > ${log_file}
  27. }
  28. clear_log
  29. [[ -d /${git_dir} ]] && rm -rf /${git_dir}
  30. cd / && git clone https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL} && cd /${git_dir} && git checkout ${branch}
  31. if [ $? -ne 0 ];then message="letsencrypt. Can't clone https://${GIT_URL}"; mail_send; exit 1;fi
  32. #certbot renew --dry-run --config-dir /${git_dir}/letsencrypt
  33. #if [ $? -ne 0 ];then message="letsencrypt. Can't execute "dry-run" renew procces. Renew certs and keys will be skipped!!!"; mail_send; exit 1;fi
  34. #clear_log
  35. certbot renew --config-dir /${git_dir}/${CERT_SUBDIR}/letsencrypt
  36. if [ $? -ne 0 ];then message="letsencrypt. Can't renew certs and keys. See log !!!"; mail_send; exit 1;fi
  37. echo "Renew keys and certs" > /tmp/commit.txt
  38. git_config && git add -A && git commit -F /tmp/commit.txt
  39. git push https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL} ${branch}
  40. if [ $? -ne 0 ];then message="letsencrypt. Can't push diff to https://${GIT_URL} !!!"; mail_send; exit 1;fi
  41. message="letsencrypt.Renew Certs and Keys are success!!!"
  42. mail_send