renewal.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. git_dir="pki"
  3. branch="100883"
  4. #git_url="git.sdsys.ru/sdsys/pki.git"
  5. function mail_send {
  6. echo "${message}"|mail -s "Attention! Certificate status!" \
  7. -S smtp=${SMTP_SERVER} \
  8. -S smtp-use-starttls \
  9. -S smtp-auth=login \
  10. -S ssl-verify=ignore \
  11. -S smtp-auth-user=${JENKINS_MAIL_USER} \
  12. -S smtp-auth-password=$(cat /run/secrets/jenkins-mail-pass) \
  13. -S nss-config-dir=/etc/pki/nssdb \
  14. -S from=${JENKINS_MAIL_USER} \
  15. ${RECIPIENT_MAIL_BOX}
  16. }
  17. function git_config {
  18. cd /${git_dir}
  19. git config --global user.email "${JENKINS_MAIL_USER}"
  20. git config --global user.name "Jenkins"
  21. }
  22. #if [ -z "$*" ]; then message="letsencrypt. No domain specified!!!"; mail_send; exit 1;fi
  23. if [ -d /${git_dir} ]
  24. then
  25. git_config && git checkout ${branch} && git pull https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL}
  26. if [ $? -ne 0 ];then message="letsencrypt. Can't pull https://${GIT_URL}"; mail_send; exit 1;fi
  27. else
  28. cd / && git clone https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL} && cd /${git_dir} && git checkout ${branch}
  29. if [ $? -ne 0 ];then message="letsencrypt. Can't clone https://${GIT_URL}"; mail_send; exit 1;fi
  30. fi
  31. #domain=$(echo "$*" | sed 's/ / -d /g')
  32. #certbot certonly --dry-run --webroot -w /var/www/html --config-dir /${git_dir}/letsencrypt -m admin@sdsys.ru -d ${domain}
  33. certbot renew --config-dir /pki/letsencrypt
  34. if [ $? -ne 0 ];then message="letsencrypt. Can't execute "dry-run" for $(echo $*). Generate cert and key will be skipped!!!"; mail_send; exit 1;fi
  35. #certbot certonly --webroot -w /var/www/html --config-dir /${git_dir}/letsencrypt -m admin@sdsys.ru -d ${domain}
  36. #if [ $? -ne 0 ];then message="letsencrypt. Can't generate cert and key for $(echo $*). See log !!!"; mail_send; exit 1;fi
  37. echo "Generate new key and cert for $(echo $*)" > /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. Certs for domain $(echo $*) is generated!!!"
  42. mail_send