diff --git a/.gitignore b/.gitignore index e5a2ded..182c4aa 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ regctl # ignore snooze file snooze.list +# ignore updates file +updates_available.txt \ No newline at end of file diff --git a/default.config b/default.config index 47b6189..e4f0507 100644 --- a/default.config +++ b/default.config @@ -32,7 +32,7 @@ ## All commented values are examples only. Modify as needed. ## ## Uncomment the line below and specify the notification channels you wish to enable in a space separated string -# NOTIFY_CHANNELS="apprise discord DSM generic HA gotify matrix ntfy pushbullet pushover slack smtp telegram" +# NOTIFY_CHANNELS="apprise discord DSM file generic HA gotify matrix ntfy pushbullet pushover slack smtp telegram" # ## Uncomment the line below and specify the number of seconds to delay notifications to enable snooze # SNOOZE_SECONDS=86400 diff --git a/dockcheck.sh b/dockcheck.sh index 9de58f5..05c239c 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERSION="v0.7.0" -# ChangeNotes: Snooze bugfix, added auth support to ntfy.sh and sendmail support to SMTP +VERSION="v0.7.1" +# ChangeNotes: Call send_notification even when no updates are available to write to file (if enabled) and clean up snooze Github="https://github.com/mag37/dockcheck" RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh" @@ -507,6 +507,8 @@ if [[ -n ${GotUpdates[*]:-} ]]; then if [[ -s "$ScriptWorkDir/urls.list" ]] && [[ "$PrintReleaseURL" == true ]]; then releasenotes; else Updates=("${GotUpdates[@]}"); fi [[ "$AutoMode" == false ]] && list_options || printf "%s\n" "${Updates[@]}" [[ "$Notify" == true ]] && { exec_if_exists_or_fail send_notification "${GotUpdates[@]}" || printf "\nCould not source notification function.\n"; } +else + [[ "$Notify" == true ]] && [[ ! -s "${ScriptWorkDir}/notify.sh" ]] && { exec_if_exists_or_fail send_notification "${GotUpdates[@]}" || printf "\nCould not source notification function.\n"; } fi # Optionally get updates if there's any diff --git a/notify_templates/notify_file.sh b/notify_templates/notify_file.sh new file mode 100644 index 0000000..9d84f00 --- /dev/null +++ b/notify_templates/notify_file.sh @@ -0,0 +1,12 @@ +### DISCLAIMER: This is a third party addition to dockcheck - best effort testing. +NOTIFY_FILE_VERSION="v0.1" +# +# 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. + +trigger_file_notification() { + NotifyFile="${ScriptWorkDir}/updates_available.txt" + + echo "${MessageBody}" > ${NotifyFile} + +} diff --git a/notify_templates/notify_v2.sh b/notify_templates/notify_v2.sh index a256311..2f6e5d8 100644 --- a/notify_templates/notify_v2.sh +++ b/notify_templates/notify_v2.sh @@ -114,6 +114,23 @@ send_notification() { UpdNotifyCount="${#Updates[@]}" fi + if [[ "${enabled_notify_channels[@]}" == *"file"* ]]; then + UpdToString=$( printf '%s, ' "${Updates[@]}" ) + UpdToString="${UpdToString%, }" + + if [[ -z "${UpdToString}" ]]; then + UpdToString="None" + fi + + printf "\nSending file notification\n" + printf -v MessageBody "${UpdToString}" + + exec_if_exists_or_fail trigger_file_notification || \ + printf "Attempted to send notification to channel file, but the function was not found. Make sure notify_file.sh is available in the ${ScriptWorkDir} directory or notify_templates subdirectory.\n" + + remove_channel file + fi + NotifyError=false if [[ "${UpdNotifyCount}" -gt 0 ]]; then @@ -238,9 +255,11 @@ notify_update_notification() { printf -v MessageBody "Notify templates on $FromHost with updates available:\n${UpdToString}\n" for channel in "${enabled_notify_channels[@]}"; do - printf "Sending notify template update notification - ${channel}\n" - exec_if_exists_or_fail trigger_${channel}_notification || \ - printf "Attempted to send notification to channel ${channel}, but the function was not found. Make sure notify_${channel}.sh is available in the ${ScriptWorkDir} directory or notify_templates subdirectory.\n" + if [[ ! "${channel}" == "file" ]]; then + printf "Sending notify template update notification - ${channel}\n" + exec_if_exists_or_fail trigger_${channel}_notification || \ + printf "Attempted to send notification to channel ${channel}, but the function was not found. Make sure notify_${channel}.sh is available in the ${ScriptWorkDir} directory or notify_templates subdirectory.\n" + fi done [[ -n "${snooze}" ]] && [[ "${NotifyError}" == "false" ]] && update_snooze "${NotifyUpdates[@]}"