Compare commits

...

61 Commits

Author SHA1 Message Date
mag37
35e33b3997 Release info + notification edits. 2024-07-24 20:49:23 +02:00
mag37
a615d759ad Version bump. 2024-07-24 20:46:23 +02:00
mag37
df310c8f50 Merge pull request #90 from mag37/smtp
smtp-changes, deprecate ssmtp, suggest msmtp
2024-07-24 20:41:25 +02:00
mag37
b1448fbb95 smtp-changes, deprecate ssmtp, suggest msmtp 2024-07-24 12:18:23 +02:00
mag37
de67cab998 Merge pull request #88 from yoyoma2/main
zero configuration DSM notification emails
2024-07-02 18:29:53 +02:00
yoyoma2
608c218281 zero configuration DSM notification emails 2024-07-02 11:56:51 -04:00
mag37
3d122f2b86 Update README.md
Notifications updates
2024-06-21 06:25:06 +02:00
mag37
8e280145b9 Merge pull request #87 from cerealconyogurt/home
Create Gotify Template.
2024-06-21 06:16:22 +02:00
cerealconyogurt
da389a04e7 Create notify_gotify.sh
adding Gotify template
2024-06-20 22:05:10 -04:00
mag37
25563d16b6 typo 2024-06-16 23:02:57 +02:00
mag37
4917c97076 Merge pull request #84 from mag37/busyfix
Compat fixes for busyboxs timeout.
2024-06-16 19:39:22 +02:00
mag37
33fc647cb1 compat.changes due to busybox 2024-06-16 19:37:18 +02:00
mag37
abec27c38a potential busybox fix 2024-06-16 07:51:32 +02:00
mag37
082b0f4c7c Merge pull request #82 from mag37/tfix
compat-fixes for timeout and array sorting.
2024-06-12 20:54:30 +02:00
mag37
8521280070 compat-fixes to arrays 2024-06-12 20:50:10 +02:00
mag37
0aac94f27c bugfix non coreutils 2024-06-10 21:09:04 +02:00
mag37
730dba5c3d version bump - bugfix 2024-06-08 19:44:14 +02:00
mag37
f8455d3787 bugfix for non amd64/arm64 arch.
added --foreground to timeout.
2024-06-08 19:43:12 +02:00
mag37
bbe9164554 versionbump 2024-06-03 22:53:10 +02:00
mag37
5d86c79710 Update dockcheck.sh
versionbump for fix
2024-06-03 22:50:07 +02:00
mag37
b0f8431dbf Update dockcheck.sh
timeout default fix
2024-06-03 22:49:14 +02:00
mag37
331d2cc5a7 Merge pull request #79 from mag37/timeout
Timeout @ registry check
2024-06-03 22:24:57 +02:00
mag37
35f460ed61 timeout info 2024-06-03 22:19:07 +02:00
mag37
aab63901d0 Added registry check timeout 2024-06-03 22:15:08 +02:00
mag37
5e53fabbf6 Merge pull request #76 from silverbios/HTTP-Method-Synapse
Update HTTP method in notify_matrix.sh
2024-04-29 13:18:28 +02:00
Alireza
8b3926fd5d Update notify_matrix.sh
Change the HTTP method from PUT to POST because in recent versions, only POST allowed from synapse server.
2024-04-29 13:32:30 +03:30
mag37
049413cf5a quickfix
Omitting error during git dir check.
2024-04-29 11:18:21 +02:00
mag37
b1b7f048a3 Update README.md 2024-04-24 19:46:49 +02:00
mag37
361e98c378 versionbump 2024-04-24 19:45:14 +02:00
mag37
d1ad0c68f6 Merge pull request #74 from mag37/cleanwork
cleanups, bugfixes
2024-04-24 19:42:27 +02:00
mag37
76697bc281 Re-formatted compose and env file checks.
Clearing bug for multi-env-container which would break.
Accounted for rare compose-path formatting which would break.
2024-04-22 21:12:00 +02:00
mag37
86649fb0fe re-written sorting of arrays 2024-04-22 21:08:02 +02:00
mag37
80f7dd9b82 removed unused var, cleaned prints 2024-04-22 21:02:13 +02:00
mag37
959f636152 Update README.md 2024-03-31 20:41:38 +02:00
mag37
d1bf9256fa added topic
Added topic variable, set to 0 if not used.
2024-03-27 21:52:02 +01:00
mag37
5513e13109 Update README.md 2024-03-27 21:49:23 +01:00
mag37
f0b2f7eab7 added matrix. 2024-02-11 16:13:23 +01:00
mag37
44a90d5e62 Merge pull request #69 from silverbios/main
Added Matrix-Synapse notification Template
2024-02-10 18:36:23 +01:00
Alireza
c63643dde8 Update Example URL 2024-02-10 21:01:42 +03:30
Alireza
b2767864ab update comments 2024-02-10 20:55:32 +03:30
Alireza
c09e813aad Update notify_matrix.sh
Fix Msgbody variable syntax
2024-02-10 20:47:36 +03:30
Alireza
0b52dd50b6 Create notify_matrix.sh
add notification template for matrix-synapse
2024-02-10 03:03:07 +03:30
mag37
b86df76fb6 tidying some
Rephrased and reordered readme.

