generate.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 git_config {
  8. cd /${git_dir}
  9. git config --global user.email "${JENKINS_MAIL_USER}"
  10. git config --global user.name "Jenkins"
  11. }
  12. function clear_log {
  13. echo -n > ${log_file}
  14. }
  15. if [ -z "$*" ]; then echo "letsencrypt. No domain specified!!!"; exit 1;fi
  16. clear_log
  17. [[ -d /${git_dir} ]] && rm -rf /${git_dir}
  18. cd / && git clone https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL} && cd /${git_dir} && git checkout ${branch}
  19. if [ $? -ne 0 ];then echo "letsencrypt. Can't clone https://${GIT_URL}"; exit 1;fi
  20. domain=$(echo "$*" | sed 's/ / -d /g')
  21. certbot certonly --dry-run --webroot -w /var/www/html --config-dir /${git_dir}/${CERT_SUBDIR}/letsencrypt -m admin@sdsys.ru -d ${domain}
  22. if [ $? -ne 0 ];then echo "letsencrypt. Can't execute "dry-run" for $(echo $*). Generate cert and key will be skipped!!!";exit 1;fi
  23. clear_log
  24. certbot certonly --webroot -w /var/www/html --config-dir /${git_dir}/${CERT_SUBDIR}/letsencrypt -m admin@sdsys.ru -d ${domain}
  25. if [ $? -ne 0 ];then echo "letsencrypt. Can't generate cert and key for $(echo $*). See log !!!";exit 1;fi
  26. echo "Generate new key and cert for $(echo $*)" > /tmp/commit.txt
  27. git_config && git add -A && git commit -F /tmp/commit.txt
  28. git push https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL} ${branch}
  29. if [ $? -ne 0 ];then echo "letsencrypt. Can't push diff to https://${GIT_URL} !!!";exit 1;fi