#!/bin/bash git_dir="pki" branch="100883" log_file="/var/log/letsencrypt/letsencrypt.log" #git_url="git.sdsys.ru/sdsys/pki.git" if [[ -z ${CERT_SUBDIR} ]];then echo "variable CERT_SUBDIR doesn't set"; exit 1;fi function git_config { cd /${git_dir} git config --global user.email "${JENKINS_MAIL_USER}" git config --global user.name "Jenkins" } function clear_log { echo -n > ${log_file} } if [ -z "$*" ]; then echo "letsencrypt. No domain specified!!!"; exit 1;fi clear_log [[ -d /${git_dir} ]] && rm -rf /${git_dir} cd / && git clone https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL} && cd /${git_dir} && git checkout ${branch} if [ $? -ne 0 ];then echo "letsencrypt. Can't clone https://${GIT_URL}"; exit 1;fi domain=$(echo "$*" | sed 's/ / -d /g') certbot certonly --dry-run --webroot -w /var/www/html --config-dir /${git_dir}/${CERT_SUBDIR}/letsencrypt -m admin@sdsys.ru -d ${domain} if [ $? -ne 0 ];then echo "letsencrypt. Can't execute "dry-run" for $(echo $*). Generate cert and key will be skipped!!!";exit 1;fi clear_log certbot certonly --webroot -w /var/www/html --config-dir /${git_dir}/${CERT_SUBDIR}/letsencrypt -m admin@sdsys.ru -d ${domain} if [ $? -ne 0 ];then echo "letsencrypt. Can't generate cert and key for $(echo $*). See log !!!";exit 1;fi echo "Generate new key and cert for $(echo $*)" > /tmp/commit.txt git_config && git add -A && git commit -F /tmp/commit.txt git push https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL} ${branch} if [ $? -ne 0 ];then echo "letsencrypt. Can't push diff to https://${GIT_URL} !!!";exit 1;fi