mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-17 18:07:46 +00:00
Compare commits
169 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
331d2cc5a7 | ||
|
|
35f460ed61 | ||
|
|
aab63901d0 | ||
|
|
5e53fabbf6 | ||
|
|
8b3926fd5d | ||
|
|
049413cf5a | ||
|
|
b1b7f048a3 | ||
|
|
361e98c378 | ||
|
|
d1ad0c68f6 | ||
|
|
76697bc281 | ||
|
|
86649fb0fe | ||
|
|
80f7dd9b82 | ||
|
|
959f636152 | ||
|
|
d1bf9256fa | ||
|
|
5513e13109 | ||
|
|
f0b2f7eab7 | ||
|
|
44a90d5e62 | ||
|
|
c63643dde8 | ||
|
|
b2767864ab | ||
|
|
c09e813aad | ||
|
|
0b52dd50b6 | ||
|
|
b86df76fb6 | ||
|
|
b8450aa774 | ||
|
|
aa9421adda | ||
|
|
f853bfd318 | ||
|
|
292b3e1a32 | ||
|
|
4c26768374 | ||
|
|
b7f8b67232 | ||
|
|
a63a509bd2 | ||
|
|
5ed3b90ca4 | ||
|
|
78d11d1b37 | ||
|
|
dfe6cf3e08 | ||
|
|
3bc7352b54 | ||
|
|
1470055329 | ||
|
|
904cd508d1 | ||
|
|
8ee1366505 | ||
|
|
c063b09003 | ||
|
|
ea096b5dbc | ||
|
|
038a30b628 | ||
|
|
24d82d74b3 | ||
|
|
8ecc354663 | ||
|
|
4a2daa9899 | ||
|
|
ae8a232a1a | ||
|
|
abbb924867 | ||
|
|
05d21a707a | ||
|
|
4817d75d94 | ||
|
|
32f6d428d3 | ||
|
|
4a8afde790 | ||
|
|
ae53fe2cc7 | ||
|
|
722fb90ce2 | ||
|
|
18947a462d | ||
|
|
0887025412 | ||
|
|
e331dda080 | ||
|
|
5b87072b11 | ||
|
|
6b2af36841 | ||
|
|
bad7bfdf86 | ||
|
|
2a604ff8bd | ||
|
|
e1b26fb772 | ||
|
|
9e4b445c50 | ||
|
|
55323b7562 | ||
|
|
51c8a7a05d | ||
|
|
6a3c78d907 | ||
|
|
4b6173683b | ||
|
|
fb4e9fd521 | ||
|
|
e00bfb1d21 | ||
|
|
77d7340e5b | ||
|
|
82f6442933 | ||
|
|
6c37e255fb | ||
|
|
61e247f0ea | ||
|
|
b540ffa119 | ||
|
|
edf6d5bd72 | ||
|
|
92ba4a184e | ||
|
|
47ebb75691 | ||
|
|
3053304356 | ||
|
|
63b35ab2c3 | ||
|
|
45dbe65c28 | ||
|
|
ae5cd4d86e | ||
|
|
58bb55c79a | ||
|
|
fe31aed33c | ||
|
|
5485a3b2cf | ||
|
|
94fd34478b | ||
|
|
8e92a3a4cb | ||
|
|
9ead0feb9f | ||
|
|
2e620cd2c0 | ||
|
|
fc7b2888f1 | ||
|
|
e15a8e9dbf | ||
|
|
342ff271ca | ||
|
|
3f56af0c8a | ||
|
|
ab3aaf1140 | ||
|
|
80a81f59d6 | ||
|
|
ba3f436ac9 | ||
|
|
24438124eb | ||
|
|
e39ea0748f | ||
|
|
ab30f22343 | ||
|
|
d39badea36 | ||
|
|
9a1f2aa7c7 | ||
|
|
15d3a96b2c | ||
|
|
fbd27d6e37 | ||
|
|
7bd5f87ed1 | ||
|
|
e24cba0078 | ||
|
|
886379dc7d | ||
|
|
488669b99a | ||
|
|
e20fdd9e85 | ||
|
|
3d1c424d23 | ||
|
|
132fda3388 | ||
|
|
cc9b3b0828 | ||
|
|
29c2c5e961 | ||
|
|
5dc9af9874 | ||
|
|
f91ca08d54 | ||
|
|
9a246b52c4 | ||
|
|
0c33f581f7 | ||
|
|
b492aacf0f | ||
|
|
f498138d4b | ||
|
|
6a3198eb08 | ||
|
|
48bfea9fbf | ||
|
|
f2fc5a4d34 | ||
|
|
f0940e81ec | ||
|
|
a25e648557 | ||
|
|
0e2bdc94ad | ||
|
|
19eb57077f | ||
|
|
1f28c9c144 | ||
|
|
0d6da201b7 | ||
|
|
ecb1256fbb | ||
|
|
afe97c9de5 | ||
|
|
9b6396f6de | ||
|
|
5e58abd8e9 | ||
|
|
3d7340c91c | ||
|
|
1decbd77b5 | ||
|
|
bcc0c63413 | ||
|
|
4a2bc2dded | ||
|
|
fd67e0dff1 | ||
|
|
0fb95ea616 | ||
|
|
e4cf54c166 | ||
|
|
e677d8513b | ||
|
|
d366d4680c | ||
|
|
76337ee326 | ||
|
|
6cd90e4597 | ||
|
|
08ae7a8d23 | ||
|
|
062c62d071 | ||
|
|
13549c2018 | ||
|
|
9094bedfd3 | ||
|
|
0d4eb4365c | ||
|
|
ac77470dee | ||
|
|
ea7a1cd171 | ||
|
|
40910d83b6 | ||
|
|
d7cc363931 | ||
|
|
4f8d6289c2 | ||
|
|
79febc7356 | ||
|
|
8acff25f0d | ||
|
|
2391d6916b | ||
|
|
e864edc40e | ||
|
|
aac065022c | ||
|
|
3e60468d47 | ||
|
|
09c1b769ca | ||
|
|
5392c48a57 | ||
|
|
cc72411de4 | ||
|
|
026d5296f8 | ||
|
|
f6e2d50949 | ||
|
|
432edbfa75 | ||
|
|
f233cf3b41 | ||
|
|
7630a95442 | ||
|
|
c7304093bd | ||
|
|
d877a86292 | ||
|
|
191d27097d | ||
|
|
4ddb54770e | ||
|
|
c50312dc83 | ||
|
|
c47c703ce9 | ||
|
|
372e79a12c | ||
|
|
5c2cf75b21 |
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# ignore users custom notify.sh
|
||||||
|
/notify.sh
|
||||||
|
# ignore the auto-installed regctl
|
||||||
|
regctl
|
||||||
176
README.md
176
README.md
@@ -1,31 +1,59 @@
|
|||||||
# dockcheck
|
<p align="center">
|
||||||
### A script checking updates for docker images **without pulling** - then selectively auto-update some/all containers.
|
<img src="extras/dockcheck_logo_by_booYah187.png" width="160" title="dockcheck">
|
||||||
___
|
</p>
|
||||||
|
<p align="center">
|
||||||
|
<img src="https://img.shields.io/badge/bash-4.3-green?style=flat-square&logo=gnubash" alt="bash">
|
||||||
|
<a href="https://www.gnu.org/licenses/gpl-3.0.html"><img src="https://img.shields.io/badge/license-GPLv3-red?style=flat-square" alt="GPLv3"></a>
|
||||||
|
<img src="https://img.shields.io/github/v/tag/mag37/dockcheck?style=flat-square&label=release" alt="release">
|
||||||
|
<a href="https://ko-fi.com/mag37"><img src="https://img.shields.io/badge/-Ko--fi-grey?style=flat-square&logo=Ko-fi" alt="Buy me a Coffee"></a>
|
||||||
|
<a href="https://liberapay.com/user-bin-rob/donate"><img src="https://img.shields.io/badge/-LiberaPay-grey?style=flat-square&logo=liberapay" alt="LiberaPay"></a>
|
||||||
|
<a href="https://github.com/sponsors/mag37"><img src="https://img.shields.io/badge/-Sponsor-grey?style=flat-square&logo=github" alt="Github Sponsor"></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
## Dependencies:
|
<h3 align="center">CLI tool to automate docker image updates. <br>No <b>pre-pull</b>, selective, optional notifications and prune when done.</h3>
|
||||||
Running docker (duh) and compose, either standalone or plugin.
|
<h2 align="center">Now with simple notification integrations!</h2>
|
||||||
[`regclient/regctl`](https://github.com/regclient/regclient) (Licensed under [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0))
|
<h4 align="center">With features like excluding specific containers, custom container labels, auto-prune when done and more.</h4>
|
||||||
User will be prompted to download `regctl` if not in `PATH` or `PWD`
|
|
||||||
|
___
|
||||||
|
## :bell: Changelog
|
||||||
|
|
||||||
|
- **v0.4.2**: Added timeout option to skip container if registry check takes too long (10s default).
|
||||||
|
- **v0.4.1**: Syntax and logic cleanups, bugfixes on multi compose and env-files.
|
||||||
|
- **v0.4.0**: Reworked selfupdate (auto git/curl/wget), general syntax cleanup, added -v for version.
|
||||||
|
- **v0.3.8**: Fixed `--env-file` logic to work with multiple env-files.
|
||||||
|
- **v0.3.7**: Added support for [labels](#bookmark-labels), added the `-f` option (force restart stack).
|
||||||
|
- **v0.3.6**: Added pushbullet template.
|
||||||
|
- **v0.3.5**: Added a simple progress bar for the registry checkup.
|
||||||
___
|
___
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## `dockcheck.sh`
|
## :mag_right: `dockcheck.sh`
|
||||||
```
|
```
|
||||||
$ ./dockcheck.sh -h
|
$ ./dockcheck.sh -h
|
||||||
Syntax: dockcheck.sh [OPTION] [part of name to filter]
|
Syntax: dockcheck.sh [OPTION] [part of name to filter]
|
||||||
Example: dockcheck.sh -a ng
|
Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall
|
||||||
|
|
||||||
Options:
|
Options:"
|
||||||
-h Print this Help.
|
|
||||||
-a|y Automatic updates, without interaction.
|
-a|y Automatic updates, without interaction.
|
||||||
|
-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.
|
||||||
|
-h Print this Help.
|
||||||
|
-i Inform - send a preconfigured notification.
|
||||||
|
-l Only update if label is set. See readme.
|
||||||
|
-m Monochrome mode, no printf color codes.
|
||||||
-n No updates, only checking availability.
|
-n No updates, only checking availability.
|
||||||
-p Auto-Prune dangling images after update.
|
-p Auto-Prune dangling images after update.
|
||||||
-r Allow updating images for docker run, wont update the container.
|
-r Allow updating images for docker run, wont update the container.
|
||||||
|
-s Include stopped containers in the check. (Logic: docker ps -a).
|
||||||
|
-t Set a timeout (in seconds) per container for registry checkups, 10 is default.
|
||||||
|
-v Prints current version.
|
||||||
```
|
```
|
||||||
|
|
||||||
Basic example:
|
|
||||||
|
### Basic example:
|
||||||
```
|
```
|
||||||
$ ./dockcheck.sh
|
$ ./dockcheck.sh
|
||||||
. . .
|
. . .
|
||||||
@@ -38,50 +66,110 @@ Containers with updates available:
|
|||||||
2) syncthing
|
2) syncthing
|
||||||
3) whoogle-search
|
3) whoogle-search
|
||||||
|
|
||||||
|
|
||||||
Choose what containers to update:
|
Choose what containers to update:
|
||||||
Enter number(s) separated by comma, [a] for all - [q] to quit:
|
Enter number(s) separated by comma, [a] for all - [q] to quit:
|
||||||
|
|
||||||
```
|
```
|
||||||
Then it proceedes to run `pull` and `up -d` on every container with updates.
|
Then it proceedes to run `pull` and `up -d` on every container with updates.
|
||||||
After the updates are complete, you'll get prompted if you'd like to prune dangling images.
|
After the updates are complete, you'll get prompted if you'd like to prune dangling images.
|
||||||
|
|
||||||
### `-r flag` :warning: disclaimer and warning:
|
___
|
||||||
|
|
||||||
|
## :nut_and_bolt: Dependencies
|
||||||
|
- Running docker (duh) and compose, either standalone or plugin.
|
||||||
|
- [regclient/regctl](https://github.com/regclient/regclient) (Licensed under [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0))
|
||||||
|
- User will be prompted to download `regctl` if not in `PATH` or `PWD`.
|
||||||
|
- regctl requires `amd64/arm64` - see [workaround](#roller_coaster-workaround-for-non-amd64--arm64) if other architecture is used.
|
||||||
|
|
||||||
|
## :tent: Install Instructions
|
||||||
|
Download the script to a directory in **PATH**, I'd suggest using `~/.local/bin` as that's usually in **PATH**.
|
||||||
|
```sh
|
||||||
|
# basic example with curl:
|
||||||
|
curl -L https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh -o ~/.local/bin/dockcheck.sh
|
||||||
|
chmod +x ~/.local/bin/dockcheck.sh
|
||||||
|
|
||||||
|
# or oneliner with wget:
|
||||||
|
wget -O ~/.local/bin/dockcheck.sh "https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh" && chmod +x ~/.local/bin/dockcheck.sh
|
||||||
|
```
|
||||||
|
Then call the script anywhere with just `dockcheck.sh`.
|
||||||
|
Add preferred `notify.sh`-template to the same directory - this will not be touched by the scripts self-update function.
|
||||||
|
|
||||||
|
|
||||||
|
## :loudspeaker: Notifications
|
||||||
|
Trigger with the `-i` flag.
|
||||||
|
Run it scheduled with `-ni` to only get notified when there's updates available!
|
||||||
|
|
||||||
|
Use a `notify_X.sh` template file, copy it to `notify.sh`, modify it to your needs!
|
||||||
|
Current templates:
|
||||||
|
- Synology [DSM](https://www.synology.com/en-global/dsm)
|
||||||
|
- Email with [sSMTP](https://wiki.debian.org/sSMTP)
|
||||||
|
- 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.
|
||||||
|
- [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.
|
||||||
|
|
||||||
|
Further additions are welcome - suggestions or PR!
|
||||||
|
<sub><sup>Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).</sup></sub>
|
||||||
|
|
||||||
|
## :bookmark: Labels
|
||||||
|
Optionally add labels to compose-files. Currently these are the usable labels:
|
||||||
|
```
|
||||||
|
labels:
|
||||||
|
mag37.dockcheck.restart-stack: true
|
||||||
|
mag37.dockcheck.update: 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.
|
||||||
|
|
||||||
|
## :roller_coaster: Workaround for non **amd64** / **arm64**
|
||||||
|
`regctl` provides binaries for amd64/arm64, to use on other architecture you could try this workaround.
|
||||||
|
Run regctl in a container wrapped in a shell script. Copied from [regclient/docs/install.md](https://github.com/regclient/regclient/blob/main/docs/install.md):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cat >regctl <<EOF
|
||||||
|
#!/bin/sh
|
||||||
|
opts=""
|
||||||
|
case "\$*" in
|
||||||
|
"registry login"*) opts="-t";;
|
||||||
|
esac
|
||||||
|
docker container run \$opts -i --rm --net host \\
|
||||||
|
-u "\$(id -u):\$(id -g)" -e HOME -v \$HOME:\$HOME \\
|
||||||
|
-v /etc/docker/certs.d:/etc/docker/certs.d:ro \\
|
||||||
|
ghcr.io/regclient/regctl:latest "\$@"
|
||||||
|
EOF
|
||||||
|
chmod 755 regctl
|
||||||
|
```
|
||||||
|
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`).
|
||||||
|
|
||||||
|
## :guardsman: Function to auth with docker hub before running
|
||||||
|
**Example** - Change names, paths, and remove cat+password flag if you rather get prompted:
|
||||||
|
```sh
|
||||||
|
function dchk {
|
||||||
|
cat ~/pwd.txt | docker login --username YourUser --password-stdin
|
||||||
|
~/dockcheck.sh "$@"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## :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.
|
||||||
|
|
||||||
|
## :warning: `-r flag` disclaimer and warning
|
||||||
**Wont auto-update the containers, only their images. (compose is recommended)**
|
**Wont auto-update the containers, only their images. (compose is recommended)**
|
||||||
`docker run` dont support using new images just by restarting a container.
|
`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.
|
Containers need to be manually stopped, removed and created again to run on the new image.
|
||||||
|
|
||||||
|
## :scroll: License
|
||||||
### :beetle: Squashed Bugs:
|
|
||||||
- ~~No options for running without updates or auto update.~~
|
|
||||||
- ~~No filter to check only specific containers.~~
|
|
||||||
- ~~Faulty registry checkups stopped the updates completely.~~
|
|
||||||
- ~~No clear checks to skip containers producing errors.~~
|
|
||||||
- ~~Multi-digest images didn't correctly check with registry, giving false positives on updates.~~
|
|
||||||
- ~~Not working with filenames other than `docker-compose.yml`~~
|
|
||||||
- ~~Lists are not alphabetically sorted (due to stacks and other parameters)~~
|
|
||||||
- ~~Old `docker-compose` binary-check sometimes returned false error~~
|
|
||||||
- ~~Stacks gets updated as whole, even if only one service is chosen.~~
|
|
||||||
- ~~Path broken occationally (from inspect) - probably due to old docker-compose binary.~~
|
|
||||||
- ~~Script breaks if one of the chosen containers are a `docker run` container.~~
|
|
||||||
- ~~Using relative paths for volumes eg. `${PWD}/data:data` will create the volumes where you stand.~~
|
|
||||||
- ~~Having no curl/wget leads to corrupt `regctl` without alerting.~~
|
|
||||||
- ~~Using custom `.env` files does not work.~~
|
|
||||||
|
|
||||||
### :hammer: Known issues
|
|
||||||
- ~~No granular choice of what to update (except initial name filter).~~
|
|
||||||
- No detailed error feedback (just skip + list what's skipped) .
|
|
||||||
|
|
||||||
## `dc_brief.sh`
|
|
||||||
Just a brief, slimmed down version of the script to only print what containers got updates, no updates or errors.
|
|
||||||
|
|
||||||
# License
|
|
||||||
dockcheck is created and released under the [GNU GPL v3.0](https://www.gnu.org/licenses/gpl-3.0-standalone.html) license.
|
dockcheck is created and released under the [GNU GPL v3.0](https://www.gnu.org/licenses/gpl-3.0-standalone.html) license.
|
||||||
|
|
||||||
|
### :floppy_disk: The [story](https://mag37.org/posts/project_dockcheck/) behind it. 1 year in retrospect.
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
## Check out a spinoff brother-project:
|
|
||||||
### [Palleri/dockcheck-web](https://github.com/Palleri/dockcheck-web) for a WebUI-front!
|
|
||||||
|
|
||||||
## Special Thanks:
|
## Special Thanks
|
||||||
- :bison: [t0rnis](https://github.com/t0rnis)
|
- :bison: [t0rnis](https://github.com/t0rnis)
|
||||||
- :leopard: [Palleri](https://github.com/Palleri)
|
- :leopard: [Palleri](https://github.com/Palleri)
|
||||||
|
|||||||
321
dockcheck.sh
321
dockcheck.sh
@@ -1,84 +1,101 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
VERSION="v0.1.9"
|
VERSION="v0.4.2"
|
||||||
|
### ChangeNotes: Added timeout option to skip container if registry check takes too long (10s default).
|
||||||
Github="https://github.com/mag37/dockcheck"
|
Github="https://github.com/mag37/dockcheck"
|
||||||
|
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
|
||||||
|
|
||||||
|
### Variables for self updating
|
||||||
|
ScriptArgs=( "$@" )
|
||||||
|
ScriptPath="$(readlink -f "$0")"
|
||||||
|
ScriptWorkDir="$(dirname "$ScriptPath")"
|
||||||
|
|
||||||
### Check if there's a new release of the script:
|
### Check if there's a new release of the script:
|
||||||
LatestRelease="$(curl -s -r 0-50 https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
|
LatestRelease="$(curl -s -r 0-50 $RawUrl | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
|
||||||
[ "$VERSION" != "$LatestRelease" ] && printf "New version available! Latest: %s - Local: %s \nGrab it here: %s \n\n" "$LatestRelease" "$VERSION" "$Github"
|
LatestChanges="$(curl -s -r 0-200 $RawUrl | sed -n "/ChangeNotes/s/### ChangeNotes: //p")"
|
||||||
|
|
||||||
|
|
||||||
### Help Function:
|
### Help Function:
|
||||||
Help() {
|
Help() {
|
||||||
echo "Syntax: dockcheck.sh [OPTION] [part of name to filter]"
|
echo "Syntax: dockcheck.sh [OPTION] [part of name to filter]"
|
||||||
echo "Example: dockcheck.sh -a ng"
|
echo "Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall"
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo "-h Print this Help."
|
|
||||||
echo "-a|y Automatic updates, without interaction."
|
echo "-a|y Automatic updates, without interaction."
|
||||||
|
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 "-h Print this Help."
|
||||||
|
echo "-i Inform - send a preconfigured notification."
|
||||||
|
echo "-l Only update if label is set. See readme."
|
||||||
|
echo "-m Monochrome mode, no printf color codes."
|
||||||
echo "-n No updates, only checking availability."
|
echo "-n No updates, only checking availability."
|
||||||
echo "-p Auto-Prune dangling images after update."
|
echo "-p Auto-Prune dangling images after update."
|
||||||
echo "-r Allow updating images for docker run, wont update the container"
|
echo "-r Allow updating images for docker run, wont 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 "-v Prints current version."
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "aynprh" options; do
|
### Colors:
|
||||||
|
c_red="\033[0;31m"
|
||||||
|
c_green="\033[0;32m"
|
||||||
|
c_yellow="\033[0;33m"
|
||||||
|
c_blue="\033[0;34m"
|
||||||
|
c_teal="\033[0;36m"
|
||||||
|
c_reset="\033[0m"
|
||||||
|
|
||||||
|
Stopped=""
|
||||||
|
while getopts "aynpfrhlisvme:d:t:" options; do
|
||||||
case "${options}" in
|
case "${options}" in
|
||||||
a|y) UpdYes="yes" ;;
|
a|y) AutoUp="yes" ;;
|
||||||
n) UpdYes="no" ;;
|
n) AutoUp="no" ;;
|
||||||
r) DrUp="yes" ;;
|
r) DRunUp="yes" ;;
|
||||||
p) PruneQ="yes" ;;
|
p) AutoPrune="yes" ;;
|
||||||
h|*) Help ; exit 0 ;;
|
l) OnlyLabel=true ;;
|
||||||
|
f) ForceRestartStacks=true ;;
|
||||||
|
i) [ -s "$ScriptWorkDir"/notify.sh ] && { source "$ScriptWorkDir"/notify.sh ; Notify="yes" ; } ;;
|
||||||
|
e) Exclude=${OPTARG} ;;
|
||||||
|
m) declare c_{red,green,yellow,blue,teal,reset}="" ;;
|
||||||
|
s) Stopped="-a" ;;
|
||||||
|
t) Timeout="${OPTARG:-10}" ;;
|
||||||
|
v) printf "%s\n" "$VERSION" ; exit 0 ;;
|
||||||
|
d) DaysOld=${OPTARG}
|
||||||
|
if ! [[ $DaysOld =~ ^[0-9]+$ ]] ; then { printf "Days -d argument given (%s) is not a number.\n" "${DaysOld}" ; exit 2 ; } ; fi ;;
|
||||||
|
h|*) Help ; exit 2 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift "$((OPTIND-1))"
|
shift "$((OPTIND-1))"
|
||||||
|
|
||||||
### Set $1 to a variable for name filtering later.
|
self_update_curl() {
|
||||||
SearchName="$1"
|
cp "$ScriptPath" "$ScriptPath".bak
|
||||||
|
if [[ $(builtin type -P curl) ]]; then
|
||||||
### Check if required binary exists in PATH or directory:
|
curl -L $RawUrl > "$ScriptPath" ; chmod +x "$ScriptPath"
|
||||||
if [[ $(builtin type -P "regctl") ]]; then regbin="regctl" ;
|
printf "\n%s\n" "--- starting over with the updated version ---"
|
||||||
elif [[ -f "./regctl" ]]; then regbin="./regctl" ;
|
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
|
||||||
else
|
exit 1 # exit the old instance
|
||||||
read -r -p "Required dependency 'regctl' missing, do you want it downloaded? y/[n] " GetDep
|
elif [[ $(builtin type -P wget) ]]; then
|
||||||
if [[ "$GetDep" =~ [yY] ]] ; then
|
wget $RawUrl -O "$ScriptPath" ; chmod +x "$ScriptPath"
|
||||||
### Check arch:
|
printf "\n%s\n" "--- starting over with the updated version ---"
|
||||||
case "$(uname --machine)" in
|
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
|
||||||
x86_64|amd64) architecture="amd64" ;;
|
exit 1 # exit the old instance
|
||||||
arm64|aarch64) architecture="arm64";;
|
|
||||||
*) echo "Architecture not supported, exiting." ; exit 1;;
|
|
||||||
esac
|
|
||||||
RegUrl="https://github.com/regclient/regclient/releases/latest/download/regctl-linux-$architecture"
|
|
||||||
if [[ $(builtin type -P curl) ]]; then curl -L $RegUrl > ./regctl ; chmod +x ./regctl ; regbin="./regctl" ;
|
|
||||||
elif [[ $(builtin type -P wget) ]]; then wget $RegUrl -O ./regctl ; chmod +x ./regctl ; regbin="./regctl" ;
|
|
||||||
else
|
|
||||||
printf "%s\n" "curl/wget not available - get regctl manually from the repo link, quitting."
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
printf "%s\n" "Dependency missing, quitting."
|
printf "curl/wget not available - download the update manually: %s \n" "$Github"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
fi
|
}
|
||||||
### final check if binary is correct
|
|
||||||
$regbin version &> /dev/null || { printf "%s\n" "regctl is not working - try to remove it and re-download it, exiting."; exit 1; }
|
|
||||||
|
|
||||||
### Check docker compose binary:
|
self_update() {
|
||||||
if docker compose version &> /dev/null ; then
|
cd "$ScriptWorkDir" || { printf "Path error, skipping update.\n" ; return ; }
|
||||||
DockerBin="docker compose"
|
if [[ $(builtin type -P git) ]] && [[ "$(git ls-remote --get-url 2>/dev/null)" =~ .*"mag37/dockcheck".* ]] ; then
|
||||||
elif docker-compose -v &> /dev/null; then
|
printf "\n%s\n" "Pulling the latest version."
|
||||||
DockerBin="docker-compose"
|
git pull --force || { printf "Git error, manually pull/clone.\n" ; return ; }
|
||||||
elif docker -v &> /dev/null; then
|
printf "\n%s\n" "--- starting over with the updated version ---"
|
||||||
printf "%s\n" "No docker compose binary available, using plain docker (Not recommended!)"
|
cd - || { printf "Path error.\n" ; return ; }
|
||||||
printf "%s\n" "'docker run' will ONLY update images, not the container itself."
|
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
|
||||||
else
|
exit 1 # exit the old instance
|
||||||
printf "%s\n" "No docker binaries available, exiting."
|
else
|
||||||
exit 1
|
cd - || { printf "Path error.\n" ; return ; }
|
||||||
fi
|
self_update_curl
|
||||||
|
fi
|
||||||
### Numbered List -function:
|
|
||||||
options() {
|
|
||||||
num=1
|
|
||||||
for i in "${GotUpdates[@]}"; do
|
|
||||||
echo "$num) $i"
|
|
||||||
((num++))
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
### Choose from list -function:
|
### Choose from list -function:
|
||||||
@@ -106,87 +123,204 @@ choosecontainers() {
|
|||||||
printf "\n"
|
printf "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datecheck() {
|
||||||
|
ImageDate=$($regbin image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 )
|
||||||
|
ImageAge=$(( ( $(date +%s) - $(date -d "$ImageDate" +%s) )/86400 ))
|
||||||
|
if [ "$ImageAge" -gt "$DaysOld" ] ; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
progress_bar() {
|
||||||
|
QueCurrent="$1"
|
||||||
|
QueTotal="$2"
|
||||||
|
((Percent=100*QueCurrent/QueTotal))
|
||||||
|
((Complete=50*Percent/100)) # change first number for width (50)
|
||||||
|
((Left=50-Complete)) # change first number for width (50)
|
||||||
|
BarComplete=$(printf "%${Complete}s" | tr " " "#")
|
||||||
|
BarLeft=$(printf "%${Left}s" | tr " " "-")
|
||||||
|
[[ "$QueTotal" == "$QueCurrent" ]] || printf "\r[%s%s] %s/%s " "$BarComplete" "$BarLeft" "$QueCurrent" "$QueTotal"
|
||||||
|
[[ "$QueTotal" == "$QueCurrent" ]] && printf "\r[%b%s%b] %s/%s \n" "$c_teal" "$BarComplete" "$c_reset" "$QueCurrent" "$QueTotal"
|
||||||
|
}
|
||||||
|
|
||||||
|
### 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 [[ -z "$AutoUp" ]] ; then
|
||||||
|
read -r -p "Would you like to update? y/[n]: " SelfUpdate
|
||||||
|
[[ "$SelfUpdate" =~ [yY] ]] && self_update
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
### Set $1 to a variable for name filtering later.
|
||||||
|
SearchName="$1"
|
||||||
|
### Create array of excludes
|
||||||
|
IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
|
||||||
|
|
||||||
|
### Check if required binary exists in PATH or directory:
|
||||||
|
if [[ $(builtin type -P "regctl") ]]; then regbin="regctl" ;
|
||||||
|
elif [[ -f "$ScriptWorkDir/regctl" ]]; then regbin="$ScriptWorkDir/regctl" ;
|
||||||
|
else
|
||||||
|
read -r -p "Required dependency 'regctl' missing, do you want it downloaded? y/[n] " GetDep
|
||||||
|
if [[ "$GetDep" =~ [yY] ]] ; then
|
||||||
|
### Check arch:
|
||||||
|
case "$(uname --machine)" in
|
||||||
|
x86_64|amd64) architecture="amd64" ;;
|
||||||
|
arm64|aarch64) architecture="arm64";;
|
||||||
|
*) echo "Architecture not supported, exiting." ; exit 1;;
|
||||||
|
esac
|
||||||
|
RegUrl="https://github.com/regclient/regclient/releases/latest/download/regctl-linux-$architecture"
|
||||||
|
if [[ $(builtin type -P curl) ]]; then curl -L $RegUrl > "$ScriptWorkDir/regctl" ; chmod +x "$ScriptWorkDir/regctl" ; regbin="$ScriptWorkDir/regctl" ;
|
||||||
|
elif [[ $(builtin type -P wget) ]]; then wget $RegUrl -O "$ScriptWorkDir/regctl" ; chmod +x "$ScriptWorkDir/regctl" ; regbin="$ScriptWorkDir/regctl" ;
|
||||||
|
else
|
||||||
|
printf "%s\n" "curl/wget not available - get regctl manually from the repo link, quitting."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
printf "%s\n" "Dependency missing, quitting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
### final check if binary is correct
|
||||||
|
$regbin version &> /dev/null || { printf "%s\n" "regctl is not working - try to remove it and re-download it, exiting."; exit 1; }
|
||||||
|
|
||||||
|
### Check docker compose binary:
|
||||||
|
if docker compose version &> /dev/null ; then DockerBin="docker compose" ;
|
||||||
|
elif docker-compose -v &> /dev/null; then DockerBin="docker-compose" ;
|
||||||
|
elif docker -v &> /dev/null; then
|
||||||
|
printf "%s\n" "No docker compose binary available, using plain docker (Not recommended!)"
|
||||||
|
printf "%s\n" "'docker run' will ONLY update images, not the container itself."
|
||||||
|
else
|
||||||
|
printf "%s\n" "No docker binaries available, exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
### Numbered List -function:
|
||||||
|
options() {
|
||||||
|
num=1
|
||||||
|
for i in "${GotUpdates[@]}"; do
|
||||||
|
echo "$num) $i"
|
||||||
|
((num++))
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
### Listing typed exclusions:
|
||||||
|
if [[ -n ${Excludes[*]} ]] ; then
|
||||||
|
printf "\n%bExcluding these names:%b\n" "$c_blue" "$c_reset"
|
||||||
|
printf "%s\n" "${Excludes[@]}"
|
||||||
|
printf "\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Variables for progress_bar function
|
||||||
|
DocCount=$(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}' | wc -l)
|
||||||
|
RegCheckQue=0
|
||||||
|
|
||||||
### Check the image-hash of every running container VS the registry
|
### Check the image-hash of every running container VS the registry
|
||||||
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
|
for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}') ; do
|
||||||
printf ". "
|
((RegCheckQue+=1))
|
||||||
|
progress_bar "$RegCheckQue" "$DocCount"
|
||||||
|
### Looping every item over the list of excluded names and skipping:
|
||||||
|
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
|
||||||
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||||
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
|
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
|
||||||
### Checking for errors while setting the variable:
|
### Checking for errors while setting the variable:
|
||||||
if RegHash=$($regbin image digest --list "$RepoUrl" 2>/dev/null) ; then
|
if RegHash=$(timeout ${Timeout} $regbin image digest --list "$RepoUrl" 2>&1) ; then
|
||||||
if [[ "$LocalHash" = *"$RegHash"* ]] ; then NoUpdates+=("$i"); else GotUpdates+=("$i"); fi
|
if [[ "$LocalHash" = *"$RegHash"* ]] ; then
|
||||||
|
NoUpdates+=("$i")
|
||||||
|
else
|
||||||
|
if [[ -n "$DaysOld" ]] && ! datecheck ; then
|
||||||
|
NoUpdates+=("+$i ${ImageAge}d")
|
||||||
|
else
|
||||||
|
GotUpdates+=("$i")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
GotErrors+=("$i")
|
# Here the RegHash is the result of an error code.
|
||||||
|
GotErrors+=("$i - ${RegHash}")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
### Sort arrays alphabetically
|
### Sort arrays alphabetically
|
||||||
IFS=$'\n'
|
readarray -td '' NoUpdates < <(printf '%s\0' "${NoUpdates[@]}" | sort -z -n)
|
||||||
NoUpdates=($(sort <<<"${NoUpdates[*]}"))
|
readarray -td '' GotUpdates < <(printf '%s\0' "${GotUpdates[@]}" | sort -z -n)
|
||||||
GotUpdates=($(sort <<<"${GotUpdates[*]}"))
|
readarray -td '' GotErrors < <(printf '%s\0' "${GotErrors[@]}" | sort -z -n)
|
||||||
GotErrors=($(sort <<<"${GotErrors[*]}"))
|
|
||||||
unset IFS
|
|
||||||
### Define how many updates are available
|
### Define how many updates are available
|
||||||
UpdCount="${#GotUpdates[@]}"
|
UpdCount="${#GotUpdates[@]}"
|
||||||
|
|
||||||
### List what containers got updates or not
|
### List what containers got updates or not
|
||||||
if [[ -n ${NoUpdates[*]} ]] ; then
|
if [[ -n ${NoUpdates[*]} ]] ; then
|
||||||
printf "\n\033[0;32mContainers on latest version:\033[0m\n"
|
printf "\n%bContainers on latest version:%b\n" "$c_green" "$c_reset"
|
||||||
printf "%s\n" "${NoUpdates[@]}"
|
printf "%s\n" "${NoUpdates[@]}"
|
||||||
fi
|
fi
|
||||||
if [[ -n ${GotErrors[*]} ]] ; then
|
if [[ -n ${GotErrors[*]} ]] ; then
|
||||||
printf "\n\033[0;31mContainers with errors, wont get updated:\033[0m\n"
|
printf "\n%bContainers with errors, wont get updated:%b\n" "$c_red" "$c_reset"
|
||||||
printf "%s\n" "${GotErrors[@]}"
|
printf "%s\n" "${GotErrors[@]}"
|
||||||
|
printf "%binfo:%b 'unauthorized' often means not found in a public registry.\n" "$c_blue" "$c_reset"
|
||||||
fi
|
fi
|
||||||
if [[ -n ${GotUpdates[*]} ]] ; then
|
if [[ -n ${GotUpdates[*]} ]] ; then
|
||||||
printf "\n\033[0;33mContainers with updates available:\033[0m\n"
|
printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset"
|
||||||
[[ -z "$UpdYes" ]] && options || printf "%s\n" "${GotUpdates[@]}"
|
[[ -z "$AutoUp" ]] && options || printf "%s\n" "${GotUpdates[@]}"
|
||||||
|
[[ -n "$Notify" ]] && { [[ $(type -t send_notification) == function ]] && send_notification "${GotUpdates[@]}" || printf "Could not source notification function.\n" ; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### Optionally get updates if there's any
|
### Optionally get updates if there's any
|
||||||
if [ -n "$GotUpdates" ] ; then
|
if [ -n "$GotUpdates" ] ; then
|
||||||
if [ -z "$UpdYes" ] ; then
|
if [ -z "$AutoUp" ] ; then
|
||||||
printf "\n\033[0;36mChoose what containers to update.\033[0m\n"
|
printf "\n%bChoose what containers to update.%b\n" "$c_teal" "$c_reset"
|
||||||
choosecontainers
|
choosecontainers
|
||||||
else
|
else
|
||||||
SelectedUpdates=( "${GotUpdates[@]}" )
|
SelectedUpdates=( "${GotUpdates[@]}" )
|
||||||
fi
|
fi
|
||||||
if [ "$UpdYes" == "${UpdYes#[Nn]}" ] ; then
|
if [ "$AutoUp" == "${AutoUp#[Nn]}" ] ; then
|
||||||
|
NumberofUpdates="${#SelectedUpdates[@]}"
|
||||||
|
CurrentQue=0
|
||||||
for i in "${SelectedUpdates[@]}"
|
for i in "${SelectedUpdates[@]}"
|
||||||
do
|
do
|
||||||
|
((CurrentQue+=1))
|
||||||
|
unset CompleteConfs
|
||||||
ContPath=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.working_dir" }}')
|
ContPath=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.working_dir" }}')
|
||||||
ContConfigFile=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.config_files" }}')
|
ContConfigFile=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.config_files" }}')
|
||||||
ContName=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.service" }}')
|
ContName=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.service" }}')
|
||||||
ContEnv=$(docker inspect "$i" --format '{{index .Config.Labels "com.docker.compose.project.environment_file" }}')
|
ContEnv=$(docker inspect "$i" --format '{{index .Config.Labels "com.docker.compose.project.environment_file" }}')
|
||||||
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
|
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||||
|
ContUpdateLabel=$(docker inspect "$i" --format '{{ index .Config.Labels "mag37.dockcheck.update" }}')
|
||||||
|
ContRestartStack=$(docker inspect "$i" --format '{{ index .Config.Labels "mag37.dockcheck.restart-stack" }}')
|
||||||
### Checking if compose-values are empty - hence started with docker run:
|
### Checking if compose-values are empty - hence started with docker run:
|
||||||
if [ -z "$ContPath" ] ; then
|
if [ -z "$ContPath" ] ; then
|
||||||
if [ "$DrUp" == "yes" ] ; then
|
if [ "$DRunUp" == "yes" ] ; then
|
||||||
docker pull "$ContImage"
|
docker pull "$ContImage"
|
||||||
printf "%s\n" "$i got a new image downloaded, rebuild manually with preferred 'docker run'-parameters"
|
printf "%s\n" "$i got a new image downloaded, rebuild manually with preferred 'docker run'-parameters"
|
||||||
else
|
else
|
||||||
printf "\n\033[33;1m%s\033[0m has no compose labels, probably started with docker run - \033[33;1mskipping\033[0m\n\n" "$i"
|
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
|
fi
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
### Checking if "com.docker.compose.project.config_files" returns the full path to the config file or just the file name
|
|
||||||
if [[ $ContConfigFile = '/'* ]] ; then
|
|
||||||
ComposeFile="$ContConfigFile"
|
|
||||||
else
|
|
||||||
ComposeFile="$ContPath/$ContConfigFile"
|
|
||||||
fi
|
|
||||||
### cd to the compose-file directory to account for people who use relative volumes, eg - ${PWD}/data:data
|
### cd to the compose-file directory to account for people who use relative volumes, eg - ${PWD}/data:data
|
||||||
cd "$(dirname "${ComposeFile}")" || { echo "Path error - skipping $i" ; continue ; }
|
cd "$ContPath" || { echo "Path error - skipping $i" ; continue ; }
|
||||||
docker pull "$ContImage"
|
## Reformatting path + multi compose
|
||||||
### Check if the container got an environment file set, use it if so:
|
if [[ $ContConfigFile = '/'* ]] ; then
|
||||||
if [ -n "$ContEnv" ]; then
|
CompleteConfs=$(for conf in ${ContConfigFile//,/ } ; do printf -- "-f %s " "$conf"; done)
|
||||||
$DockerBin -f "$ComposeFile" --env-file "$ContEnv" up -d "$ContName"
|
|
||||||
else
|
else
|
||||||
$DockerBin -f "$ComposeFile" up -d "$ContName"
|
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"
|
||||||
|
### Check if the container got an environment file set and reformat it
|
||||||
|
if [ -n "$ContEnv" ]; then ContEnvs=$(for env in ${ContEnv//,/ } ; do printf -- "--env-file %s " "$env"; done) ; fi
|
||||||
|
### Check if the whole stack should be restarted
|
||||||
|
if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]] ; then
|
||||||
|
$DockerBin ${CompleteConfs} stop ; $DockerBin ${CompleteConfs} ${ContEnvs} up -d
|
||||||
|
else
|
||||||
|
$DockerBin ${CompleteConfs} ${ContEnvs} up -d ${ContName}
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
printf "\033[0;32mAll done!\033[0m\n"
|
printf "\n%bAll done!%b\n" "$c_green" "$c_reset"
|
||||||
[[ -z "$PruneQ" ]] && read -r -p "Would you like to prune dangling images? y/[n]: " PruneQ
|
[[ -z "$AutoPrune" ]] && read -r -p "Would you like to prune dangling images? y/[n]: " AutoPrune
|
||||||
[[ "$PruneQ" =~ [yY] ]] && docker image prune -f
|
[[ "$AutoPrune" =~ [yY] ]] && docker image prune -f
|
||||||
else
|
else
|
||||||
printf "\nNo updates installed, exiting.\n"
|
printf "\nNo updates installed, exiting.\n"
|
||||||
fi
|
fi
|
||||||
@@ -195,3 +329,4 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|||||||
BIN
example.gif
BIN
example.gif
Binary file not shown.
|
Before Width: | Height: | Size: 333 KiB |
BIN
extras/apprise-ex1.png
Normal file
BIN
extras/apprise-ex1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 155 KiB |
BIN
extras/apprise-ex2.png
Normal file
BIN
extras/apprise-ex2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 114 KiB |
130
extras/apprise_quickstart.md
Normal file
130
extras/apprise_quickstart.md
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
# A small guide on getting started with Apprise notifications.
|
||||||
|
|
||||||
|
|
||||||
|
## Standalone docker container: [linuxserver/apprise-api](https://hub.docker.com/r/linuxserver/apprise-api)
|
||||||
|
|
||||||
|
Set up the docker compose as preferred:
|
||||||
|
```yaml
|
||||||
|
---
|
||||||
|
version: "2.1"
|
||||||
|
services:
|
||||||
|
apprise-api:
|
||||||
|
image: lscr.io/linuxserver/apprise-api:latest
|
||||||
|
container_name: apprise-api
|
||||||
|
environment:
|
||||||
|
- PUID=1000
|
||||||
|
- PGID=1000
|
||||||
|
- TZ=Etc/UTC
|
||||||
|
volumes:
|
||||||
|
- /path/to/apprise-api/config:/config
|
||||||
|
ports:
|
||||||
|
- 8000:8000
|
||||||
|
restart: unless-stopped
|
||||||
|
```
|
||||||
|
|
||||||
|
Then browse to the webui.
|
||||||
|

|
||||||
|
Here you'll click **Configuration Manager**, read the overview and then click on **Configuration**.
|
||||||
|
Under **Configuration** you'll craft/paste your notification config.
|
||||||
|
|
||||||
|

|
||||||
|
The simplest way is just paste the url's as is (like in the example above).
|
||||||
|
There are many ways to customize with tags, groups, json and more. Read [caronc/apprise-api](https://github.com/caronc/apprise-api) for more info!
|
||||||
|
|
||||||
|
Look at the [apprise wiki: Notification Services](https://github.com/caronc/apprise/wiki) for more info about how the url syntax for different services works.
|
||||||
|
|
||||||
|
|
||||||
|
You can also use the [caronc/apprise-api](https://github.com/caronc/apprise-api) to host the api as a frontend to an already existing **Apprise**-setup on the host.
|
||||||
|
|
||||||
|
|
||||||
|
### Customize the **notify.sh** file.
|
||||||
|
After you're done with the setup of the container and tried your notifications, you can copy the `notify_apprise.sh` file to `notify.sh` and start editing it.
|
||||||
|
|
||||||
|
Comment out/remove the bare metal apprise-command (starting with `apprise -vv -t...`).
|
||||||
|
Uncomment and edit the `AppriseURL` variable and *curl* line
|
||||||
|
It should look something like this when curling the API:
|
||||||
|
```bash
|
||||||
|
send_notification() {
|
||||||
|
Updates=("$@")
|
||||||
|
UpdToString=$( printf "%s\n" "${Updates[@]}" )
|
||||||
|
FromHost=$(hostname)
|
||||||
|
|
||||||
|
printf "\nSending Apprise notification\n"
|
||||||
|
|
||||||
|
MessageTitle="$FromHost - updates available."
|
||||||
|
# Setting the MessageBody variable here.
|
||||||
|
read -d '\n' MessageBody << __EOF
|
||||||
|
Containers on $FromHost with updates available:
|
||||||
|
|
||||||
|
$UpdToString
|
||||||
|
|
||||||
|
__EOF
|
||||||
|
|
||||||
|
AppriseURL="http://IP.or.mydomain.tld:8000/notify/apprise"
|
||||||
|
curl -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
That's all!
|
||||||
|
___
|
||||||
|
___
|
||||||
|
|
||||||
|
|
||||||
|
## On host installed **Apprise**
|
||||||
|
Follow the official guide on [caronc/apprise](https://github.com/caronc/apprise)!
|
||||||
|
|
||||||
|
### A brief, basic "get started"
|
||||||
|
|
||||||
|
- Install **apprise**
|
||||||
|
- python package `pip install apprise`
|
||||||
|
- packaged in EPEL/Fedora `dnf install apprise`
|
||||||
|
- packaged in AUR `[yay/pikaur/paru/other] apprise`
|
||||||
|
|
||||||
|
- Create a config file with your notification credentials (source of notifications):
|
||||||
|
```ini
|
||||||
|
mailto://user:password@yahoo.com
|
||||||
|
slack://token_a/token_b/token_c
|
||||||
|
kodi://example.com
|
||||||
|
```
|
||||||
|
Then either source the notifications with `-c=/path/to/config/apprise` or store them in *PATH* to skip referencing (`~/.apprise` or `~/.config/apprise`).
|
||||||
|
|
||||||
|
- Test apprise with a single notification:
|
||||||
|
- `apprise -vv -t 'test title' -b 'test notification body' 'mailto://myemail:mypass@gmail.com'`
|
||||||
|
- Set up your notification URL's and test them.
|
||||||
|
- Look at the [apprise wiki: Notification Services](https://github.com/caronc/apprise/wiki) for more info about how the url syntax for different services works.
|
||||||
|
|
||||||
|
### When done, customize the **notify.sh** file.
|
||||||
|
After you're done with the setup of the container and tried your notifications, you can copy the `notify_apprise.sh` file to `notify.sh` and start editing it.
|
||||||
|
|
||||||
|
Replace the url's corresponding to the services you've configured.
|
||||||
|
```bash
|
||||||
|
send_notification() {
|
||||||
|
Updates=("$@")
|
||||||
|
UpdToString=$( printf "%s\n" "${Updates[@]}" )
|
||||||
|
FromHost=$(hostname)
|
||||||
|
|
||||||
|
printf "\nSending Apprise notification\n"
|
||||||
|
|
||||||
|
MessageTitle="$FromHost - updates available."
|
||||||
|
# Setting the MessageBody variable here.
|
||||||
|
read -d '\n' MessageBody << __EOF
|
||||||
|
Containers on $FromHost with updates available:
|
||||||
|
|
||||||
|
$UpdToString
|
||||||
|
|
||||||
|
__EOF
|
||||||
|
|
||||||
|
# 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}/
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
That's all!
|
||||||
|
___
|
||||||
|
___
|
||||||
15
dc_brief.sh → extras/dc_brief.sh
Normal file → Executable file
15
dc_brief.sh → extras/dc_brief.sh
Normal file → Executable file
@@ -1,8 +1,22 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
### If not in PATH, set full path. Else just "regctl"
|
### If not in PATH, set full path. Else just "regctl"
|
||||||
regbin="regctl"
|
regbin="regctl"
|
||||||
|
### options to allow exclude:
|
||||||
|
while getopts "e:" options; do
|
||||||
|
case "${options}" in
|
||||||
|
e) Exclude=${OPTARG} ;;
|
||||||
|
*) exit 0 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift "$((OPTIND-1))"
|
||||||
|
### Create array of excludes
|
||||||
|
IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
|
||||||
|
|
||||||
SearchName="$1"
|
SearchName="$1"
|
||||||
|
|
||||||
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
|
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
|
||||||
|
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
|
||||||
printf ". "
|
printf ". "
|
||||||
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||||
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
|
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
|
||||||
@@ -34,3 +48,4 @@ if [[ -n ${GotUpdates[*]} ]] ; then
|
|||||||
printf "\n\033[0;33mContainers with updates available:\033[0m\n"
|
printf "\n\033[0;33mContainers with updates available:\033[0m\n"
|
||||||
printf "%s\n" "${GotUpdates[@]}"
|
printf "%s\n" "${GotUpdates[@]}"
|
||||||
fi
|
fi
|
||||||
|
printf "\n\n"
|
||||||
BIN
extras/dockcheck_logo_by_booYah187.png
Normal file
BIN
extras/dockcheck_logo_by_booYah187.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
27
extras/errorCheck.sh
Executable file
27
extras/errorCheck.sh
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
SearchName="$1"
|
||||||
|
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
|
||||||
|
echo "------------ $i ------------"
|
||||||
|
ContPath=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.working_dir" }}')
|
||||||
|
[ -z "$ContPath" ] && { "$i has no compose labels - skipping" ; continue ; }
|
||||||
|
ContConfigFile=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.config_files" }}')
|
||||||
|
ContName=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.service" }}')
|
||||||
|
ContEnv=$(docker inspect "$i" --format '{{index .Config.Labels "com.docker.compose.project.environment_file" }}')
|
||||||
|
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||||
|
|
||||||
|
if [[ $ContConfigFile = '/'* ]] ; then
|
||||||
|
ComposeFile="$ContConfigFile"
|
||||||
|
else
|
||||||
|
ComposeFile="$ContPath/$ContConfigFile"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "Service name:\t\t$ContName"
|
||||||
|
echo -e "Project working dir:\t$ContPath"
|
||||||
|
echo -e "Compose files:\t\t$ComposeFile"
|
||||||
|
echo -e "Environment files:\t$ContEnv"
|
||||||
|
echo -e "Container image:\t$ContImage"
|
||||||
|
echo
|
||||||
|
echo "Mounts:"
|
||||||
|
docker inspect -f '{{ range .Mounts }}{{ .Source }}:{{ .Destination }}{{ printf "\n" }}{{ end }}' "$i"
|
||||||
|
echo
|
||||||
|
done
|
||||||
BIN
extras/example.gif
Normal file
BIN
extras/example.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 404 KiB |
1
extras/temp
Normal file
1
extras/temp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
temp
|
||||||
34
notify_DSM.sh
Normal file
34
notify_DSM.sh
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||||
|
#
|
||||||
|
# Copy/rename this file to notify.sh to enable email notifications on Synology DSM
|
||||||
|
# DSM Notification Email has to be configured manually.
|
||||||
|
# Modify to your liking - changing SendMailTo and Subject and content.
|
||||||
|
|
||||||
|
send_notification() {
|
||||||
|
Updates=("$@")
|
||||||
|
UpdToString=$( printf "%s\n" "${Updates[@]}" )
|
||||||
|
FromHost=$(hostname)
|
||||||
|
|
||||||
|
# User variables:
|
||||||
|
# change this to your usual destination for synology DSM notification emails
|
||||||
|
SendMailTo="me@mydomain.com"
|
||||||
|
SubjectTag="diskstation"
|
||||||
|
|
||||||
|
printf "\nSending email notification.\n"
|
||||||
|
|
||||||
|
ssmtp $SendMailTo << __EOF
|
||||||
|
From: "$FromHost" <$SendMailTo>
|
||||||
|
date:$(date -R)
|
||||||
|
To: <$SendMailTo>
|
||||||
|
Subject: [$SubjectTag] Updates available on $FromHost
|
||||||
|
Content-Type: text/plain; charset=UTF-8; format=flowed
|
||||||
|
Content-Transfer-Encoding: 7bit
|
||||||
|
|
||||||
|
The following containers on $FromHost have updates available:
|
||||||
|
|
||||||
|
$UpdToString
|
||||||
|
|
||||||
|
From $FromHost
|
||||||
|
|
||||||
|
__EOF
|
||||||
|
}
|
||||||
37
notify_apprise.sh
Normal file
37
notify_apprise.sh
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
send_notification() {
|
||||||
|
Updates=("$@")
|
||||||
|
UpdToString=$( printf "%s\n" "${Updates[@]}" )
|
||||||
|
FromHost=$(hostname)
|
||||||
|
|
||||||
|
printf "\nSending Apprise notification\n"
|
||||||
|
|
||||||
|
MessageTitle="$FromHost - updates available."
|
||||||
|
# Setting the MessageBody variable here.
|
||||||
|
read -d '\n' MessageBody << __EOF
|
||||||
|
Containers on $FromHost with updates available:
|
||||||
|
|
||||||
|
$UpdToString
|
||||||
|
|
||||||
|
__EOF
|
||||||
|
|
||||||
|
# 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}/
|
||||||
|
|
||||||
|
### 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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
14
notify_generic.sh
Normal file
14
notify_generic.sh
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||||
|
#
|
||||||
|
# Copy/rename this file to notify.sh to enable the notification snippet.
|
||||||
|
# generic sample, the "Hello World" of notification addons
|
||||||
|
|
||||||
|
send_notification() {
|
||||||
|
Updates=("$@")
|
||||||
|
UpdToString=$( printf "%s\n" "${Updates[@]}" )
|
||||||
|
FromHost=$(hostname)
|
||||||
|
|
||||||
|
# platform specific notification code would go here
|
||||||
|
printf "\n%bGeneric notification addon:%b" "$c_green" "$c_reset"
|
||||||
|
printf "\nThe following docker containers on %s need to be updated:\n%s\n" "$FromHost" "$UpdToString"
|
||||||
|
}
|
||||||
28
notify_matrix.sh
Normal file
28
notify_matrix.sh
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
|
||||||
|
send_notification() {
|
||||||
|
Updates=("$@")
|
||||||
|
UpdToString=$( printf "%s\n" "${Updates[@]}" )
|
||||||
|
FromHost=$(hostname)
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
# 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\"}"
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
}
|
||||||
31
notify_ntfy-sh.sh
Normal file
31
notify_ntfy-sh.sh
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
send_notification() {
|
||||||
|
Updates=("$@")
|
||||||
|
UpdToString=$( printf "%s\n" "${Updates[@]}" )
|
||||||
|
FromHost=$(hostname)
|
||||||
|
|
||||||
|
printf "\nSending ntfy.sh notification\n"
|
||||||
|
|
||||||
|
MessageTitle="$FromHost - updates available."
|
||||||
|
# Setting the MessageBody variable here.
|
||||||
|
read -d '\n' MessageBody << __EOF
|
||||||
|
Containers on $FromHost with updates available:
|
||||||
|
|
||||||
|
$UpdToString
|
||||||
|
|
||||||
|
__EOF
|
||||||
|
|
||||||
|
# Modify to fit your setup:
|
||||||
|
NtfyUrl="ntfy.sh/YourUniqueTopicName"
|
||||||
|
|
||||||
|
curl -sS -o /dev/null --show-error --fail \
|
||||||
|
-H "Title: $MessageTitle" \
|
||||||
|
-d "$MessageBody" \
|
||||||
|
$NtfyUrl
|
||||||
|
|
||||||
|
}
|
||||||
27
notify_pushbullet.sh
Normal file
27
notify_pushbullet.sh
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
send_notification() {
|
||||||
|
Updates=("$@")
|
||||||
|
UpdToString=$( printf "%s\n" "${Updates[@]}" )
|
||||||
|
FromHost=$(hostname)
|
||||||
|
|
||||||
|
# platform specific notification code would go here
|
||||||
|
printf "\nSending pushbullet notification\n"
|
||||||
|
|
||||||
|
MessageTitle="$FromHost - updates available."
|
||||||
|
# Setting the MessageBody variable here.
|
||||||
|
MessageBody="Containers on $FromHost with updates available: $UpdToString"
|
||||||
|
|
||||||
|
# Modify to fit your setup:
|
||||||
|
PushUrl="https://api.pushbullet.com/v2/pushes"
|
||||||
|
PushToken="Your Pushbullet token here"
|
||||||
|
|
||||||
|
# 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 @-
|
||||||
|
|
||||||
|
}
|
||||||
32
notify_ssmtp.sh
Normal file
32
notify_ssmtp.sh
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||||
|
#
|
||||||
|
# Copy/rename this file to notify.sh to enable the notification snipppet.
|
||||||
|
# sSMTP has to be installed and configured manually.
|
||||||
|
# Modify to fit your setup - changing SendMailFrom, SendMailTo, SubjectTag
|
||||||
|
|
||||||
|
send_notification() {
|
||||||
|
Updates=("$@")
|
||||||
|
UpdToString=$( printf "%s\n" "${Updates[@]}" )
|
||||||
|
FromHost=$(hostname)
|
||||||
|
|
||||||
|
# User variables:
|
||||||
|
SendMailFrom="me@mydomain.tld"
|
||||||
|
SendMailTo="me@mydomain.tld"
|
||||||
|
SubjectTag="dockcheck"
|
||||||
|
|
||||||
|
printf "\nSending email notification.\n"
|
||||||
|
|
||||||
|
ssmtp $SendMailTo << __EOF
|
||||||
|
From: "$FromHost" <$SendMailFrom>
|
||||||
|
date:$(date -R)
|
||||||
|
To: <$SendMailTo>
|
||||||
|
Subject: [$SubjectTag] Updates available on $FromHost
|
||||||
|
Content-Type: text/plain; charset=UTF-8; format=flowed
|
||||||
|
Content-Transfer-Encoding: 7bit
|
||||||
|
|
||||||
|
The following containers on $FromHost have updates available:
|
||||||
|
|
||||||
|
$UpdToString
|
||||||
|
|
||||||
|
__EOF
|
||||||
|
}
|
||||||
27
notify_telegram.sh
Normal file
27
notify_telegram.sh
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
send_notification() {
|
||||||
|
Updates=("$@")
|
||||||
|
UpdToString=$( printf "%s\n" "${Updates[@]}" )
|
||||||
|
FromHost=$(hostname)
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
# 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}"
|
||||||
|
|
||||||
|
curl -sS -o /dev/null --fail -X POST "$TelegramUrl/sendMessage" -H 'Content-Type: application/json' -d "$TelegramData"
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user