Removed "coded by human" - I cant know what contributors use :)
2024-02-04 21:15:21 +01:00
mag37
b8450aa774 added telegram 2024-02-02 21:39:00 +01:00
mag37
aa9421adda Merge pull request #68 from mag37/selfup_cleanup
selfupdate rework, -v option, syntax cleanup
2024-02-02 21:27:43 +01:00
mag37
f853bfd318 typos 2024-02-02 21:21:56 +01:00
mag37
292b3e1a32 Version bump + readme 2024-02-02 21:18:19 +01:00
mag37
4c26768374 Added -v option, prints version 2024-02-02 20:52:01 +01:00
mag37
b7f8b67232 Merge pull request #65 from Nionor/main
Added Telegram template.
2024-02-02 20:47:42 +01:00
Nionor
a63a509bd2 Add files via upload
Added Telegram template.
2024-02-02 16:00:04 +01:00
mag37
5ed3b90ca4 syntax cleanup 2024-02-01 20:19:04 +01:00
mag37
78d11d1b37 Self update rework
Now just y/n and checking if it's the right git directory, else
curl/wget.
2024-01-31 21:33:14 +01:00
mag37
dfe6cf3e08 arithmetic formatting 2024-01-28 20:08:17 +01:00
mag37
3bc7352b54 Bugfix zerodivision -s option 2024-01-28 15:43:33 +01:00
mag37
1470055329 Merge pull request #62 from mag37/env-rework
Reworked --env-file logic.
2024-01-27 09:41:41 +01:00
mag37
904cd508d1 --env-file version bump 2024-01-27 09:39:37 +01:00
mag37
8ee1366505 typo 2024-01-26 21:53:15 +01:00
mag37
c063b09003 reworked --env-file logic 2024-01-26 20:45:32 +01:00
mag37
ea096b5dbc Merge pull request #58 from thomas-mc-work/patch-1
modified update notification
2024-01-24 22:17:37 +01:00
Thomas McWork
038a30b628 add colors to version update notice 2024-01-24 21:28:53 +01:00
Thomas McWork
24d82d74b3 modified update notification
Slightly changed the notation of the local/latest version to simplify the visual impression. But it's a matter of taste.
2024-01-24 21:22:49 +01:00
7 changed files with 259 additions and 98 deletions

View File

