From d2e5678b18d6a046d315656f95a8088e8c799fef Mon Sep 17 00:00:00 2001 From: Oliver Cervera Date: Fri, 10 May 2024 11:12:36 +0200 Subject: [PATCH 1/4] Email address check Check for email address before attempting to send the report, in case the user has no email configured. --- snapraid-aio-script.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/snapraid-aio-script.sh b/snapraid-aio-script.sh index e544f96..baf4bb9 100644 --- a/snapraid-aio-script.sh +++ b/snapraid-aio-script.sh @@ -8,7 +8,7 @@ ###################### # SCRIPT VARIABLES # ###################### -SNAPSCRIPTVERSION="3.3.1" +SNAPSCRIPTVERSION="3.3.2" # Read SnapRAID version SNAPRAIDVERSION="$(snapraid -V | sed -e 's/snapraid v\(.*\)by.*/\1/')" @@ -359,11 +359,12 @@ fi # if email or hook service are enabled, will be sent now if [ "$EMAIL_ADDRESS" ] || [ -x "$HOOK_NOTIFICATION" ] || [ "$HEALTHCHECKS" -eq 1 ] || [ "$TELEGRAM" -eq 1 ] || [ "$DISCORD" -eq 1 ]; then # Add a topline to email body and send a long mail - sed_me "1s:^:##$SUBJECT \n:" "${TMP_OUTPUT}" - if [ "$VERBOSITY" -eq 1 ]; then + sed_me "1s:^:##$SUBJECT \n:" "${TMP_OUTPUT}" + # send long mail if verbosity is set to 1 + if [ "$VERBOSITY" -eq 1 ]; then send_mail < "$TMP_OUTPUT" else - # or send a short mail + # or send a short mail trim_log < "$TMP_OUTPUT" | send_mail fi fi @@ -917,7 +918,7 @@ function send_mail(){ if [ -x "$HOOK_NOTIFICATION" ]; then echo -e "Notification user script is set. Calling it now [$(date)]" $HOOK_NOTIFICATION "$SUBJECT" "$body" - else + elif [ "$EMAIL_ADDRESS" ]; then echo -e "Email address is set. Sending email report to **$EMAIL_ADDRESS** [$(date)]" $MAIL_BIN -a 'Content-Type: text/html' -s "$SUBJECT" -r "$FROM_EMAIL_ADDRESS" "$EMAIL_ADDRESS" \ < <(echo "$body") From f8fecfe0d18f8e67ea48c54bc61b20969b5b375e Mon Sep 17 00:00:00 2001 From: Oliver Cervera Date: Fri, 10 May 2024 11:13:28 +0200 Subject: [PATCH 2/4] Update script-config.sh --- script-config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script-config.sh b/script-config.sh index 234533d..c31aef9 100644 --- a/script-config.sh +++ b/script-config.sh @@ -1,5 +1,5 @@ #!/bin/bash -CONFIG_VERSION="3.3.1" +CONFIG_VERSION="3.3.2" ###################### # USER VARIABLES # ###################### From 5072bb4747cf7648c79f9a55381b9ba9ea495c73 Mon Sep 17 00:00:00 2001 From: Oliver Cervera Date: Fri, 10 May 2024 11:18:14 +0200 Subject: [PATCH 3/4] Update version --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index bea438e..4772543 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.3.1 +3.3.2 From 3f05775cee4716d71db92a12154f624684126868 Mon Sep 17 00:00:00 2001 From: Oliver Cervera Date: Fri, 10 May 2024 12:08:42 +0200 Subject: [PATCH 4/4] Improve check of "ADD_DEL_THRESHOLD" Check for "ADD_DEL_THRESHOLD" before usage in some conditions. It produced errors at the end of emails in 4 cases. --- snapraid-aio-script.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/snapraid-aio-script.sh b/snapraid-aio-script.sh index baf4bb9..5b31746 100644 --- a/snapraid-aio-script.sh +++ b/snapraid-aio-script.sh @@ -795,15 +795,17 @@ SUMMARY: Equal [$EQ_COUNT] - Added [$ADD_COUNT] - Deleted [$DEL_COUNT] - Moved [ fi if [ "$DEL_COUNT" -ge "$DEL_THRESHOLD" ] && [ "$UPDATE_COUNT" -ge "$UP_THRESHOLD" ] && [ "$DO_SYNC" -eq 0 ]; then + if [ "$(echo "$ADD_DEL_THRESHOLD" == 0 | bc -l)" -eq 1 ]; then MSG="Multiple violations - Deleted files ($DEL_COUNT) / ($DEL_THRESHOLD) and changed files ($UPDATE_COUNT) / ($UP_THRESHOLD)" - if [ "$(echo "$ADD_DEL_RATIO < $ADD_DEL_THRESHOLD" | bc -l)" -eq 1 ]; then - MSG="Multiple violations - Deleted files ($DEL_COUNT) / ($DEL_THRESHOLD), add/delete ratio ($ADD_DEL_RATIO) / ($ADD_DEL_THRESHOLD), and changed files ($UPDATE_COUNT) / ($UP_THRESHOLD)" + elif [ "$(echo "$ADD_DEL_RATIO < $ADD_DEL_THRESHOLD" | bc -l)" -eq 1 ]; then + MSG="Multiple violations - Deleted files ($DEL_COUNT) / ($DEL_THRESHOLD), add/delete ratio ($ADD_DEL_RATIO) / ($ADD_DEL_THRESHOLD), and changed files ($UPDATE_COUNT) / ($UP_THRESHOLD)" fi - fi + fi if [ "$DEL_COUNT" -ge "$DEL_THRESHOLD" ] && [ "$UPDATE_COUNT" -ge "$UP_THRESHOLD" ] && [ "$DO_SYNC" -eq 1 ]; then - MSG="Sync forced with multiple violations - Deleted files ($DEL_COUNT) / ($DEL_THRESHOLD) and changed files ($UPDATE_COUNT) / ($UP_THRESHOLD)" - if [ "$(echo "$ADD_DEL_RATIO < $ADD_DEL_THRESHOLD" | bc -l)" -eq 1 ]; then + if [ "$(echo "$ADD_DEL_THRESHOLD" == 0 | bc -l)" -eq 1 ]; then + MSG="Sync forced with multiple violations - Deleted files ($DEL_COUNT) / ($DEL_THRESHOLD) and changed files ($UPDATE_COUNT) / ($UP_THRESHOLD)" + elif [ "$(echo "$ADD_DEL_RATIO < $ADD_DEL_THRESHOLD" | bc -l)" -eq 1 ]; then MSG="Sync forced with multiple violations - Deleted files ($DEL_COUNT) / ($DEL_THRESHOLD), add/delete ratio ($ADD_DEL_RATIO) / ($ADD_DEL_THRESHOLD), and changed files ($UPDATE_COUNT) / ($UP_THRESHOLD)" fi fi