renewal.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. git_dir="pki/${CERT_SUBDIR}"
  3. branch="100883"
  4. log_file="/var/log/letsencrypt/letsencrypt.log"
  5. #git_url="git.sdsys.ru/sdsys/pki.git"
  6. [[ -z ${GIT_URL} ]] && exit 0
  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. if [ -d /${git_dir} ]
  30. then
  31. git_config && git checkout ${branch} && git pull https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL}
  32. if [ $? -ne 0 ];then message="letsencrypt. Can't pull https://${GIT_URL}"; mail_send; exit 1;fi
  33. else
  34. cd / && git clone https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL} && cd /${git_dir} && git checkout ${branch}
  35. if [ $? -ne 0 ];then message="letsencrypt. Can't clone https://${GIT_URL}"; mail_send; exit 1;fi
  36. fi
  37. #certbot renew --dry-run --config-dir /${git_dir}/letsencrypt
  38. #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
  39. #clear_log
  40. certbot renew --config-dir /${git_dir}/letsencrypt
  41. if [ $? -ne 0 ];then message="letsencrypt. Can't renew certs and keys. See log !!!"; mail_send; exit 1;fi
  42. echo "Renew keys and certs" > /tmp/commit.txt
  43. git_config && git add -A && git commit -F /tmp/commit.txt
  44. git push https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL} ${branch}
  45. if [ $? -ne 0 ];then message="letsencrypt. Can't push diff to https://${GIT_URL} !!!"; mail_send; exit 1;fi
  46. message="letsencrypt.Renew Certs and Keys are success!!!"
  47. mail_send