From 2b3da35e19c2c1f45c7575862af5d026b9f4ab9c Mon Sep 17 00:00:00 2001 From: Martin Berghaus Date: Thu, 23 Oct 2025 00:34:26 +0200 Subject: [PATCH] small improvements, especially the handling of AUTOACME_PATH_IN_GIT_REPOSITORY --- script/ssl/renewCerts.sh | 2 +- script/ssl/start.sh | 34 +++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/script/ssl/renewCerts.sh b/script/ssl/renewCerts.sh index 062a345..de12af9 100644 --- a/script/ssl/renewCerts.sh +++ b/script/ssl/renewCerts.sh @@ -290,7 +290,7 @@ function setup(){ popd > /dev/null 2>&1 isInstalled \ && echo \ - && echo 'Now this script can be added into cron-tab (crontab -e),like this e.g.:' \ + && echo 'Now this script can be added into cron-tab (crontab -e), like this e.g.:' \ && echo \ && echo '# Each day at 6:00am renew certificates:' \ && echo '0 6 * * * /renewCerts.sh --http --own > /var/log/renewCerts.sh.log 2>&1' \ diff --git a/script/ssl/start.sh b/script/ssl/start.sh index e5982d5..d63e2bd 100644 --- a/script/ssl/start.sh +++ b/script/ssl/start.sh @@ -1,5 +1,30 @@ #/bin/bash +function createEnvironmentFile() { + local _ENVIRONMENT_FILE _REPOSITORY_FOLDER + _ENVIRONMENT_FILE="${ENVIRONMENT_FILE:?"createEnvironmentFile(): Missing global parameter ENVIRONMENT_FILE"}" + _REPOSITORY_FOLDER="${AUTOACME_REPOSITORY_FOLDER:?"createEnvironmentFile(): Missing global parameter AUTOACME_REPOSITORY_FOLDER"}" + readonly _ENVIRONMENT_FILE _REPOSITORY_FOLDER + + # Save environment for cronjob + export -p | grep -v -E "(HOME|OLDPWD|PWD|SHLVL)" > "${_ENVIRONMENT_FILE}" + + [ "${AUTOACME_GIT_REPOSITORY_VIA_SSH}" == "" ] \ + && echo "declare -x AUTOACME_RESULT_CERTS=\"${AUTOACME_REPOSITORY_FOLDER#/}\"" >> "${_ENVIRONMENT_FILE}" \ + && echo "SUCCESS: saved environment (without git) into file '${_ENVIRONMENT_FILE}'." \ + && return 0 + + echo "declare -x AUTOACME_RESULT_CERTS=\"${AUTOACME_REPOSITORY_FOLDER}${AUTOACME_PATH_IN_GIT_REPOSITORY#/}\"" >> "${_ENVIRONMENT_FILE}" \ + && echo "SUCCESS: saved environment (with git) into file '${_ENVIRONMENT_FILE}'." \ + && return 0 + + echo + echo "FAILED: something went wrong during the creation of the environment file: '${_ENVIRONMENT_FILE}'..." + echo " This file is mandantory to use 'renewCerts.sh' with cron." + echo + return 1 +} + function ensureThereAreSSHKeys() { grep -F 'ssh' "/root/.ssh/id_ed25519.pub" &> /dev/null \ && echo "SUCCESS: ssh-keys found, printing public key:" \ @@ -81,6 +106,9 @@ function ensureRepositoryIsAvailableAndWritable() { } function prepareThisRuntimeForUsingGitOrIgnore() { + createEnvironmentFile \ + || return 1 + [ "${AUTOACME_GIT_REPOSITORY_VIA_SSH}" == "" ] \ && echo "There is no git repository specified." \ && echo "To distribute all keys and certificates via a git repository set environment variable:" \ @@ -101,6 +129,7 @@ function prepareThisRuntimeForUsingGitOrIgnore() { } AUTOACME_REPOSITORY_FOLDER="/root/acmeResults/" +ENVIRONMENT_FILE="/autoACME.env" echo echo '################################################################################' @@ -108,11 +137,6 @@ echo "# Container started at $(date +%F_%T) on host ${AUTOACME_CONTAINER_HOSTNAM echo '################################################################################' echo -# Save environment for cronjob -export -p | grep -v -E "(HOME|OLDPWD|PWD|SHLVL)" > "/autoACME.env" \ - && echo "declare -x AUTOACME_RESULT_CERTS=\"${AUTOACME_REPOSITORY_FOLDER}${AUTOACME_PATH_IN_GIT_REPOSITORY#/}\"" >> "/autoACME.env" \ - && echo "SUCCESS: saved environment into file '/autoACME.env'." - # Log start and truncate file: /autoACME.log echo > /autoACME.log