Compare commits

...

97 Commits

Author SHA1 Message Date
mag37
5b87072b11 version bump, ntfy.sh and errors on registry fail 2024-01-15 20:53:51 +01:00
mag37
6b2af36841 Added ntfy.sh template 2024-01-15 20:47:51 +01:00
mag37
bad7bfdf86 Added ntfy.sh template 2024-01-15 20:47:04 +01:00
mag37
2a604ff8bd Added error messages on registry fail. 2024-01-15 20:27:45 +01:00
mag37
e1b26fb772 cleanup.md 2024-01-14 20:32:46 +01:00
mag37
9e4b445c50 Added url 2024-01-13 20:34:34 +01:00
mag37
55323b7562 added apprise quickstart 2024-01-13 19:53:50 +01:00
mag37
51c8a7a05d added apprise quickstart + images 2024-01-13 19:45:03 +01:00
mag37
6a3c78d907 cleanup 2024-01-07 14:26:35 +01:00
mag37
4b6173683b Merge pull request #55 from freekngdom/main
ignore the auto-installed regctl
2024-01-07 08:28:06 +01:00
Eric
fb4e9fd521 ignore the auto-installed regctl 2024-01-06 16:17:37 -08:00
mag37
e00bfb1d21 typo 2024-01-06 20:52:03 +01:00
mag37
77d7340e5b Apprise & New option -i
Added new option -i, inform - to send notifications.
2024-01-06 20:45:34 +01:00
mag37
82f6442933 modified apprise-notify 2024-01-06 20:33:21 +01:00
mag37
6c37e255fb formatting 2024-01-06 17:30:00 +01:00
mag37
61e247f0ea formatting 2024-01-06 17:29:35 +01:00
mag37
b540ffa119 fixed link 2024-01-06 08:44:07 +01:00
mag37
edf6d5bd72 added architecture workaround 2024-01-06 08:40:26 +01:00
mag37
92ba4a184e edits 2024-01-06 07:47:41 +01:00
mag37
47ebb75691 Added option -i 2024-01-06 00:11:33 +01:00
mag37
3053304356 fixes 2024-01-05 21:51:43 +01:00
mag37
63b35ab2c3 formatting 2024-01-05 21:49:36 +01:00
mag37
45dbe65c28 typos 2024-01-05 21:47:14 +01:00
mag37
ae5cd4d86e Updated README 2024-01-05 21:45:13 +01:00
mag37
58bb55c79a added .gitignore to safeguard users custom notify.sh 2024-01-05 21:17:30 +01:00
mag37
fe31aed33c Edited generic template 2024-01-05 20:55:08 +01:00
mag37
5485a3b2cf Added apprise notify template. 2024-01-05 20:42:53 +01:00
mag37
94fd34478b Added ssmtp notify template. 2024-01-05 20:42:25 +01:00
mag37
8e92a3a4cb New updates to readme 2024-01-03 21:56:07 +01:00
mag37
9ead0feb9f Merge pull request #51 from yoyoma2/main
add a generic sample notification and a DSM notification addon
2024-01-03 21:42:57 +01:00
yoyoma2
2e620cd2c0 final tweaks to notification addons 2024-01-03 12:41:18 -05:00
mag37
fc7b2888f1 Update notify_generic.sh
Added disclaimer.
2024-01-03 11:07:08 +01:00
mag37
e15a8e9dbf Update notify_DSM.sh
Added disclaimer + some more info
2024-01-03 11:06:37 +01:00
mag37
342ff271ca Update notify_DSM.sh
Added the passed array to a variable.
Created printable string with newlines.
2024-01-03 11:01:41 +01:00
mag37
3f56af0c8a Update notify_generic.sh
Set the passed in array to a variable.
Made a printable string with newlines.
Edited formatting some.
2024-01-03 10:57:00 +01:00
yoyoma2
ab3aaf1140 add a sample a DSM notification addon 2024-01-01 13:46:09 -05:00
mag37
80a81f59d6 Merge pull request #50 from mag37/printf_rework
Added option -m, monochrome mode + cleaning.
2023-12-23 20:54:45 +01:00
mag37
ba3f436ac9 Added -m option, monochrome mode. 2023-12-23 20:52:04 +01:00
mag37
24438124eb cleaned up some variable names and help-section 2023-12-23 20:47:23 +01:00
mag37
e39ea0748f Update dockcheck.sh
Added -m, Monochrome Mode.
2023-12-19 22:52:11 +01:00
mag37
ab30f22343 rework of the printf's color escape codes 2023-12-19 20:24:34 +01:00
mag37
d39badea36 Upd README.md 2023-12-14 20:55:55 +01:00
mag37
9a1f2aa7c7 Upd README.md 2023-12-14 20:44:53 +01:00
mag37
15d3a96b2c Merge pull request #47 from mag37/agecheck
datecheck merge.
2023-12-14 13:28:39 +01:00
mag37
fbd27d6e37 Changed datecheck logic.
Printing how old in days a skipped "too new" image is.
2023-12-14 09:06:19 +01:00
mag37
7bd5f87ed1 Upd README 2023-12-13 20:16:20 +01:00
mag37
e24cba0078 upd readme 3.0 2023-12-13 19:59:58 +01:00
mag37
886379dc7d v3.0 big commit, added date-check function 2023-12-13 19:50:58 +01:00
mag37
488669b99a Update README.md
added recent change info.
2023-12-09 10:59:27 +01:00
mag37
e20fdd9e85 regctl logic changes, check and download will match the scripts workdir. 2023-12-09 10:56:22 +01:00
mag37
3d1c424d23 Update dockcheck.sh
added a regctl-check for when regctl is within the pwd.
(as suggested by @yoyoma2 )
2023-11-19 20:20:05 +01:00
mag37
132fda3388 Update README.md 2023-08-29 20:42:00 +02:00
mag37
cc9b3b0828 Update README.md 2023-08-28 21:31:18 +02:00
mag37
29c2c5e961 Merge pull request #41 from elchanly/elchanly-patch-1
Update dockcheck.sh to include stopped containers
2023-08-28 21:26:12 +02:00
mag37
5dc9af9874 Update dockcheck.sh
Did some changes to the logic, cleaned some whitespace.
2023-08-28 21:24:23 +02:00
elchanly
f91ca08d54 Update dockcheck.sh to include stopped containers
as suggested in reddit, this is proposed to include stopped containers
take into account im not skilled in this programming language but i wanted to contribute.
2023-08-21 23:56:03 +02:00
mag37
9a246b52c4 Merge pull request #39 from mag37/fixing
Fixes `dc_brief.sh` to only exclude exact matches.
2023-07-11 23:33:02 +02:00
mag37
0c33f581f7 Removed old exclude-logic 2023-07-11 23:30:46 +02:00
mag37
b492aacf0f minor edits 2023-07-11 23:11:14 +02:00
mag37
f498138d4b Added recent "exclude containers"-bugfix to the dc_brief.sh 2023-07-11 23:05:34 +02:00
mag37
6a3198eb08 Update dockcheck.sh
patched the self_update logic to respect (and skip interaction) if `-y|a` flag is passed.
2023-06-28 18:03:56 +02:00
mag37
48bfea9fbf Merge pull request #36 from mag37/dev1
Fixes the Exclude-option to only exclude exact matches. 
Formatting: Added counter and info message on current update.
2023-06-27 20:45:12 +02:00
mag37
f2fc5a4d34 Updated: 2.4 info 2023-06-27 19:45:21 +02:00
mag37
f0940e81ec Fixes to the Exclude-option to only exclude exact matches, instead of
wildcarding and excluding by mistake.