@@ -2,7 +2,6 @@
<img src="extras/dockcheck_logo_by_booYah187.png" width="160" title="dockcheck"> <img src="extras/dockcheck_logo_by_booYah187.png" width="160" title="dockcheck">
</p> </p>
<p align="center"> <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"> <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> <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"> <img src="https://img.shields.io/github/v/tag/mag37/dockcheck?style=flat-square&label=release" alt="release">
@@ -11,27 +10,26 @@
<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> <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> </p>
<h3 align="center">A script checking updates for docker images <b>without pulling</b><br>Then selectively auto-update containers.</h3> <h3 align="center">CLI tool to automate docker image updates. <br>No <b>pre-pull</b>, selective, optional notifications and prune when done.</h3>
<h2 align="center">Now with a simple Apprise integration!</h2> <h2 align="center">Now with simple notification integrations!</h2>
<h4 align="center">With features like excluding specific containers, filter by name, auto-prune dangling images and more.</h4> <h4 align="center">With features like excluding specific containers, custom container labels, auto-prune when done and more.</h4>
___ ___
## :bell: Changelog ## :bell: Changelog
* Create notify_gotify.sh by @cerealconyogurt in https://github.com/mag37/dockcheck/pull/87
* zero configuration DSM notification emails by @yoyoma2 in https://github.com/mag37/dockcheck/pull/88
* smtp-changes, deprecate ssmtp, suggest msmtp by @mag37 in https://github.com/mag37/dockcheck/pull/90
- **v0.4.7**: Notification Template changes to gotify(new!), DSM(improved), SMTP(deprecation alternative).
- **v0.4.6**: Compatibility changes to timeout, due to busybox.
- **v0.4.5**: Bugfixes, compatibility changes to timeout and arrays.
- **v0.4.3**: 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.7**: Added support for [labels](#bookmark-labels), added the `-f` option (force restart stack).
- **v0.3.6**: Added pushbullet template. - **v0.3.6**: Added pushbullet template.
- **v0.3.5**: Added a simple progress bar for the registry checkup. - **v0.3.5**: Added a simple progress bar for the registry checkup.
- **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.
___
## :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.
___ ___
@@ -56,6 +54,8 @@ Options:"
-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). -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.
``` ```
@@ -78,19 +78,45 @@ 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.
___
## :nut_and_bolt: Dependencies
- Running docker (duh) and compose, either standalone or plugin.
- Bash shell or compatible shell of at least v4.3
- [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 ## :loudspeaker: Notifications
Trigger with the `-i` flag. Trigger with the `-i` flag.
Run it scheduled with `-ni` to only get notified when there's updates available! 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! Use a `notify_X.sh` template file, copy it to `notify.sh`, modify it to your needs! (notify.sh is added to .gitignore)
Current templates: **Current templates:**
- Synology [DSM](https://www.synology.com/en-global/dsm) - Synology [DSM](https://www.synology.com/en-global/dsm)
- Email with [sSMTP](https://wiki.debian.org/sSMTP) - Email with [mSMTP](https://wiki.debian.org/msmtp) (or deprecated alternative [sSMTP](https://wiki.debian.org/sSMTP))
- Apprise (with it's [multitude](https://github.com/caronc/apprise#supported-notifications) of notifications) - 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) - 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) - Read the [QuickStart](extras/apprise_quickstart.md)
- [ntfy.sh](https://ntfy.sh/) - HTTP-based pub-sub notifications. - [ntfy.sh](https://ntfy.sh/) - HTTP-based pub-sub notifications.
- [Gotify](https://gotify.net/) - a simple server for sending and receiving messages.
- [Pushbullet](https://www.pushbullet.com/) - connecting different devices with cross-platform features. - [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! Further additions are welcome - suggestions or PR!
<sub><sup>Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).</sup></sub> <sub><sup>Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).</sup></sub>
@@ -125,6 +151,15 @@ 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`). 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 ## :hammer: Known issues
- No detailed error feedback (just skip + list what's skipped). - No detailed error feedback (just skip + list what's skipped).
- Not respecting `--profile` options when re-creating the container. - Not respecting `--profile` options when re-creating the container.

View File

@@ -1,13 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
VERSION="v0.3.7" VERSION="v0.4.7"
### ChangeNotes: Added label support (see readme) and -f (force restart stack) option. ### ChangeNotes: Notification template changes for: gotify(new), DSM(improved), SMTP(deprecation alternative).
Github="https://github.com/mag37/dockcheck" Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh" RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
### Variables for self updating ### Variables for self updating
ScriptArgs=( "$@" ) ScriptArgs=( "$@" )
ScriptPath="$(readlink -f "$0")" ScriptPath="$(readlink -f "$0")"
ScriptName="$(basename "$ScriptPath")"
ScriptWorkDir="$(dirname "$ScriptPath")" ScriptWorkDir="$(dirname "$ScriptPath")"
### Check if there's a new release of the script: ### Check if there's a new release of the script:
@@ -31,8 +30,10 @@ Help() {
echo "-m Monochrome mode, no printf color codes." 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 "-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."
} }
### Colors: ### Colors:
@@ -43,8 +44,9 @@ c_blue="\033[0;34m"
c_teal="\033[0;36m" c_teal="\033[0;36m"
c_reset="\033[0m" c_reset="\033[0m"
Timeout=10
Stopped="" Stopped=""
while getopts "aynpfrhlisme:d:" options; do while getopts "aynpfrhlisvme:d:t:" options; do
case "${options}" in case "${options}" in
a|y) AutoUp="yes" ;; a|y) AutoUp="yes" ;;
n) AutoUp="no" ;; n) AutoUp="no" ;;
@@ -52,10 +54,12 @@ while getopts "aynpfrhlisme:d:" options; do
p) AutoPrune="yes" ;; p) AutoPrune="yes" ;;
l) OnlyLabel=true ;; l) OnlyLabel=true ;;
f) ForceRestartStacks=true ;; f) ForceRestartStacks=true ;;
i) [ -s $ScriptWorkDir/notify.sh ] && { source $ScriptWorkDir/notify.sh ; Notify="yes" ; } ;; i) [ -s "$ScriptWorkDir"/notify.sh ] && { source "$ScriptWorkDir"/notify.sh ; Notify="yes" ; } ;;
e) Exclude=${OPTARG} ;; e) Exclude=${OPTARG} ;;
m) declare c_{red,green,yellow,blue,teal,reset}="" ;; m) declare c_{red,green,yellow,blue,teal,reset}="" ;;
s) Stopped="-a" ;; s) Stopped="-a" ;;
t) Timeout="${OPTARG}" ;;
v) printf "%s\n" "$VERSION" ; exit 0 ;;
d) DaysOld=${OPTARG} d) DaysOld=${OPTARG}
if ! [[ $DaysOld =~ ^[0-9]+$ ]] ; then { printf "Days -d argument given (%s) is not a number.\n" "${DaysOld}" ; exit 2 ; } ; fi ;; if ! [[ $DaysOld =~ ^[0-9]+$ ]] ; then { printf "Days -d argument given (%s) is not a number.\n" "${DaysOld}" ; exit 2 ; } ; fi ;;
h|*) Help ; exit 2 ;; h|*) Help ; exit 2 ;;
@@ -63,37 +67,35 @@ while getopts "aynpfrhlisme:d:" options; do
done done
shift "$((OPTIND-1))" shift "$((OPTIND-1))"
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() { self_update_curl() {
cp "$ScriptPath" "$ScriptPath".bak cp "$ScriptPath" "$ScriptPath".bak
if [[ $(builtin type -P curl) ]]; then if [[ $(builtin type -P curl) ]]; then
curl -L $RawUrl > "$ScriptPath" ; chmod +x "$ScriptPath" curl -L $RawUrl > "$ScriptPath" ; chmod +x "$ScriptPath"
printf "%s\n" "--- starting over with the updated version ---" printf "\n%s\n" "--- starting over with the updated version ---"
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
exit 1 # exit the old instance
elif [[ $(builtin type -P wget) ]]; then
wget $RawUrl -O "$ScriptPath" ; chmod +x "$ScriptPath"
printf "\n%s\n" "--- starting over with the updated version ---"
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
exit 1 # exit the old instance exit 1 # exit the old instance
else else
printf "curl not available - download the update manually: %s \n" "$RawUrl" printf "curl/wget not available - download the update manually: %s \n" "$Github"
fi fi
} }
self_update_select() {
read -r -p "Choose update procedure (or do it manually) - git/curl/[no]: " SelfUpQ self_update() {
if [[ "$SelfUpQ" == "git" ]]; then self_update_git ; cd "$ScriptWorkDir" || { printf "Path error, skipping update.\n" ; return ; }
elif [[ "$SelfUpQ" == "curl" ]]; then self_update_curl ; if [[ $(builtin type -P git) ]] && [[ "$(git ls-remote --get-url 2>/dev/null)" =~ .*"mag37/dockcheck".* ]] ; then
else printf "Download it manually from the repo: %s \n\n" "$Github" printf "\n%s\n" "Pulling the latest version."
git pull --force || { printf "Git error, manually pull/clone.\n" ; return ; }
printf "\n%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
else
cd - || { printf "Path error.\n" ; return ; }
self_update_curl
fi fi
} }
@@ -124,8 +126,8 @@ choosecontainers() {
datecheck() { datecheck() {
ImageDate=$($regbin image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 ) ImageDate=$($regbin image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 )
ImageAge=$((($(date +%s) - $(date -d "$ImageDate" +%s))/86400)) ImageAge=$(( ( $(date +%s) - $(date -d "$ImageDate" +%s) )/86400 ))
if [ $ImageAge -gt $DaysOld ] ; then if [ "$ImageAge" -gt "$DaysOld" ] ; then
return 0 return 0
else else
return 1 return 1
@@ -135,17 +137,23 @@ datecheck() {
progress_bar() { progress_bar() {
QueCurrent="$1" QueCurrent="$1"
QueTotal="$2" QueTotal="$2"
((Percent=100*${QueCurrent}/${QueTotal})) ((Percent=100*QueCurrent/QueTotal))
((Complete=50*${Percent}/100)) # change first number for width (50) ((Complete=50*Percent/100)) # change first number for width (50)
((Left=50-${Complete})) # change first number for width (50) ((Left=50-Complete)) # change first number for width (50)
BarComplete=$(printf "%${Complete}s" | tr " " "#") BarComplete=$(printf "%${Complete}s" | tr " " "#")
BarLeft=$(printf "%${Left}s" | tr " " "-") BarLeft=$(printf "%${Left}s" | tr " " "-")
[[ $QueTotal == $QueCurrent ]] || printf "\r[%s%s] %s/%s " $BarComplete $BarLeft $QueCurrent $QueTotal [[ "$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 [[ "$QueTotal" == "$QueCurrent" ]] && printf "\r[%b%s%b] %s/%s \n" "$c_teal" "$BarComplete" "$c_reset" "$QueCurrent" "$QueTotal"
} }
### Version check & initiate self update ### 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 ; } 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. ### Set $1 to a variable for name filtering later.
SearchName="$1" SearchName="$1"
@@ -200,25 +208,36 @@ done
### Listing typed exclusions: ### Listing typed exclusions:
if [[ -n ${Excludes[*]} ]] ; then if [[ -n ${Excludes[*]} ]] ; then
printf "\n%bExcluding these names:%b\n" $c_blue $c_reset printf "\n%bExcluding these names:%b\n" "$c_blue" "$c_reset"
printf "%s\n" "${Excludes[@]}" printf "%s\n" "${Excludes[@]}"
printf "\n" printf "\n"
fi fi
# Variables for progress_bar function # Variables for progress_bar function
DocCount=$(docker ps --filter "name=$SearchName" --format '{{.Names}}' | wc -l) DocCount=$(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}' | wc -l)
RegCheckQue=0 RegCheckQue=0
### Testing and setting timeout binary
t_out=$(type -P "timeout")
if [[ $t_out ]]; then
t_out=$(realpath $t_out 2>/dev/null || readlink -f $t_out)
if [[ $t_out =~ "busybox" ]]; then
t_out="timeout ${Timeout}"
else t_out="timeout --foreground ${Timeout}"
fi
else t_out=""
fi
### 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 $Stopped --filter "name=$SearchName" --format '{{.Names}}') ; do for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}') ; do
((RegCheckQue+=1)) ((RegCheckQue+=1))
progress_bar $RegCheckQue $DocCount progress_bar "$RegCheckQue" "$DocCount"
### Looping every item over the list of excluded names and skipping: ### Looping every item over the list of excluded names and skipping:
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done 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>&1) ; then if RegHash=$(${t_out} $regbin image digest --list "$RepoUrl" 2>&1) ; then
if [[ "$LocalHash" = *"$RegHash"* ]] ; then if [[ "$LocalHash" = *"$RegHash"* ]] ; then
NoUpdates+=("$i") NoUpdates+=("$i")
else else
@@ -238,8 +257,9 @@ done
IFS=$'\n' IFS=$'\n'
NoUpdates=($(sort <<<"${NoUpdates[*]}")) NoUpdates=($(sort <<<"${NoUpdates[*]}"))
GotUpdates=($(sort <<<"${GotUpdates[*]}")) GotUpdates=($(sort <<<"${GotUpdates[*]}"))
GotErrors=($(sort <<<"${GotErrors[*]}"))
unset IFS unset IFS
### Define how many updates are available ### Define how many updates are available
UpdCount="${#GotUpdates[@]}" UpdCount="${#GotUpdates[@]}"
@@ -251,12 +271,12 @@ fi
if [[ -n ${GotErrors[*]} ]] ; then if [[ -n ${GotErrors[*]} ]] ; then
printf "\n%bContainers with errors, wont get updated:%b\n" "$c_red" "$c_reset" 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.%b\n" "$c_blue" "$c_reset" 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%bContainers with updates available:%b\n" "$c_yellow" "$c_reset" printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset"
[[ -z "$AutoUp" ]] && options || printf "%s\n" "${GotUpdates[@]}" [[ -z "$AutoUp" ]] && options || printf "%s\n" "${GotUpdates[@]}"
[[ ! -z "$Notify" ]] && { [[ $(type -t send_notification) == function ]] && send_notification "${GotUpdates[@]}" || printf "Could not source notification function.\n" ; } [[ -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
@@ -291,34 +311,25 @@ if [ -n "$GotUpdates" ] ; then
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 "$ContPath" || { echo "Path error - skipping $i" ; continue ; } cd "$ContPath" || { echo "Path error - skipping $i" ; continue ; }
## Reformatting path + multi compose
if [[ $ContConfigFile = '/'* ]] ; then
CompleteConfs=$(for conf in ${ContConfigFile//,/ } ; do printf -- "-f %s " "$conf"; done)
else
CompleteConfs=$(for conf in ${ContConfigFile//,/ } ; do printf -- "-f %s/%s " "$ContPath" "$conf"; done)
fi
printf "\n%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset" 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 ### Checking if Label Only -option is set, and if container got the label
[[ "$OnlyLabel" == true ]] && { [[ "$ContUpdateLabel" != true ]] && { echo "No label, skipping" ; continue ; } } [[ "$OnlyLabel" == true ]] && { [[ "$ContUpdateLabel" != true ]] && { echo "No update label, skipping." ; continue ; } }
docker pull "$ContImage" docker pull "$ContImage"
### Reformat for multi-compose: ### Check if the container got an environment file set and reformat it
IFS=',' read -r -a Confs <<< "$ComposeFile" ; unset IFS if [ -n "$ContEnv" ]; then ContEnvs=$(for env in ${ContEnv//,/ } ; do printf -- "--env-file %s " "$env"; done) ; fi
for conf in "${Confs[@]}"; do CompleteConfs+="-f $conf " ; done ### Check if the whole stack should be restarted
### Check if the container got an environment file set, use it if so:
if [ -n "$ContEnv" ]; then # also checking if stack should be restarted
if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]] ; then if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]] ; then
$DockerBin ${CompleteConfs[@]} stop ; $DockerBin ${CompleteConfs[@]} --env-file "$ContEnv" up -d $DockerBin ${CompleteConfs} stop ; $DockerBin ${CompleteConfs} ${ContEnvs} up -d
else else
$DockerBin ${CompleteConfs[@]} --env-file "$ContEnv" up -d "$ContName" # unquoted array to allow split - rework? $DockerBin ${CompleteConfs} ${ContEnvs} up -d ${ContName}
fi
else
if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]] ; then
$DockerBin ${CompleteConfs[@]} stop ; $DockerBin ${CompleteConfs[@]} up -d
else
$DockerBin ${CompleteConfs[@]} up -d "$ContName"
fi
fi fi
done done
printf "\n%bAll done!%b\n" "$c_green" "$c_reset" printf "\n%bAll done!%b\n" "$c_green" "$c_reset"

View File

@@ -1,26 +1,46 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing. ### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
# INFO: ssmtp is depcerated - consider to use msmtp instead.
# #
# Copy/rename this file to notify.sh to enable email notifications on Synology DSM # Copy/rename this file to notify.sh to enable the notification snipppet.
# DSM Notification Email has to be configured manually. # mSMTP/sSMTP has to be installed and configured manually.
# The existing DSM Notification Email configuration will be used automatically.
# Modify to your liking - changing SendMailTo and Subject and content. # Modify to your liking - changing SendMailTo and Subject and content.
MSMTP=$(which msmtp)
SSMTP=$(which ssmtp)
if [ -n $MSMPT ] ; then
MAIL=$MSMTP
elif [ -n $SSMTP ] && [ -z $MAIL ] ; then
MAIL=$SSMTP
else
echo "No msmtp or ssmtp binary found in PATH: $PATH" ; exit 1
fi
send_notification() { send_notification() {
Updates=("$@") Updates=("$@")
UpdToString=$( printf "%s\n" "${Updates[@]}" ) UpdToString=$( printf "%s\n" "${Updates[@]}" )
FromHost=$(hostname) FromHost=$(hostname)
CfgFile="/usr/syno/etc/synosmtp.conf"
# User variables: # User variables:
# change this to your usual destination for synology DSM notification emails # Automatically sends to your usual destination for synology DSM notification emails.
SendMailTo="me@mydomain.com" # You can also manually override by assigning something else to SendMailTo below.
SubjectTag="diskstation" SendMailTo=$(grep 'eventmail1' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')
#SendMailTo="me@mydomain.com"
SubjectTag=$(grep 'eventsubjectprefix' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')
SenderName=$(grep 'smtp_from_name' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')
SenderMail=$(grep 'smtp_from_mail' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')
SenderMail=${SenderMail:-$(grep 'eventmail1' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')}
printf "\nSending email notification.\n" printf "\nSending email notification.\n"
ssmtp $SendMailTo << __EOF $MAIL $SendMailTo << __EOF
From: "$FromHost" <$SendMailTo> From: "$SenderName" <$SenderMail>
date:$(date -R) date:$(date -R)
To: <$SendMailTo> To: <$SendMailTo>
Subject: [$SubjectTag] Updates available on $FromHost Subject: $SubjectTag Updates available on $FromHost
Content-Type: text/plain; charset=UTF-8; format=flowed Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit Content-Transfer-Encoding: 7bit
@@ -28,7 +48,6 @@ The following containers on $FromHost have updates available:
$UpdToString $UpdToString
From $FromHost From $SenderName
__EOF __EOF
} }

29
notify_gotify.sh Normal file
View File

@@ -0,0 +1,29 @@
### 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 GotifyUrl and GotifyToken.
send_notification() {
Updates=("$@")
UpdToString=$( printf "%s\n" "${Updates[@]}" )
FromHost=$(hostname)
# platform specific notification code would go here
printf "\nSending Gotify notification\n"
# Setting the MessageTitle and MessageBody variable here.
MessageTitle="${FromHost} - updates available."
MessageBody="Containers on ${FromHost} with updates available: ${UpdToString}"
# Modify to fit your setup:
GotifyToken="Your Gotify token here"
GotifyUrl="https://api.gotify/message?token=${GotifyToken}"
curl \
-F "title=${MessageTitle}" \
-F "message=${MessageBody}" \
-F "priority=5" \
-X POST "${GotifyUrl}" &> /dev/null
}

28
notify_matrix.sh Normal file
View 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"
}

View File

@@ -1,9 +1,21 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing. ### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
# INFO: ssmtp is depcerated - consider to use msmtp instead.
# #
# Copy/rename this file to notify.sh to enable the notification snipppet. # Copy/rename this file to notify.sh to enable the notification snipppet.
# sSMTP has to be installed and configured manually. # mSMTP/sSMTP has to be installed and configured manually.
# Modify to fit your setup - changing SendMailFrom, SendMailTo, SubjectTag # Modify to fit your setup - changing SendMailFrom, SendMailTo, SubjectTag
MSMTP=$(which msmtp)
SSMTP=$(which ssmtp)
if [ -n $MSMPT ] ; then
MAIL=$MSMTP
elif [ -n $SSMTP ] && [ -z $MAIL ] ; then
MAIL=$SSMTP
else
echo "No msmtp or ssmtp binary found in PATH: $PATH" ; exit 1
fi
send_notification() { send_notification() {
Updates=("$@") Updates=("$@")
UpdToString=$( printf "%s\n" "${Updates[@]}" ) UpdToString=$( printf "%s\n" "${Updates[@]}" )
@@ -16,7 +28,7 @@ SubjectTag="dockcheck"
printf "\nSending email notification.\n" printf "\nSending email notification.\n"
ssmtp $SendMailTo << __EOF $MAIL $SendMailTo << __EOF
From: "$FromHost" <$SendMailFrom> From: "$FromHost" <$SendMailFrom>
date:$(date -R) date:$(date -R)
To: <$SendMailTo> To: <$SendMailTo>

27
notify_telegram.sh Normal file
View 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"
}