mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-18 02:17:46 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
923736c413 | ||
|
|
7d825f36c9 | ||
|
|
29dffbb9b3 | ||
|
|
588c22afc9 | ||
|
|
39c69b7648 | ||
|
|
35e33b3997 | ||
|
|
a615d759ad | ||
|
|
df310c8f50 | ||
|
|
b1448fbb95 | ||
|
|
de67cab998 | ||
|
|
608c218281 | ||
|
|
3d122f2b86 | ||
|
|
8e280145b9 | ||
|
|
da389a04e7 | ||
|
|
25563d16b6 | ||
|
|
4917c97076 | ||
|
|
33fc647cb1 | ||
|
|
abec27c38a | ||
|
|
082b0f4c7c | ||
|
|
8521280070 | ||
|
|
0aac94f27c | ||
|
|
730dba5c3d | ||
|
|
f8455d3787 | ||
|
|
bbe9164554 | ||
|
|
5d86c79710 | ||
|
|
b0f8431dbf |
11
.pre-commit-config.yaml
Normal file
11
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v4.6.0
|
||||||
|
hooks:
|
||||||
|
- id: check-yaml
|
||||||
|
- id: check-added-large-files
|
||||||
|
- id: trailing-whitespace
|
||||||
|
args: [--markdown-linebreak-ext=md]
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: mixed-line-ending
|
||||||
|
args: ['--fix=lf']
|
||||||
14
README.md
14
README.md
@@ -17,7 +17,11 @@
|
|||||||
___
|
___
|
||||||
## :bell: Changelog
|
## :bell: Changelog
|
||||||
|
|
||||||
- **v0.4.2**: Added timeout option to skip container if registry check takes too long (10s default).
|
- **v0.4.8**: Rewrote prune logic to not prompt with options `-a|-y` or `-n`. Auto prune with `-p`.
|
||||||
|
- **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.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.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.8**: Fixed `--env-file` logic to work with multiple env-files.
|
||||||
@@ -76,6 +80,7 @@ ___
|
|||||||
|
|
||||||
## :nut_and_bolt: Dependencies
|
## :nut_and_bolt: Dependencies
|
||||||
- Running docker (duh) and compose, either standalone or plugin.
|
- 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))
|
- [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`.
|
- 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.
|
- regctl requires `amd64/arm64` - see [workaround](#roller_coaster-workaround-for-non-amd64--arm64) if other architecture is used.
|
||||||
@@ -98,14 +103,15 @@ Add preferred `notify.sh`-template to the same directory - this will not be touc
|
|||||||
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.
|
- [Telegram](https://telegram.org/) - Telegram chat API.
|
||||||
- [Matrix-Synapse](https://github.com/element-hq/synapse) - [Matrix](https://matrix.org/), open, secure, decentralised communication.
|
- [Matrix-Synapse](https://github.com/element-hq/synapse) - [Matrix](https://matrix.org/), open, secure, decentralised communication.
|
||||||
|
|||||||
33
dockcheck.sh
33
dockcheck.sh
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
VERSION="v0.4.2"
|
VERSION="v0.4.8"
|
||||||
### ChangeNotes: Added timeout option to skip container if registry check takes too long (10s default).
|
### ChangeNotes: Rewrote prune to not prompt (default no) if -a|-y or -n flags are used. -p will still autoprune.
|
||||||
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"
|
||||||
|
|
||||||
@@ -44,6 +44,7 @@ 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 "aynpfrhlisvme:d:t:" options; do
|
while getopts "aynpfrhlisvme:d:t:" options; do
|
||||||
case "${options}" in
|
case "${options}" in
|
||||||
@@ -57,7 +58,7 @@ while getopts "aynpfrhlisvme:d:t:" options; do
|
|||||||
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:-10}" ;;
|
t) Timeout="${OPTARG}" ;;
|
||||||
v) printf "%s\n" "$VERSION" ; exit 0 ;;
|
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 ;;
|
||||||
@@ -216,6 +217,17 @@ fi
|
|||||||
DocCount=$(docker ps $Stopped --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))
|
||||||
@@ -224,8 +236,8 @@ for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}')
|
|||||||
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=$(timeout ${Timeout} $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
|
||||||
@@ -242,9 +254,11 @@ for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}')
|
|||||||
done
|
done
|
||||||
|
|
||||||
### Sort arrays alphabetically
|
### Sort arrays alphabetically
|
||||||
readarray -td '' NoUpdates < <(printf '%s\0' "${NoUpdates[@]}" | sort -z -n)
|
IFS=$'\n'
|
||||||
readarray -td '' GotUpdates < <(printf '%s\0' "${GotUpdates[@]}" | sort -z -n)
|
NoUpdates=($(sort <<<"${NoUpdates[*]}"))
|
||||||
readarray -td '' GotErrors < <(printf '%s\0' "${GotErrors[@]}" | sort -z -n)
|
GotUpdates=($(sort <<<"${GotUpdates[*]}"))
|
||||||
|
unset IFS
|
||||||
|
|
||||||
|
|
||||||
### Define how many updates are available
|
### Define how many updates are available
|
||||||
UpdCount="${#GotUpdates[@]}"
|
UpdCount="${#GotUpdates[@]}"
|
||||||
@@ -319,7 +333,7 @@ if [ -n "$GotUpdates" ] ; then
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
printf "\n%bAll done!%b\n" "$c_green" "$c_reset"
|
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
|
if [[ -z "$AutoPrune" ]] && [[ -z "$AutoUp" ]]; then read -r -p "Would you like to prune dangling images? y/[n]: " AutoPrune ; fi
|
||||||
[[ "$AutoPrune" =~ [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"
|
||||||
@@ -329,4 +343,3 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,5 +33,3 @@ apprise -vv -t "$MessageTitle" -b "$MessageBody" \
|
|||||||
# curl -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL
|
# curl -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
29
notify_gotify.sh
Normal file
29
notify_gotify.sh
Normal 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
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
Reference in New Issue
Block a user