tomishinets.v před 5 roky
rodič
revize
6335312e7a
1 změnil soubory, kde provedl 11 přidání a 10 odebrání
  1. 11 10
      renewal.sh

+ 11 - 10
renewal.sh

@@ -6,18 +6,14 @@ ERR_SUBJ='Error during renewal certs and keys!!!'
 LOG_FILE=/var/log/letsencrypt/renewal-$(date +%Y-%m-%d).log
 branch=master
 git_dir=pki
-
+#git_url="git.sdsys.ru/sdsys/pki.git"
 
 . /tmp/err_trap
 
-#git_url="git.sdsys.ru/sdsys/pki.git"
-
 if [[ -z ${CERT_SUBDIR} ]];then echo "variable CERT_SUBDIR doesn't set"; exit 1;fi
 [[ ${CERT_SUBDIR} == "dev_iru" ]] && exit 0
 
-
 mail_send() {
-                set +e
                 echo "$1"|mail -s "Attention! Certificate renewal status!" \
                 -S smtp=${SMTP_SERVER} \
                 -S smtp-use-starttls \
@@ -31,10 +27,17 @@ mail_send() {
                 ${RECIPIENT_MAIL_BOX}
 }
 
-git_config() {
+git_push() {
               cd /${git_dir}
+              echo "Renew keys and certs" > /tmp/commit.txt
               git config --global user.email "${JENKINS_MAIL_USER}"
               git config --global user.name "Jenkins"
+              git add -A 
+              if [[ ! -z $(git status -s) ]];then
+                    git commit -F /tmp/commit.txt
+                    git push https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_URL} ${branch}
+              fi
+
 }
 
 clear_log() {
@@ -51,15 +54,13 @@ cd / && git clone https://${GIT_USER}:$(cat /run/secrets/provision-pass)@${GIT_U
 
 #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
+
 echo "Renewal certs and keys"
 certbot renew --config-dir /${git_dir}/${CERT_SUBDIR}/letsencrypt >> ${LOG_FILE} 2>&1
 
 echo "Git push ${GIT_URL}"
-echo "Renew keys and certs" > /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}
+git_push
 
 echo "Send ${LOG_FILE} to ${RECIPIENT_MAIL_BOX}"
 mail_send "LETSENCRYPT!!! Renew Certs and Keys are success!!!"