From e54f225a78b253fe3d85b888451d0c563831e716 Mon Sep 17 00:00:00 2001 From: vorezal <37914382+vorezal@users.noreply.github.com> Date: Mon, 20 Apr 2026 14:36:54 -0400 Subject: [PATCH] File notification and JSON output fixes (#281) * File notification and JSON output fixes * Truncate notify file(s) on first write and then append * Strip wrapping double quotes from Dockcheck update tempcsv variable before jsonification * Eliminate separate truncate step --- notify_templates/notify_file.sh | 12 ++++++++---- notify_templates/notify_v2.sh | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/notify_templates/notify_file.sh b/notify_templates/notify_file.sh index 75aa74a..f87504e 100644 --- a/notify_templates/notify_file.sh +++ b/notify_templates/notify_file.sh @@ -1,5 +1,5 @@ ### DISCLAIMER: This is a third party addition to dockcheck - best effort testing. -NOTIFY_FILE_VERSION="v0.1" +NOTIFY_FILE_VERSION="v0.2" # # Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script. # If you instead wish make your own modifications, make a copy in the same directory as the main dockcheck.sh script. @@ -13,10 +13,14 @@ trigger_file_notification() { UpperChannel="FILE" fi + FileTruncVar="${UpperChannel}_TRUNC" FilePathVar="${UpperChannel}_PATH" - NotifyFile="${!FilePathVar:=${ScriptWorkDir}/updates_available.txt}" - echo "${MessageBody}" > ${NotifyFile} - + if [[ ${!FileTruncVar:=0} -eq 0 ]]; then + echo "${MessageBody}" > ${NotifyFile} + declare -g ${FileTruncVar}=1 + else + echo "${MessageBody}" >> ${NotifyFile} + fi } diff --git a/notify_templates/notify_v2.sh b/notify_templates/notify_v2.sh index a44870a..8d288bf 100644 --- a/notify_templates/notify_v2.sh +++ b/notify_templates/notify_v2.sh @@ -205,7 +205,7 @@ format_output() { FormattedOutput=$(jq --compact-output --null-input --arg updates "${tempcsv}" '($updates | split("\\n")) | map(split(",")) | {"updates": map({"script_name": .[0], "installed_version": .[1], "latest_version": .[2]})}') elif [[ "${UpdateType}" == "dockcheck_update" ]]; then # dockcheck update case - FormattedOutput=$(jq --compact-output --null-input --arg updates "${tempcsv}" '($updates | split("\\n")) | map(split(",")) | {"updates": map({"script_name": .[0], "installed_version": .[1], "latest_version": .[2], "release_notes": (.[3:] | join(","))})}') + FormattedOutput=$(jq --compact-output --null-input --arg updates "${tempcsv//\"/}" '($updates | split("\\n")) | map(split(",")) | {"updates": map({"script_name": .[0], "installed_version": .[1], "latest_version": .[2], "release_notes": (.[3:] | join(","))})}') else FormattedOutput="Invalid input" fi