From e4b5aaeb9d4f69293eff16404e8f9aedf9886169 Mon Sep 17 00:00:00 2001
From: op4lat <155382511+op4lat@users.noreply.github.com>
Date: Wed, 7 May 2025 05:29:21 -0400
Subject: [PATCH 01/55] Enable markdown (#172)
---
notify_templates/notify_ntfy-sh.sh | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/notify_templates/notify_ntfy-sh.sh b/notify_templates/notify_ntfy-sh.sh
index dc6d24f..686c7a4 100644
--- a/notify_templates/notify_ntfy-sh.sh
+++ b/notify_templates/notify_ntfy-sh.sh
@@ -11,10 +11,17 @@ trigger_notification() {
# Modify to fit your setup:
NtfyUrl="ntfy.sh/YourUniqueTopicName"
+ if [[ "$PrintMarkdownURL" == true ]]; then
+ ContentType="Markdown: yes"
+ else
+ ContentType="Markdown: no" #text/plain
+ fi
+
curl -sS -o /dev/null --show-error --fail \
-H "Title: $MessageTitle" \
+ -H "$ContentType" \
-d "$MessageBody" \
- $NtfyUrl
+ "$NtfyUrl"
}
send_notification() {
From ba107a424f3615278618f588a049ebdfd98efbfd Mon Sep 17 00:00:00 2001
From: mag37
Date: Wed, 7 May 2025 11:31:34 +0200
Subject: [PATCH 02/55] version bump
---
notify_templates/notify_ntfy-sh.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/notify_templates/notify_ntfy-sh.sh b/notify_templates/notify_ntfy-sh.sh
index 686c7a4..996f275 100644
--- a/notify_templates/notify_ntfy-sh.sh
+++ b/notify_templates/notify_ntfy-sh.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_NTFYSH_VERSION="v0.1"
+NOTIFY_NTFYSH_VERSION="v0.2"
#
# Copy/rename this file to notify.sh to enable the notification snippet.
# Setup app and subscription at https://ntfy.sh
From 8e444a688f4175086e3e1b606a507b376ef76a4c Mon Sep 17 00:00:00 2001
From: mag37
Date: Sun, 11 May 2025 20:50:09 +0200
Subject: [PATCH 03/55] Update rework (#178)
* first iteration rewriting the update logic
* formatting fixes
* Added an option to have compose up only target the specific container.
Used with either -F flag, config variable or label.
* Skipping update check on non-compose containers unless option is set
* Versionbump
Added new info and upped the version number.
---
README.md | 21 ++++++------
default.config | 5 +--
dockcheck.sh | 88 +++++++++++++++++++++++++++++++++++---------------
3 files changed, 77 insertions(+), 37 deletions(-)
diff --git a/README.md b/README.md
index e5ace87..8e8efae 100644
--- a/README.md
+++ b/README.md
@@ -20,10 +20,15 @@
___
## :bell: Changelog
+- **v0.6.4**: Restructured the update process - first pulls all updates, then recreates all containers.
+ - Added logic to skip update check on non-compose containers (unless `-r` option).
+ - Added option `-F` to revert to `compose up -d ` targeting specific container and not the stack.
+ - Also added corresponding label and config-option.
+ - Added markdown formatting to `notify_ntfy-sh.sh` template.
- **v0.6.3**: Some fixes and changes:
- Stops when a container recreation (compose up -d) fails, also `up`s the whole stack now.
- `-M`, Markdown format url-releasenotes in notification (requires template rework, look at gotify!)
- - Added [addons/DSM/README.md](./addons/DSM/README.md) added for more info Synology DSM info.
+ - Added [addons/DSM/README.md](./addons/DSM/README.md) for more info Synology DSM info.
- Permission checks - graceful exit if no docker permissions + checking if root for pkg-manager.
- **v0.6.2**: Style and colour changes, prometheus hotfix, new options:
- `-u`, Allow auto self update of dockcheck.sh
@@ -33,11 +38,6 @@ ___
- xargs/pipefail, removed `-set -e` bash option for now.
- unbound variables fixed (hopefully)
- dependency installer from pkgmanager rewritten
-- **v0.6.0**: Refactored a lot of code, cleaner logic and syntax, safer variables.
- - Safer bash options with `set -euo pipefail`, `shopt -s nullglob` and `failglob`.
- - Added a `default.conf` for user settings - persistent through updates.
- - Added `notify_slack.sh` template for slack curl api.
-
___
@@ -54,7 +54,8 @@ Options:
-c D Exports metrics as prom file for the prometheus node_exporter. Provide the collector textfile directory.
-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower.
-e X Exclude containers, separated by comma.
--f Force stack restart after update. Caution: restarts once for every updated container within stack.
+-f Force stop+start stack after update. Caution: restarts once for every updated container within stack.
+-F Only compose up the specific container, not the whole compose stack (useful for master-compose structure).
-h Print this Help.
-i Inform - send a preconfigured notification.
-I Prints custom releasenote urls alongside each container with updates (requires urls.list).
@@ -204,11 +205,13 @@ See [discussion here](https://github.com/mag37/dockcheck/discussions/145).
Optionally add labels to compose-files. Currently these are the usable labels:
```
labels:
- mag37.dockcheck.restart-stack: true
mag37.dockcheck.update: true
+ mag37.dockcheck.only-specific-container: true
+ mag37.dockcheck.restart-stack: true
```
-- `mag37.dockcheck.restart-stack: true` works instead of the `-f` option, forcing stop+restart on the whole compose-stack (Caution: Will restart on every updated container within stack).
- `mag37.dockcheck.update: true` will when used with the `-l` option only update containers with this label and skip the rest. Will still list updates as usual.
+- `mag37.dockcheck.only-specific-container: true` works instead of the `-F` option, specifying the updated container when doing compose up, like `docker compose up -d homer`.
+- `mag37.dockcheck.restart-stack: true` works instead of the `-f` option, forcing stop+restart on the whole compose-stack (Caution: Will restart on every updated container within stack).
## :roller_coaster: Workaround for non **amd64** / **arm64**
`regctl` provides binaries for amd64/arm64, to use on other architecture you could try this workaround.
diff --git a/default.config b/default.config
index 0a69d00..406ccbf 100644
--- a/default.config
+++ b/default.config
@@ -17,8 +17,9 @@
#DaysOld="5" # Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower.
#Stopped="-a" # Include stopped containers in the check. (Logic: docker ps -a).
#OnlyLabel=true # Only update if label is set. See readme.
-#ForceRestartStacks=true # Force stack restart after update. Caution.
+#ForceRestartStacks=true # Force stop+start stack after update. Caution: restarts once for every updated container within stack.
#DRunUp=true # Allow updating images for docker run, wont update the container.
#MonoMode=true # Monochrome mode, no printf colour codes and hides progress bar.
#PrintReleaseURL=true # Prints custom releasenote urls alongside each container with updates (requires urls.list)`
-#PrintMarkdownURL=true # Prints custom releasenote urls as markdown
+#PrintMarkdownURL=true # Prints custom releasenote urls as markdown
+#OnlySpecific=true # Only compose up the specific container, not the whole compose. (useful for master-compose structure).
diff --git a/dockcheck.sh b/dockcheck.sh
index 1a2aa72..9e7de0b 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-VERSION="v0.6.3"
-### ChangeNotes: Permission checks, now compose up on whole stack, -M markdown option added.
+VERSION="v0.6.4"
+### ChangeNotes: Restructured update process - first pulls all images, then recreates all containers. Added -F option.
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
@@ -34,7 +34,8 @@ Help() {
echo "-c Exports metrics as prom file for the prometheus node_exporter. Provide the collector textfile directory."
echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower."
echo "-e X Exclude containers, separated by comma."
- echo "-f Force stack restart after update. Caution: restarts once for every updated container within stack."
+ echo "-f Force stop+start stack after update. Caution: restarts once for every updated container within stack."
+ echo "-F Only compose up the specific container, not the whole compose stack (useful for master-compose structure)."
echo "-h Print this Help."
echo "-i Inform - send a preconfigured notification."
echo "-I Prints custom releasenote urls alongside each container with updates (requires urls.list)."
@@ -72,6 +73,8 @@ Stopped=${Stopped:=""}
CollectorTextFileDirectory=${CollectorTextFileDirectory:-}
Exclude=${Exclude:-}
DaysOld=${DaysOld:-}
+OnlySpecific=false
+SpecificContainer=${SpecificContainer:=""}
Excludes=()
GotUpdates=()
NoUpdates=()
@@ -88,13 +91,14 @@ c_blue="\033[0;34m"
c_teal="\033[0;36m"
c_reset="\033[0m"
-while getopts "ayfhiIlmMnprsuvc:e:d:t:x:" options; do
+while getopts "ayfFhiIlmMnprsuvc:e:d:t:x:" options; do
case "${options}" in
a|y) AutoMode=true ;;
c) CollectorTextFileDirectory="${OPTARG}" ;;
d) DaysOld=${OPTARG} ;;
e) Exclude=${OPTARG} ;;
f) ForceRestartStacks=true ;;
+ F) OnlySpecific=true ;;
i) Notify=true ;;
I) PrintReleaseURL=true ;;
l) OnlyLabel=true ;;
@@ -195,9 +199,6 @@ choosecontainers() {
done
fi
done
- printf "\n%bUpdating container(s):%b\n" "$c_blue" "$c_reset"
- printf "%s\n" "${SelectedUpdates[@]}"
- printf "\n"
}
datecheck() {
@@ -385,6 +386,15 @@ check_image() {
fi
done
+ # Skipping non-compose containers unless option is set
+ ContLabels=$(docker inspect "$i" --format '{{json .Config.Labels}}')
+ ContPath=$($jqbin -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels")
+ [[ "$ContPath" == "null" ]] && ContPath=""
+ if [[ -z "$ContPath" ]] && [[ "$DRunUp" == false ]]; then
+ printf "%s\n" "NoUpdates !$i - not checked, no compose file"
+ return
+ fi
+
local NoUpdates GotUpdates GotErrors
ImageId=$(docker inspect "$i" --format='{{.Image}}')
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
@@ -409,7 +419,7 @@ check_image() {
# Make required functions and variables available to subprocesses
export -f check_image datecheck
export Excludes_string="${Excludes[*]:-}" # Can only export scalar variables
-export t_out regbin RepoUrl DaysOld
+export t_out regbin RepoUrl DaysOld DRunUp jqbin
# Check for POSIX xargs with -P option, fallback without async
if (echo "test" | xargs -P 2 >/dev/null 2>&1) && [[ "$MaxAsync" != 0 ]]; then
@@ -483,10 +493,41 @@ if [[ -n "${GotUpdates:-}" ]]; then
SelectedUpdates=( "${GotUpdates[@]}" )
fi
if [[ "$DontUpdate" == false ]]; then
+ printf "\n%bUpdating container(s):%b\n" "$c_blue" "$c_reset"
+ printf "%s\n" "${SelectedUpdates[@]}"
+
NumberofUpdates="${#SelectedUpdates[@]}"
+
CurrentQue=0
- for i in "${SelectedUpdates[@]}"
- do
+ for i in "${SelectedUpdates[@]}"; do
+ ((CurrentQue+=1))
+ printf "\n%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset"
+ ContLabels=$(docker inspect "$i" --format '{{json .Config.Labels}}')
+ ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
+ ContPath=$($jqbin -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels")
+ [[ "$ContPath" == "null" ]] && ContPath=""
+ ContUpdateLabel=$($jqbin -r '."mag37.dockcheck.update"' <<< "$ContLabels")
+ [[ "$ContUpdateLabel" == "null" ]] && ContUpdateLabel=""
+ # Checking if Label Only -option is set, and if container got the label
+ [[ "$OnlyLabel" == true ]] && { [[ "$ContUpdateLabel" != true ]] && { echo "No update label, skipping."; continue; } }
+
+ # Checking if compose-values are empty - hence started with docker run
+ if [[ -z "$ContPath" ]]; then
+ if [[ "$DRunUp" == true ]]; then
+ docker pull "$ContImage"
+ printf "%s\n" "$i got a new image downloaded, rebuild manually with preferred 'docker run'-parameters"
+ else
+ printf "\n%b%s%b has no compose labels, probably started with docker run - %bskipping%b\n\n" "$c_yellow" "$i" "$c_reset" "$c_yellow" "$c_reset"
+ fi
+ continue
+ fi
+
+ docker pull "$ContImage" || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; }
+ done
+ printf "\n%bDone pulling updates. %bRecreating updated containers.%b\n" "$c_green" "$c_blue" "$c_reset"
+
+ CurrentQue=0
+ for i in "${SelectedUpdates[@]}"; do
((CurrentQue+=1))
unset CompleteConfs
# Extract labels and metadata
@@ -504,17 +545,12 @@ if [[ -n "${GotUpdates:-}" ]]; then
[[ "$ContUpdateLabel" == "null" ]] && ContUpdateLabel=""
ContRestartStack=$($jqbin -r '."mag37.dockcheck.restart-stack"' <<< "$ContLabels")
[[ "$ContRestartStack" == "null" ]] && ContRestartStack=""
+ ContOnlySpecific=$($jqbin -r '."mag37.dockcheck.only-specific-container"' <<< "$ContLabels")
+ [[ "$ContRestartStack" == "null" ]] && ContRestartStack=""
# Checking if compose-values are empty - hence started with docker run
- if [[ -z "$ContPath" ]]; then
- if [[ "$DRunUp" == true ]]; then
- docker pull "$ContImage"
- printf "%s\n" "$i got a new image downloaded, rebuild manually with preferred 'docker run'-parameters"
- else
- printf "\n%b%s%b has no compose labels, probably started with docker run - %bskipping%b\n\n" "$c_yellow" "$i" "$c_reset" "$c_yellow" "$c_reset"
- fi
- continue
- fi
+ [[ -z "$ContPath" ]] && continue
+
# cd to the compose-file directory to account for people who use relative volumes
cd "$ContPath" || { printf "\n%bPath error - skipping%b %s" "$c_red" "$c_reset" "$i"; continue; }
## Reformatting path + multi compose
@@ -523,22 +559,22 @@ if [[ -n "${GotUpdates:-}" ]]; then
else
CompleteConfs=$(for conf in ${ContConfigFile//,/ }; do printf -- "-f %s/%s " "$ContPath" "$conf"; done)
fi
- printf "\n%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset"
- # Checking if Label Only -option is set, and if container got the label
- [[ "$OnlyLabel" == true ]] && { [[ "$ContUpdateLabel" != true ]] && { echo "No update label, skipping."; continue; } }
- docker pull "$ContImage" || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; }
# Check if the container got an environment file set and reformat it
ContEnvs=""
if [[ -n "$ContEnv" ]]; then ContEnvs=$(for env in ${ContEnv//,/ }; do printf -- "--env-file %s " "$env"; done); fi
+ # Set variable when compose up should only target the specific container, not the stack
+ if [[ $OnlySpecific == true ]] || [[ $ContOnlySpecific == true ]]; then SpecificContainer="$ContName"; fi
+
+ printf "\n%bNow recreating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset"
# Check if the whole stack should be restarted
if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]]; then
- ${DockerBin} ${CompleteConfs} stop; ${DockerBin} ${CompleteConfs} ${ContEnvs} up -d
+ ${DockerBin} ${CompleteConfs} stop; ${DockerBin} ${CompleteConfs} ${ContEnvs} up -d || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; }
else
- ${DockerBin} ${CompleteConfs} ${ContEnvs} up -d || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; }
+ ${DockerBin} ${CompleteConfs} ${ContEnvs} up -d ${SpecificContainer} || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; }
fi
done
if [[ "$AutoPrune" == false ]] && [[ "$AutoMode" == false ]]; then printf "\n"; read -rep "Would you like to prune dangling images? y/[n]: " AutoPrune; fi
- if [[ "$AutoPrune" == true ]] || [[ "$AutoPrune" =~ [yY] ]]; then docker image prune -f; fi
+ if [[ "$AutoPrune" == true ]] || [[ "$AutoPrune" =~ [yY] ]]; then printf "\n Auto pruning.."; docker image prune -f; fi
printf "\n%bAll done!%b\n" "$c_green" "$c_reset"
else
printf "\nNo updates installed, exiting.\n"
From 7ce523c37d6b7a2ddd4fd721e08f1f32dc4398a3 Mon Sep 17 00:00:00 2001
From: mag37
Date: Mon, 12 May 2025 07:28:49 +0200
Subject: [PATCH 04/55] added sponsor
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 8e8efae..dab4307 100644
--- a/README.md
+++ b/README.md
@@ -272,6 +272,7 @@ dockcheck is created and released under the [GNU GPL v3.0](https://www.gnu.org/l
- [avegy](https://github.com/avegy)
- [eichhorn](https://github.com/eichhorn)
+- [stepdg](https://github.com/stepdg)
___
From d80fba750f55c6c88c41dcf21e73996033c6ec18 Mon Sep 17 00:00:00 2001
From: mag37
Date: Mon, 12 May 2025 15:54:34 +0200
Subject: [PATCH 05/55] quickfix printfs
---
dockcheck.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/dockcheck.sh b/dockcheck.sh
index 9e7de0b..4ad9a89 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -257,7 +257,7 @@ binary_downloader() {
GetUrl="${BinaryUrl/TEMP/"$architecture"}"
if command -v curl &>/dev/null; then curl -L "$GetUrl" > "$ScriptWorkDir/$BinaryName";
elif command -v wget &>/dev/null; then wget "$GetUrl" -O "$ScriptWorkDir/$BinaryName";
- else printf "%s\n" "curl/wget not available - get $BinaryName manually from the repo link, exiting."; exit 1;
+ else printf "\n%bcurl/wget not available - get %s manually from the repo link, exiting.%b" "$c_red" "$BinaryName" "$c_reset"; exit 1;
fi
[[ -f "$ScriptWorkDir/$BinaryName" ]] && chmod +x "$ScriptWorkDir/$BinaryName"
}
@@ -288,7 +288,7 @@ dependency_check() {
if command -v "$AppName" &>/dev/null; then export "$AppVar"="$AppName";
elif [[ -f "$ScriptWorkDir/$AppName" ]]; then export "$AppVar"="$ScriptWorkDir/$AppName";
else
- printf "%s\n" "Required dependency %b'%s'%b missing, do you want to install it?\n" "$c_teal" "$AppName" "$c_reset"
+ printf "\nRequired dependency %b'%s'%b missing, do you want to install it?\n" "$c_teal" "$AppName" "$c_reset"
read -r -p "y: With packagemanager (sudo). / s: Download static binary. y/s/[n] " GetBin
GetBin=${GetBin:-no} # set default to no if nothing is given
if [[ "$GetBin" =~ [yYsS] ]]; then
@@ -481,7 +481,7 @@ if [[ -n ${GotUpdates[*]:-} ]]; then
printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset"
if [[ -s "$ScriptWorkDir/urls.list" ]] && [[ "$PrintReleaseURL" == true ]]; then releasenotes; else Updates=("${GotUpdates[@]}"); fi
[[ "$AutoMode" == false ]] && list_options || printf "%s\n" "${Updates[@]}"
- [[ "$Notify" == true ]] && { type -t send_notification &>/dev/null && send_notification "${GotUpdates[@]}" || printf "Could not source notification function.\n"; }
+ [[ "$Notify" == true ]] && { type -t send_notification &>/dev/null && send_notification "${GotUpdates[@]}" || printf "\nCould not source notification function.\n"; }
fi
# Optionally get updates if there's any
From b2d80d036a1896b6d278d40c0ea89874142c9c44 Mon Sep 17 00:00:00 2001
From: mag37
Date: Wed, 14 May 2025 20:55:09 +0200
Subject: [PATCH 06/55] info about -r option
---
README.md | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index dab4307..4e33e3d 100644
--- a/README.md
+++ b/README.md
@@ -250,17 +250,18 @@ function dchk {
}
```
+## :warning: `-r flag` disclaimer and warning
+**Wont auto-update the containers, only their images. (compose is recommended)**
+`docker run` dont support using new images just by restarting a container.
+Containers need to be manually stopped, removed and created again to run on the new image.
+Using the `-r` option together with eg. `-i` and `-n` to just check for updates and send notifications and not update is safe though!
+
## :hammer: Known issues
- No detailed error feedback (just skip + list what's skipped).
- Not respecting `--profile` options when re-creating the container.
- Not working well with containers created by **Portainer**.
- **Watchtower** might cause issues due to retagging images when checking for updates (and thereby pulling new images).
-## :warning: `-r flag` disclaimer and warning
-**Wont auto-update the containers, only their images. (compose is recommended)**
-`docker run` dont support using new images just by restarting a container.
-Containers need to be manually stopped, removed and created again to run on the new image.
-
## :wrench: Debugging
If you hit issues, you could check the output of the `extras/errorCheck.sh` script for clues.
Another option is to run the main script with debugging in a subshell `bash -x dockcheck.sh` - if there's a particular container/image that's causing issues you can filter for just that through `bash -x dockcheck.sh nginx`.
From e4b93d113cf54d2392789abbf76923b1d2e65971 Mon Sep 17 00:00:00 2001
From: mag37
Date: Thu, 15 May 2025 15:49:49 +0200
Subject: [PATCH 07/55] fixed variable errors
---
dockcheck.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dockcheck.sh b/dockcheck.sh
index 4ad9a89..615fcd9 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -73,7 +73,7 @@ Stopped=${Stopped:=""}
CollectorTextFileDirectory=${CollectorTextFileDirectory:-}
Exclude=${Exclude:-}
DaysOld=${DaysOld:-}
-OnlySpecific=false
+OnlySpecific=${OnlySpecific:=false}
SpecificContainer=${SpecificContainer:=""}
Excludes=()
GotUpdates=()
@@ -546,7 +546,7 @@ if [[ -n "${GotUpdates:-}" ]]; then
ContRestartStack=$($jqbin -r '."mag37.dockcheck.restart-stack"' <<< "$ContLabels")
[[ "$ContRestartStack" == "null" ]] && ContRestartStack=""
ContOnlySpecific=$($jqbin -r '."mag37.dockcheck.only-specific-container"' <<< "$ContLabels")
- [[ "$ContRestartStack" == "null" ]] && ContRestartStack=""
+ [[ "$ContOnlySpecific" == "null" ]] && ContRestartStack=""
# Checking if compose-values are empty - hence started with docker run
[[ -z "$ContPath" ]] && continue
From c63e2441faf8ed6001a44ce256ae91eab71f807f Mon Sep 17 00:00:00 2001
From: vorezal <37914382+vorezal@users.noreply.github.com>
Date: Sun, 25 May 2025 12:26:13 -0400
Subject: [PATCH 08/55] Refactor notifications and add helper functions (#182)
* Refactor notifications and add helper functions
* Add helper functions to simplify sourcing files and executing functions if they exist
* Create notify_v2.sh wrapper script
* Simplify and consolidate notification logic within notify_v2.sh
* Support notification management via environment variables
* Move secrets to dockcheck.config
* Fix NOTIFY_CHANNELS default value when not set
* Feedback changes
* Remove leading spaces from MessageBody
* Check for valid notify v2 variables
* Warn on missing configuration and bypass notifications
* Update readme
* Additional feedback fixes
* More comments in default.config with different # depth for comments and settings
* Rename NOTIFY_TOPIC_NAME variable to NTFY_TOPIC_NAME for consistency
* Add TELEGRAM_TOPIC_ID
* Fix AppriseURL variable
* Add an ending newline to all MessageBody statements for consistency
* Remove troubleshooting echo statement
* Prevent attempting to trigger notifications for notification templates if versions are the same
---------
Co-authored-by: Matthew Oleksowicz
---
README.md | 25 ++++++--
default.config | 60 +++++++++++++++++--
dockcheck.sh | 50 ++++++++++------
notify_templates/notify_DSM.sh | 52 +++--------------
notify_templates/notify_apprise.sh | 67 +++++++--------------
notify_templates/notify_discord.sh | 47 ++++-----------
notify_templates/notify_generic.sh | 41 +------------
notify_templates/notify_gotify.sh | 73 +++++++----------------
notify_templates/notify_matrix.sh | 58 +++++-------------
notify_templates/notify_ntfy-sh.sh | 68 ++++++----------------
notify_templates/notify_pushbullet.sh | 55 ++++--------------
notify_templates/notify_pushover.sh | 67 ++++++---------------
notify_templates/notify_slack.sh | 62 +++++---------------
notify_templates/notify_smtp.sh | 54 ++++-------------
notify_templates/notify_telegram.sh | 67 ++++++---------------
notify_templates/notify_v2.sh | 84 +++++++++++++++++++++++++++
16 files changed, 366 insertions(+), 564 deletions(-)
create mode 100644 notify_templates/notify_v2.sh
diff --git a/README.md b/README.md
index 4e33e3d..27ef1ad 100644
--- a/README.md
+++ b/README.md
@@ -20,6 +20,12 @@
___
## :bell: Changelog
+- **v0.6.5**: Refactored notification logic. See notify_templates/notify_v2.sh for upgrade steps.
+ - Added helper functions to simplify sourcing files and executing functions if they exist.
+ - Created notify_v2.sh wrapper script.
+ - Simplified and consolidated notification logic within notify_v2.sh.
+ - Added support for notification management via environment variables.
+ - Moved notification secrets to dockcheck.config.
- **v0.6.4**: Restructured the update process - first pulls all updates, then recreates all containers.
- Added logic to skip update check on non-compose containers (unless `-r` option).
- Added option `-F` to revert to `compose up -d ` targeting specific container and not the stack.
@@ -126,11 +132,22 @@ Alternatively create an alias where specific flags and values are set.
Example `alias dc=dockcheck.sh -p -x 10 -t 3`.
## :loudspeaker: Notifications
-Trigger with the `-i` flag if `notify.sh` is present and configured.
-Will send a list of containers with updates available and a notification when `dockcheck.sh` itself has an update.
-Run it scheduled with `-ni` to only get notified when there's updates available!
+Trigger with the `-i` flag.
+If `notify.sh` is present and configured, it will be used. Otherwise, `notify_v2.sh` will be enabled.
+Will send a list of containers with updates available and a notification when `dockcheck.sh` itself has an update.
+Run it scheduled with `-ni` to only get notified when there's updates available!
+
+V2 installation and configuration (tag v0.6.5 or later):
+Remove or rename `notify.sh` if previously configured using the legacy method.
+Uncomment and set the NOTIFY_CHANNELS environment variable in `dockcheck.config` to a space separated string of your desired notification channels to enable.
+Uncomment and set the environment variables related to the enabled notification channels.
+It is recommended not to make changes directly to the `notify_X.sh` template files and to use only environment variables defined in `dockcheck.config` using this method.
+
+Legacy installation and configuration:
+Use a previous version of a `notify_X.sh` template file (tag v0.6.4 or earlier) from the **notify_templates** directory,
+copy it to `notify.sh` alongside the script, modify it to your needs! (notify.sh is added to .gitignore)
+
-Use a `notify_X.sh` template file from the **notify_templates** directory, copy it to `notify.sh` alongside the script, modify it to your needs! (notify.sh is added to .gitignore)
**Current templates:**
- Synology [DSM](https://www.synology.com/en-global/dsm)
- Email with [mSMTP](https://wiki.debian.org/msmtp) (or deprecated alternative [sSMTP](https://wiki.debian.org/sSMTP))
diff --git a/default.config b/default.config
index 406ccbf..9c13be0 100644
--- a/default.config
+++ b/default.config
@@ -1,9 +1,9 @@
### Custom user variables
-# Copy this file to "dockcheck.config" to make it active
-# Can be placed in ~/.config/ or alongside dockcheck.sh
-#
-# Uncomment and set your preferred configuration variables here
-# This will not be replaced on updates
+## Copy this file to "dockcheck.config" to make it active
+## Can be placed in ~/.config/ or alongside dockcheck.sh
+##
+## Uncomment and set your preferred configuration variables here
+## This will not be replaced on updates
#Timeout=10 # Set a timeout (in seconds) per container for registry checkups.
#MaxAsync=10 # Set max asynchronous subprocesses, 1 default, 0 to disable.
@@ -23,3 +23,53 @@
#PrintReleaseURL=true # Prints custom releasenote urls alongside each container with updates (requires urls.list)`
#PrintMarkdownURL=true # Prints custom releasenote urls as markdown
#OnlySpecific=true # Only compose up the specific container, not the whole compose. (useful for master-compose structure).
+
+### Notify settings
+## 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 gotify matrix ntfy-sh pushbullet pushover slack smtp telegram"
+#
+## Uncomment to not send notifications when dockcheck itself has updates.
+# DISABLE_DOCKCHECK_NOTIFICATION=false
+## Uncomment to not send notifications when notify scripts themselves have updates.
+# DISABLE_NOTIFY_NOTIFICATION=false
+#
+## Apprise configuration variables. Set APPRISE_PAYLOAD to make a CLI call or set APPRISE_URL to make an API request instead.
+# APPRISE_PAYLOAD='mailto://myemail:mypass@gmail.com
+# mastodons://{token}@{host}
+# pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b
+# tgram://{bot_token}/{chat_id}/'
+# APPRISE_URL="http://apprise.mydomain.tld:1234/notify/apprise"
+#
+# DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/"
+#
+# DSM_SENDMAILTO="me@mydomain.com"
+# DSM_SUBJECTTAG="Email Subject Prefix"
+#
+# GOTIFY_DOMAIN="https://gotify.domain.tld"
+# GOTIFY_TOKEN="token-value"
+#
+# MATRIX_ACCESS_TOKEN="token-value"
+# MATRIX_ROOM_ID="myroom"
+# MATRIX_SERVER_URL="https://matrix.yourdomain.tld"
+#
+# NTFY_TOPIC_NAME="YourUniqueTopicName"
+#
+# PUSHBULLET_URL="https://api.pushbullet.com/v2/pushes"
+# PUSHBULLET_TOKEN="token-value"
+#
+# PUSHOVER_URL="https://api.pushover.net/1/messages.json"
+# PUSHOVER_USER_KEY="userkey"
+# PUSHOVER_TOKEN="token-value"
+#
+# SLACK_CHANNEL_ID=mychannel
+# SLACK_ACCESS_TOKEN=xoxb-token-value
+#
+# SMTP_MAIL_FROM="me@mydomain.tld"
+# SMTP_MAIL_TO="you@yourdomain.tld"
+# SMTP_SUBJECT_TAG="dockcheck"
+#
+# TELEGRAM_CHAT_ID="mychatid"
+# TELEGRAM_TOKEN="token-value"
+# TELEGRAM_TOPIC_ID="0"
diff --git a/dockcheck.sh b/dockcheck.sh
index 615fcd9..a0a5be2 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-VERSION="v0.6.4"
-### ChangeNotes: Restructured update process - first pulls all images, then recreates all containers. Added -F option.
+VERSION="v0.6.5"
+### ChangeNotes: Refactored notification logic. See README.md for upgrade steps.
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
@@ -17,12 +17,17 @@ ScriptWorkDir="$(dirname "$ScriptPath")"
LatestRelease="$(curl -s -r 0-50 "$RawUrl" | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
LatestChanges="$(curl -s -r 0-200 "$RawUrl" | sed -n "/ChangeNotes/s/# ChangeNotes: //p")"
+# Source helper functions
+source_if_exists() {
+ if [[ -s "$1" ]]; then source "$1"; fi
+}
+
+source_if_exists_or_fail() {
+ [[ -s "$1" ]] && source "$1"
+}
+
# User customizable defaults
-if [[ -s "${HOME}/.config/dockcheck.config" ]]; then
- source "${HOME}/.config/dockcheck.config"
-elif [[ -s "${ScriptWorkDir}/dockcheck.config" ]]; then
- source "${ScriptWorkDir}/dockcheck.config"
-fi
+source_if_exists_or_fail "${HOME}/.config/dockcheck.config" || source_if_exists "${ScriptWorkDir}/dockcheck.config"
# Help Function
Help() {
@@ -120,14 +125,16 @@ shift "$((OPTIND-1))"
# Set $1 to a variable for name filtering later
SearchName="${1:-}"
+# Basic notify configuration check
+if [[ "${Notify}" == true ]] && [[ ! -s "${ScriptWorkDir}/notify.sh" ]] && [[ -z "${NOTIFY_CHANNELS:-}" ]]; then
+ printf "Using v2 notifications with -i flag passed but no notify channels configured in dockcheck.config. This will result in no notifications being sent.\n"
+fi
+
# Setting up options and sourcing functions
if [[ "$DontUpdate" == true ]]; then AutoMode=true; fi
if [[ "$MonoMode" == true ]]; then declare c_{red,green,yellow,blue,teal,reset}=""; fi
if [[ "$Notify" == true ]]; then
- if [[ -s "${ScriptWorkDir}/notify.sh" ]]; then
- source "${ScriptWorkDir}/notify.sh"
- else Notify=false
- fi
+ source_if_exists_or_fail "${ScriptWorkDir}/notify.sh" || source_if_exists_or_fail "${ScriptWorkDir}/notify_templates/notify_v2.sh" || Notify=false
fi
if [[ -n "$Exclude" ]]; then
IFS=',' read -ra Excludes <<< "$Exclude"
@@ -148,6 +155,14 @@ if [[ -n "$CollectorTextFileDirectory" ]]; then
fi
fi
+exec_if_exists() {
+ if [[ $(type -t $1) == function ]]; then "$@"; fi
+}
+
+exec_if_exists_or_fail() {
+ [[ $(type -t $1) == function ]] && "$@"
+}
+
self_update_curl() {
cp "$ScriptPath" "$ScriptPath".bak
if command -v curl &>/dev/null; then
@@ -335,10 +350,13 @@ if [[ "$VERSION" != "$LatestRelease" ]]; then
[[ "$SelfUpdate" =~ [yY] ]] && self_update
elif [[ "$AutoMode" == true ]] && [[ "$AutoSelfUpdate" == true ]]; then self_update;
else
- [[ "$Notify" == true ]] && { [[ $(type -t dockcheck_notification) == function ]] && dockcheck_notification "$VERSION" "$LatestRelease" "$LatestChanges" || printf "Could not source notification function.\n"; }
+ [[ "$Notify" == true ]] && { exec_if_exists_or_fail dockcheck_notification "$VERSION" "$LatestRelease" "$LatestChanges" || printf "Could not source notification function.\n"; }
fi
fi
+# Version check for notify templates
+[[ "$Notify" == true ]] && { exec_if_exists_or_fail notify_update_notification || printf "Could not source notify notification function.\n"; }
+
dependency_check "regctl" "regbin" "https://github.com/regclient/regclient/releases/latest/download/regctl-linux-TEMP"
dependency_check "jq" "jqbin" "https://github.com/jqlang/jq/releases/latest/download/jq-linux-TEMP"
@@ -457,11 +475,7 @@ unset IFS
# Run the prometheus exporter function
if [[ -n "${CollectorTextFileDirectory:-}" ]]; then
- if type -t prometheus_exporter &>/dev/null; then
- prometheus_exporter ${#NoUpdates[@]} ${#GotUpdates[@]} ${#GotErrors[@]}
- else
- printf "%s\n" "Could not source prometheus exporter function."
- fi
+ exec_if_exists_or_fail prometheus_exporter ${#NoUpdates[@]} ${#GotUpdates[@]} ${#GotErrors[@]} || printf "%s\n" "Could not source prometheus exporter function."
fi
# Define how many updates are available
@@ -481,7 +495,7 @@ if [[ -n ${GotUpdates[*]:-} ]]; then
printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset"
if [[ -s "$ScriptWorkDir/urls.list" ]] && [[ "$PrintReleaseURL" == true ]]; then releasenotes; else Updates=("${GotUpdates[@]}"); fi
[[ "$AutoMode" == false ]] && list_options || printf "%s\n" "${Updates[@]}"
- [[ "$Notify" == true ]] && { type -t send_notification &>/dev/null && send_notification "${GotUpdates[@]}" || printf "\nCould not source notification function.\n"; }
+ [[ "$Notify" == true ]] && { 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_DSM.sh b/notify_templates/notify_DSM.sh
index ddbc2c6..17d697f 100644
--- a/notify_templates/notify_DSM.sh
+++ b/notify_templates/notify_DSM.sh
@@ -1,11 +1,10 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_DSM_VERSION="v0.1"
+NOTIFY_DSM_VERSION="v0.2"
# INFO: ssmtp is deprecated - consider to use msmtp instead.
#
-# Copy/rename this file to notify.sh to enable the notification snipppet.
# mSMTP/sSMTP has to be installed and configured manually.
# The existing DSM Notification Email configuration will be used automatically.
-# Modify to your liking - changing SendMailTo and Subject and content.
+# Do not modify this file directly. Set DSM_SENDMAILTO and DSM_SUBJECTTAG in your dockcheck.config file.
MSMTP=$(which msmtp)
SSMTP=$(which ssmtp)
@@ -18,18 +17,17 @@ else
echo "No msmtp or ssmtp binary found in PATH: $PATH" ; exit 1
fi
-FromHost=$(hostname)
-
-trigger_notification() {
+trigger_DSM_notification() {
CfgFile="/usr/syno/etc/synosmtp.conf"
# User variables:
# Automatically sends to your usual destination for synology DSM notification emails.
-# You can also manually override by assigning something else to SendMailTo below.
-SendMailTo=$(grep 'eventmail1' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')
-#SendMailTo="me@mydomain.com"
+# You can also manually override by assigning something else to DSM_SENDMAILTO in dockcheck.config.
+SendMailTo=${DSM_SENDMAILTO:-$(grep 'eventmail1' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')}
+# e.g. DSM_SENDMAILTO="me@mydomain.com"
-SubjectTag=$(grep 'eventsubjectprefix' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')
+SubjectTag=${DSM_SUBJECTTAG:-$(grep 'eventsubjectprefix' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')}
+# e.g. DSM_SUBJECTTAG="Email Subject Prefix"
SenderName=$(grep 'smtp_from_name' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')
SenderMail=$(grep 'smtp_from_mail' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')
SenderMail=${SenderMail:-$(grep 'eventmail1' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')}
@@ -38,7 +36,7 @@ $MailPkg $SendMailTo << __EOF
From: "$SenderName" <$SenderMail>
date:$(date -R)
To: <$SendMailTo>
-Subject: $SubjectTag $MessageTitle $FromHost
+Subject: $SubjectTag $MessageTitle
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
@@ -48,35 +46,3 @@ __EOF
# This ensures DSM's container manager will also see the update
/var/packages/ContainerManager/target/tool/image_upgradable_checker
}
-
-send_notification() {
- [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
-
- printf "\nSending email notification.\n"
-
- MessageTitle="Updates available on"
- # Setting the MessageBody variable here.
- printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n\n$UpdToString"
-
- trigger_notification
-}
-
-### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
-### to not send notifications when dockcheck itself has updates.
-dockcheck_notification() {
- printf "\nSending email dockcheck notification.\n"
-
- MessageTitle="New version of dockcheck available on"
- # Setting the MessageBody variable here.
- printf -v MessageBody "Installed version: $1\nLatest version: $2\n\nChangenotes: $3\n"
-
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_DSM.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_DSM_VERSION/s/NOTIFY_DSM_VERSION=//p" | tr -d '"')"
- if [[ "$NOTIFY_DSM_VERSION" != "$LatestNotifyRelease" ]] ; then
- printf -v NotifyUpdate "\n\nnotify_DSM.sh update avialable:\n $NOTIFY_DSM_VERSION -> $LatestNotifyRelease\n"
- MessageBody="${MessageBody}${NotifyUpdate}"
- fi
-
- trigger_notification
-}
diff --git a/notify_templates/notify_apprise.sh b/notify_templates/notify_apprise.sh
index fef4303..e71a4df 100644
--- a/notify_templates/notify_apprise.sh
+++ b/notify_templates/notify_apprise.sh
@@ -1,55 +1,30 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_APPRISE_VERSION="v0.1"
+NOTIFY_APPRISE_VERSION="v0.2"
#
-# Copy/rename this file to notify.sh to enable the notification snippet.
# Required receiving services must already be set up.
-# Modify to fit your setup - if API, set AppriseURL to your Apprise ip/domain.
+# Do not modify this file directly. Set APPRISE_PAYLOAD in your dockcheck.config file.
+# If API, set APPRISE_URL instead.
-FromHost=$(hostname)
+if [[ -z "${APPRISE_PAYLOAD:-}" ]] && [[ -z "${APPRISE_URL:-}" ]]; then
+ printf "Apprise notification channel enabled, but required configuration variables are missing. Apprise notifications will not be sent.\n"
-trigger_notification() {
+ remove_channel apprise
+fi
- ### Modify to fit your setup:
- apprise -vv -t "$MessageTitle" -b "$MessageBody" \
- mailto://myemail:mypass@gmail.com \
- mastodons://{token}@{host} \
- pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b \
- tgram://{bot_token}/{chat_id}/
+trigger_apprise_notification() {
- ### If you use the Apprise-API - Comment out the apprise command above.
- ### Uncomment the AppriseURL and the curl-line below:
- # AppriseURL="http://apprise.mydomain.tld:1234/notify/apprise"
- # curl -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL
-}
+ if [[ -n "${APPRISE_PAYLOAD:-}" ]]; then
+ apprise -vv -t "$MessageTitle" -b "$MessageBody" \
+ ${APPRISE_PAYLOAD}
+ fi
-send_notification() {
- [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
+ # e.g. APPRISE_PAYLOAD='mailto://myemail:mypass@gmail.com
+ # mastodons://{token}@{host}
+ # pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b
+ # tgram://{bot_token}/{chat_id}/'
- printf "\nSending Apprise notification\n"
-
- MessageTitle="$FromHost - updates available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString"
-
- trigger_notification
-}
-
-### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
-### to not send notifications when dockcheck itself has updates.
-dockcheck_notification() {
- printf "\nSending Apprise dockcheck notification\n"
-
- MessageTitle="$FromHost - New version of dockcheck available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3"
-
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_apprise.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_APPRISE_VERSION/s/NOTIFY_APPRISE_VERSION=//p" | tr -d '"')"
- if [[ "$NOTIFY_APPRISE_VERSION" != "$LatestNotifyRelease" ]] ; then
- printf -v NotifyUpdate "\n\nnotify_apprise.sh update avialable:\n $NOTIFY_APPRISE_VERSION -> $LatestNotifyRelease\n"
- MessageBody="${MessageBody}${NotifyUpdate}"
- fi
-
- trigger_notification
-}
+ if [[ -n "${APPRISE_URL:-}" ]]; then
+ AppriseURL="${APPRISE_URL}"
+ curl -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL # e.g. APPRISE_URL=http://apprise.mydomain.tld:1234/notify/apprise
+ fi
+}
\ No newline at end of file
diff --git a/notify_templates/notify_discord.sh b/notify_templates/notify_discord.sh
index 5728f74..a28cda5 100644
--- a/notify_templates/notify_discord.sh
+++ b/notify_templates/notify_discord.sh
@@ -1,43 +1,18 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_DISCORD_VERSION="v0.1"
+NOTIFY_DISCORD_VERSION="v0.2"
#
-# Copy/rename this file to notify.sh to enable the notification snippet.
# Required receiving services must already be set up.
-# Modify to fit your setup - set DiscordWebhookUrl
+# Do not modify this file directly. Set DISCORD_WEBHOOK_URL in your dockcheck.config file.
-FromHost=$(hostname)
+if [[ -z "${DISCORD_WEBHOOK_URL:-}" ]]; then
+ printf "Discord notification channel enabled, but required configuration variables are missing. Discord notifications will not be sent.\n"
-trigger_notification() {
- # Modify to fit your setup:
- DiscordWebhookUrl="PasteYourFullDiscordWebhookURL"
+ remove_channel discord
+fi
- MsgBody="{\"username\":\"$FromHost\",\"content\":\"$MessageBody\"}"
- curl -sS -o /dev/null --fail -X POST -H "Content-Type: application/json" -d "$MsgBody" "$DiscordWebhookUrl"
-}
-
-send_notification() {
- [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
-
- printf "\nSending Discord notification\n"
- # Setting the MessageBody variable here.
- MessageBody="🐋 Containers on $FromHost with updates available: \n$UpdToString"
-
- trigger_notification
-}
-
-### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
-### to not send notifications when dockcheck itself has updates.
-dockcheck_notification() {
- printf "\nSending Discord dockcheck notification\n"
- MessageBody="$FromHost - New version of dockcheck available: \n Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3"
-
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_discord.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_DISCORD_VERSION/s/NOTIFY_DISCORD_VERSION=//p" | tr -d '"')"
- if [[ "$NOTIFY_DISCORD_VERSION" != "$LatestNotifyRelease" ]] ; then
- printf -v NotifyUpdate "\n\nnotify_discord.sh update avialable:\n $NOTIFY_DISCORD_VERSION -> $LatestNotifyRelease\n"
- MessageBody="${MessageBody}${NotifyUpdate}"
- fi
-
- trigger_notification
+trigger_discord_notification() {
+ DiscordWebhookUrl="${DISCORD_WEBHOOK_URL}" # e.g. DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/
+
+ MsgBody="{\"username\":\"$FromHost\",\"content\":\"$MessageBody\"}"
+ curl -sS -o /dev/null --fail -X POST -H "Content-Type: application/json" -d "$MsgBody" "$DiscordWebhookUrl"
}
diff --git a/notify_templates/notify_generic.sh b/notify_templates/notify_generic.sh
index 700e84a..cbcbf6e 100644
--- a/notify_templates/notify_generic.sh
+++ b/notify_templates/notify_generic.sh
@@ -1,44 +1,9 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_GENERIC_VERSION="v0.1"
+NOTIFY_GENERIC_VERSION="v0.2"
#
-# Copy/rename this file to notify.sh to enable the notification snippet.
# generic sample, the "Hello World" of notification addons
-FromHost=$(hostname)
-
-trigger_notification() {
- # Modify to fit your setup:
+trigger_generic_notification() {
printf "\n$MessageTitle\n"
printf "\n$MessageBody\n"
-}
-
-send_notification() {
- [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
-
- # platform specific notification code would go here
- printf "\n%bGeneric notification addon:%b" "$c_green" "$c_reset"
- MessageTitle="$FromHost - updates available."
- printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString"
-
- trigger_notification
-}
-
-### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
-### to not send notifications when dockcheck itself has updates.
-dockcheck_notification() {
- printf "\nGeneric dockcheck notification\n"
-
- MessageTitle="$FromHost - New version of dockcheck available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3"
-
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_generic.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_GENERIC_VERSION/s/NOTIFY_GENERIC_VERSION=//p" | tr -d '"')"
- if [[ "$NOTIFY_GENERIC_VERSION" != "$LatestNotifyRelease" ]] ; then
- printf -v NotifyUpdate "\n\nnotify_generic.sh update avialable:\n $NOTIFY_GENERIC_VERSION -> $LatestNotifyRelease\n"
- MessageBody="${MessageBody}${NotifyUpdate}"
- fi
-
- trigger_notification
-}
+}
\ No newline at end of file
diff --git a/notify_templates/notify_gotify.sh b/notify_templates/notify_gotify.sh
index 94d1d97..f66e7e8 100644
--- a/notify_templates/notify_gotify.sh
+++ b/notify_templates/notify_gotify.sh
@@ -1,61 +1,30 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_GOTIFY_VERSION="v0.2"
+NOTIFY_GOTIFY_VERSION="v0.3"
#
-# Copy/rename this file to notify.sh to enable the notification snippet.
# Required receiving services must already be set up.
-# Modify to fit your setup - set GotifyUrl and GotifyToken.
+# Do not modify this file directly. Set GOTIFY_TOKEN and GOTIFY_DOMAIN in your dockcheck.config file.
-FromHost=$(hostname)
+if [[ -z "${GOTIFY_TOKEN:-}" ]] || [[ -z "${GOTIFY_DOMAIN:-}" ]]; then
+ printf "Gotify notification channel enabled, but required configuration variables are missing. Gotify notifications will not be sent.\n"
-trigger_notification() {
- # Modify to fit your setup:
- GotifyToken="Your Gotify token here"
- GotifyUrl="https://api.gotify/message?token=${GotifyToken}"
+ remove_channel gotify
+fi
- if [[ "$PrintMarkdownURL" == true ]]; then
- ContentType="text/markdown"
- else
- ContentType="text/plain"
- fi
+trigger_gotify_notification() {
+ GotifyToken="${GOTIFY_TOKEN}" # e.g. GOTIFY_TOKEN=token-value
+ GotifyUrl="${GOTIFY_DOMAIN}/message?token=${GotifyToken}" # e.g. GOTIFY_URL=https://gotify.domain.tld
- JsonData=$( jq -n \
- --arg body "$MessageBody" \
- --arg title "$MessageTitle" \
- --arg type "$ContentType" \
- '{message: $body, title: $title, priority: 5, extras: {"client::display": {"contentType": $type}}}' )
+ if [[ "$PrintMarkdownURL" == true ]]; then
+ ContentType="text/markdown"
+ else
+ ContentType="text/plain"
+ fi
- curl -s -S --data "${JsonData}" -H 'Content-Type: application/json' -X POST "${GotifyUrl}" 1> /dev/null
-}
-
-send_notification() {
- [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
-
- # platform specific notification code would go here
- printf "\nSending Gotify notification\n"
-
- # Setting the MessageTitle and MessageBody variable here.
- MessageTitle="${FromHost} - updates available."
- printf -v MessageBody "Containers on $FromHost with updates available:\n$UpdToString"
-
- trigger_notification
-}
-
-### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
-### to not send notifications when dockcheck itself has updates.
-dockcheck_notification() {
- printf "\nSending Gotify dockcheck notification\n"
-
- MessageTitle="$FromHost - New version of dockcheck available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3"
-
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_gotify.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_GOTIFY_VERSION/s/NOTIFY_GOTIFY_VERSION=//p" | tr -d '"')"
- if [[ "$NOTIFY_GOTIFY_VERSION" != "$LatestNotifyRelease" ]] ; then
- printf -v NotifyUpdate "\n\nnotify_gotify.sh update avialable:\n $NOTIFY_GOTIFY_VERSION -> $LatestNotifyRelease\n"
- MessageBody="${MessageBody}${NotifyUpdate}"
- fi
-
- trigger_notification
+ JsonData=$( jq -n \
+ --arg body "$MessageBody" \
+ --arg title "$MessageTitle" \
+ --arg type "$ContentType" \
+ '{message: $body, title: $title, priority: 5, extras: {"client::display": {"contentType": $type}}}' )
+
+ curl -s -S --data "${JsonData}" -H 'Content-Type: application/json' -X POST "${GotifyUrl}" 1> /dev/null
}
diff --git a/notify_templates/notify_matrix.sh b/notify_templates/notify_matrix.sh
index 686a4b1..87215ae 100644
--- a/notify_templates/notify_matrix.sh
+++ b/notify_templates/notify_matrix.sh
@@ -1,51 +1,21 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_MATRIX_VERSION="v0.1"
+NOTIFY_MATRIX_VERSION="v0.2"
#
-# Copy/rename this file to notify.sh to enable the notification snippet.
# Required receiving services must already be set up.
-# Modify to fit your setup - set MatrixServer, Room_id and AccessToken
+# Do not modify this file directly. Set MATRIX_ACCESS_TOKEN, MATRIX_ROOM_ID, and MATRIX_SERVER_URL in your dockcheck.config file.
-FromHost=$(hostname)
+if [[ -z "${MATRIX_ACCESS_TOKEN:-}" ]] || [[ -z "${MATRIX_ROOM_ID}:-" ]] || [[ -z "${MATRIX_SERVER_URL}:-" ]]; then
+ printf "Matrix notification channel enabled, but required configuration variables are missing. Matrix notifications will not be sent.\n"
-trigger_notification() {
- # Modify to fit your setup:
- AccessToken="Your Matrix token here"
- Room_id="Enter Room_id here"
- MatrixServer="Enter Your HomeServer URL"
- MsgBody="{\"msgtype\":\"m.text\",\"body\":\"$MessageBody\"}"
+ remove_channel matrix
+fi
- # URL Example: https://matrix.org/_matrix/client/r0/rooms/!xxxxxx:example.com/send/m.room.message?access_token=xxxxxxxx
- curl -sS -o /dev/null --fail -X POST "$MatrixServer/_matrix/client/r0/rooms/$Room_id/send/m.room.message?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody"
-}
+trigger_matrix_notification() {
+ AccessToken="${MATRIX_ACCESS_TOKEN}" # e.g. MATRIX_ACCESS_TOKEN=token-value
+ Room_id="${MATRIX_ROOM_ID}" # e.g. MATRIX_ROOM_ID=myroom
+ MatrixServer="${MATRIX_SERVER_URL}" # e.g. MATRIX_SERVER_URL=http://matrix.yourdomain.tld
+ MsgBody="{\"msgtype\":\"m.text\",\"body\":\"$MessageBody\"}"
-send_notification() {
- [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
-
- # platform specific notification code would go here
- printf "\nSending Matrix notification\n"
-
- # Setting the MessageBody variable here.
- MessageBody="🐋 Containers on $FromHost with updates available: \n$UpdToString"
-
- trigger_notification
-}
-
-### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
-### to not send notifications when dockcheck itself has updates.
-dockcheck_notification() {
- printf "\nSending Matrix dockcheck notification\n"
-
- MessageTitle="$FromHost - New version of dockcheck available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3"
-
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_matrix.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_MATRIX_VERSION/s/NOTIFY_MATRIX_VERSION=//p" | tr -d '"')"
- if [[ "$NOTIFY_MATRIX_VERSION" != "$LatestNotifyRelease" ]] ; then
- printf -v NotifyUpdate "\n\nnotify_matrix.sh update avialable:\n $NOTIFY_MATRIX_VERSION -> $LatestNotifyRelease\n"
- MessageBody="${MessageBody}${NotifyUpdate}"
- fi
-
- trigger_notification
-}
+ # URL Example: https://matrix.org/_matrix/client/r0/rooms/!xxxxxx:example.com/send/m.room.message?access_token=xxxxxxxx
+ curl -sS -o /dev/null --fail -X POST "$MatrixServer/_matrix/client/r0/rooms/$Room_id/send/m.room.message?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody"
+}
\ No newline at end of file
diff --git a/notify_templates/notify_ntfy-sh.sh b/notify_templates/notify_ntfy-sh.sh
index 996f275..0b5cc3a 100644
--- a/notify_templates/notify_ntfy-sh.sh
+++ b/notify_templates/notify_ntfy-sh.sh
@@ -1,57 +1,27 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_NTFYSH_VERSION="v0.2"
+NOTIFY_NTFYSH_VERSION="v0.3"
#
-# Copy/rename this file to notify.sh to enable the notification snippet.
# Setup app and subscription at https://ntfy.sh
-# Use your unique Topic Name in the URL below.
+# Do not modify this file directly. Set NTFY_TOPIC_NAME in your dockcheck.config file.
-FromHost=$(hostname)
+if [[ -z "${NTFY_TOPIC_NAME:-}" ]]; then
+ printf "Ntfy.sh notification channel enabled, but required configuration variables are missing. Ntfy.sh notifications will not be sent.\n"
-trigger_notification() {
- # Modify to fit your setup:
- NtfyUrl="ntfy.sh/YourUniqueTopicName"
+ remove_channel ntfy-sh
+fi
- if [[ "$PrintMarkdownURL" == true ]]; then
- ContentType="Markdown: yes"
- else
- ContentType="Markdown: no" #text/plain
- fi
+trigger_ntfy-sh_notification() {
+ NtfyUrl="ntfy.sh/${NTFY_TOPIC_NAME}" # e.g. NTFY_TOPIC_NAME=YourUniqueTopicName
- curl -sS -o /dev/null --show-error --fail \
- -H "Title: $MessageTitle" \
- -H "$ContentType" \
- -d "$MessageBody" \
- "$NtfyUrl"
-}
-
-send_notification() {
- [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
-
- printf "\nSending ntfy.sh notification\n"
-
- MessageTitle="$FromHost - updates available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString"
-
- trigger_notification
-}
-
-### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
-### to not send notifications when dockcheck itself has updates.
-dockcheck_notification() {
- printf "\nSending ntfy.sh dockcheck notification\n"
-
- MessageTitle="$FromHost - New version of dockcheck available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3"
-
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_ntfy-sh.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_NTFYSH_VERSION/s/NOTIFY_NTFYSH_VERSION=//p" | tr -d '"')"
- if [[ "$NOTIFY_NTFYSH_VERSION" != "$LatestNotifyRelease" ]] ; then
- printf -v NotifyUpdate "\n\nnotify_ntfy-sh.sh update avialable:\n $NOTIFY_NTFYSH_VERSION -> $LatestNotifyRelease\n"
- MessageBody="${MessageBody}${NotifyUpdate}"
- fi
-
- trigger_notification
+ if [[ "$PrintMarkdownURL" == true ]]; then
+ ContentType="Markdown: yes"
+ else
+ ContentType="Markdown: no" #text/plain
+ fi
+
+ curl -sS -o /dev/null --show-error --fail \
+ -H "Title: $MessageTitle" \
+ -H "$ContentType" \
+ -d "$MessageBody" \
+ "$NtfyUrl"
}
diff --git a/notify_templates/notify_pushbullet.sh b/notify_templates/notify_pushbullet.sh
index 0df62cb..4bad2ff 100644
--- a/notify_templates/notify_pushbullet.sh
+++ b/notify_templates/notify_pushbullet.sh
@@ -1,51 +1,20 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_PUSHBULLET_VERSION="v0.1"
+NOTIFY_PUSHBULLET_VERSION="v0.2"
#
-# Copy/rename this file to notify.sh to enable the notification snippet.
# Required receiving services must already be set up.
# Requires jq installed and in PATH.
-# Modify to fit your setup - set Url and Token.
+# Do not modify this file directly. Set PUSHBULLET_TOKEN and PUSHBULLET_URL in your dockcheck.config file.
-FromHost=$(hostname)
+if [[ -z "${PUSHBULLET_URL:-}" ]] || [[ -z "${PUSHBULLET_TOKEN:-}" ]]; then
+ printf "Pushbullet notification channel enabled, but required configuration variables are missing. Pushbullet notifications will not be sent.\n"
-trigger_notification() {
- # Modify to fit your setup:
- PushUrl="https://api.pushbullet.com/v2/pushes"
- PushToken="Your Pushbullet token here"
+ remove_channel pushbullet
+fi
- # Requires jq to process json data
- jq -n --arg title "$MessageTitle" --arg body "$MessageBody" '{body: $body, title: $title, type: "note"}' | curl -sS -o /dev/null --show-error --fail -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @-
-}
+trigger_pushbullet_notification() {
+ PushUrl="${PUSHBULLET_URL}" # e.g. PUSHBULLET_URL=https://api.pushbullet.com/v2/pushes
+ PushToken="${PUSHBULLET_TOKEN}" # e.g. PUSHBULLET_TOKEN=token-value
-send_notification() {
- [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
-
- # platform specific notification code would go here
- printf "\nSending pushbullet notification\n"
-
- MessageTitle="$FromHost - updates available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString"
-
- trigger_notification
-}
-
-### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
-### to not send notifications when dockcheck itself has updates.
-dockcheck_notification() {
- printf "\nSending pushbullet dockcheck notification\n"
-
- MessageTitle="$FromHost - New version of dockcheck available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3"
-
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_pushbullet.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_PUSHBULLET_VERSION/s/NOTIFY_PUSHBULLET_VERSION=//p" | tr -d '"')"
- if [[ "$NOTIFY_PUSHBULLET_VERSION" != "$LatestNotifyRelease" ]] ; then
- printf -v NotifyUpdate "\n\nnotify_pushbullet.sh update avialable:\n $NOTIFY_PUSHBULLET_VERSION -> $LatestNotifyRelease\n"
- MessageBody="${MessageBody}${NotifyUpdate}"
- fi
-
- trigger_notification
-}
+ # Requires jq to process json data
+ jq -n --arg title "$MessageTitle" --arg body "$MessageBody" '{body: $body, title: $title, type: "note"}' | curl -sS -o /dev/null --show-error --fail -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @-
+}
\ No newline at end of file
diff --git a/notify_templates/notify_pushover.sh b/notify_templates/notify_pushover.sh
index dc28493..16fff6a 100644
--- a/notify_templates/notify_pushover.sh
+++ b/notify_templates/notify_pushover.sh
@@ -1,57 +1,26 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_PUSHOVER_VERSION="v0.1"
+NOTIFY_PUSHOVER_VERSION="v0.2"
#
-# Copy/rename this file to notify.sh to enable the notification snippet.
# Required receiving services must already be set up.
# Requires jq installed and in PATH.
-# Modify to fit your setup - set Url and Token.
+# Do not modify this file directly. Set PUSHOVER_USER_KEY, PUSHOVER_TOKEN, and PUSHOVER_URL in your dockcheck.config file.
-FromHost=$(hostname)
+if [[ -z "${PUSHOVER_URL:-}" ]] || [[ -z "${PUSHOVER_USER_KEY:-}" ]] || [[ -z "${PUSHOVER_TOKEN:-}" ]]; then
+ printf "Pushover notification channel enabled, but required configuration variables are missing. Pushover notifications will not be sent.\n"
-trigger_notification() {
- # Modify to fit your setup:
- PushoverUrl="https://api.pushover.net/1/messages.json"
- PushoverUserKey="Your Pushover User Key Here"
- PushoverToken="Your Pushover API Token Here"
+ remove_channel pushover
+fi
- # Sending the notification via Pushover
- curl -sS -o /dev/null --show-error --fail -X POST \
- -F "token=$PushoverToken" \
- -F "user=$PushoverUserKey" \
- -F "title=$MessageTitle" \
- -F "message=$MessageBody" \
- $PushoverUrl
-}
+trigger_pushover_notification() {
+ PushoverUrl="${PUSHOVER_URL}" # e.g. PUSHOVER_URL=https://api.pushover.net/1/messages.json
+ PushoverUserKey="${PUSHOVER_USER_KEY}" # e.g. PUSHOVER_USER_KEY=userkey
+ PushoverToken="${PUSHOVER_TOKEN}" # e.g. PUSHOVER_TOKEN=token-value
-send_notification() {
- [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
-
- # platform specific notification code would go here
- printf "\nSending pushover notification\n"
-
- MessageTitle="$FromHost - updates available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString"
-
- trigger_notification
-}
-
-### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
-### to not send notifications when dockcheck itself has updates.
-dockcheck_notification() {
- printf "\nSending pushover dockcheck notification\n"
-
- MessageTitle="$FromHost - New version of dockcheck available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3"
-
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_pushover.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_PUSHOVER_VERSION/s/NOTIFY_PUSHOVER_VERSION=//p" | tr -d '"')"
- if [[ "$NOTIFY_PUSHOVER_VERSION" != "$LatestNotifyRelease" ]] ; then
- printf -v NotifyUpdate "\n\nnotify_pushover.sh update avialable:\n $NOTIFY_PUSHOVER_VERSION -> $LatestNotifyRelease\n"
- MessageBody="${MessageBody}${NotifyUpdate}"
- fi
-
- trigger_notification
-}
+ # Sending the notification via Pushover
+ curl -sS -o /dev/null --show-error --fail -X POST \
+ -F "token=$PushoverToken" \
+ -F "user=$PushoverUserKey" \
+ -F "title=$MessageTitle" \
+ -F "message=$MessageBody" \
+ $PushoverUrl
+}
\ No newline at end of file
diff --git a/notify_templates/notify_slack.sh b/notify_templates/notify_slack.sh
index 56ed28b..6dc3b28 100644
--- a/notify_templates/notify_slack.sh
+++ b/notify_templates/notify_slack.sh
@@ -1,52 +1,22 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_SLACK_VERSION="v0.1"
+NOTIFY_SLACK_VERSION="v0.2"
#
-# Copy/rename this file to notify.sh in the same directory as dockcheck.sh to enable the notification snippet.
-# Setu app and token at https://api.slack.com/tutorials/tracks/posting-messages-with-curl
-# Add your AccessToken and ChannelID below
+# Setup app and token at https://api.slack.com/tutorials/tracks/posting-messages-with-curl
+# Do not modify this file directly. Set SLACK_ACCESS_TOKEN, and SLACK_CHANNEL_ID in your dockcheck.config file.
-FromHost=$(hostname)
+if [[ -z "${SLACK_ACCESS_TOKEN:-}" ]] || [[ -z "${SLACK_CHANNEL_ID:-}" ]]; then
+ printf "Slack notification channel enabled, but required configuration variables are missing. Slack notifications will not be sent.\n"
-trigger_notification() {
- # Modify to fit your setup:
- AccessToken="xoxb-not-a-real-token-this-will-not-work"
- ChannelID="C123456"
- SlackUrl="https://slack.com/api/chat.postMessage"
+ remove_channel slack
+fi
- curl -sS -o /dev/null --show-error --fail \
- -d "text=$MessageBody" -d "channel=$ChannelID" \
- -H "Authorization: Bearer $AccessToken" \
- -X POST $SlackUrl
-}
-
-send_notification() {
- [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
-
- printf "\nSending Slack notification\n"
-
- MessageTitle="$FromHost - updates available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString"
-
- trigger_notification
-}
-
-### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
-### to not send notifications when dockcheck itself has updates.
-dockcheck_notification() {
- printf "\nSending Slack dockcheck notification\n"
-
- MessageTitle="$FromHost - New version of dockcheck available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3"
-
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_slack.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_SLACK_VERSION/s/NOTIFY_SLACK_VERSION=//p" | tr -d '"')"
- if [[ "$NOTIFY_SLACK_VERSION" != "$LatestNotifyRelease" ]] ; then
- printf -v NotifyUpdate "\n\nnotify_slack.sh update avialable:\n $NOTIFY_SLACK_VERSION -> $LatestNotifyRelease\n"
- MessageBody="${MessageBody}${NotifyUpdate}"
- fi
-
- trigger_notification
+trigger_slack_notification() {
+ AccessToken="${SLACK_ACCESS_TOKEN}" # e.g. SLACK_ACCESS_TOKEN=some-token
+ ChannelID="${SLACK_CHANNEL_ID}" # e.g. CHANNEL_ID=mychannel
+ SlackUrl="https://slack.com/api/chat.postMessage"
+
+ curl -sS -o /dev/null --show-error --fail \
+ -d "text=$MessageBody" -d "channel=$ChannelID" \
+ -H "Authorization: Bearer $AccessToken" \
+ -X POST $SlackUrl
}
diff --git a/notify_templates/notify_smtp.sh b/notify_templates/notify_smtp.sh
index 55e325b..8573640 100644
--- a/notify_templates/notify_smtp.sh
+++ b/notify_templates/notify_smtp.sh
@@ -1,10 +1,15 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_SMTP_VERSION="v0.1"
+NOTIFY_SMTP_VERSION="v0.2"
# INFO: ssmtp is depcerated - consider to use msmtp instead.
#
-# Copy/rename this file to notify.sh to enable the notification snipppet.
# mSMTP/sSMTP has to be installed and configured manually.
-# Modify to fit your setup - changing SendMailFrom, SendMailTo, SubjectTag
+# Do not modify this file directly. Set SMTP_MAIL_FROM, SMTP_MAIL_TO, and SMTP_SUBJECT_TAG in your dockcheck.config file.
+
+if [[ -z "${SMTP_MAIL_FROM:-}" ]] || [[ -z "${SMTP_MAIL_TO:-}" ]] || [[ -z "${SMTP_SUBJECT_TAG:-}" ]]; then
+ printf "SMTP notification channel enabled, but required configuration variables are missing. SMTP notifications will not be sent.\n"
+
+ remove_channel smtp
+fi
MSMTP=$(which msmtp)
SSMTP=$(which ssmtp)
@@ -17,13 +22,10 @@ else
echo "No msmtp or ssmtp binary found in PATH: $PATH" ; exit 1
fi
-FromHost=$(hostname)
-
-trigger_notification() {
-# User variables:
-SendMailFrom="me@mydomain.tld"
-SendMailTo="me@mydomain.tld"
-SubjectTag="dockcheck"
+trigger_smtp_notification() {
+SendMailFrom="${SMTP_MAIL_FROM}" # e.g. MAIL_FROM=me@mydomain.tld
+SendMailTo="${SMTP_MAIL_TO}" # e.g. MAIL_TO=me@mydomain.tld
+SubjectTag="${SMTP_SUBJECT_TAG}" # e.g. SUBJECT_TAG=dockcheck
$MailPkg $SendMailTo << __EOF
From: "$FromHost" <$SendMailFrom>
@@ -37,35 +39,3 @@ $MessageBody
__EOF
}
-
-send_notification() {
- [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
-
- printf "\nSending email notification.\n"
-
- MessageTitle="Updates available on"
- # Setting the MessageBody variable here.
- printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n\n$UpdToString"
-
- trigger_notification
-}
-
-### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
-### to not send notifications when dockcheck itself has updates.
-dockcheck_notification() {
- printf "\nSending email dockcheck notification.\n"
-
- MessageTitle="New version of dockcheck available on"
- # Setting the MessageBody variable here.
- printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3"
-
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_smtp.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_SMTP_VERSION/s/NOTIFY_SMTP_VERSION=//p" | tr -d '"')"
- if [[ "$NOTIFY_SMTP_VERSION" != "$LatestNotifyRelease" ]] ; then
- printf -v NotifyUpdate "\n\nnotify_smtp.sh update avialable:\n $NOTIFY_SMTP_VERSION -> $LatestNotifyRelease\n"
- MessageBody="${MessageBody}${NotifyUpdate}"
- fi
-
- trigger_notification
-}
diff --git a/notify_templates/notify_telegram.sh b/notify_templates/notify_telegram.sh
index 0850e51..1230524 100644
--- a/notify_templates/notify_telegram.sh
+++ b/notify_templates/notify_telegram.sh
@@ -1,58 +1,27 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_TELEGRAM_VERSION="v0.1"
+NOTIFY_TELEGRAM_VERSION="v0.2"
#
-# Copy/rename this file to notify.sh to enable the notification snippet.
# Required receiving services must already be set up.
-# Modify to fit your setup - set TelegramChatId and TelegramToken.
+# Do not modify this file directly. Set TELEGRAM_CHAT_ID and TELEGRAM_TOKEN in your dockcheck.config file.
-FromHost=$(hostname)
+if [[ -z "${TELEGRAM_CHAT_ID:-}" ]] || [[ -z "${TELEGRAM_TOKEN:-}" ]]; then
+ printf "Telegram notification channel enabled, but required configuration variables are missing. Telegram notifications will not be sent.\n"
-trigger_notification() {
+ remove_channel telegram
+fi
- if [[ "$PrintMarkdownURL" == true ]]; then
- ParseMode="Markdown"
- else
- ParseMode="HTML"
- fi
+trigger_telegram_notification() {
+ if [[ "$PrintMarkdownURL" == true ]]; then
+ ParseMode="Markdown"
+ else
+ ParseMode="HTML"
+ fi
- # Modify to fit your setup:
- TelegramToken="Your Telegram token here"
- TelegramChatId="Your Telegram ChatId here"
- TelegramUrl="https://api.telegram.org/bot$TelegramToken"
- TelegramTopicID=12345678 ## Set to 0 if not using specific topic within chat
- TelegramData="{\"chat_id\":\"$TelegramChatId\",\"text\":\"$MessageBody\",\"message_thread_id\":\"$TelegramTopicID\",\"disable_notification\": false}"
+ TelegramToken="${TELEGRAM_TOKEN}" # e.g. TELEGRAM_TOKEN=token-value
+ TelegramChatId="${TELEGRAM_CHAT_ID}" # e.g. TELEGRAM_CHAT_ID=mychatid
+ TelegramUrl="https://api.telegram.org/bot$TelegramToken"
+ TelegramTopicID=${TELEGRAM_TOPIC_ID:="0"}
+ TelegramData="{\"chat_id\":\"$TelegramChatId\",\"text\":\"$MessageBody\",\"message_thread_id\":\"$TelegramTopicID\",\"disable_notification\": false}"
- curl -sS -o /dev/null --fail -X POST "$TelegramUrl/sendMessage" -H 'Content-Type: application/json' -d "$TelegramData"
-}
-
-send_notification() {
- [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
-
- # platform specific notification code would go here
- printf "\nSending Telegram notification\n"
-
- # Setting the MessageBody variable here.
- MessageBody="🐋 Containers on $FromHost with updates available: \n$UpdToString"
-
- trigger_notification
-}
-
-### Rename (eg. disabled_dockcheck_notification), remove or comment out the following function
-### to not send notifications when dockcheck itself has updates.
-dockcheck_notification() {
- printf "\nSending Telegram dockcheck notification\n"
-
- MessageTitle="$FromHost - New version of dockcheck available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "$FromHost - New version of dockcheck available.\n\nInstalled version: $1 \nLatest version: $2 \n\nChangenotes: $3"
-
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_telegram.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_TELEGRAM_VERSION/s/NOTIFY_TELEGRAM_VERSION=//p" | tr -d '"')"
- if [[ "$NOTIFY_TELEGRAM_VERSION" != "$LatestNotifyRelease" ]] ; then
- printf -v NotifyUpdate "\n\nnotify_telegram.sh update avialable:\n $NOTIFY_TELEGRAM_VERSION -> $LatestNotifyRelease\n"
- MessageBody="${MessageBody}${NotifyUpdate}"
- fi
-
- trigger_notification
+ curl -sS -o /dev/null --fail -X POST "$TelegramUrl/sendMessage" -H 'Content-Type: application/json' -d "$TelegramData"
}
diff --git a/notify_templates/notify_v2.sh b/notify_templates/notify_v2.sh
new file mode 100644
index 0000000..3beb5ef
--- /dev/null
+++ b/notify_templates/notify_v2.sh
@@ -0,0 +1,84 @@
+NOTIFY_V2_VERSION="v0.1"
+#
+# If migrating from an older notify template, remove your existing notify.sh file.
+# Enable and configure all required notification variables in your dockcheck.config file, e.g.:
+# NOTIFY_CHANNELS=apprise gotify slack
+# SLACK_TOKEN=xoxb-some-token-value
+# GOTIFY_TOKEN=some.token
+
+enabled_notify_channels=( ${NOTIFY_CHANNELS:-} )
+
+FromHost=$(hostname)
+
+remove_channel() {
+ local temp_array=()
+ for channel in "${enabled_notify_channels[@]}"; do
+ [[ "${channel}" != "$1" ]] && temp_array+=("${channel}")
+ done
+ enabled_notify_channels=( "${temp_array[@]}" )
+}
+
+for channel in "${enabled_notify_channels[@]}"; do
+ source_if_exists "${ScriptWorkDir}/notify_templates/notify_${channel}.sh"
+done
+
+send_notification() {
+ [[ -s "$ScriptWorkDir"/urls.list ]] && releasenotes || Updates=("$@")
+ UpdToString=$( printf '%s\\n' "${Updates[@]}" )
+
+ for channel in "${enabled_notify_channels[@]}"; do
+ printf "\nSending ${channel} notification\n"
+
+ MessageTitle="$FromHost - updates available."
+ # Setting the MessageBody variable here.
+ printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString\n"
+
+ exec_if_exists trigger_${channel}_notification "$@"
+ done
+}
+
+### Set DISABLE_DOCKCHECK_NOTIFICATION=false in dockcheck.config
+### to not send notifications when dockcheck itself has updates.
+dockcheck_notification() {
+ if [[ ! "${DISABLE_DOCKCHECK_NOTIFICATION:-}" = "true" ]]; then
+ MessageTitle="$FromHost - New version of dockcheck available."
+ # Setting the MessageBody variable here.
+ printf -v MessageBody "Installed version: $1\nLatest version: $2\n\nChangenotes: $3\n"
+
+ if [[ ${#enabled_notify_channels[@]} -gt 0 ]]; then printf "\n"; fi
+ for channel in "${enabled_notify_channels[@]}"; do
+ printf "Sending dockcheck update notification - ${channel}\n"
+ exec_if_exists trigger_${channel}_notification
+ done
+ fi
+}
+
+### Set DISABLE_NOTIFY_UPDATE_NOTIFICATION=false in dockcheck.config
+### to not send notifications when notify scripts themselves have updates.
+notify_update_notification() {
+ if [[ ! "${DISABLE_NOTIFY_UPDATE_NOTIFICATION:-}" = "true" ]]; then
+ update_channels=( "${enabled_notify_channels[@]}" "v2" )
+
+ for notify_script in "${update_channels[@]}"; do
+ upper_channel=$(tr '[:lower:]' '[:upper:]' <<< "$notify_script")
+ VersionVar="NOTIFY_${upper_channel}_VERSION"
+ if [[ -n "${!VersionVar}" ]]; then
+ RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_${notify_script}.sh"
+ LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_${upper_channel}_VERSION/s/NOTIFY_${upper_channel}_VERSION=//p" | tr -d '"')"
+ LatestNotifyRelease=${LatestNotifyRelease:-undefined}
+ if [[ ! "${LatestNotifyRelease}" = "undefined" ]]; then
+ if [[ "${!VersionVar}" != "$LatestNotifyRelease" ]] ; then
+ MessageTitle="$FromHost - New version of notify_${notify_script}.sh available."
+
+ printf -v MessageBody "notify_${notify_script}.sh update available:\n ${!VersionVar} -> $LatestNotifyRelease\n"
+
+ for channel in "${enabled_notify_channels[@]}"; do
+ printf "Sending notify_${notify_script}.sh update notification - ${channel}\n"
+ exec_if_exists trigger_${channel}_notification
+ done
+ fi
+ fi
+ fi
+ done
+ fi
+}
From 57f7580477df15a73ec5b2317ac8ce8701578cf8 Mon Sep 17 00:00:00 2001
From: mag37
Date: Sun, 25 May 2025 18:27:12 +0200
Subject: [PATCH 09/55] Update dockcheck.sh
lowering version until a few more tweaks are done.
---
dockcheck.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dockcheck.sh b/dockcheck.sh
index a0a5be2..8b07094 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
-VERSION="v0.6.5"
+VERSION="v0.6.4"
### ChangeNotes: Refactored notification logic. See README.md for upgrade steps.
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
From 5e7d4f0b8a4eb11c9353c308eea901e2256ffb1b Mon Sep 17 00:00:00 2001
From: mag37
Date: Sun, 25 May 2025 18:39:34 +0200
Subject: [PATCH 10/55] minor tweaks; curl/wget retries, missing variable fix
in root-check
---
README.md | 13 +++++--------
dockcheck.sh | 18 +++++++++---------
2 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index 27ef1ad..e66eb7d 100644
--- a/README.md
+++ b/README.md
@@ -23,9 +23,10 @@ ___
- **v0.6.5**: Refactored notification logic. See notify_templates/notify_v2.sh for upgrade steps.
- Added helper functions to simplify sourcing files and executing functions if they exist.
- Created notify_v2.sh wrapper script.
- - Simplified and consolidated notification logic within notify_v2.sh.
- - Added support for notification management via environment variables.
- - Moved notification secrets to dockcheck.config.
+ - Simplified and consolidated notification logic within notify_v2.sh.
+ - Added support for notification management via environment variables.
+ - Moved notification secrets to **dockcheck.config**.
+ - Added retries to wget/curl to not get empty responses when github is slow.
- **v0.6.4**: Restructured the update process - first pulls all updates, then recreates all containers.
- Added logic to skip update check on non-compose containers (unless `-r` option).
- Added option `-F` to revert to `compose up -d ` targeting specific container and not the stack.
@@ -40,10 +41,6 @@ ___
- `-u`, Allow auto self update of dockcheck.sh
- `-I`, Print container release URLs in the CLI "choose update" list. (please contribute to `urls.list`)
- Extras: `-m`, Monochrome mode now hides the progress bar.
-- **v0.6.1**: Hotfixes: (try removing set+shopt+shopt if debugging more errors)
- - xargs/pipefail, removed `-set -e` bash option for now.
- - unbound variables fixed (hopefully)
- - dependency installer from pkgmanager rewritten
___
@@ -64,7 +61,7 @@ Options:
-F Only compose up the specific container, not the whole compose stack (useful for master-compose structure).
-h Print this Help.
-i Inform - send a preconfigured notification.
--I Prints custom releasenote urls alongside each container with updates (requires urls.list).
+-I Prints custom releasenote urls alongside each container with updates in CLI output (requires urls.list).
-l Only update if label is set. See readme.
-m Monochrome mode, no printf colour codes and hides progress bar.
-M Prints custom releasenote urls as markdown (requires template support).
diff --git a/dockcheck.sh b/dockcheck.sh
index 8b07094..3144622 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
VERSION="v0.6.4"
-### ChangeNotes: Refactored notification logic. See README.md for upgrade steps.
+# ChangeNotes: Refactored notification logic. See README.md for upgrade steps.
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
@@ -14,8 +14,8 @@ ScriptPath="$(readlink -f "$0")"
ScriptWorkDir="$(dirname "$ScriptPath")"
# Check if there's a new release of the script
-LatestRelease="$(curl -s -r 0-50 "$RawUrl" | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
-LatestChanges="$(curl -s -r 0-200 "$RawUrl" | sed -n "/ChangeNotes/s/# ChangeNotes: //p")"
+LatestRelease="$(curl --retry 3 --retry-delay 1 --retry-max-time 10 -s -r 0-50 "$RawUrl" | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
+LatestChanges="$(curl --retry 3 --retry-delay 1 --retry-max-time 10 -s -r 0-200 "$RawUrl" | sed -n "/ChangeNotes/s/# ChangeNotes: //p")"
# Source helper functions
source_if_exists() {
@@ -43,7 +43,7 @@ Help() {
echo "-F Only compose up the specific container, not the whole compose stack (useful for master-compose structure)."
echo "-h Print this Help."
echo "-i Inform - send a preconfigured notification."
- echo "-I Prints custom releasenote urls alongside each container with updates (requires urls.list)."
+ echo "-I Prints custom releasenote urls alongside each container with updates in CLI output (requires urls.list)."
echo "-l Only update if label is set. See readme."
echo "-m Monochrome mode, no printf colour codes and hides progress bar."
echo "-M Prints custom releasenote urls as markdown (requires template support)."
@@ -166,12 +166,12 @@ exec_if_exists_or_fail() {
self_update_curl() {
cp "$ScriptPath" "$ScriptPath".bak
if command -v curl &>/dev/null; then
- curl -L $RawUrl > "$ScriptPath"; chmod +x "$ScriptPath"
+ curl --retry 3 --retry-delay 1 --retry-max-time 10 -L $RawUrl > "$ScriptPath"; chmod +x "$ScriptPath"
printf "\n%b---%b starting over with the updated version %b---%b\n" "$c_yellow" "$c_teal" "$c_yellow" "$c_reset"
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
exit 1 # Exit the old instance
elif command -v wget &>/dev/null; then
- wget $RawUrl -O "$ScriptPath"; chmod +x "$ScriptPath"
+ wget --waitretry=1 --timeout=15 -t 10 $RawUrl -O "$ScriptPath"; chmod +x "$ScriptPath"
printf "\n%b---%b starting over with the updated version %b---%b\n" "$c_yellow" "$c_teal" "$c_yellow" "$c_reset"
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
exit 0 # exit the old instance
@@ -270,8 +270,8 @@ binary_downloader() {
*) printf "\n%bArchitecture not supported, exiting.%b\n" "$c_red" "$c_reset"; exit 1;;
esac
GetUrl="${BinaryUrl/TEMP/"$architecture"}"
- if command -v curl &>/dev/null; then curl -L "$GetUrl" > "$ScriptWorkDir/$BinaryName";
- elif command -v wget &>/dev/null; then wget "$GetUrl" -O "$ScriptWorkDir/$BinaryName";
+ if command -v curl &>/dev/null; then curl --retry 3 --retry-delay 1 --retry-max-time 10 -L "$GetUrl" > "$ScriptWorkDir/$BinaryName";
+ elif command -v wget &>/dev/null; then wget --waitretry=1 --timeout=15 -t 10 "$GetUrl" -O "$ScriptWorkDir/$BinaryName";
else printf "\n%bcurl/wget not available - get %s manually from the repo link, exiting.%b" "$c_red" "$BinaryName" "$c_reset"; exit 1;
fi
[[ -f "$ScriptWorkDir/$BinaryName" ]] && chmod +x "$ScriptWorkDir/$BinaryName"
@@ -285,7 +285,7 @@ distro_checker() {
elif [[ -f /etc/arch-release ]]; then
[[ "$isRoot" == true ]] && PkgInstaller="pacman -S" || PkgInstaller="sudo pacman -S"
elif [[ -f /etc/debian_version ]]; then
- [[ "" == true ]] && PkgInstaller="apt-get install" || PkgInstaller="sudo apt-get install"
+ [[ "$isRoot" == true ]] && PkgInstaller="apt-get install" || PkgInstaller="sudo apt-get install"
elif [[ -f /etc/redhat-release ]]; then
[[ "$isRoot" == true ]] && PkgInstaller="dnf install" || PkgInstaller="sudo dnf install"
elif [[ -f /etc/SuSE-release ]]; then
From ec09612274d1c37529a8d691ace52f0c2203ce83 Mon Sep 17 00:00:00 2001
From: mag37
Date: Sun, 25 May 2025 18:44:20 +0200
Subject: [PATCH 11/55] version bump
Version bump after minor tweaks.
Should probably learn to squash properly.. soon!
---
dockcheck.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dockcheck.sh b/dockcheck.sh
index 3144622..f5bbad7 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
-VERSION="v0.6.4"
+VERSION="v0.6.5"
# ChangeNotes: Refactored notification logic. See README.md for upgrade steps.
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
From 22871442db509e42a5c8f0f3aecac3d7d7675bab Mon Sep 17 00:00:00 2001
From: mag37
Date: Mon, 26 May 2025 07:27:51 +0200
Subject: [PATCH 12/55] hotfix suppress noise
Suppressed noise about not being able to source notification (new function) when on legacy notification template.
---
dockcheck.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dockcheck.sh b/dockcheck.sh
index f5bbad7..cccc6dc 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -355,7 +355,7 @@ if [[ "$VERSION" != "$LatestRelease" ]]; then
fi
# Version check for notify templates
-[[ "$Notify" == true ]] && { exec_if_exists_or_fail notify_update_notification || printf "Could not source notify notification function.\n"; }
+[[ "$Notify" == true ]] && [[ ! -s "${ScriptWorkDir}/notify.sh" ]] && { exec_if_exists_or_fail notify_update_notification || printf "Could not source notify notification function.\n"; }
dependency_check "regctl" "regbin" "https://github.com/regclient/regclient/releases/latest/download/regctl-linux-TEMP"
dependency_check "jq" "jqbin" "https://github.com/jqlang/jq/releases/latest/download/jq-linux-TEMP"
From 57650f16736359cb49217896c54f20e946727fbb Mon Sep 17 00:00:00 2001
From: vorezal <37914382+vorezal@users.noreply.github.com>
Date: Thu, 29 May 2025 16:43:34 -0400
Subject: [PATCH 13/55] Notify_v2.sh bug fixes (#188)
* Notify_v2.sh bug fixes
* Clarify notify_v2.sh usage in README.md
* Fix JSON newline handling in Discord and Telegram channels
* Additional error messages when notification templates fail to be sourced
* Additional variable for self-hosted ntfy.sh domain
* Notify_v2.sh additional fixes
* Clarify usage in README.md and notify template comments
* Support sourcing template files from project root
* Add days old message to notification title
* Handle JSON with jq in Discord and Telegram templates
* Tweak notify_v2.sh usage docs and comments
* Remove extra newline from notification body
* replaced jq with jqbin, reodered setting of jqbin, changed source for hostname var
* moved the setting of jqbin a bit further up after further testing
---------
Co-authored-by: Matthew Oleksowicz
Co-authored-by: mag37
---
.gitignore | 2 +-
README.md | 24 +++++++++++++++++++-
default.config | 2 ++
dockcheck.sh | 6 ++---
notify_templates/notify_DSM.sh | 4 +++-
notify_templates/notify_apprise.sh | 4 +++-
notify_templates/notify_discord.sh | 14 ++++++++----
notify_templates/notify_gotify.sh | 6 +++--
notify_templates/notify_matrix.sh | 4 +++-
notify_templates/notify_ntfy-sh.sh | 13 +++++++----
notify_templates/notify_pushbullet.sh | 8 ++++---
notify_templates/notify_pushover.sh | 4 +++-
notify_templates/notify_slack.sh | 4 +++-
notify_templates/notify_smtp.sh | 4 +++-
notify_templates/notify_telegram.sh | 16 ++++++++++----
notify_templates/notify_v2.sh | 32 ++++++++++++++++++---------
16 files changed, 109 insertions(+), 38 deletions(-)
diff --git a/.gitignore b/.gitignore
index da5921c..da6210f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
# ignore users custom notify.sh
-/notify.sh
+/notify*.sh
/urls.list
# ignore user config
/dockcheck.config
diff --git a/README.md b/README.md
index e66eb7d..73662bb 100644
--- a/README.md
+++ b/README.md
@@ -136,9 +136,31 @@ Run it scheduled with `-ni` to only get notified when there's updates available!
V2 installation and configuration (tag v0.6.5 or later):
Remove or rename `notify.sh` if previously configured using the legacy method.
+Make certain your project directory is laid out as below. You only need the notify_v2.sh file and any notification templates you wish to enable, but there is no harm in having all of them present.
+```
+ .
+├── notify_templates/
+│ ├── notify_DSM.sh
+│ ├── notify_apprise.sh
+│ ├── notify_discord.sh
+│ ├── notify_generic.sh
+│ ├── notify_gotify.sh
+│ ├── notify_matrix.sh
+│ ├── notify_ntfy-sh.sh
+│ ├── notify_pushbullet.sh
+│ ├── notify_pushover.sh
+│ ├── notify_slack.sh
+│ ├── notify_smtp.sh
+│ ├── notify_telegram.sh
+│ └── notify_v2.sh
+├── dockcheck.config
+├── dockcheck.sh
+└── urls.list # optional
+```
+If you wish to customize `notify_v2.sh` or the notify templates yourself, you may copy them to your project root directory alongside the main dockcheck.sh script (where they will also be ignored by git).
Uncomment and set the NOTIFY_CHANNELS environment variable in `dockcheck.config` to a space separated string of your desired notification channels to enable.
Uncomment and set the environment variables related to the enabled notification channels.
-It is recommended not to make changes directly to the `notify_X.sh` template files and to use only environment variables defined in `dockcheck.config` using this method.
+It is recommended not to make changes directly to the `notify_X.sh` template files within the `notify_templates` subdirectory and instead use only environment variables defined in `dockcheck.config` using this method.
Legacy installation and configuration:
Use a previous version of a `notify_X.sh` template file (tag v0.6.4 or earlier) from the **notify_templates** directory,
diff --git a/default.config b/default.config
index 9c13be0..cd26f57 100644
--- a/default.config
+++ b/default.config
@@ -54,6 +54,8 @@
# MATRIX_ROOM_ID="myroom"
# MATRIX_SERVER_URL="https://matrix.yourdomain.tld"
#
+## ntfy.sh or your custom domain with no trailing /
+# NTFY_DOMAIN="ntfy.sh"
# NTFY_TOPIC_NAME="YourUniqueTopicName"
#
# PUSHBULLET_URL="https://api.pushbullet.com/v2/pushes"
diff --git a/dockcheck.sh b/dockcheck.sh
index cccc6dc..3a2a04e 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -332,6 +332,9 @@ dependency_check() {
${!AppVar} "$VerFlag" &> /dev/null || { printf "%s\n" "$AppName is not working - try to remove it and re-download it, exiting."; exit 1; }
}
+dependency_check "regctl" "regbin" "https://github.com/regclient/regclient/releases/latest/download/regctl-linux-TEMP"
+dependency_check "jq" "jqbin" "https://github.com/jqlang/jq/releases/latest/download/jq-linux-TEMP"
+
# Numbered List function
# if urls.list exists add release note url per line
list_options() {
@@ -357,9 +360,6 @@ fi
# Version check for notify templates
[[ "$Notify" == true ]] && [[ ! -s "${ScriptWorkDir}/notify.sh" ]] && { exec_if_exists_or_fail notify_update_notification || printf "Could not source notify notification function.\n"; }
-dependency_check "regctl" "regbin" "https://github.com/regclient/regclient/releases/latest/download/regctl-linux-TEMP"
-dependency_check "jq" "jqbin" "https://github.com/jqlang/jq/releases/latest/download/jq-linux-TEMP"
-
# Check docker compose binary
docker info &>/dev/null || { printf "\n%bYour current user does not have permissions to the docker socket - may require root / docker group. Exiting.%b\n" "$c_red" "$c_reset"; exit 1; }
if docker compose version &>/dev/null; then DockerBin="docker compose" ;
diff --git a/notify_templates/notify_DSM.sh b/notify_templates/notify_DSM.sh
index 17d697f..edfb51f 100644
--- a/notify_templates/notify_DSM.sh
+++ b/notify_templates/notify_DSM.sh
@@ -4,7 +4,9 @@ NOTIFY_DSM_VERSION="v0.2"
#
# mSMTP/sSMTP has to be installed and configured manually.
# The existing DSM Notification Email configuration will be used automatically.
-# Do not modify this file directly. Set DSM_SENDMAILTO and DSM_SUBJECTTAG in your dockcheck.config file.
+# 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.
+# Do not modify this file directly within the "notify_templates" subdirectory. Set DSM_SENDMAILTO and DSM_SUBJECTTAG in your dockcheck.config file.
MSMTP=$(which msmtp)
SSMTP=$(which ssmtp)
diff --git a/notify_templates/notify_apprise.sh b/notify_templates/notify_apprise.sh
index e71a4df..4da3d71 100644
--- a/notify_templates/notify_apprise.sh
+++ b/notify_templates/notify_apprise.sh
@@ -2,7 +2,9 @@
NOTIFY_APPRISE_VERSION="v0.2"
#
# Required receiving services must already be set up.
-# Do not modify this file directly. Set APPRISE_PAYLOAD in your dockcheck.config file.
+# 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.
+# Do not modify this file directly within the "notify_templates" subdirectory. Set APPRISE_PAYLOAD in your dockcheck.config file.
# If API, set APPRISE_URL instead.
if [[ -z "${APPRISE_PAYLOAD:-}" ]] && [[ -z "${APPRISE_URL:-}" ]]; then
diff --git a/notify_templates/notify_discord.sh b/notify_templates/notify_discord.sh
index a28cda5..97bf1fa 100644
--- a/notify_templates/notify_discord.sh
+++ b/notify_templates/notify_discord.sh
@@ -1,8 +1,10 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_DISCORD_VERSION="v0.2"
+NOTIFY_DISCORD_VERSION="v0.3"
#
# Required receiving services must already be set up.
-# Do not modify this file directly. Set DISCORD_WEBHOOK_URL in your dockcheck.config file.
+# 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.
+# Do not modify this file directly within the "notify_templates" subdirectory. Set DISCORD_WEBHOOK_URL in your dockcheck.config file.
if [[ -z "${DISCORD_WEBHOOK_URL:-}" ]]; then
printf "Discord notification channel enabled, but required configuration variables are missing. Discord notifications will not be sent.\n"
@@ -13,6 +15,10 @@ fi
trigger_discord_notification() {
DiscordWebhookUrl="${DISCORD_WEBHOOK_URL}" # e.g. DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/
- MsgBody="{\"username\":\"$FromHost\",\"content\":\"$MessageBody\"}"
- curl -sS -o /dev/null --fail -X POST -H "Content-Type: application/json" -d "$MsgBody" "$DiscordWebhookUrl"
+ JsonData=$( "$jqbin" -n \
+ --arg username "$FromHost" \
+ --arg body "$MessageBody" \
+ '{"username": $username, "content": $body}' )
+
+ curl -sS -o /dev/null --fail -X POST -H "Content-Type: application/json" -d "$JsonData" "$DiscordWebhookUrl"
}
diff --git a/notify_templates/notify_gotify.sh b/notify_templates/notify_gotify.sh
index f66e7e8..4e373d6 100644
--- a/notify_templates/notify_gotify.sh
+++ b/notify_templates/notify_gotify.sh
@@ -2,7 +2,9 @@
NOTIFY_GOTIFY_VERSION="v0.3"
#
# Required receiving services must already be set up.
-# Do not modify this file directly. Set GOTIFY_TOKEN and GOTIFY_DOMAIN in your dockcheck.config file.
+# 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.
+# Do not modify this file directly within the "notify_templates" subdirectory. Set GOTIFY_TOKEN and GOTIFY_DOMAIN in your dockcheck.config file.
if [[ -z "${GOTIFY_TOKEN:-}" ]] || [[ -z "${GOTIFY_DOMAIN:-}" ]]; then
printf "Gotify notification channel enabled, but required configuration variables are missing. Gotify notifications will not be sent.\n"
@@ -20,7 +22,7 @@ trigger_gotify_notification() {
ContentType="text/plain"
fi
- JsonData=$( jq -n \
+ JsonData=$( "$jqbin" -n \
--arg body "$MessageBody" \
--arg title "$MessageTitle" \
--arg type "$ContentType" \
diff --git a/notify_templates/notify_matrix.sh b/notify_templates/notify_matrix.sh
index 87215ae..8cf20b5 100644
--- a/notify_templates/notify_matrix.sh
+++ b/notify_templates/notify_matrix.sh
@@ -2,7 +2,9 @@
NOTIFY_MATRIX_VERSION="v0.2"
#
# Required receiving services must already be set up.
-# Do not modify this file directly. Set MATRIX_ACCESS_TOKEN, MATRIX_ROOM_ID, and MATRIX_SERVER_URL in your dockcheck.config file.
+# 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.
+# Do not modify this file directly within the "notify_templates" subdirectory. Set MATRIX_ACCESS_TOKEN, MATRIX_ROOM_ID, and MATRIX_SERVER_URL in your dockcheck.config file.
if [[ -z "${MATRIX_ACCESS_TOKEN:-}" ]] || [[ -z "${MATRIX_ROOM_ID}:-" ]] || [[ -z "${MATRIX_SERVER_URL}:-" ]]; then
printf "Matrix notification channel enabled, but required configuration variables are missing. Matrix notifications will not be sent.\n"
diff --git a/notify_templates/notify_ntfy-sh.sh b/notify_templates/notify_ntfy-sh.sh
index 0b5cc3a..5a189c5 100644
--- a/notify_templates/notify_ntfy-sh.sh
+++ b/notify_templates/notify_ntfy-sh.sh
@@ -1,17 +1,22 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_NTFYSH_VERSION="v0.3"
+NOTIFY_NTFYSH_VERSION="v0.4"
#
# Setup app and subscription at https://ntfy.sh
-# Do not modify this file directly. Set NTFY_TOPIC_NAME in your dockcheck.config file.
+# 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.
+# Do not modify this file directly within the "notify_templates" subdirectory. Set NTFY_DOMAIN and NTFY_TOPIC_NAME in your dockcheck.config file.
-if [[ -z "${NTFY_TOPIC_NAME:-}" ]]; then
+if [[ -z "${NTFY_DOMAIN:-}" ]] || [[ -z "${NTFY_TOPIC_NAME:-}" ]]; then
printf "Ntfy.sh notification channel enabled, but required configuration variables are missing. Ntfy.sh notifications will not be sent.\n"
remove_channel ntfy-sh
fi
trigger_ntfy-sh_notification() {
- NtfyUrl="ntfy.sh/${NTFY_TOPIC_NAME}" # e.g. NTFY_TOPIC_NAME=YourUniqueTopicName
+ NtfyUrl="${NTFY_DOMAIN}/${NTFY_TOPIC_NAME}"
+ # e.g.
+ # NTFY_DOMAIN=ntfy.sh
+ # NTFY_TOPIC_NAME=YourUniqueTopicName
if [[ "$PrintMarkdownURL" == true ]]; then
ContentType="Markdown: yes"
diff --git a/notify_templates/notify_pushbullet.sh b/notify_templates/notify_pushbullet.sh
index 4bad2ff..182c78d 100644
--- a/notify_templates/notify_pushbullet.sh
+++ b/notify_templates/notify_pushbullet.sh
@@ -3,7 +3,9 @@ NOTIFY_PUSHBULLET_VERSION="v0.2"
#
# Required receiving services must already be set up.
# Requires jq installed and in PATH.
-# Do not modify this file directly. Set PUSHBULLET_TOKEN and PUSHBULLET_URL in your dockcheck.config file.
+# 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.
+# Do not modify this file directly within the "notify_templates" subdirectory. Set PUSHBULLET_TOKEN and PUSHBULLET_URL in your dockcheck.config file.
if [[ -z "${PUSHBULLET_URL:-}" ]] || [[ -z "${PUSHBULLET_TOKEN:-}" ]]; then
printf "Pushbullet notification channel enabled, but required configuration variables are missing. Pushbullet notifications will not be sent.\n"
@@ -16,5 +18,5 @@ trigger_pushbullet_notification() {
PushToken="${PUSHBULLET_TOKEN}" # e.g. PUSHBULLET_TOKEN=token-value
# Requires jq to process json data
- jq -n --arg title "$MessageTitle" --arg body "$MessageBody" '{body: $body, title: $title, type: "note"}' | curl -sS -o /dev/null --show-error --fail -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @-
-}
\ No newline at end of file
+ "$jqbin" -n --arg title "$MessageTitle" --arg body "$MessageBody" '{body: $body, title: $title, type: "note"}' | curl -sS -o /dev/null --show-error --fail -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @-
+}
diff --git a/notify_templates/notify_pushover.sh b/notify_templates/notify_pushover.sh
index 16fff6a..2f8bdda 100644
--- a/notify_templates/notify_pushover.sh
+++ b/notify_templates/notify_pushover.sh
@@ -3,7 +3,9 @@ NOTIFY_PUSHOVER_VERSION="v0.2"
#
# Required receiving services must already be set up.
# Requires jq installed and in PATH.
-# Do not modify this file directly. Set PUSHOVER_USER_KEY, PUSHOVER_TOKEN, and PUSHOVER_URL in your dockcheck.config file.
+# 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.
+# Do not modify this file directly within the "notify_templates" subdirectory. Set PUSHOVER_USER_KEY, PUSHOVER_TOKEN, and PUSHOVER_URL in your dockcheck.config file.
if [[ -z "${PUSHOVER_URL:-}" ]] || [[ -z "${PUSHOVER_USER_KEY:-}" ]] || [[ -z "${PUSHOVER_TOKEN:-}" ]]; then
printf "Pushover notification channel enabled, but required configuration variables are missing. Pushover notifications will not be sent.\n"
diff --git a/notify_templates/notify_slack.sh b/notify_templates/notify_slack.sh
index 6dc3b28..a760f3d 100644
--- a/notify_templates/notify_slack.sh
+++ b/notify_templates/notify_slack.sh
@@ -2,7 +2,9 @@
NOTIFY_SLACK_VERSION="v0.2"
#
# Setup app and token at https://api.slack.com/tutorials/tracks/posting-messages-with-curl
-# Do not modify this file directly. Set SLACK_ACCESS_TOKEN, and SLACK_CHANNEL_ID in your dockcheck.config file.
+# 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.
+# Do not modify this file directly within the "notify_templates" subdirectory. Set SLACK_ACCESS_TOKEN, and SLACK_CHANNEL_ID in your dockcheck.config file.
if [[ -z "${SLACK_ACCESS_TOKEN:-}" ]] || [[ -z "${SLACK_CHANNEL_ID:-}" ]]; then
printf "Slack notification channel enabled, but required configuration variables are missing. Slack notifications will not be sent.\n"
diff --git a/notify_templates/notify_smtp.sh b/notify_templates/notify_smtp.sh
index 8573640..2889475 100644
--- a/notify_templates/notify_smtp.sh
+++ b/notify_templates/notify_smtp.sh
@@ -3,7 +3,9 @@ NOTIFY_SMTP_VERSION="v0.2"
# INFO: ssmtp is depcerated - consider to use msmtp instead.
#
# mSMTP/sSMTP has to be installed and configured manually.
-# Do not modify this file directly. Set SMTP_MAIL_FROM, SMTP_MAIL_TO, and SMTP_SUBJECT_TAG in your dockcheck.config file.
+# 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.
+# Do not modify this file directly within the "notify_templates" subdirectory. Set SMTP_MAIL_FROM, SMTP_MAIL_TO, and SMTP_SUBJECT_TAG in your dockcheck.config file.
if [[ -z "${SMTP_MAIL_FROM:-}" ]] || [[ -z "${SMTP_MAIL_TO:-}" ]] || [[ -z "${SMTP_SUBJECT_TAG:-}" ]]; then
printf "SMTP notification channel enabled, but required configuration variables are missing. SMTP notifications will not be sent.\n"
diff --git a/notify_templates/notify_telegram.sh b/notify_templates/notify_telegram.sh
index 1230524..d254490 100644
--- a/notify_templates/notify_telegram.sh
+++ b/notify_templates/notify_telegram.sh
@@ -1,8 +1,10 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_TELEGRAM_VERSION="v0.2"
+NOTIFY_TELEGRAM_VERSION="v0.3"
#
# Required receiving services must already be set up.
-# Do not modify this file directly. Set TELEGRAM_CHAT_ID and TELEGRAM_TOKEN in your dockcheck.config file.
+# 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.
+# Do not modify this file directly within the "notify_templates" subdirectory. Set TELEGRAM_CHAT_ID and TELEGRAM_TOKEN in your dockcheck.config file.
if [[ -z "${TELEGRAM_CHAT_ID:-}" ]] || [[ -z "${TELEGRAM_TOKEN:-}" ]]; then
printf "Telegram notification channel enabled, but required configuration variables are missing. Telegram notifications will not be sent.\n"
@@ -21,7 +23,13 @@ trigger_telegram_notification() {
TelegramChatId="${TELEGRAM_CHAT_ID}" # e.g. TELEGRAM_CHAT_ID=mychatid
TelegramUrl="https://api.telegram.org/bot$TelegramToken"
TelegramTopicID=${TELEGRAM_TOPIC_ID:="0"}
- TelegramData="{\"chat_id\":\"$TelegramChatId\",\"text\":\"$MessageBody\",\"message_thread_id\":\"$TelegramTopicID\",\"disable_notification\": false}"
- curl -sS -o /dev/null --fail -X POST "$TelegramUrl/sendMessage" -H 'Content-Type: application/json' -d "$TelegramData"
+ JsonData=$( "$jqbin" -n \
+ --arg chatid "$TelegramChatId" \
+ --arg text "$MessageBody" \
+ --arg thread "$TelegramTopicID" \
+ --arg parse_mode "$ParseMode" \
+ '{"chat_id": $chatid, "text": $text, "message_thread_id": $thread, "disable_notification": false, "parse_mode": $parse_mode, "disable_web_page_preview": true}' )
+
+ curl -sS -o /dev/null --fail -X POST "$TelegramUrl/sendMessage" -H 'Content-Type: application/json' -d "$JsonData"
}
diff --git a/notify_templates/notify_v2.sh b/notify_templates/notify_v2.sh
index 3beb5ef..5990e1a 100644
--- a/notify_templates/notify_v2.sh
+++ b/notify_templates/notify_v2.sh
@@ -1,6 +1,8 @@
-NOTIFY_V2_VERSION="v0.1"
+NOTIFY_V2_VERSION="v0.2"
#
# If migrating from an older notify template, remove your existing notify.sh file.
+# 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.
# Enable and configure all required notification variables in your dockcheck.config file, e.g.:
# NOTIFY_CHANNELS=apprise gotify slack
# SLACK_TOKEN=xoxb-some-token-value
@@ -8,7 +10,7 @@ NOTIFY_V2_VERSION="v0.1"
enabled_notify_channels=( ${NOTIFY_CHANNELS:-} )
-FromHost=$(hostname)
+FromHost=$(cat /etc/hostname)
remove_channel() {
local temp_array=()
@@ -19,21 +21,29 @@ remove_channel() {
}
for channel in "${enabled_notify_channels[@]}"; do
- source_if_exists "${ScriptWorkDir}/notify_templates/notify_${channel}.sh"
+ source_if_exists_or_fail "${ScriptWorkDir}/notify_${channel}.sh" || \
+ source_if_exists_or_fail "${ScriptWorkDir}/notify_templates/notify_${channel}.sh" || \
+ printf "The notification channel ${channel} is enabled, but notify_${channel}.sh was not found. Check the ${ScriptWorkDir} directory or the notify_templates subdirectory.\n"
done
send_notification() {
[[ -s "$ScriptWorkDir"/urls.list ]] && releasenotes || Updates=("$@")
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
+ UpdToString=${UpdToString%\\n}
for channel in "${enabled_notify_channels[@]}"; do
printf "\nSending ${channel} notification\n"
- MessageTitle="$FromHost - updates available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString\n"
+ # To be added in the MessageBody if "-d X" was used
+ # leading space is left intentionally for clean output
+ [[ -n "$DaysOld" ]] && msgdaysold="with images ${DaysOld}+ days old " || msgdaysold=""
- exec_if_exists trigger_${channel}_notification "$@"
+ MessageTitle="$FromHost - updates ${msgdaysold}available."
+ # Setting the MessageBody variable here.
+ printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n${UpdToString}\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"
done
}
@@ -48,7 +58,8 @@ dockcheck_notification() {
if [[ ${#enabled_notify_channels[@]} -gt 0 ]]; then printf "\n"; fi
for channel in "${enabled_notify_channels[@]}"; do
printf "Sending dockcheck update notification - ${channel}\n"
- exec_if_exists trigger_${channel}_notification
+ 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"
done
fi
}
@@ -62,7 +73,7 @@ notify_update_notification() {
for notify_script in "${update_channels[@]}"; do
upper_channel=$(tr '[:lower:]' '[:upper:]' <<< "$notify_script")
VersionVar="NOTIFY_${upper_channel}_VERSION"
- if [[ -n "${!VersionVar}" ]]; then
+ if [[ -n "${!VersionVar:-}" ]]; then
RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_${notify_script}.sh"
LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_${upper_channel}_VERSION/s/NOTIFY_${upper_channel}_VERSION=//p" | tr -d '"')"
LatestNotifyRelease=${LatestNotifyRelease:-undefined}
@@ -74,7 +85,8 @@ notify_update_notification() {
for channel in "${enabled_notify_channels[@]}"; do
printf "Sending notify_${notify_script}.sh update notification - ${channel}\n"
- exec_if_exists trigger_${channel}_notification
+ 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"
done
fi
fi
From 68c057e62dbd58a11d454668a8e1e50db2e7b48a Mon Sep 17 00:00:00 2001
From: mag37
Date: Thu, 29 May 2025 23:03:46 +0200
Subject: [PATCH 14/55] v0.6.6 bump and info
---
README.md | 11 ++--
dockcheck.sh | 4 +-
notify_templates/urls.list | 100 +++++++++++++++++++++++--------------
3 files changed, 72 insertions(+), 43 deletions(-)
diff --git a/README.md b/README.md
index 73662bb..af2f45d 100644
--- a/README.md
+++ b/README.md
@@ -20,6 +20,13 @@
___
## :bell: Changelog
+- **v0.6.6**: Notify_v2 bugfixes
+ - Clearer readme and error messages
+ - Sourcing templates from either project root or subdirectory
+ - Consistent newline handling
+ - Added (when using `-d`) days old message to notification title
+ - Added ntfy.sh self hosted domain option to config
+ - jq fixes to templates (and properly using $jqbin)
- **v0.6.5**: Refactored notification logic. See notify_templates/notify_v2.sh for upgrade steps.
- Added helper functions to simplify sourcing files and executing functions if they exist.
- Created notify_v2.sh wrapper script.
@@ -37,10 +44,6 @@ ___
- `-M`, Markdown format url-releasenotes in notification (requires template rework, look at gotify!)
- Added [addons/DSM/README.md](./addons/DSM/README.md) for more info Synology DSM info.
- Permission checks - graceful exit if no docker permissions + checking if root for pkg-manager.
-- **v0.6.2**: Style and colour changes, prometheus hotfix, new options:
- - `-u`, Allow auto self update of dockcheck.sh
- - `-I`, Print container release URLs in the CLI "choose update" list. (please contribute to `urls.list`)
- - Extras: `-m`, Monochrome mode now hides the progress bar.
___
diff --git a/dockcheck.sh b/dockcheck.sh
index 3a2a04e..992a267 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-VERSION="v0.6.5"
-# ChangeNotes: Refactored notification logic. See README.md for upgrade steps.
+VERSION="v0.6.6"
+# ChangeNotes: notify_v2 bugfixes - clarify readme and error messages, better sourcing templates, tweaks.
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
diff --git a/notify_templates/urls.list b/notify_templates/urls.list
index 31ad44a..2b31c3b 100644
--- a/notify_templates/urls.list
+++ b/notify_templates/urls.list
@@ -1,49 +1,75 @@
-# This is a list of container names and releasenote urls, separated by space.
-# Modify, add and (if necessary) remove to fit your needs.
# Additions are welcome! Append your list to the git-repo, use generic names and sensible urls.
+# Modify, add and (if necessary) remove to fit your needs.
+# This is a list of container names and releasenote urls, separated by space.
-apprise-api https://github.com/linuxserver/docker-apprise-api/releases
-homer https://github.com/bastienwirtz/homer/releases
-nginx https://github.com/docker-library/official-images/blob/master/library/nginx
-vaultwarden-server https://github.com/dani-garcia/vaultwarden/releases
-bruceforce-vaultwarden-backup https://github.com/Bruceforce/vaultwarden-backup/blob/main/CHANGELOG.md
actual_server https://actualbudget.org/blog
-gotify https://github.com/gotify/server/releases
-traefik https://github.com/traefik/traefik/releases
-caddy https://github.com/caddyserver/caddy/releases
-homarr https://github.com/homarr-labs/homarr/releases
-dozzle https://github.com/amir20/dozzle/releases
-beszel https://github.com/henrygd/beszel/releases
-forgejo https://codeberg.org/forgejo/forgejo/releases
-dockge https://github.com/louislam/dockge/releases
-cup https://github.com/sergi0g/cup/releases
-
-calibre https://github.com/linuxserver/docker-calibre/releases
-calibre-web https://github.com/linuxserver/docker-calibre-web/releases
-readarr https://github.com/Readarr/Readarr/releases
+apprise-api https://github.com/linuxserver/docker-apprise-api/releases
audiobookshelf https://github.com/advplyr/audiobookshelf/releases
-
-gluetun https://github.com/qdm12/gluetun/releases
bazarr https://github.com/morpheus65535/bazarr/releases
bazarr-ls https://github.com/linuxserver/docker-bazarr/releases
+beszel https://github.com/henrygd/beszel/releases
+bookstack https://github.com/BookStackApp/BookStack/releases
+bruceforce-vaultwarden-backup https://github.com/Bruceforce/vaultwarden-backup/blob/main/CHANGELOG.md
+caddy https://github.com/caddyserver/caddy/releases
+calibre https://github.com/linuxserver/docker-calibre/releases
+calibre-web https://github.com/linuxserver/docker-calibre-web/releases
+cleanuperr https://github.com/flmorg/cleanuperr/releases
+cross-seed https://github.com/cross-seed/cross-seed/releases
+cup https://github.com/sergi0g/cup/releases
+dockge https://github.com/louislam/dockge/releases
+dozzle https://github.com/amir20/dozzle/releases
+flatnotes https://github.com/dullage/flatnotes/releases
+forgejo https://codeberg.org/forgejo/forgejo/releases
+fressrss https://github.com/FreshRSS/FreshRSS/releases
+gluetun https://github.com/qdm12/gluetun/releases
+go2rtc https://github.com/AlexxIT/go2rtc/releases
+gotify https://github.com/gotify/server/releases
+hbbr https://github.com/rustdesk/rustdesk-server/releases
+hbbs https://github.com/rustdesk/rustdesk-server/releases
+homarr https://github.com/homarr-labs/homarr/releases
+home-assistant https://github.com/home-assistant/core/releases/
+homer https://github.com/bastienwirtz/homer/releases
+immich_machine_learning https://github.com/immich-app/immich/releases
+immich_postgres https://github.com/tensorchord/VectorChord/releases
+immich_redis https://github.com/valkey-io/valkey/releases
+immich_server https://github.com/immich-app/immich/releases
+jellyfin https://github.com/jellyfin/jellyfin/releases
+jellyseerr https://github.com/Fallenbagel/jellyseerr/releases
+jellystat https://github.com/CyferShepard/Jellystat/releases
+librespeed https://github.com/librespeed/speedtest/releases
+lidarr https://github.com/Lidarr/Lidarr/releases/
+lidarr-ls https://github.com/linuxserver/docker-lidarr/releases
+lubelogger https://github.com/hargata/lubelog/releases
+mattermost https://github.com/mattermost/mattermost/releases
+mealie https://github.com/mealie-recipes/mealie/releases
+meilisearch https://github.com/meilisearch/meilisearch/releases
+monica https://github.com/monicahq/monica/releases
+mqtt https://github.com/eclipse/mosquitto/tags
+nextcloud-aio-mastercontainer https://github.com/nextcloud/all-in-one/releases
+nginx https://github.com/docker-library/official-images/blob/master/library/nginx
+owncast https://github.com/owncast/owncast/releases
prowlarr https://github.com/Prowlarr/Prowlarr/releases
prowlarr-ls https://github.com/linuxserver/docker-prowlarr/releases
+qbittorrent https://www.qbittorrent.org/news
+qbittorrent-nox https://www.qbittorrent.org/news
+radarr https://github.com/Radarr/Radarr/releases/
+radarr-ls https://github.com/linuxserver/docker-radarr/releases
+readarr https://github.com/Readarr/Readarr/releases
+readeck https://codeberg.org/readeck/readeck/releases
recyclarr https://github.com/recyclarr/recyclarr/releases
+roundcubemail https://github.com/roundcube/roundcubemail/releases
sabnzbd https://github.com/linuxserver/docker-sabnzbd/releases
-sonarr https://github.com/linuxserver/docker-sonarr/releases
-radarr https://github.com/linuxserver/docker-radarr/releases
-lidarr https://github.com/linuxserver/docker-lidarr/releases
-jellyseerr https://github.com/Fallenbagel/jellyseerr/releases
-jellyfin https://github.com/jellyfin/jellyfin/releases
-tautulli https://github.com/Tautulli/Tautulli/releases
-cleanuperr https://github.com/flmorg/cleanuperr/releases
+scrutiny https://github.com/AnalogJ/scrutiny/releases
+sftpgo https://github.com/drakkan/sftpgo/releases
slskd https://github.com/slskd/slskd/releases
-
-home-assistant https://github.com/home-assistant/docker/releases
+snappymail https://github.com/the-djmaze/snappymail/releases
+sonarr https://github.com/Sonarr/Sonarr/releases/
+sonarr-ls https://github.com/linuxserver/docker-sonarr/releases
+syncthing https://github.com/syncthing/syncthing/releases
+tautulli https://github.com/Tautulli/Tautulli/releases
+thelounge https://github.com/thelounge/thelounge/releases
+traefik https://github.com/traefik/traefik/releases
+vaultwarden-server https://github.com/dani-garcia/vaultwarden/releases
+watchtower https://github.com/beatkind/watchtower/releases
+wud https://github.com/getwud/wud/releases
zigbee2mqtt https://github.com/Koenkk/zigbee2mqtt/releases
-mqtt https://github.com/eclipse/mosquitto/tags
-
-bookstack https://github.com/BookStackApp/BookStack/releases
-lubelogger https://github.com/hargata/lubelog/releases
-mealie https://github.com/mealie-recipes/mealie/releases
-flatnotes https://github.com/dullage/flatnotes/releases
From 67648efbe87467e94e1dfe785ec5883b4953f5bb Mon Sep 17 00:00:00 2001
From: Christopher Berg
Date: Sat, 31 May 2025 21:55:21 +0200
Subject: [PATCH 15/55] ntfy notification bug fixes (#197)
---
default.config | 2 +-
notify_templates/{notify_ntfy-sh.sh => notify_ntfy.sh} | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
rename notify_templates/{notify_ntfy-sh.sh => notify_ntfy.sh} (81%)
diff --git a/default.config b/default.config
index cd26f57..0e590c2 100644
--- a/default.config
+++ b/default.config
@@ -28,7 +28,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 gotify matrix ntfy-sh pushbullet pushover slack smtp telegram"
+# NOTIFY_CHANNELS="apprise discord DSM generic gotify matrix ntfy pushbullet pushover slack smtp telegram"
#
## Uncomment to not send notifications when dockcheck itself has updates.
# DISABLE_DOCKCHECK_NOTIFICATION=false
diff --git a/notify_templates/notify_ntfy-sh.sh b/notify_templates/notify_ntfy.sh
similarity index 81%
rename from notify_templates/notify_ntfy-sh.sh
rename to notify_templates/notify_ntfy.sh
index 5a189c5..b977d6d 100644
--- a/notify_templates/notify_ntfy-sh.sh
+++ b/notify_templates/notify_ntfy.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_NTFYSH_VERSION="v0.4"
+NOTIFY_NTFY_VERSION="v0.4"
#
# Setup app and subscription at https://ntfy.sh
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
@@ -7,12 +7,12 @@ NOTIFY_NTFYSH_VERSION="v0.4"
# Do not modify this file directly within the "notify_templates" subdirectory. Set NTFY_DOMAIN and NTFY_TOPIC_NAME in your dockcheck.config file.
if [[ -z "${NTFY_DOMAIN:-}" ]] || [[ -z "${NTFY_TOPIC_NAME:-}" ]]; then
- printf "Ntfy.sh notification channel enabled, but required configuration variables are missing. Ntfy.sh notifications will not be sent.\n"
+ printf "Ntfy notification channel enabled, but required configuration variables are missing. Ntfy notifications will not be sent.\n"
- remove_channel ntfy-sh
+ remove_channel ntfy
fi
-trigger_ntfy-sh_notification() {
+trigger_ntfy_notification() {
NtfyUrl="${NTFY_DOMAIN}/${NTFY_TOPIC_NAME}"
# e.g.
# NTFY_DOMAIN=ntfy.sh
From 4a16d2f1eaa0498ed24a7bf5abba49bba4a5d348 Mon Sep 17 00:00:00 2001
From: mag37
Date: Sat, 31 May 2025 22:02:52 +0200
Subject: [PATCH 16/55] -r clarification
Clarified the help message for the -r option.
---
dockcheck.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dockcheck.sh b/dockcheck.sh
index 992a267..45e03cc 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -49,7 +49,7 @@ Help() {
echo "-M Prints custom releasenote urls as markdown (requires template support)."
echo "-n No updates; only checking availability without interaction."
echo "-p Auto-prune dangling images after update."
- echo "-r Allow updating images for docker run; won't update the container."
+ echo "-r Allow checking for updates/updating images for docker run containers. Won't update the container."
echo "-s Include stopped containers in the check. (Logic: docker ps -a)."
echo "-t Set a timeout (in seconds) per container for registry checkups, 10 is default."
echo "-u Allow automatic self updates - caution as this will pull new code and autorun it."
From 272615166e4c4d6953f6a027a2736f406ee37195 Mon Sep 17 00:00:00 2001
From: mag37
Date: Sat, 31 May 2025 22:05:35 +0200
Subject: [PATCH 17/55] ntfy rename
Corrected all mentions of the ntfy template with its new name.
Also clarified the help message of the -r option.
---
README.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index af2f45d..ce036c3 100644
--- a/README.md
+++ b/README.md
@@ -25,7 +25,7 @@ ___
- Sourcing templates from either project root or subdirectory
- Consistent newline handling
- Added (when using `-d`) days old message to notification title
- - Added ntfy.sh self hosted domain option to config
+ - Added ntfy self hosted domain option to config
- jq fixes to templates (and properly using $jqbin)
- **v0.6.5**: Refactored notification logic. See notify_templates/notify_v2.sh for upgrade steps.
- Added helper functions to simplify sourcing files and executing functions if they exist.
@@ -38,7 +38,7 @@ ___
- Added logic to skip update check on non-compose containers (unless `-r` option).
- Added option `-F` to revert to `compose up -d ` targeting specific container and not the stack.
- Also added corresponding label and config-option.
- - Added markdown formatting to `notify_ntfy-sh.sh` template.
+ - Added markdown formatting to `notify_ntfy.sh` template.
- **v0.6.3**: Some fixes and changes:
- Stops when a container recreation (compose up -d) fails, also `up`s the whole stack now.
- `-M`, Markdown format url-releasenotes in notification (requires template rework, look at gotify!)
@@ -70,7 +70,7 @@ Options:
-M Prints custom releasenote urls as markdown (requires template support).
-n No updates, only checking availability.
-p Auto-Prune dangling images after update.
--r Allow updating images for docker run, wont update the container.
+-r Allow checking for updates/updating images for docker run containers. Won't update the container.
-s Include stopped containers in the check. (Logic: docker ps -a).
-t N Set a timeout (in seconds) per container for registry checkups, 10 is default.
-u Allow automatic self updates - caution as this will pull new code and autorun it.
@@ -149,7 +149,7 @@ Make certain your project directory is laid out as below. You only need the noti
│ ├── notify_generic.sh
│ ├── notify_gotify.sh
│ ├── notify_matrix.sh
-│ ├── notify_ntfy-sh.sh
+│ ├── notify_ntfy.sh
│ ├── notify_pushbullet.sh
│ ├── notify_pushover.sh
│ ├── notify_slack.sh
@@ -176,7 +176,7 @@ copy it to `notify.sh` alongside the script, modify it to your needs! (notify.sh
- Apprise (with it's [multitude](https://github.com/caronc/apprise#supported-notifications) of notifications)
- both native [caronc/apprise](https://github.com/caronc/apprise) and the standalone [linuxserver/docker-apprise-api](https://github.com/linuxserver/docker-apprise-api)
- Read the [QuickStart](extras/apprise_quickstart.md)
-- [ntfy.sh](https://ntfy.sh/) - HTTP-based pub-sub notifications.
+- [ntfy](https://ntfy.sh/) - HTTP-based pub-sub notifications.
- [Gotify](https://gotify.net/) - a simple server for sending and receiving messages.
- [Pushbullet](https://www.pushbullet.com/) - connecting different devices with cross-platform features.
- [Telegram](https://telegram.org/) - Telegram chat API.
From a0e11de38354b1b0fa798d13ee64bcbb49e702c7 Mon Sep 17 00:00:00 2001
From: vorezal <37914382+vorezal@users.noreply.github.com>
Date: Tue, 24 Jun 2025 09:16:48 -0400
Subject: [PATCH 18/55] Snooze feature, curl, and consolidation (#200)
* Snooze feature, curl, and consolidation
* Added snooze feature to delay notifications
* Added configurable default curl arguments
* Consolidated and standardized notify template update notifications
* Added curl error handling
* Snooze comment fix
* Grep, curl args, and variable init adjustments
* Modified grep commands to make use of word boundaries in order to avoid matching on substrings
* Set CurlRetryDelay, CurlRetryCount, and CurlConnectTimeout as individual variables
* Used :- for variable initialization where assignment is redundant
* Update dockcheck.sh change notes and fix variable collision
* Remove unnecessary cat and clarify readme
* reformatting
---------
Co-authored-by: Matthew Oleksowicz
Co-authored-by: mag37
---
.gitignore | 2 +
README.md | 45 +++--
default.config | 6 +
dockcheck.sh | 76 ++++----
notify_templates/notify_DSM.sh | 7 +-
notify_templates/notify_apprise.sh | 12 +-
notify_templates/notify_discord.sh | 8 +-
notify_templates/notify_gotify.sh | 8 +-
notify_templates/notify_matrix.sh | 8 +-
notify_templates/notify_ntfy.sh | 8 +-
notify_templates/notify_pushbullet.sh | 8 +-
notify_templates/notify_pushover.sh | 8 +-
notify_templates/notify_slack.sh | 8 +-
notify_templates/notify_smtp.sh | 6 +-
notify_templates/notify_telegram.sh | 8 +-
notify_templates/notify_v2.sh | 250 +++++++++++++++++++++-----
16 files changed, 350 insertions(+), 118 deletions(-)
diff --git a/.gitignore b/.gitignore
index da6210f..e5a2ded 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,5 @@
/dockcheck.config
# ignore the auto-installed regctl
regctl
+# ignore snooze file
+snooze.list
diff --git a/README.md b/README.md
index ce036c3..751e7b2 100644
--- a/README.md
+++ b/README.md
@@ -20,6 +20,11 @@
___
## :bell: Changelog
+- **v0.6.7**: Snooze feature, curl, and consolidation
+ - Added snooze feature to delay notifications
+ - Added configurable default curl arguments
+ - Consolidated and standardized notify template update notifications
+ - Added curl error handling
- **v0.6.6**: Notify_v2 bugfixes
- Clearer readme and error messages
- Sourcing templates from either project root or subdirectory
@@ -34,16 +39,6 @@ ___
- Added support for notification management via environment variables.
- Moved notification secrets to **dockcheck.config**.
- Added retries to wget/curl to not get empty responses when github is slow.
-- **v0.6.4**: Restructured the update process - first pulls all updates, then recreates all containers.
- - Added logic to skip update check on non-compose containers (unless `-r` option).
- - Added option `-F` to revert to `compose up -d ` targeting specific container and not the stack.
- - Also added corresponding label and config-option.
- - Added markdown formatting to `notify_ntfy.sh` template.
-- **v0.6.3**: Some fixes and changes:
- - Stops when a container recreation (compose up -d) fails, also `up`s the whole stack now.
- - `-M`, Markdown format url-releasenotes in notification (requires template rework, look at gotify!)
- - Added [addons/DSM/README.md](./addons/DSM/README.md) for more info Synology DSM info.
- - Permission checks - graceful exit if no docker permissions + checking if root for pkg-manager.
___
@@ -137,8 +132,7 @@ If `notify.sh` is present and configured, it will be used. Otherwise, `notify_v2
Will send a list of containers with updates available and a notification when `dockcheck.sh` itself has an update.
Run it scheduled with `-ni` to only get notified when there's updates available!
-V2 installation and configuration (tag v0.6.5 or later):
-Remove or rename `notify.sh` if previously configured using the legacy method.
+#### Installation and configuration:
Make certain your project directory is laid out as below. You only need the notify_v2.sh file and any notification templates you wish to enable, but there is no harm in having all of them present.
```
.
@@ -160,17 +154,30 @@ Make certain your project directory is laid out as below. You only need the noti
├── dockcheck.sh
└── urls.list # optional
```
-If you wish to customize `notify_v2.sh` or the notify templates yourself, you may copy them to your project root directory alongside the main dockcheck.sh script (where they will also be ignored by git).
Uncomment and set the NOTIFY_CHANNELS environment variable in `dockcheck.config` to a space separated string of your desired notification channels to enable.
-Uncomment and set the environment variables related to the enabled notification channels.
-It is recommended not to make changes directly to the `notify_X.sh` template files within the `notify_templates` subdirectory and instead use only environment variables defined in `dockcheck.config` using this method.
+Uncomment and set the environment variables related to the enabled notification channels.
+It is recommended to only edit the environmental variables in `dockcheck.config` and not make changes directly to the `notify_X.sh` template files within the `notify_templates` subdirectory.
+If you wish to customize the notify templates yourself, you may copy them to your project root directory alongside the main `dockcheck.sh` script (where they will also be ignored by git).
+Customizing `notify_v2.sh` is handled the same as customizing the templates, but it must be renamed to `notify.sh` within the `dockcheck.sh` root directory.
-Legacy installation and configuration:
+
+#### Legacy installation and configuration:
Use a previous version of a `notify_X.sh` template file (tag v0.6.4 or earlier) from the **notify_templates** directory,
copy it to `notify.sh` alongside the script, modify it to your needs! (notify.sh is added to .gitignore)
+#### Snooze feature:
+**Use case:** You wish to be notified of available updates in a timely manner, but do not require reminders after the initial notification with the same frequency.
+e.g. *Dockcheck is scheduled to run every hour. You will receive an update notification within an hour of availability.*
+**Snooze enabled:** you will not receive another notification about updates for this container for a configurable period of time.
+**Snooze disabled:** you will receive additional notifications every hour.
-**Current templates:**
+To enable snooze, uncomment the `SNOOZE_SECONDS` variable in your `dockcheck.config` file and set it to the number of seconds you wish to prevent duplicate alerts.
+The true snooze duration will be 60 seconds less than your configure value to account for minor scheduling or script run time issues.
+If an update becomes available for an item that is not snoozed, notifications will be sent and include all available updates for that item's category, even snoozed items.
+`dockcheck.sh` updates, notification template updates, and container updates are considered three separate categories.
+
+
+#### Current notify templates:
- Synology [DSM](https://www.synology.com/en-global/dsm)
- Email with [mSMTP](https://wiki.debian.org/msmtp) (or deprecated alternative [sSMTP](https://wiki.debian.org/sSMTP))
- Apprise (with it's [multitude](https://github.com/caronc/apprise#supported-notifications) of notifications)
@@ -185,7 +192,7 @@ copy it to `notify.sh` alongside the script, modify it to your needs! (notify.sh
- [Discord](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) - Discord webhooks.
- [Slack](https://api.slack.com/tutorials/tracks/posting-messages-with-curl) - Slack curl api
-Further additions are welcome - suggestions or PR!
+Further additions are welcome - suggestions or PRs!
Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).
### :date: Release notes addon
@@ -228,7 +235,7 @@ See the [README.md](./addons/prometheus/README.md) for more detailed information
Contributed by [tdralle](https://github.com/tdralle).
### :small_orange_diamond: Zabbix config to monitor docker image updates
-If you already use Zabbix - this config will Shows number of available docker image updates on host.
+If you already use Zabbix - this config will show numbers of available docker image updates on host.
Example: *2 Docker Image updates on host-xyz*
See project: [thetorminal/zabbix-docker-image-updates](https://github.com/thetorminal/zabbix-docker-image-updates)
diff --git a/default.config b/default.config
index 0e590c2..2831591 100644
--- a/default.config
+++ b/default.config
@@ -23,6 +23,9 @@
#PrintReleaseURL=true # Prints custom releasenote urls alongside each container with updates (requires urls.list)`
#PrintMarkdownURL=true # Prints custom releasenote urls as markdown
#OnlySpecific=true # Only compose up the specific container, not the whole compose. (useful for master-compose structure).
+#CurlRetryDelay=1 # Time between curl retries
+#CurlRetryCount=3 # Max number of curl retries
+#CurlConnectTimeout=5 # Time to wait for curl to establish a connection before failing
### Notify settings
## All commented values are examples only. Modify as needed.
@@ -30,6 +33,9 @@
## Uncomment the line below and specify the notification channels you wish to enable in a space separated string
# NOTIFY_CHANNELS="apprise discord DSM generic 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
+#
## Uncomment to not send notifications when dockcheck itself has updates.
# DISABLE_DOCKCHECK_NOTIFICATION=false
## Uncomment to not send notifications when notify scripts themselves have updates.
diff --git a/dockcheck.sh b/dockcheck.sh
index 45e03cc..d341ce9 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-VERSION="v0.6.6"
-# ChangeNotes: notify_v2 bugfixes - clarify readme and error messages, better sourcing templates, tweaks.
+VERSION="v0.6.7"
+# ChangeNotes: snooze feature (see readme), curl arguments, cleanup.
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
@@ -13,10 +13,6 @@ ScriptArgs=( "$@" )
ScriptPath="$(readlink -f "$0")"
ScriptWorkDir="$(dirname "$ScriptPath")"
-# Check if there's a new release of the script
-LatestRelease="$(curl --retry 3 --retry-delay 1 --retry-max-time 10 -s -r 0-50 "$RawUrl" | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
-LatestChanges="$(curl --retry 3 --retry-delay 1 --retry-max-time 10 -s -r 0-200 "$RawUrl" | sed -n "/ChangeNotes/s/# ChangeNotes: //p")"
-
# Source helper functions
source_if_exists() {
if [[ -s "$1" ]]; then source "$1"; fi
@@ -60,31 +56,32 @@ Help() {
}
# Initialise variables
-Timeout=${Timeout:=10}
-MaxAsync=${MaxAsync:=1}
-BarWidth=${BarWidth:=50}
-AutoMode=${AutoMode:=false}
-DontUpdate=${DontUpdate:=false}
-AutoPrune=${AutoPrune:=false}
-AutoSelfUpdate=${AutoSelfUpdate:=false}
-OnlyLabel=${OnlyLabel:=false}
-Notify=${Notify:=false}
-ForceRestartStacks=${ForceRestartStacks:=false}
-DRunUp=${DRunUp:=false}
-MonoMode=${MonoMode:=false}
-PrintReleaseURL=${PrintReleaseURL:=false}
-PrintMarkdownURL=${PrintMarkdownURL:=false}
-Stopped=${Stopped:=""}
+Timeout=${Timeout:-10}
+MaxAsync=${MaxAsync:-1}
+BarWidth=${BarWidth:-50}
+AutoMode=${AutoMode:-false}
+DontUpdate=${DontUpdate:-false}
+AutoPrune=${AutoPrune:-false}
+AutoSelfUpdate=${AutoSelfUpdate:-false}
+OnlyLabel=${OnlyLabel:-false}
+Notify=${Notify:-false}
+ForceRestartStacks=${ForceRestartStacks:-false}
+DRunUp=${DRunUp:-false}
+MonoMode=${MonoMode:-false}
+PrintReleaseURL=${PrintReleaseURL:-false}
+PrintMarkdownURL=${PrintMarkdownURL:-false}
+Stopped=${Stopped:-""}
CollectorTextFileDirectory=${CollectorTextFileDirectory:-}
Exclude=${Exclude:-}
DaysOld=${DaysOld:-}
-OnlySpecific=${OnlySpecific:=false}
-SpecificContainer=${SpecificContainer:=""}
+OnlySpecific=${OnlySpecific:-false}
+SpecificContainer=${SpecificContainer:-""}
Excludes=()
GotUpdates=()
NoUpdates=()
GotErrors=()
SelectedUpdates=()
+CurlArgs="--retry ${CurlRetryCount:=3} --retry-delay ${CurlRetryDelay:=1} --connect-timeout ${CurlConnectTimeout:=5} -sf"
regbin=""
jqbin=""
@@ -125,6 +122,11 @@ shift "$((OPTIND-1))"
# Set $1 to a variable for name filtering later
SearchName="${1:-}"
+# Check if there's a new release of the script
+LatestSnippet="$(curl ${CurlArgs} -r 0-200 "$RawUrl" || printf "undefined")"
+LatestRelease="$(echo "${LatestSnippet}" | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
+LatestChanges="$(echo "${LatestSnippet}" | sed -n "/ChangeNotes/s/# ChangeNotes: //p")"
+
# Basic notify configuration check
if [[ "${Notify}" == true ]] && [[ ! -s "${ScriptWorkDir}/notify.sh" ]] && [[ -z "${NOTIFY_CHANNELS:-}" ]]; then
printf "Using v2 notifications with -i flag passed but no notify channels configured in dockcheck.config. This will result in no notifications being sent.\n"
@@ -166,7 +168,7 @@ exec_if_exists_or_fail() {
self_update_curl() {
cp "$ScriptPath" "$ScriptPath".bak
if command -v curl &>/dev/null; then
- curl --retry 3 --retry-delay 1 --retry-max-time 10 -L $RawUrl > "$ScriptPath"; chmod +x "$ScriptPath"
+ curl ${CurlArgs} -L $RawUrl > "$ScriptPath"; chmod +x "$ScriptPath" || { printf "ERROR: Failed to curl updated Dockcheck.sh script. Skipping update.\n"; return 1; }
printf "\n%b---%b starting over with the updated version %b---%b\n" "$c_yellow" "$c_teal" "$c_yellow" "$c_reset"
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
exit 1 # Exit the old instance
@@ -270,7 +272,7 @@ binary_downloader() {
*) printf "\n%bArchitecture not supported, exiting.%b\n" "$c_red" "$c_reset"; exit 1;;
esac
GetUrl="${BinaryUrl/TEMP/"$architecture"}"
- if command -v curl &>/dev/null; then curl --retry 3 --retry-delay 1 --retry-max-time 10 -L "$GetUrl" > "$ScriptWorkDir/$BinaryName";
+ if command -v curl &>/dev/null; then curl ${CurlArgs} -L "$GetUrl" > "$ScriptWorkDir/$BinaryName" || { printf "ERROR: Failed to curl binary dependency. Rerun the script to retry.\n"; exit 1; }
elif command -v wget &>/dev/null; then wget --waitretry=1 --timeout=15 -t 10 "$GetUrl" -O "$ScriptWorkDir/$BinaryName";
else printf "\n%bcurl/wget not available - get %s manually from the repo link, exiting.%b" "$c_red" "$BinaryName" "$c_reset"; exit 1;
fi
@@ -346,15 +348,19 @@ list_options() {
}
# Version check & initiate self update
-if [[ "$VERSION" != "$LatestRelease" ]]; then
- printf "New version available! %b%s%b ⇒ %b%s%b \n Change Notes: %s \n" "$c_yellow" "$VERSION" "$c_reset" "$c_green" "$LatestRelease" "$c_reset" "$LatestChanges"
- if [[ "$AutoMode" == false ]]; then
- read -r -p "Would you like to update? y/[n]: " SelfUpdate
- [[ "$SelfUpdate" =~ [yY] ]] && self_update
- elif [[ "$AutoMode" == true ]] && [[ "$AutoSelfUpdate" == true ]]; then self_update;
- else
- [[ "$Notify" == true ]] && { exec_if_exists_or_fail dockcheck_notification "$VERSION" "$LatestRelease" "$LatestChanges" || printf "Could not source notification function.\n"; }
+if [[ "$LatestRelease" != "undefined" ]]; then
+ if [[ "$VERSION" != "$LatestRelease" ]]; then
+ printf "New version available! %b%s%b ⇒ %b%s%b \n Change Notes: %s \n" "$c_yellow" "$VERSION" "$c_reset" "$c_green" "$LatestRelease" "$c_reset" "$LatestChanges"
+ if [[ "$AutoMode" == false ]]; then
+ read -r -p "Would you like to update? y/[n]: " SelfUpdate
+ [[ "$SelfUpdate" =~ [yY] ]] && self_update
+ elif [[ "$AutoMode" == true ]] && [[ "$AutoSelfUpdate" == true ]]; then self_update;
+ else
+ [[ "$Notify" == true ]] && { exec_if_exists_or_fail dockcheck_notification "$VERSION" "$LatestRelease" "$LatestChanges" || printf "Could not source notification function.\n"; }
+ fi
fi
+else
+ printf "ERROR: Failed to curl latest Dockcheck.sh release version.\n"
fi
# Version check for notify templates
@@ -420,7 +426,7 @@ check_image() {
# Checking for errors while setting the variable
if RegHash=$($t_out "$regbin" -v error image digest --list "$RepoUrl" 2>&1); then
- if [[ "$LocalHash" = *"$RegHash"* ]]; then
+ if [[ "$LocalHash" == *"$RegHash"* ]]; then
printf "%s\n" "NoUpdates $i"
else
if [[ -n "${DaysOld:-}" ]] && ! datecheck; then
@@ -568,7 +574,7 @@ if [[ -n "${GotUpdates:-}" ]]; then
# cd to the compose-file directory to account for people who use relative volumes
cd "$ContPath" || { printf "\n%bPath error - skipping%b %s" "$c_red" "$c_reset" "$i"; continue; }
## Reformatting path + multi compose
- if [[ $ContConfigFile = '/'* ]]; then
+ if [[ $ContConfigFile == '/'* ]]; then
CompleteConfs=$(for conf in ${ContConfigFile//,/ }; do printf -- "-f %s " "$conf"; done)
else
CompleteConfs=$(for conf in ${ContConfigFile//,/ }; do printf -- "-f %s/%s " "$ContPath" "$conf"; done)
diff --git a/notify_templates/notify_DSM.sh b/notify_templates/notify_DSM.sh
index edfb51f..08d85c1 100644
--- a/notify_templates/notify_DSM.sh
+++ b/notify_templates/notify_DSM.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_DSM_VERSION="v0.2"
+NOTIFY_DSM_VERSION="v0.3"
# INFO: ssmtp is deprecated - consider to use msmtp instead.
#
# mSMTP/sSMTP has to be installed and configured manually.
@@ -45,6 +45,11 @@ Content-Transfer-Encoding: 7bit
$MessageBody
From $SenderName
__EOF
+
+if [[ $? -gt 0 ]]; then
+ NotifyError=true
+fi
+
# This ensures DSM's container manager will also see the update
/var/packages/ContainerManager/target/tool/image_upgradable_checker
}
diff --git a/notify_templates/notify_apprise.sh b/notify_templates/notify_apprise.sh
index 4da3d71..1fa94de 100644
--- a/notify_templates/notify_apprise.sh
+++ b/notify_templates/notify_apprise.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_APPRISE_VERSION="v0.2"
+NOTIFY_APPRISE_VERSION="v0.3"
#
# Required receiving services must already be set up.
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
@@ -18,6 +18,10 @@ trigger_apprise_notification() {
if [[ -n "${APPRISE_PAYLOAD:-}" ]]; then
apprise -vv -t "$MessageTitle" -b "$MessageBody" \
${APPRISE_PAYLOAD}
+
+ if [[ $? -gt 0 ]]; then
+ NotifyError=true
+ fi
fi
# e.g. APPRISE_PAYLOAD='mailto://myemail:mypass@gmail.com
@@ -27,6 +31,10 @@ trigger_apprise_notification() {
if [[ -n "${APPRISE_URL:-}" ]]; then
AppriseURL="${APPRISE_URL}"
- curl -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL # e.g. APPRISE_URL=http://apprise.mydomain.tld:1234/notify/apprise
+ curl -S -o /dev/null ${CurlArgs} -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL # e.g. APPRISE_URL=http://apprise.mydomain.tld:1234/notify/apprise
+
+ if [[ $? -gt 0 ]]; then
+ NotifyError=true
+ fi
fi
}
\ No newline at end of file
diff --git a/notify_templates/notify_discord.sh b/notify_templates/notify_discord.sh
index 97bf1fa..fa1a32d 100644
--- a/notify_templates/notify_discord.sh
+++ b/notify_templates/notify_discord.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_DISCORD_VERSION="v0.3"
+NOTIFY_DISCORD_VERSION="v0.4"
#
# Required receiving services must already be set up.
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
@@ -20,5 +20,9 @@ trigger_discord_notification() {
--arg body "$MessageBody" \
'{"username": $username, "content": $body}' )
- curl -sS -o /dev/null --fail -X POST -H "Content-Type: application/json" -d "$JsonData" "$DiscordWebhookUrl"
+ curl -S -o /dev/null ${CurlArgs} -X POST -H "Content-Type: application/json" -d "$JsonData" "$DiscordWebhookUrl"
+
+ if [[ $? -gt 0 ]]; then
+ NotifyError=true
+ fi
}
diff --git a/notify_templates/notify_gotify.sh b/notify_templates/notify_gotify.sh
index 4e373d6..d3d2c67 100644
--- a/notify_templates/notify_gotify.sh
+++ b/notify_templates/notify_gotify.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_GOTIFY_VERSION="v0.3"
+NOTIFY_GOTIFY_VERSION="v0.4"
#
# Required receiving services must already be set up.
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
@@ -28,5 +28,9 @@ trigger_gotify_notification() {
--arg type "$ContentType" \
'{message: $body, title: $title, priority: 5, extras: {"client::display": {"contentType": $type}}}' )
- curl -s -S --data "${JsonData}" -H 'Content-Type: application/json' -X POST "${GotifyUrl}" 1> /dev/null
+ curl -S -o /dev/null ${CurlArgs} --data "${JsonData}" -H 'Content-Type: application/json' -X POST "${GotifyUrl}" 1> /dev/null
+
+ if [[ $? -gt 0 ]]; then
+ NotifyError=true
+ fi
}
diff --git a/notify_templates/notify_matrix.sh b/notify_templates/notify_matrix.sh
index 8cf20b5..bcff5d2 100644
--- a/notify_templates/notify_matrix.sh
+++ b/notify_templates/notify_matrix.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_MATRIX_VERSION="v0.2"
+NOTIFY_MATRIX_VERSION="v0.3"
#
# Required receiving services must already be set up.
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
@@ -19,5 +19,9 @@ trigger_matrix_notification() {
MsgBody="{\"msgtype\":\"m.text\",\"body\":\"$MessageBody\"}"
# URL Example: https://matrix.org/_matrix/client/r0/rooms/!xxxxxx:example.com/send/m.room.message?access_token=xxxxxxxx
- curl -sS -o /dev/null --fail -X POST "$MatrixServer/_matrix/client/r0/rooms/$Room_id/send/m.room.message?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody"
+ curl -S -o /dev/null ${CurlArgs} -X POST "$MatrixServer/_matrix/client/r0/rooms/$Room_id/send/m.room.message?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody"
+
+ if [[ $? -gt 0 ]]; then
+ NotifyError=true
+ fi
}
\ No newline at end of file
diff --git a/notify_templates/notify_ntfy.sh b/notify_templates/notify_ntfy.sh
index b977d6d..d413a2c 100644
--- a/notify_templates/notify_ntfy.sh
+++ b/notify_templates/notify_ntfy.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_NTFY_VERSION="v0.4"
+NOTIFY_NTFYSH_VERSION="v0.5"
#
# Setup app and subscription at https://ntfy.sh
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
@@ -24,9 +24,13 @@ trigger_ntfy_notification() {
ContentType="Markdown: no" #text/plain
fi
- curl -sS -o /dev/null --show-error --fail \
+ curl -S -o /dev/null ${CurlArgs} \
-H "Title: $MessageTitle" \
-H "$ContentType" \
-d "$MessageBody" \
"$NtfyUrl"
+
+ if [[ $? -gt 0 ]]; then
+ NotifyError=true
+ fi
}
diff --git a/notify_templates/notify_pushbullet.sh b/notify_templates/notify_pushbullet.sh
index 182c78d..78dec0b 100644
--- a/notify_templates/notify_pushbullet.sh
+++ b/notify_templates/notify_pushbullet.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_PUSHBULLET_VERSION="v0.2"
+NOTIFY_PUSHBULLET_VERSION="v0.3"
#
# Required receiving services must already be set up.
# Requires jq installed and in PATH.
@@ -18,5 +18,9 @@ trigger_pushbullet_notification() {
PushToken="${PUSHBULLET_TOKEN}" # e.g. PUSHBULLET_TOKEN=token-value
# Requires jq to process json data
- "$jqbin" -n --arg title "$MessageTitle" --arg body "$MessageBody" '{body: $body, title: $title, type: "note"}' | curl -sS -o /dev/null --show-error --fail -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @-
+ "$jqbin" -n --arg title "$MessageTitle" --arg body "$MessageBody" '{body: $body, title: $title, type: "note"}' | curl -S -o /dev/null ${CurlArgs} -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @-
+
+ if [[ $? -gt 0 ]]; then
+ NotifyError=true
+ fi
}
diff --git a/notify_templates/notify_pushover.sh b/notify_templates/notify_pushover.sh
index 2f8bdda..60ffad6 100644
--- a/notify_templates/notify_pushover.sh
+++ b/notify_templates/notify_pushover.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_PUSHOVER_VERSION="v0.2"
+NOTIFY_PUSHOVER_VERSION="v0.3"
#
# Required receiving services must already be set up.
# Requires jq installed and in PATH.
@@ -19,10 +19,14 @@ trigger_pushover_notification() {
PushoverToken="${PUSHOVER_TOKEN}" # e.g. PUSHOVER_TOKEN=token-value
# Sending the notification via Pushover
- curl -sS -o /dev/null --show-error --fail -X POST \
+ curl -S -o /dev/null ${CurlArgs} -X POST \
-F "token=$PushoverToken" \
-F "user=$PushoverUserKey" \
-F "title=$MessageTitle" \
-F "message=$MessageBody" \
$PushoverUrl
+
+ if [[ $? -gt 0 ]]; then
+ NotifyError=true
+ fi
}
\ No newline at end of file
diff --git a/notify_templates/notify_slack.sh b/notify_templates/notify_slack.sh
index a760f3d..0a9cd7a 100644
--- a/notify_templates/notify_slack.sh
+++ b/notify_templates/notify_slack.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_SLACK_VERSION="v0.2"
+NOTIFY_SLACK_VERSION="v0.3"
#
# Setup app and token at https://api.slack.com/tutorials/tracks/posting-messages-with-curl
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
@@ -17,8 +17,12 @@ trigger_slack_notification() {
ChannelID="${SLACK_CHANNEL_ID}" # e.g. CHANNEL_ID=mychannel
SlackUrl="https://slack.com/api/chat.postMessage"
- curl -sS -o /dev/null --show-error --fail \
+ curl -S -o /dev/null ${CurlArgs} \
-d "text=$MessageBody" -d "channel=$ChannelID" \
-H "Authorization: Bearer $AccessToken" \
-X POST $SlackUrl
+
+ if [[ $? -gt 0 ]]; then
+ NotifyError=true
+ fi
}
diff --git a/notify_templates/notify_smtp.sh b/notify_templates/notify_smtp.sh
index 2889475..f07588c 100644
--- a/notify_templates/notify_smtp.sh
+++ b/notify_templates/notify_smtp.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_SMTP_VERSION="v0.2"
+NOTIFY_SMTP_VERSION="v0.3"
# INFO: ssmtp is depcerated - consider to use msmtp instead.
#
# mSMTP/sSMTP has to be installed and configured manually.
@@ -40,4 +40,8 @@ Content-Transfer-Encoding: 7bit
$MessageBody
__EOF
+
+if [[ $? -gt 0 ]]; then
+ NotifyError=true
+fi
}
diff --git a/notify_templates/notify_telegram.sh b/notify_templates/notify_telegram.sh
index d254490..4f114eb 100644
--- a/notify_templates/notify_telegram.sh
+++ b/notify_templates/notify_telegram.sh
@@ -1,5 +1,5 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
-NOTIFY_TELEGRAM_VERSION="v0.3"
+NOTIFY_TELEGRAM_VERSION="v0.4"
#
# Required receiving services must already be set up.
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
@@ -31,5 +31,9 @@ trigger_telegram_notification() {
--arg parse_mode "$ParseMode" \
'{"chat_id": $chatid, "text": $text, "message_thread_id": $thread, "disable_notification": false, "parse_mode": $parse_mode, "disable_web_page_preview": true}' )
- curl -sS -o /dev/null --fail -X POST "$TelegramUrl/sendMessage" -H 'Content-Type: application/json' -d "$JsonData"
+ curl -S -o /dev/null ${CurlArgs} -X POST "$TelegramUrl/sendMessage" -H 'Content-Type: application/json' -d "$JsonData"
+
+ if [[ $? -gt 0 ]]; then
+ NotifyError=true
+ fi
}
diff --git a/notify_templates/notify_v2.sh b/notify_templates/notify_v2.sh
index 5990e1a..a34acfa 100644
--- a/notify_templates/notify_v2.sh
+++ b/notify_templates/notify_v2.sh
@@ -1,17 +1,28 @@
-NOTIFY_V2_VERSION="v0.2"
+NOTIFY_V2_VERSION="v0.3"
#
# If migrating from an older notify template, remove your existing notify.sh file.
# 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.
+# If you instead wish make your own modifications, make a copy in the same directory as the main dockcheck.sh script and rename to notify.sh.
# Enable and configure all required notification variables in your dockcheck.config file, e.g.:
# NOTIFY_CHANNELS=apprise gotify slack
# SLACK_TOKEN=xoxb-some-token-value
# GOTIFY_TOKEN=some.token
+# Number of seconds to snooze identical update notifications based on local image name
+# or dockcheck.sh/notify.sh template file updates.
+# Actual snooze will be 60 seconds less to avoid the chance of missed notifications due to minor scheduling or script run time issues.
+snooze="${SNOOZE_SECONDS:-}"
+SnoozeFile="${ScriptWorkDir}/snooze.list"
+
enabled_notify_channels=( ${NOTIFY_CHANNELS:-} )
FromHost=$(cat /etc/hostname)
+CurrentEpochTime=$(date +"%Y-%m-%dT%H:%M:%S")
+CurrentEpochSeconds=$(date +%s)
+
+NotifyError=false
+
remove_channel() {
local temp_array=()
for channel in "${enabled_notify_channels[@]}"; do
@@ -26,71 +37,222 @@ for channel in "${enabled_notify_channels[@]}"; do
printf "The notification channel ${channel} is enabled, but notify_${channel}.sh was not found. Check the ${ScriptWorkDir} directory or the notify_templates subdirectory.\n"
done
+notify_containers_count() {
+ unset NotifyContainers
+ NotifyContainers=()
+
+ [[ ! -f "${SnoozeFile}" ]] && touch "${SnoozeFile}"
+
+ for update in "$@"
+ do
+ read -a container <<< "${update}"
+ found=$(grep -w "${container[0]}" "${SnoozeFile}" || printf "")
+
+ if [[ -n "${found}" ]]; then
+ read -a arr <<< "${found}"
+ CheckEpochSeconds=$(( $(date -d "${arr[1]}" +%s 2>/dev/null) + ${snooze} - 60 )) || CheckEpochSeconds=$(( $(date -f "%Y-%m-%d" -j "${arr[1]}" +%s) + ${snooze} - 60 ))
+ if [[ "${CurrentEpochSeconds}" -gt "${CheckEpochSeconds}" ]]; then
+ NotifyContainers+=("${update}")
+ fi
+ else
+ NotifyContainers+=("${update}")
+ fi
+ done
+
+ printf "${#NotifyContainers[@]}"
+}
+
+update_snooze() {
+
+ [[ ! -f "${SnoozeFile}" ]] && touch "${SnoozeFile}"
+
+ for arg in "$@"
+ do
+ read -a entry <<< "${arg}"
+ found=$(grep -w "${entry[0]}" "${SnoozeFile}" || printf "")
+
+ if [[ -n "${found}" ]]; then
+ sed -e "s/${entry[0]}.*/${entry[0]} ${CurrentEpochTime}/" "${SnoozeFile}" > "${SnoozeFile}.new"
+ mv "${SnoozeFile}.new" "${SnoozeFile}"
+ else
+ printf "${entry[0]} ${CurrentEpochTime}\n" >> "${SnoozeFile}"
+ fi
+ done
+}
+
+cleanup_snooze() {
+ unset NotifyEntries
+ NotifyEntries=()
+ switch=""
+
+ [[ ! -f "${SnoozeFile}" ]] && touch "${SnoozeFile}"
+
+ for arg in "$@"
+ do
+ read -a entry <<< "${arg}"
+ NotifyEntries+=("${entry[0]}")
+ done
+
+ if [[ ! "${NotifyEntries[@]}" == *".sh"* ]]; then
+ switch="-v"
+ fi
+
+ while read -r entry datestamp; do
+ if [[ ! "${NotifyEntries[@]}" == *"$entry"* ]]; then
+ sed -e "/${entry}/d" "${SnoozeFile}" > "${SnoozeFile}.new"
+ mv "${SnoozeFile}.new" "${SnoozeFile}"
+ fi
+ done <<< "$(grep ${switch} '\.sh ' ${SnoozeFile})"
+}
+
send_notification() {
[[ -s "$ScriptWorkDir"/urls.list ]] && releasenotes || Updates=("$@")
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
- UpdToString=${UpdToString%\\n}
- for channel in "${enabled_notify_channels[@]}"; do
- printf "\nSending ${channel} notification\n"
+ if [[ -n "${snooze}" ]] && [[ -f "${SnoozeFile}" ]]; then
+ UpdNotifyCount=$(notify_containers_count "${Updates[@]}")
+ else
+ UpdNotifyCount="${#Updates[@]}"
+ fi
- # To be added in the MessageBody if "-d X" was used
- # leading space is left intentionally for clean output
- [[ -n "$DaysOld" ]] && msgdaysold="with images ${DaysOld}+ days old " || msgdaysold=""
+ NotifyError=false
- MessageTitle="$FromHost - updates ${msgdaysold}available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n${UpdToString}\n"
+ if [[ "${UpdNotifyCount}" -gt 0 ]]; then
+ UpdToString=$( printf '%s\\n' "${Updates[@]}" )
+ UpdToString=${UpdToString%\\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"
- done
+ for channel in "${enabled_notify_channels[@]}"; do
+ printf "\nSending ${channel} notification\n"
+
+ # To be added in the MessageBody if "-d X" was used
+ # leading space is left intentionally for clean output
+ [[ -n "$DaysOld" ]] && msgdaysold="with images ${DaysOld}+ days old " || msgdaysold=""
+
+ MessageTitle="$FromHost - updates ${msgdaysold}available."
+ # Setting the MessageBody variable here.
+ printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n${UpdToString}\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"
+ done
+
+ [[ -n "${snooze}" ]] && [[ "${NotifyError}" == "false" ]] && update_snooze "${Updates[@]}"
+ fi
+
+ [[ -n "${snooze}" ]] && cleanup_snooze "${Updates[@]}"
}
### Set DISABLE_DOCKCHECK_NOTIFICATION=false in dockcheck.config
### to not send notifications when dockcheck itself has updates.
dockcheck_notification() {
- if [[ ! "${DISABLE_DOCKCHECK_NOTIFICATION:-}" = "true" ]]; then
- MessageTitle="$FromHost - New version of dockcheck available."
- # Setting the MessageBody variable here.
- printf -v MessageBody "Installed version: $1\nLatest version: $2\n\nChangenotes: $3\n"
+ if [[ ! "${DISABLE_DOCKCHECK_NOTIFICATION:-}" == "true" ]]; then
+ DockcheckNotify=false
+ NotifyError=false
- if [[ ${#enabled_notify_channels[@]} -gt 0 ]]; then printf "\n"; fi
- for channel in "${enabled_notify_channels[@]}"; do
- printf "Sending dockcheck 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"
- done
+ if [[ -n "${snooze}" ]] && [[ -f "${SnoozeFile}" ]]; then
+ found=$(grep -w "dockcheck\.sh" "${SnoozeFile}" || printf "")
+ if [[ -n "${found}" ]]; then
+ read -a arr <<< "${found}"
+ CheckEpochSeconds=$(( $(date -d "${arr[1]}" +%s 2>/dev/null) + ${snooze} - 60 )) || CheckEpochSeconds=$(( $(date -f "%Y-%m-%d" -j "${arr[1]}" +%s) + ${snooze} - 60 ))
+ if [[ "${CurrentEpochSeconds}" -gt "${CheckEpochSeconds}" ]]; then
+ DockcheckNotify=true
+ fi
+ else
+ DockcheckNotify=true
+ fi
+ else
+ DockcheckNotify=true
+ fi
+
+ if [[ "${DockcheckNotify}" == "true" ]]; then
+ MessageTitle="$FromHost - New version of dockcheck available."
+ # Setting the MessageBody variable here.
+ printf -v MessageBody "Installed version: $1\nLatest version: $2\n\nChangenotes: $3\n"
+
+ if [[ ${#enabled_notify_channels[@]} -gt 0 ]]; then printf "\n"; fi
+ for channel in "${enabled_notify_channels[@]}"; do
+ printf "Sending dockcheck 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"
+ done
+
+ if [[ -n "${snooze}" ]] && [[ -f "${SnoozeFile}" ]]; then
+ if [[ "${NotifyError}" == "false" ]]; then
+ if [[ -n "${found}" ]]; then
+ sed -e "s/dockcheck\.sh.*/dockcheck\.sh ${CurrentEpochTime}/" "${SnoozeFile}" > "${SnoozeFile}.new"
+ mv "${SnoozeFile}.new" "${SnoozeFile}"
+ else
+ printf "dockcheck.sh ${CurrentEpochTime}\n" >> "${SnoozeFile}"
+ fi
+ fi
+ fi
+ fi
fi
}
### Set DISABLE_NOTIFY_UPDATE_NOTIFICATION=false in dockcheck.config
### to not send notifications when notify scripts themselves have updates.
notify_update_notification() {
- if [[ ! "${DISABLE_NOTIFY_UPDATE_NOTIFICATION:-}" = "true" ]]; then
- update_channels=( "${enabled_notify_channels[@]}" "v2" )
+ if [[ ! "${DISABLE_NOTIFY_UPDATE_NOTIFICATION:-}" == "true" ]]; then
+ NotifyUpdateNotify=false
+ NotifyError=false
- for notify_script in "${update_channels[@]}"; do
- upper_channel=$(tr '[:lower:]' '[:upper:]' <<< "$notify_script")
- VersionVar="NOTIFY_${upper_channel}_VERSION"
+ UpdateChannels=( "${enabled_notify_channels[@]}" "v2" )
+
+ for NotifyScript in "${UpdateChannels[@]}"; do
+ UpperChannel=$(tr '[:lower:]' '[:upper:]' <<< "$NotifyScript")
+ VersionVar="NOTIFY_${UpperChannel}_VERSION"
if [[ -n "${!VersionVar:-}" ]]; then
- RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_${notify_script}.sh"
- LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_${upper_channel}_VERSION/s/NOTIFY_${upper_channel}_VERSION=//p" | tr -d '"')"
- LatestNotifyRelease=${LatestNotifyRelease:-undefined}
- if [[ ! "${LatestNotifyRelease}" = "undefined" ]]; then
- if [[ "${!VersionVar}" != "$LatestNotifyRelease" ]] ; then
- MessageTitle="$FromHost - New version of notify_${notify_script}.sh available."
-
- printf -v MessageBody "notify_${notify_script}.sh update available:\n ${!VersionVar} -> $LatestNotifyRelease\n"
-
- for channel in "${enabled_notify_channels[@]}"; do
- printf "Sending notify_${notify_script}.sh 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"
- done
+ RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_${NotifyScript}.sh"
+ LatestNotifySnippet="$(curl ${CurlArgs} -r 0-150 "$RawNotifyUrl" || printf "undefined")"
+ LatestNotifyRelease="$(echo "$LatestNotifySnippet" | sed -n "/${VersionVar}/s/${VersionVar}=//p" | tr -d '"')"
+ if [[ ! "${LatestNotifyRelease}" == "undefined" ]]; then
+ if [[ "${!VersionVar}" != "${LatestNotifyRelease}" ]] ; then
+ Updates+=("${NotifyScript}.sh ${!VersionVar} -> ${LatestNotifyRelease}")
fi
fi
fi
done
+
+ if [[ -n "${snooze}" ]] && [[ -f "${SnoozeFile}" ]]; then
+ for update in "${Updates[@]}"; do
+ read -a NotifyScript <<< "${update}"
+ found=$(grep -w "${NotifyScript}" "${SnoozeFile}" || printf "")
+ if [[ -n "${found}" ]]; then
+ read -a arr <<< "${found}"
+ CheckEpochSeconds=$(( $(date -d "${arr[1]}" +%s 2>/dev/null) + ${snooze} - 60 )) || CheckEpochSeconds=$(( $(date -f "%Y-%m-%d" -j "${arr[1]}" +%s) + ${snooze} - 60 ))
+ if [[ "${CurrentEpochSeconds}" -gt "${CheckEpochSeconds}" ]]; then
+ NotifyUpdateNotify=true
+ fi
+ else
+ NotifyUpdateNotify=true
+ fi
+ done
+ else
+ NotifyUpdateNotify=true
+ fi
+
+ if [[ "${NotifyUpdateNotify}" == "true" ]]; then
+ if [[ "${#Updates[@]}" -gt 0 ]]; then
+ UpdToString=$( printf '%s\\n' "${Updates[@]}" )
+ UpdToString=${UpdToString%\\n}
+ NotifyError=false
+
+ MessageTitle="$FromHost - New version of notify templates available."
+
+ 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"
+ done
+
+ [[ -n "${snooze}" ]] && [[ "${NotifyError}" == "false" ]] && update_snooze "${Updates[@]}"
+ fi
+ fi
+
+ UpdatesPlusDockcheck=("${Updates[@]}")
+ UpdatesPlusDockcheck+=("dockcheck.sh")
+ [[ -n "${snooze}" ]] && cleanup_snooze "${UpdatesPlusDockcheck[@]}"
fi
}
From 77f024bb81a741fbc74638ab3e267b17ea8c5e72 Mon Sep 17 00:00:00 2001
From: vorezal <37914382+vorezal@users.noreply.github.com>
Date: Fri, 27 Jun 2025 03:10:31 -0400
Subject: [PATCH 19/55] Fix unbound variable, potential collision, and config
variable. (#209)
* Fix unbound variable, potential collision, and config variable.
* Return 0 when notification functions finish successfully
---------
Co-authored-by: Matthew Oleksowicz
---
notify_templates/notify_v2.sh | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/notify_templates/notify_v2.sh b/notify_templates/notify_v2.sh
index a34acfa..3329512 100644
--- a/notify_templates/notify_v2.sh
+++ b/notify_templates/notify_v2.sh
@@ -139,6 +139,8 @@ send_notification() {
fi
[[ -n "${snooze}" ]] && cleanup_snooze "${Updates[@]}"
+
+ return 0
}
### Set DISABLE_DOCKCHECK_NOTIFICATION=false in dockcheck.config
@@ -187,14 +189,17 @@ dockcheck_notification() {
fi
fi
fi
+
+ return 0
}
-### Set DISABLE_NOTIFY_UPDATE_NOTIFICATION=false in dockcheck.config
+### Set DISABLE_NOTIFY_NOTIFICATION=false in dockcheck.config
### to not send notifications when notify scripts themselves have updates.
notify_update_notification() {
- if [[ ! "${DISABLE_NOTIFY_UPDATE_NOTIFICATION:-}" == "true" ]]; then
+ if [[ ! "${DISABLE_NOTIFY_NOTIFICATION:-}" == "true" ]]; then
NotifyUpdateNotify=false
NotifyError=false
+ NotifyUpdates=()
UpdateChannels=( "${enabled_notify_channels[@]}" "v2" )
@@ -207,14 +212,14 @@ notify_update_notification() {
LatestNotifyRelease="$(echo "$LatestNotifySnippet" | sed -n "/${VersionVar}/s/${VersionVar}=//p" | tr -d '"')"
if [[ ! "${LatestNotifyRelease}" == "undefined" ]]; then
if [[ "${!VersionVar}" != "${LatestNotifyRelease}" ]] ; then
- Updates+=("${NotifyScript}.sh ${!VersionVar} -> ${LatestNotifyRelease}")
+ NotifyUpdates+=("${NotifyScript}.sh ${!VersionVar} -> ${LatestNotifyRelease}")
fi
fi
fi
done
if [[ -n "${snooze}" ]] && [[ -f "${SnoozeFile}" ]]; then
- for update in "${Updates[@]}"; do
+ for update in "${NotifyUpdates[@]}"; do
read -a NotifyScript <<< "${update}"
found=$(grep -w "${NotifyScript}" "${SnoozeFile}" || printf "")
if [[ -n "${found}" ]]; then
@@ -232,8 +237,8 @@ notify_update_notification() {
fi
if [[ "${NotifyUpdateNotify}" == "true" ]]; then
- if [[ "${#Updates[@]}" -gt 0 ]]; then
- UpdToString=$( printf '%s\\n' "${Updates[@]}" )
+ if [[ "${#NotifyUpdates[@]}" -gt 0 ]]; then
+ UpdToString=$( printf '%s\\n' "${NotifyUpdates[@]}" )
UpdToString=${UpdToString%\\n}
NotifyError=false
@@ -247,12 +252,14 @@ notify_update_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"
done
- [[ -n "${snooze}" ]] && [[ "${NotifyError}" == "false" ]] && update_snooze "${Updates[@]}"
+ [[ -n "${snooze}" ]] && [[ "${NotifyError}" == "false" ]] && update_snooze "${NotifyUpdates[@]}"
fi
fi
- UpdatesPlusDockcheck=("${Updates[@]}")
+ UpdatesPlusDockcheck=("${NotifyUpdates[@]}")
UpdatesPlusDockcheck+=("dockcheck.sh")
[[ -n "${snooze}" ]] && cleanup_snooze "${UpdatesPlusDockcheck[@]}"
fi
+
+ return 0
}
From d37e1a102434b17ac9f0e5bcaee607839ecf2262 Mon Sep 17 00:00:00 2001
From: mag37
Date: Fri, 27 Jun 2025 09:22:10 +0200
Subject: [PATCH 20/55] Bugfixes for unbound variable, potential collision and
config variable mismatch
Version bump to alert users of the latest bugfixes for unbound variable, potential collision and config variable mismatch.
---
notify_templates/notify_v2.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/notify_templates/notify_v2.sh b/notify_templates/notify_v2.sh
index 3329512..c2d8538 100644
--- a/notify_templates/notify_v2.sh
+++ b/notify_templates/notify_v2.sh
@@ -1,4 +1,4 @@
-NOTIFY_V2_VERSION="v0.3"
+NOTIFY_V2_VERSION="v0.4"
#
# If migrating from an older notify template, remove your existing notify.sh file.
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
From 69c06de1bddf6ac9a691b476c80434ad6cad360a Mon Sep 17 00:00:00 2001
From: op4lat <155382511+op4lat@users.noreply.github.com>
Date: Tue, 1 Jul 2025 16:19:15 -0400
Subject: [PATCH 21/55] Add DisplaySourcedFiles variable (#207)
* Add DisplaySourcedFiles variable to be used in source_if_exists and source_if_exists_or_fail functions
* Added return 0 as to not throw wrong exit code.
* Delete source_if_exists. source_if_exists_or_fail returns success or failure. Failure doesn't stop the script
---------
Co-authored-by: Elephant Quater
Co-authored-by: mag37
---
default.config | 1 +
dockcheck.sh | 14 ++++++++------
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/default.config b/default.config
index 2831591..27bb52c 100644
--- a/default.config
+++ b/default.config
@@ -26,6 +26,7 @@
#CurlRetryDelay=1 # Time between curl retries
#CurlRetryCount=3 # Max number of curl retries
#CurlConnectTimeout=5 # Time to wait for curl to establish a connection before failing
+#DisplaySourcedFiles=false # Display what files are being sourced/used
### Notify settings
## All commented values are examples only. Modify as needed.
diff --git a/dockcheck.sh b/dockcheck.sh
index d341ce9..183027c 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -14,16 +14,18 @@ ScriptPath="$(readlink -f "$0")"
ScriptWorkDir="$(dirname "$ScriptPath")"
# Source helper functions
-source_if_exists() {
- if [[ -s "$1" ]]; then source "$1"; fi
-}
-
source_if_exists_or_fail() {
- [[ -s "$1" ]] && source "$1"
+ if [[ -s "$1" ]]; then
+ source "$1"
+ [[ "${DisplaySourcedFiles:-false}" == true ]] && echo " * sourced config: ${1}"
+ return 0
+ else
+ return 1
+ fi
}
# User customizable defaults
-source_if_exists_or_fail "${HOME}/.config/dockcheck.config" || source_if_exists "${ScriptWorkDir}/dockcheck.config"
+source_if_exists_or_fail "${HOME}/.config/dockcheck.config" || source_if_exists_or_fail "${ScriptWorkDir}/dockcheck.config"
# Help Function
Help() {
From a1e7446753d582aac1e41ddec23c960c08812bd0 Mon Sep 17 00:00:00 2001
From: mag37
Date: Tue, 1 Jul 2025 22:27:54 +0200
Subject: [PATCH 22/55] version bump + readme
---
README.md | 5 ++++-
dockcheck.sh | 4 ++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 751e7b2..be80a36 100644
--- a/README.md
+++ b/README.md
@@ -20,6 +20,9 @@
___
## :bell: Changelog
+- **v0.6.8**:
+ - Bugfix: Unbound variable in notify_v2.sh
+ - New option: "DisplaySourcedFiles" *config* added to list what files get sourced
- **v0.6.7**: Snooze feature, curl, and consolidation
- Added snooze feature to delay notifications
- Added configurable default curl arguments
@@ -168,7 +171,7 @@ copy it to `notify.sh` alongside the script, modify it to your needs! (notify.sh
#### Snooze feature:
**Use case:** You wish to be notified of available updates in a timely manner, but do not require reminders after the initial notification with the same frequency.
e.g. *Dockcheck is scheduled to run every hour. You will receive an update notification within an hour of availability.*
-**Snooze enabled:** you will not receive another notification about updates for this container for a configurable period of time.
+**Snooze enabled:** you will not receive another notification about updates for this container for a configurable period of time.
**Snooze disabled:** you will receive additional notifications every hour.
To enable snooze, uncomment the `SNOOZE_SECONDS` variable in your `dockcheck.config` file and set it to the number of seconds you wish to prevent duplicate alerts.
diff --git a/dockcheck.sh b/dockcheck.sh
index 183027c..dafa2ce 100755
--- a/dockcheck.sh
+++ b/dockcheck.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-VERSION="v0.6.7"
-# ChangeNotes: snooze feature (see readme), curl arguments, cleanup.
+VERSION="v0.6.8"
+# ChangeNotes: bugfix unbound variable in notify_v2, new option "DisplaySourcedFiles" added to config
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
From 98e996caa3cca8e2d048b672aa22f2d33ed90dbc Mon Sep 17 00:00:00 2001
From: mag37
Date: Mon, 7 Jul 2025 10:49:32 +0200
Subject: [PATCH 23/55] added paypay sponsor
---
README.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/README.md b/README.md
index be80a36..dfac061 100644
--- a/README.md
+++ b/README.md
@@ -5,9 +5,11 @@
+
+
CLI tool to automate docker image updates or notifying when updates are available.
From e2dbd69c5e428b94b1b7966b257f304a890e87e1 Mon Sep 17 00:00:00 2001
From: Rasmus Lundsgaard
Date: Mon, 14 Jul 2025 13:59:07 +0200
Subject: [PATCH 24/55] first version of notification to Home Assistant (#213)
* first working version of notification to Home Assistant
* add documentation links
* update readme for notify_HA
---
README.md | 2 ++
default.config | 7 ++++++-
notify_templates/notify_HA.sh | 31 +++++++++++++++++++++++++++++++
3 files changed, 39 insertions(+), 1 deletion(-)
create mode 100755 notify_templates/notify_HA.sh
diff --git a/README.md b/README.md
index dfac061..6fec3fc 100644
--- a/README.md
+++ b/README.md
@@ -147,6 +147,7 @@ Make certain your project directory is laid out as below. You only need the noti
│ ├── notify_discord.sh
│ ├── notify_generic.sh
│ ├── notify_gotify.sh
+│ ├── notify_HA.sh
│ ├── notify_matrix.sh
│ ├── notify_ntfy.sh
│ ├── notify_pushbullet.sh
@@ -190,6 +191,7 @@ If an update becomes available for an item that is not snoozed, notifications wi
- Read the [QuickStart](extras/apprise_quickstart.md)
- [ntfy](https://ntfy.sh/) - HTTP-based pub-sub notifications.
- [Gotify](https://gotify.net/) - a simple server for sending and receiving messages.
+- [Home Assistant](https://www.home-assistant.io/integrations/notify/) - Connection to the notify [integrations](https://www.home-assistant.io/integrations/#notifications).
- [Pushbullet](https://www.pushbullet.com/) - connecting different devices with cross-platform features.
- [Telegram](https://telegram.org/) - Telegram chat API.
- [Matrix-Synapse](https://github.com/element-hq/synapse) - [Matrix](https://matrix.org/), open, secure, decentralised communication.
diff --git a/default.config b/default.config
index 27bb52c..49457f0 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 gotify matrix ntfy pushbullet pushover slack smtp telegram"
+# NOTIFY_CHANNELS="apprise discord DSM 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
@@ -57,6 +57,10 @@
# GOTIFY_DOMAIN="https://gotify.domain.tld"
# GOTIFY_TOKEN="token-value"
#
+# HA_ENTITY="entity"
+# HA_TOKEN="token"
+# HA_URL="https://your.homeassistant.url"
+#
# MATRIX_ACCESS_TOKEN="token-value"
# MATRIX_ROOM_ID="myroom"
# MATRIX_SERVER_URL="https://matrix.yourdomain.tld"
@@ -82,3 +86,4 @@
# TELEGRAM_CHAT_ID="mychatid"
# TELEGRAM_TOKEN="token-value"
# TELEGRAM_TOPIC_ID="0"
+
diff --git a/notify_templates/notify_HA.sh b/notify_templates/notify_HA.sh
new file mode 100755
index 0000000..dda74be
--- /dev/null
+++ b/notify_templates/notify_HA.sh
@@ -0,0 +1,31 @@
+### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
+NOTIFY_HA_VERSION="v0.1"
+#
+# This is an integration that makes it possible to send notifications via Home Assistant (https://www.home-assistant.io/integrations/notify/)
+# You need to generate a long-lived access token in Home Sssistant to be used here (https://developers.home-assistant.io/docs/auth_api/#long-lived-access-token)
+# 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.
+# Do not modify this file directly within the "notify_templates" subdirectory. Set HA_ENTITY, HA_URL and HA_TOKEN in your dockcheck.config file.
+
+if [[ -z "${HA_ENTITY:-}" ]] || [[ -z "${HA_URL:-}" ]] || [[ -z "${HA_TOKEN:-}" ]]; then
+ printf "Home Assistant notification channel enabled, but required configuration variables are missing. Home assistant notifications will not be sent.\n"
+
+ remove_channel HA
+fi
+
+trigger_HA_notification() {
+ AccessToken="${HA_TOKEN}"
+ Url="${HA_URL}/api/services/notify/${HA_ENTITY}"
+ JsonData=$( "$jqbin" -n \
+ --arg body "$MessageBody" \
+ '{"title": "dockcheck update", "message": $body}' )
+
+ curl -S -o /dev/null ${CurlArgs} \
+ -H "Authorization: Bearer $AccessToken" \
+ -H "Content-Type: application/json" \
+ -d "$JsonData" -X POST $Url
+
+ if [[ $? -gt 0 ]]; then
+ NotifyError=true
+ fi
+}
From cfa74adc3db524e4e89b5dcfb562f8d0d666d4fa Mon Sep 17 00:00:00 2001
From: mag37
Date: Sat, 19 Jul 2025 00:40:50 +0200
Subject: [PATCH 25/55] added new logo
---
extras/dockcheck_colour.png | Bin 0 -> 147760 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 extras/dockcheck_colour.png
diff --git a/extras/dockcheck_colour.png b/extras/dockcheck_colour.png
new file mode 100644
index 0000000000000000000000000000000000000000..1ae6f8f14c0ce2c007c4756d896e0d0c72a59f8d
GIT binary patch
literal 147760
zcmeFZXH=9~(>99ZC^H5SL6GdgC;|c^NND0HK|w)4K*@p%l0%b2<1i{2QGy~3DmGC-
zBxjK*AUR2fCP=2qxliq8p6B~cSnK>b|IXWMG4wR|z3;tiS6y}0Rl5zirKWuR2+I*F
zDyrkxuPJC!QBnVfettU)pPYXg`4oQrZh!5r6BQNvGxT#HY@GA}K4iu!-oa|wJ;b`+
zb9_MM>gp=^$kxiq?4JDtK|4qDH}ldgR8(iEt}Fa?+bwo>VAH98-FtG=mD57hx90c>
zs^15HrPcVLpc3^!-(|EfeDwMQzL!6~%{FD~=jP^;zwR8`HnzS=`26PeeV3E9#6MkJ
zysm$KfM>W)I``L!KM$N(A1IY;d6#~N`p_>MZ@0JIZfDh5R*Y$#O-pSR@|GPkNY^US
zIRJnD@{IYn1HO&P<7wOP8Oc`DG`=48Z$YZ{B
zgB^Z7e?Z-QtU4fbHq2nK^F4fEO^YJmI^l{irvUzYtLCFnO;zETdRkmWeYJ({Ga6~TTiyItSw$rrX$|meWpOfhJoiqFe!%!<=bc!?
z(D5go$=X(ZyZH?~7PkD=*+Y^iy|*!1NoWqj$oG5h-yAp1S