Added a counter + message about which container updating.
2023-06-27 19:34:20 +02:00
mag37
a25e648557 Changes to the Exclude-option to only exclude exact matches. 2023-06-21 20:09:31 +02:00
mag37
0e2bdc94ad Update README.md 2023-03-08 12:48:36 +01:00
mag37
19eb57077f selfupd-edit
Changed to if git fails, it'll return to ask for curl/manual.
2023-03-05 21:59:08 +01:00
mag37
1f28c9c144 Update README.md 2023-03-05 21:41:08 +01:00
mag37
0d6da201b7 Update dockcheck.sh
changed url
2023-03-05 21:25:22 +01:00
mag37
ecb1256fbb Merge pull request #32 from mag37/selfupdate
selfupdate func
2023-03-05 21:24:03 +01:00
mag37
afe97c9de5 rdy for main
All in all: 
- Added a self update function, calling either a curl or a git function to update the script.
- Added a dirty changenote-message, will look into improvements later to not curl twice.
2023-03-05 21:19:54 +01:00
mag37
9b6396f6de cleaning
quoting, added env-file check.
2023-03-05 21:13:23 +01:00
mag37
5e58abd8e9 Update dockcheck.sh 2023-03-05 20:45:43 +01:00
mag37
3d7340c91c added changenotes
Addded a dirty way to write out latest changes.
Will try to improve on this later.
2023-03-05 20:44:05 +01:00
mag37
1decbd77b5 cleaning
Just minor cleaning, rearranging
2023-03-05 14:18:57 +01:00
mag37
bcc0c63413 rearranged functions
Moved up choosecontainer-function to the rest of the functions.
Cleaning.
2023-03-05 14:08:56 +01:00
mag37
4a2bc2dded Cleaning
Quoted a variable, reformatted a message
2023-03-05 13:50:28 +01:00
mag37
fd67e0dff1 Update dockcheck.sh 2023-03-04 21:35:47 +01:00
mag37
0fb95ea616 Update dockcheck.sh 2023-03-04 21:28:25 +01:00
mag37
e4cf54c166 Update dockcheck.sh 2023-03-04 21:27:18 +01:00
mag37
e677d8513b Update dockcheck.sh 2023-03-04 21:25:32 +01:00
mag37
d366d4680c Update dockcheck.sh 2023-03-04 20:31:38 +01:00
mag37
76337ee326 Update dockcheck.sh 2023-03-04 20:31:20 +01:00
mag37
6cd90e4597 Update dockcheck.sh 2023-03-04 20:27:13 +01:00
mag37
08ae7a8d23 Update dockcheck.sh 2023-03-04 20:21:31 +01:00
mag37
062c62d071 Update dockcheck.sh 2023-03-04 20:06:41 +01:00
mag37
13549c2018 Update dockcheck.sh 2023-03-04 20:06:08 +01:00
mag37
9094bedfd3 Update dockcheck.sh 2023-03-04 20:05:27 +01:00
mag37
0d4eb4365c Update dockcheck.sh 2023-03-04 20:02:30 +01:00
mag37
ac77470dee Update dockcheck.sh 2023-03-04 20:00:20 +01:00
mag37
ea7a1cd171 Added selfupdating
Added a selfupdating function.
Fixed a forgotten variable (compose-array).
2023-03-04 19:56:26 +01:00
mag37
40910d83b6 Delete example.gif 2023-03-04 09:58:55 +01:00
mag37
d7cc363931 Update README.md 2023-03-04 09:57:31 +01:00
mag37
4f8d6289c2 Update README.md
added donation buttons
added logo by [booYah187](https://github.com/booYah187)
2023-03-04 09:56:16 +01:00
mag37
79febc7356 moved examples.gif 2023-03-04 09:52:46 +01:00
mag37
8acff25f0d added logo
created by https://github.com/booYah187
2023-03-04 09:50:29 +01:00
mag37
2391d6916b Create temp 2023-03-04 09:47:53 +01:00
17 changed files with 553 additions and 126 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# ignore users custom notify.sh
/notify.sh
# ignore the auto-installed regctl
regctl

135
README.md
View File

@@ -1,45 +1,60 @@
# dockcheck
### A script checking updates for docker images **without pulling** - then selectively auto-update some/all containers.
<p align="center">
<img src="extras/dockcheck_logo_by_booYah187.png" width="160" title="dockcheck">
</p>
<p align="center">
<img src="https://img.shields.io/badge/coded%20by%20Human-100%25-yellow?style=flat-square" alt="No AI!">
<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>
### :warning: URGENT!
The 2.0 change had a breaking error - compose-recreation might have included previous containers compose-file.
If you've had odd errors, you can use the [errorCheck.sh](https://github.com/mag37/dockcheck/blob/main/errorCheck.sh) script to list current running container configs in a readable way. Look especially for **Compose files** listed in wrong places.
Recreate the suspicious container(s) manually with `docker compose down && docker compose up -d`.
<h3 align="center">A script checking updates for docker images <b>without pulling</b><br>Then selectively auto-update containers.</h3>
<h2 align="center">Now with a simple Apprise integration!</h2>
<h4 align="center">With features like excluding specific containers, filter by name, auto-prune dangling images and more.</h4>
### :pushpin: Recent changes:
- **v0.2.2**: Fixed breaking errors with multi-compose, odd breakage and working dir error.
- **v0.2.1**: Added option to exclude a list of containers.
- **v0.2.1**: Added multi-compose support (eg. override).
- **v0.2.0**: Fixed error with container:tag definition.
- **v0.1.9:** Fixed custom env-support.
- **v0.1.8:** Added option to prune dangling images.
___
## :bell: Changelog
- **v0.3.4**: Added ntfy.sh template and error message on registry fail.
- **v0.3.3**: Added Apprise template and the option `-i` inform - to send notifications.
- **v0.3.2**: Added a notify function to wrap a notify-script, currently DSM/Ssmtp + template script.
- **v0.3.1**: Addded option `-m` , monochrome mode - no printf color codes.
- **v0.3.0**: Added option `-d N`, age (days) new images have to be before being pulled and updated.
- **v0.2.6**: regctl check / download logic changed. Now using the scripts directory as primary location.
___
## 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`
## :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](#workaround-for-non-amd64--arm64) if other architecture is used.
___
![](https://github.com/mag37/dockcheck/blob/main/example.gif)
![](extras/example.gif)
## `dockcheck.sh`
## :mag_right: `dockcheck.sh`
```
$ ./dockcheck.sh -h
Syntax: dockcheck.sh [OPTION] [part of name to filter]
Example: dockcheck.sh -a -e nextcloud,heimdall
Options:
-h Print this Help.
-a|y Automatic updates, without interaction.
-n No updates, only checking availability.
-p Auto-Prune dangling images after update.
-e Exclude containers, separated by comma.
-r Allow updating images for docker run, wont update the container.
Syntax: dockcheck.sh [OPTION] [part of name to filter]
Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall
Options:
-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.
-h Print this Help.
-i Inform - send a preconfigured notification.
-m Monochrome mode, no printf color codes.
-n No updates, only checking availability.
-p Auto-Prune dangling images after update.
-r Allow updating images for docker run, wont update the container.
-s Include stopped containers in the check. (Logic: docker ps -a)
```
Basic example:
### Basic example:
```
$ ./dockcheck.sh
. . .
@@ -52,33 +67,65 @@ Containers with updates available:
2) syncthing
3) whoogle-search
Choose what containers to update:
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.
After the updates are complete, you'll get prompted if you'd like to prune dangling images.
### `-r flag` :warning: disclaimer and warning:
## :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)
Further additions are welcome - suggestions or PR!
<sub><sup>Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).</sup></sub>
## :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`).
## :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)**
`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.
### :hammer: Known issues
- No detailed error feedback (just skip + list what's skipped) .
- Not respecting `--profile` options when re-creating the container.
## `dc_brief.sh`
Just a brief, slimmed down version of the script to only print what containers got updates, no updates or errors.
# License
## :scroll: 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 the mirror.
___
## 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)
- :leopard: [Palleri](https://github.com/Palleri)

View File

@@ -1,88 +1,96 @@
#!/usr/bin/env bash
VERSION="v0.2.2-URGENT"
VERSION="v0.3.4"
### ChangeNotes: Added ntfy.sh template and error message on registry fail.
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")"
ScriptName="$(basename "$ScriptPath")"
ScriptWorkDir="$(dirname "$ScriptPath")"
### 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 '"')"
[ "$VERSION" != "$LatestRelease" ] && printf "New version available! Latest: %s - Local: %s \nGrab it here: %s \n\n" "$LatestRelease" "$VERSION" "$Github"
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")"
### Help Function:
Help() {
echo "Syntax: dockcheck.sh [OPTION] [part of name to filter]"
echo "Example: dockcheck.sh -a -e nextcloud,heimdall"
echo "Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall"
echo
echo "Options:"
echo "-h Print this Help."
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 "-h Print this Help."
echo "-i Inform - send a preconfigured notification."
echo "-m Monochrome mode, no printf color codes."
echo "-n No updates, only checking availability."
echo "-e Exclude containers, separated by comma."
echo "-p Auto-Prune dangling images after update."
echo "-r Allow updating images for docker run, wont update the container"
echo "-s Include stopped containers in the check. (Logic: docker ps -a)"
}
while getopts "aynprhe:" 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 "aynprhisme:d:" options; do
case "${options}" in
a|y) UpdYes="yes" ;;
n) UpdYes="no" ;;
r) DrUp="yes" ;;
p) PruneQ="yes" ;;
e) Exclude=${OPTARG} ;;
h|*) Help ; exit 0 ;;
a|y) AutoUp="yes" ;;
n) AutoUp="no" ;;
r) DRunUp="yes" ;;
p) AutoPrune="yes" ;;
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" ;;
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
done
shift "$((OPTIND-1))"
### 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 "./regctl" ]]; then regbin="./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 > ./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
self_update_git() {
cd "$ScriptWorkDir" || { printf "Path error, skipping update.\n" ; return ; }
[[ $(builtin type -P git) ]] || { printf "Git not installed, skipping update.\n" ; return ; }
ScriptUpstream=$(git rev-parse --abbrev-ref --symbolic-full-name "@{upstream}") || { printf "Script not in git directory, choose a different method.\n" ; self_update_select ; return ; }
git fetch
[ -n "$(git diff --name-only "$ScriptUpstream" "$ScriptName")" ] && {
printf "%s\n" "Pulling the latest version."
git pull --force
printf "%s\n" "--- starting over with the updated version ---"
cd - || { printf "Path error.\n" ; return ; }
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
exit 1 # exit the old instance
}
echo "Local is already latest."
}
self_update_curl() {
cp "$ScriptPath" "$ScriptPath".bak
if [[ $(builtin type -P curl) ]]; then
curl -L $RawUrl > "$ScriptPath" ; chmod +x "$ScriptPath"
printf "%s\n" "--- starting over with the updated version ---"
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
exit 1 # exit the old instance
else
printf "%s\n" "Dependency missing, quitting."
exit 1
printf "curl not available - download the update manually: %s \n" "$RawUrl"
fi
}
self_update_select() {
read -r -p "Choose update procedure (or do it manually) - git/curl/[no]: " SelfUpQ
if [[ "$SelfUpQ" == "git" ]]; then self_update_git ;
elif [[ "$SelfUpQ" == "curl" ]]; then self_update_curl ;
else printf "Download it manually from the repo: %s \n\n" "$Github"
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
}
### Choose from list -function:
@@ -110,17 +118,99 @@ choosecontainers() {
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
}
### Version check & initiate self update
[[ "$VERSION" != "$LatestRelease" ]] && { printf "New version available! Local: %s - Latest: %s \n Change Notes: %s \n" "$VERSION" "$LatestRelease" "$LatestChanges" ; [[ -z "$AutoUp" ]] && self_update_select ; }
### 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
### Check the image-hash of every running container VS the registry
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
[[ " ${Excludes[*]} " =~ ${i} ]] && continue; # Skip if the container is excluded
for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}') ; do
### Looping every item over the list of excluded names and skipping:
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
printf ". "
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
### Checking for errors while setting the variable:
if RegHash=$($regbin image digest --list "$RepoUrl" 2>/dev/null) ; then
if [[ "$LocalHash" = *"$RegHash"* ]] ; then NoUpdates+=("$i"); else GotUpdates+=("$i"); fi
if RegHash=$($regbin image digest --list "$RepoUrl" 2>&1) ; then
if [[ "$LocalHash" = *"$RegHash"* ]] ; then
NoUpdates+=("$i")
else
if [[ -n "$DaysOld" ]] && ! datecheck ; then
NoUpdates+=("+$i ${ImageAge}d")
else
GotUpdates+=("$i")
fi
fi
else
GotErrors+=("$i")
# Here the RegHash is the result of an error code.
GotErrors+=("$i - ${RegHash}")
fi
done
@@ -135,29 +225,34 @@ UpdCount="${#GotUpdates[@]}"
### List what containers got updates or not
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[@]}"
fi
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 "%binfo:%b 'unauthorized' often means not found in a public registry.%b\n" "$c_blue" "$c_reset"
fi
if [[ -n ${GotUpdates[*]} ]] ; then
printf "\n\033[0;33mContainers with updates available:\033[0m\n"
[[ -z "$UpdYes" ]] && options || printf "%s\n" "${GotUpdates[@]}"
printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset"
[[ -z "$AutoUp" ]] && options || printf "%s\n" "${GotUpdates[@]}"
[[ ! -z "$Notify" ]] && { [[ $(type -t send_notification) == function ]] && send_notification "${GotUpdates[@]}" || printf "Could not source notification function.\n" ; }
fi
### Optionally get updates if there's any
if [ -n "$GotUpdates" ] ; then
if [ -z "$UpdYes" ] ; then
printf "\n\033[0;36mChoose what containers to update.\033[0m\n"
if [ -z "$AutoUp" ] ; then
printf "\n%bChoose what containers to update.%b\n" "$c_teal" "$c_reset"
choosecontainers
else
SelectedUpdates=( "${GotUpdates[@]}" )
fi
if [ "$UpdYes" == "${UpdYes#[Nn]}" ] ; then
if [ "$AutoUp" == "${AutoUp#[Nn]}" ] ; then
NumberofUpdates="${#SelectedUpdates[@]}"
CurrentQue=0
for i in "${SelectedUpdates[@]}"
do
((CurrentQue+=1))
unset CompleteConfs
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" }}')
@@ -166,11 +261,11 @@ if [ -n "$GotUpdates" ] ; then
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
### Checking if compose-values are empty - hence started with docker run:
if [ -z "$ContPath" ] ; then
if [ "$DrUp" == "yes" ] ; then
if [ "$DRunUp" == "yes" ] ; then
docker pull "$ContImage"
printf "%s\n" "$i got a new image downloaded, rebuild manually with preferred 'docker run'-parameters"
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
continue
fi
@@ -182,9 +277,10 @@ if [ -n "$GotUpdates" ] ; then
fi
### cd to the compose-file directory to account for people who use relative volumes, eg - ${PWD}/data:data
cd "$ContPath" || { echo "Path error - skipping $i" ; continue ; }
printf "\n%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset"
docker pull "$ContImage"
### Reformat for multi-compose:
IFS=',' read -r -a Confs <<< "$ContConfigFile" ; unset IFS
IFS=',' read -r -a Confs <<< "$ComposeFile" ; unset IFS
for conf in "${Confs[@]}"; do CompleteConfs+="-f $conf " ; done
### Check if the container got an environment file set, use it if so:
@@ -194,9 +290,9 @@ if [ -n "$GotUpdates" ] ; then
$DockerBin ${CompleteConfs[@]} up -d "$ContName" # unquoted array to allow split - rework?
fi
done
printf "\033[0;32mAll done!\033[0m\n"
[[ -z "$PruneQ" ]] && read -r -p "Would you like to prune dangling images? y/[n]: " PruneQ
[[ "$PruneQ" =~ [yY] ]] && docker image prune -f
printf "\n%bAll done!%b\n" "$c_green" "$c_reset"
[[ -z "$AutoPrune" ]] && read -r -p "Would you like to prune dangling images? y/[n]: " AutoPrune
[[ "$AutoPrune" =~ [yY] ]] && docker image prune -f
else
printf "\nNo updates installed, exiting.\n"
fi

Binary file not shown.

Before

Width:  |  Height:  |  Size: 333 KiB

BIN
extras/apprise-ex1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

BIN
extras/apprise-ex2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

View 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.
![](apprise-ex1.png)
Here you'll click **Configuration Manager**, read the overview and then click on **Configuration**.
Under **Configuration** you'll craft/paste your notification config.
![](apprise-ex2.png)
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!
___
___

View File

@@ -16,7 +16,7 @@ IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
SearchName="$1"
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
[[ " ${Excludes[*]} " =~ ${i} ]] && continue; # Skip if the container is excluded
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
printf ". "
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

3
errorCheck.sh → extras/errorCheck.sh Normal file → Executable file
View File

@@ -18,9 +18,10 @@ for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
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
docker inspect -f '{{ range .Mounts }}{{ .Source }}:{{ .Destination }}{{ printf "\n" }}{{ end }}' "$i"
echo
done

BIN
extras/example.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 KiB

1
extras/temp Normal file
View File

@@ -0,0 +1 @@
temp

34
notify_DSM.sh Normal file
View 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
View 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
View 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"
}

31
notify_ntfy-sh.sh Normal file
View 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
}

32
notify_ssmtp.sh Normal file
View 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
}