From b3da29a515761b5bbecc5b08837009ff50b0d7a2 Mon Sep 17 00:00:00 2001 From: Jonathan Starck Date: Sun, 22 Oct 2023 22:39:41 +0200 Subject: [PATCH] Add Debug --- entry.sh | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/entry.sh b/entry.sh index 56d905a..b23943a 100644 --- a/entry.sh +++ b/entry.sh @@ -13,49 +13,53 @@ echo borgmatic $borgmaticver echo $borgver echo apprise $apprisever -# Uncomment the following lines for debugging to display the initial values of BORG_PASSPHRASE and BORG_PASSPHRASE_FILE. -# echo "Before: BORG_PASSPHRASE: ${BORG_PASSPHRASE}" -# echo "Before: BORG_PASSPHRASE_FILE: ${BORG_PASSPHRASE_FILE}" +# Enable initial debug logging based on the DEBUG_SECRETS environment variable. +# Logs the initial values of BORG_PASSPHRASE and BORG_PASSPHRASE_FILE. +if [ "${DEBUG_SECRETS}" = "true" ] || [ "${DEBUG_SECRETS}" = "1" ]; then + echo "Before: BORG_PASSPHRASE: ${BORG_PASSPHRASE}" + echo "Before: BORG_PASSPHRASE_FILE: ${BORG_PASSPHRASE_FILE}" +fi -# Iterate through all environment variables with the prefix 'BORG'. +# Loop through all environment variables that start with 'BORG'. for var_name in $(set | grep '^BORG' | awk -F= '{print $1}'); do - # Retrieve the current value of the environment variable in question. + # Retrieve the current value of each environment variable. var_value=$(eval echo \$$var_name) - # Check if the variable name ends with the suffix '_FILE'. + # Check if the variable's name ends with '_FILE'. if [[ "$var_name" =~ _FILE$ ]]; then - # Remove the '_FILE' suffix to derive the name of the corresponding "non-FILE" variable. + # Strip the '_FILE' suffix to obtain the corresponding variable name. original_var_name=${var_name%_FILE} - # Check if the original (non-FILE) environment variable is already set and capture its value. + # Retrieve the value of the original environment variable, if it exists. original_var_value=$(eval echo \$$original_var_name) - # Verify that the *_FILE variable is set, that the file it points to exists, and that the file is not empty. + # Ensure the *_FILE variable is valid, and the referenced file exists and is not empty. if [ -n "$var_value" ] && [ -s "$var_value" ]; then - # Notify the user if the original (non-FILE) variable is being overwritten. + # Notify user if original variable is being overwritten. if [ -n "$original_var_value" ]; then echo "Note: $original_var_name was already set but is being overwritten by $var_name" fi - # Read the file content and store it in the original (non-FILE) environment variable. + # Update the original variable with the content of the file. export "$original_var_name"=$(cat "$var_value") echo "Setting $original_var_name from the content of $var_value" - # Remove the original *_FILE environment variable + # Unset the *_FILE environment variable. unset "$var_name" echo "Unsetting $var_name" else - # Issue an error message if the file does not exist or is empty. + # Issue an error if the *_FILE variable is not properly set, or the file does not exist or is empty. echo "Error: File $var_value does not exist or is empty." fi fi done -# Uncomment the following lines for debugging to display the final values of BORG_PASSPHRASE and BORG_PASSPHRASE_FILE. -# echo "After: BORG_PASSPHRASE: ${BORG_PASSPHRASE}" -# echo "After: BORG_PASSPHRASE_FILE: ${BORG_PASSPHRASE_FILE}" -# exit 1 - +# Enable final debug logging based on the DEBUG_SECRETS environment variable. +# Logs the final values of BORG_PASSPHRASE and BORG_PASSPHRASE_FILE. +if [ "${DEBUG_SECRETS}" = "true" ] || [ "${DEBUG_SECRETS}" = "1" ]; then + echo "After: BORG_PASSPHRASE: ${BORG_PASSPHRASE}" + echo "After: BORG_PASSPHRASE_FILE: ${BORG_PASSPHRASE_FILE}" +fi if [ $# -eq 0 ]; then