renewal.sh 2.1 KB

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