tomishinets.v 5 سال پیش
والد
کامیت
45c7a80a4f
3فایلهای تغییر یافته به همراه25 افزوده شده و 44 حذف شده
  1. 7 0
      Jenkinsfile.generate
  2. 11 33
      generate.sh
  3. 7 11
      renewal.sh

+ 7 - 0
Jenkinsfile.generate

@@ -40,6 +40,13 @@ pipeline {
       echo "CleaningUp work directory"
       deleteDir()
     }
+    success {
+      mail charset: 'UTF-8',
+           subject: "Jenkins build ERROR",
+           mimeType: 'text/html',
+           to: "${mailto}",
+           body: "<b>ATTENTION!!!</b> <b><br> Jenkins job successed.\n\n <b><br>Project Name:</b> ${env.JOB_NAME} <b><br>Generate certs and key for ${domain}</b> <b><br>\nBuild Number:</b> ${env.BUILD_NUMBER} <b><br>\nURL Build:</b> ${RUN_DISPLAY_URL}"
+    }
     failure {
       mail charset: 'UTF-8',
            subject: "Jenkins build ERROR",

+ 11 - 33
generate.sh

@@ -1,25 +1,11 @@
 #!/bin/bash
 
-git_dir="pki/${CERT_SUBDIR}"
+git_dir="pki"
 branch="100883"
 log_file="/var/log/letsencrypt/letsencrypt.log"
 #git_url="git.sdsys.ru/sdsys/pki.git"
 
-[[ -z ${GIT_URL} ]] && exit 0
-
-function mail_send {
-              echo "${message}"|mail -s "Attention! Certificate status!" \
-              -S smtp=${SMTP_SERVER} \
-              -S smtp-use-starttls \
-              -S smtp-auth=login \
-              -S ssl-verify=ignore \
-              -S smtp-auth-user=${JENKINS_MAIL_USER} \
-              -S smtp-auth-password=$(cat /run/secrets/jenkins-mail-pass) \
-              -S nss-config-dir=/etc/pki/nssdb \
-              -S from=${JENKINS_MAIL_USER} \
-              -a ${log_file} \
-              ${RECIPIENT_MAIL_BOX}
-}
+[[ -z ${CERT_SUBDIR} ]] && exit 1
 
 function git_config {
               cd /${git_dir}
@@ -31,32 +17,24 @@ function clear_log {
               echo -n > ${log_file}
 }
 
-if [ -z "$*" ]; then message="letsencrypt. No domain specified!!!"; mail_send; exit 1;fi
+if [ -z "$*" ]; then echo "letsencrypt. No domain specified!!!"; exit 1;fi
 
 clear_log
 
-if [ -d /${git_dir} ]
-then
-  git_config && git checkout ${branch} && git pull https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL}
-  if [ $? -ne 0 ];then message="letsencrypt. Can't pull https://${GIT_URL}"; mail_send; exit 1;fi
-else
-  cd / && git clone https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL} && cd /${git_dir} && git checkout ${branch}
-  if [ $? -ne 0 ];then message="letsencrypt. Can't clone https://${GIT_URL}"; mail_send; exit 1;fi
-fi
+[[ -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}/letsencrypt -m admin@sdsys.ru -d ${domain}
-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
+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}/letsencrypt -m admin@sdsys.ru -d ${domain}
-if [ $? -ne 0 ];then message="letsencrypt. Can't generate cert and key for $(echo $*). See log !!!"; mail_send; exit 1;fi
+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 message="letsencrypt. Can't push diff to https://${GIT_URL} !!!"; mail_send; exit 1;fi
-
-message="letsencrypt. Certs for domain $(echo $*) is generated!!!"
-mail_send
+if [ $? -ne 0 ];then echo "letsencrypt. Can't push diff to https://${GIT_URL} !!!";exit 1;fi

+ 7 - 11
renewal.sh

@@ -1,11 +1,11 @@
 #!/bin/bash
 
-git_dir="pki/${CERT_SUBDIR}"
+git_dir="pki"
 branch="100883"
 log_file="/var/log/letsencrypt/letsencrypt.log"
 #git_url="git.sdsys.ru/sdsys/pki.git"
 
-[[ -z ${GIT_URL} ]] && exit 0
+[[ -z ${CERT_SUBDIR} ]] && exit 1
 
 function mail_send {
               echo "${message}"|mail -s "Attention! Certificate status!" \
@@ -33,21 +33,17 @@ function clear_log {
 
 clear_log
 
-if [ -d /${git_dir} ]
-then
-  git_config && git checkout ${branch} && git pull https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL}
-  if [ $? -ne 0 ];then message="letsencrypt. Can't pull https://${GIT_URL}"; mail_send; exit 1;fi
-else
-  cd / && git clone https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL} && cd /${git_dir} && git checkout ${branch}
-  if [ $? -ne 0 ];then message="letsencrypt. Can't clone https://${GIT_URL}"; mail_send; exit 1;fi
-fi
+[[ -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 message="letsencrypt. Can't clone https://${GIT_URL}"; mail_send; exit 1;fi
+
 
 #certbot renew --dry-run --config-dir /${git_dir}/letsencrypt
 #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
 
 #clear_log
 
-certbot renew --config-dir /${git_dir}/letsencrypt
+certbot renew --config-dir /${git_dir}/${CERT_SUBDIR}/letsencrypt
 if [ $? -ne 0 ];then message="letsencrypt. Can't renew certs and keys. See log !!!"; mail_send; exit 1;fi
 
 echo "Renew keys and certs" > /tmp/commit.txt