Skip to content

Commit 77d7340

Browse files
authored
Apprise & New option -i
Added new option -i, inform - to send notifications.
2 parents 8e92a3a + 82f6442 commit 77d7340

File tree

7 files changed

+137
-24
lines changed

7 files changed

+137
-24
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# ignore users custom notify.sh
2+
/notify.sh

README.md

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<h4 align="center">With features like excluding specific containers, filter by name, auto-prune dangling images and more.</h4</h3>
1616

1717

18-
### :bell: Recent changes
18+
### :bell: Changelog
19+
- **v0.3.3**: Added Apprise template and the option `-i` inform - to send notifications.
1920
- **v0.3.2**: Added a notify function to wrap a notify-script, currently DSM/Ssmtp + template script.
2021
- **v0.3.1**: Addded option `-m` , monochrome mode - no printf color codes.
2122
- **v0.3.0**: Added option `-d N`, age (days) new images have to be before being pulled and updated.
@@ -31,9 +32,10 @@
3132
___
3233

3334
## Dependencies
34-
Running docker (duh) and compose, either standalone or plugin.
35-
[`regclient/regctl`](https://github.com/regclient/regclient) (Licensed under [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0))
36-
User will be prompted to download `regctl` if not in `PATH` or `PWD`
35+
- Running docker (duh) and compose, either standalone or plugin.
36+
- [`regclient/regctl`](https://github.com/regclient/regclient) (Licensed under [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0))
37+
- User will be prompted to download `regctl` if not in `PATH` or `PWD`.
38+
- regctl requires `amd64/arm64` - see [workaround](#workaround-for-non-amd64--arm64) if other architecture is used.
3739
___
3840

3941

@@ -42,18 +44,20 @@ ___
4244
## `dockcheck.sh`
4345
```
4446
$ ./dockcheck.sh -h
45-
Syntax: dockcheck.sh [OPTION] [part of name to filter]
47+
Syntax: dockcheck.sh [OPTION] [part of name to filter]
4648
Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall
4749
4850
Options:
49-
-h Print this Help.
5051
-a|y Automatic updates, without interaction.
51-
-n No updates, only checking availability.
52+
-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower.
5253
-e X Exclude containers, separated by comma.
53-
-d N Only update to new images that are N+ days old. Lists too recent with +prefix. 2xSlower.
54+
-h Print this Help.
55+
-i Inform - send a preconfigured notification.
56+
-m Monochrome mode, no printf color codes.
57+
-n No updates, only checking availability.
5458
-p Auto-Prune dangling images after update.
5559
-r Allow updating images for docker run, wont update the container.
56-
-s Include stopped containers in the check. (Logic: docker ps -a).
60+
-s Include stopped containers in the check. (Logic: docker ps -a)
5761
```
5862

5963
Basic example:
@@ -75,9 +79,20 @@ Enter number(s) separated by comma, [a] for all - [q] to quit:
7579
Then it proceedes to run `pull` and `up -d` on every container with updates.
7680
After the updates are complete, you'll get prompted if you'd like to prune dangling images.
7781

78-
### Notifications:
82+
### :loudspeaker: Notifications
83+
Trigger with the `-i` flag.
84+
Run it scheduled with `-ni` to only get notified when there's updates available!
85+
86+
Use a `notify_X.sh` template file, copy it to `notify.sh`, modify it to your needs!
87+
Current templates:
88+
- Synology [DSM](https://www.synology.com/en-global/dsm)
89+
- Email with [sSMTP](https://wiki.debian.org/sSMTP)
90+
- Apprise (with it's [multitude](https://github.com/caronc/apprise#supported-notifications) of notifications)
91+
- both native [caronc/apprise](https://github.com/caronc/apprise) and the standalone [linuxserver/docker-apprise-api](https://github.com/linuxserver/docker-apprise-api)
92+
93+
Further additions are welcome - suggestions or PR!
94+
Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).
7995

80-
A simple email notification function is added, with a generic example and DSM/Ssmtp script by [yoyoma2](https://github.com/yoyoma2). Further addons are welcome, suggestions or PR!
8196

8297
### :warning: `-r flag` disclaimer and warning
8398
**Wont auto-update the containers, only their images. (compose is recommended)**
@@ -89,6 +104,27 @@ Containers need to be manually stopped, removed and created again to run on the
89104
- Not respecting `--profile` options when re-creating the container.
90105
- Not working well with containers created by Portainer.
91106

107+
### Workaround for non **amd64** / **arm64**
108+
`regctl` provides binaries for amd64/arm64, to use on other architecture you could try this workaround.
109+
Run regctl in a contianer wrapped in a shell script. Copied from [regclient/docs/install.md](https://github.com/regclient/regclient/blob/main/docs/install.md):
110+
111+
```sh
112+
cat >regctl <<EOF
113+
#!/bin/sh
114+
opts=""
115+
case "\$*" in
116+
"registry login"*) opts="-t";;
117+
esac
118+
docker container run \$opts -i --rm --net host \\
119+
-u "\$(id -u):\$(id -g)" -e HOME -v \$HOME:\$HOME \\
120+
-v /etc/docker/certs.d:/etc/docker/certs.d:ro \\
121+
ghcr.io/regclient/regctl:latest "\$@"
122+
EOF
123+
chmod 755 regctl
124+
```
125+
Test it with `./regctl --help` and then either add the file to the same path as *dockcheck.sh* or in your path (eg. `~/.local/bin/regctl`).
126+
127+
92128
## `dc_brief.sh`
93129
Just a brief, slimmed down version of the script to only print what containers got updates, no updates or errors.
94130

dockcheck.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
2-
VERSION="v0.3.2"
3-
### ChangeNotes: Added a notify function - template and email script (DSM etc)
2+
VERSION="v0.3.3"
3+
### ChangeNotes: Added option -i, inform - notify. Added Appraise template.
44
Github="https://github.com/mag37/dockcheck"
55
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
66

@@ -14,7 +14,6 @@ ScriptWorkDir="$(dirname "$ScriptPath")"
1414
LatestRelease="$(curl -s -r 0-50 $RawUrl | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
1515
LatestChanges="$(curl -s -r 0-200 $RawUrl | sed -n "/ChangeNotes/s/### ChangeNotes: //p")"
1616

17-
[ -s $ScriptWorkDir/notify.sh ] && source $ScriptWorkDir/notify.sh
1817

1918
### Help Function:
2019
Help() {
@@ -26,6 +25,7 @@ Help() {
2625
echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower."
2726
echo "-e X Exclude containers, separated by comma."
2827
echo "-h Print this Help."
28+
echo "-i Inform - send a preconfigured notification."
2929
echo "-m Monochrome mode, no printf color codes."
3030
echo "-n No updates, only checking availability."
3131
echo "-p Auto-Prune dangling images after update."
@@ -41,14 +41,14 @@ c_blue="\033[0;34m"
4141
c_teal="\033[0;36m"
4242
c_reset="\033[0m"
4343

44-
4544
Stopped=""
46-
while getopts "aynprhsme:d:" options; do
45+
while getopts "aynprhisme:d:" options; do
4746
case "${options}" in
4847
a|y) AutoUp="yes" ;;
4948
n) AutoUp="no" ;;
5049
r) DRunUp="yes" ;;
5150
p) AutoPrune="yes" ;;
51+
i) [ -s $ScriptWorkDir/notify.sh ] && { source $ScriptWorkDir/notify.sh ; Notify="yes" ; } ;;
5252
e) Exclude=${OPTARG} ;;
5353
m) declare c_{red,green,yellow,blue,teal,reset}="" ;;
5454
s) Stopped="-a" ;;
@@ -234,7 +234,7 @@ fi
234234
if [[ -n ${GotUpdates[*]} ]] ; then
235235
printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset"
236236
[[ -z "$AutoUp" ]] && options || printf "%s\n" "${GotUpdates[@]}"
237-
[[ $(type -t send_notification) == function ]] && send_notification "${GotUpdates[@]}"
237+
[[ ! -z "$Notify" ]] && { [[ $(type -t send_notification) == function ]] && send_notification "${GotUpdates[@]}" || printf "Could not source notification function.\n" ; }
238238
fi
239239

240240
### Optionally get updates if there's any

notify_DSM.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
2-
# Copy/rename this file to notify.sh to enable email notifications on synology DSM
2+
#
3+
# Copy/rename this file to notify.sh to enable email notifications on Synology DSM
4+
# DSM Notification Email has to be configured manually.
35
# Modify to your liking - changing SendMailTo and Subject and content.
46

57
send_notification() {
68
Updates=("$@")
79
UpdToString=$( printf "%s\n" "${Updates[@]}" )
8-
# change this to your usual destination for synology DSM notification emails
9-
1010
FromHost=$(hostname)
1111

12-
printf "\nSending email notification\n"
12+
# User variables:
13+
# change this to your usual destination for synology DSM notification emails
14+
SendMailTo="[email protected]"
15+
SubjectTag="diskstation"
16+
17+
printf "\nSending email notification.\n"
1318

1419
ssmtp $SendMailTo << __EOF
1520
From: "$FromHost" <$SendMailTo>
1621
date:$(date -R)
1722
To: <$SendMailTo>
18-
Subject: [diskstation] Some docker containers need to be updated
23+
Subject: [$SubjectTag] Updates available on $FromHost
1924
Content-Type: text/plain; charset=UTF-8; format=flowed
2025
Content-Transfer-Encoding: 7bit
2126
22-
The following docker containers on $FromHost need to be updated:
27+
The following containers on $FromHost have updates available:
2328
2429
$UpdToString
2530

notify_apprise.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
2+
#
3+
# Copy/rename this file to notify.sh to enable the notification snippet.
4+
# Required receiving services must already be set up.
5+
# Modify to fit your setup - if API, set AppriseURL to your Apprise ip/domain.
6+
7+
send_notification() {
8+
Updates=("$@")
9+
UpdToString=$( printf "%s\n" "${Updates[@]}" )
10+
FromHost=$(hostname)
11+
12+
printf "\nSending Apprise notification\n"
13+
14+
MessageTitle="$FromHost - updates available."
15+
# Setting the MessageBody variable here.
16+
read -d '\n' MessageBody << __EOF
17+
Containers on $FromHost with updates available:
18+
19+
$UpdToString
20+
21+
__EOF
22+
23+
# Modify to fit your setup:
24+
apprise -vv -t "$MessageTitle" -b "$MessageBody" \
25+
mailto://myemail:[email protected] \
26+
mastodons://{token}@{host} \
27+
pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b \
28+
tgram://{bot_token}/{chat_id}/
29+
30+
### If you use the Apprise-API - Comment out the apprise command above.
31+
### Uncomment the AppriseURL and the curl-line below:
32+
# AppriseURL="http://apprise.mydomain.tld:1234/notify/apprise"
33+
# curl -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL
34+
35+
}
36+
37+

notify_generic.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
2-
# Copy/rename this file to notify.sh to enable email/text notifications
2+
#
3+
# Copy/rename this file to notify.sh to enable the notification snippet.
34
# generic sample, the "Hello World" of notification addons
45

56
send_notification() {

notify_ssmtp.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
2+
#
3+
# Copy/rename this file to notify.sh to enable the notification snipppet.
4+
# sSMTP has to be installed and configured manually.
5+
# Modify to fit your setup - changing SendMailFrom, SendMailTo, SubjectTag
6+
7+
send_notification() {
8+
Updates=("$@")
9+
UpdToString=$( printf "%s\n" "${Updates[@]}" )
10+
FromHost=$(hostname)
11+
12+
# User variables:
13+
SendMailFrom="[email protected]"
14+
SendMailTo="[email protected]"
15+
SubjectTag="dockcheck"
16+
17+
printf "\nSending email notification.\n"
18+
19+
ssmtp $SendMailTo << __EOF
20+
From: "$FromHost" <$SendMailFrom>
21+
date:$(date -R)
22+
To: <$SendMailTo>
23+
Subject: [$SubjectTag] Updates available on $FromHost
24+
Content-Type: text/plain; charset=UTF-8; format=flowed
25+
Content-Transfer-Encoding: 7bit
26+
27+
The following containers on $FromHost have updates available:
28+
29+
$UpdToString
30+
31+
__EOF
32+
}

0 commit comments

Comments
 (0)