mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-17 18:07:46 +00:00
Compare commits
69 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e92a3a4cb | ||
|
|
9ead0feb9f | ||
|
|
2e620cd2c0 | ||
|
|
fc7b2888f1 | ||
|
|
e15a8e9dbf | ||
|
|
342ff271ca | ||
|
|
3f56af0c8a | ||
|
|
ab3aaf1140 | ||
|
|
80a81f59d6 | ||
|
|
ba3f436ac9 | ||
|
|
24438124eb | ||
|
|
e39ea0748f | ||
|
|
ab30f22343 | ||
|
|
d39badea36 | ||
|
|
9a1f2aa7c7 | ||
|
|
15d3a96b2c | ||
|
|
fbd27d6e37 | ||
|
|
7bd5f87ed1 | ||
|
|
e24cba0078 | ||
|
|
886379dc7d | ||
|
|
488669b99a | ||
|
|
e20fdd9e85 | ||
|
|
3d1c424d23 | ||
|
|
132fda3388 | ||
|
|
cc9b3b0828 | ||
|
|
29c2c5e961 | ||
|
|
5dc9af9874 | ||
|
|
f91ca08d54 | ||
|
|
9a246b52c4 | ||
|
|
0c33f581f7 | ||
|
|
b492aacf0f | ||
|
|
f498138d4b | ||
|
|
6a3198eb08 | ||
|
|
48bfea9fbf | ||
|
|
f2fc5a4d34 | ||
|
|
f0940e81ec | ||
|
|
a25e648557 | ||
|
|
0e2bdc94ad | ||
|
|
19eb57077f | ||
|
|
1f28c9c144 | ||
|
|
0d6da201b7 | ||
|
|
ecb1256fbb | ||
|
|
afe97c9de5 | ||
|
|
9b6396f6de | ||
|
|
5e58abd8e9 | ||
|
|
3d7340c91c | ||
|
|
1decbd77b5 | ||
|
|
bcc0c63413 | ||
|
|
4a2bc2dded | ||
|
|
fd67e0dff1 | ||
|
|
0fb95ea616 | ||
|
|
e4cf54c166 | ||
|
|
e677d8513b | ||
|
|
d366d4680c | ||
|
|
76337ee326 | ||
|
|
6cd90e4597 | ||
|
|
08ae7a8d23 | ||
|
|
062c62d071 | ||
|
|
13549c2018 | ||
|
|
9094bedfd3 | ||
|
|
0d4eb4365c | ||
|
|
ac77470dee | ||
|
|
ea7a1cd171 | ||
|
|
40910d83b6 | ||
|
|
d7cc363931 | ||
|
|
4f8d6289c2 | ||
|
|
79febc7356 | ||
|
|
8acff25f0d | ||
|
|
2391d6916b |
73
README.md
73
README.md
@@ -1,42 +1,59 @@
|
||||
# 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>
|
||||
<h4 align="center">With features like excluding specific containers, filter by name, auto-prune dangling images and more.</h4</h3>
|
||||
|
||||
### :pushpin: Recent changes:
|
||||
|
||||
### :bell: Recent changes
|
||||
- **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.
|
||||
- **v0.2.5**: Added a new option `-s` to include stopped containers in the check for updates.
|
||||
- **v0.2.4**: Fixed a bug with the Exclude-logic to only exclude exact matches. Added a counter.
|
||||
- **v0.2.3**: Added a self updating function (curl/git) and a ugly changenote-message for updates.
|
||||
- **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.
|
||||
___
|
||||
|
||||
## Dependencies:
|
||||
## 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`
|
||||
___
|
||||
|
||||
|
||||

|
||||

|
||||
|
||||
## `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:
|
||||
-h Print this Help.
|
||||
-a|y Automatic updates, without interaction.
|
||||
-n No updates, only checking availability.
|
||||
-e X Exclude containers, separated by comma.
|
||||
-d N Only update to new images that are N+ days old. Lists too recent with +prefix. 2xSlower.
|
||||
-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:
|
||||
@@ -52,22 +69,25 @@ 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:
|
||||
### Notifications:
|
||||
|
||||
A simple email notification function is added, with a generic example and DSM/Ssmtp script by [yoyoma2](https://github.com/yoyoma2). Further addons are welcome, suggestions or PR!
|
||||
|
||||
### :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) .
|
||||
- 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.
|
||||
|
||||
## `dc_brief.sh`
|
||||
Just a brief, slimmed down version of the script to only print what containers got updates, no updates or errors.
|
||||
@@ -76,9 +96,8 @@ Just a brief, slimmed down version of the script to only print what containers g
|
||||
dockcheck is created and released under the [GNU GPL v3.0](https://www.gnu.org/licenses/gpl-3.0-standalone.html) license.
|
||||
___
|
||||
|
||||
## Check out a spinoff brother-project:
|
||||
### [Palleri/dockcheck-web](https://github.com/Palleri/dockcheck-web) for a WebUI-front!
|
||||
### Check out a spinoff project: [Palleri/DCW](https://github.com/Palleri/DCW) for a WebUI-front with exporters and notifications.
|
||||
|
||||
## Special Thanks:
|
||||
## Special Thanks
|
||||
- :bison: [t0rnis](https://github.com/t0rnis)
|
||||
- :leopard: [Palleri](https://github.com/Palleri)
|
||||
|
||||
@@ -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}}')
|
||||
|
||||
250
dockcheck.sh
250
dockcheck.sh
@@ -1,88 +1,96 @@
|
||||
#!/usr/bin/env bash
|
||||
VERSION="v0.2.2-URGENT"
|
||||
VERSION="v0.3.2"
|
||||
### ChangeNotes: Added a notify function - template and email script (DSM etc)
|
||||
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")"
|
||||
|
||||
[ -s $ScriptWorkDir/notify.sh ] && source $ScriptWorkDir/notify.sh
|
||||
|
||||
### 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 "-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 "aynprhsme: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" ;;
|
||||
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,15 +118,96 @@ 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 [[ "$LocalHash" = *"$RegHash"* ]] ; then
|
||||
NoUpdates+=("$i")
|
||||
else
|
||||
if [[ -n "$DaysOld" ]] && ! datecheck ; then
|
||||
NoUpdates+=("+$i ${ImageAge}d")
|
||||
else
|
||||
GotUpdates+=("$i")
|
||||
fi
|
||||
fi
|
||||
else
|
||||
GotErrors+=("$i")
|
||||
fi
|
||||
@@ -135,29 +224,33 @@ 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[@]}"
|
||||
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[@]}"
|
||||
[[ $(type -t send_notification) == function ]] && send_notification "${GotUpdates[@]}"
|
||||
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 +259,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 +275,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 +288,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
|
||||
|
||||
3
errorCheck.sh
Normal file → Executable file
3
errorCheck.sh
Normal file → Executable 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
example.gif
BIN
example.gif
Binary file not shown.
|
Before Width: | Height: | Size: 333 KiB |
BIN
extras/dockcheck_logo_by_booYah187.png
Normal file
BIN
extras/dockcheck_logo_by_booYah187.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
BIN
extras/example.gif
Normal file
BIN
extras/example.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 404 KiB |
1
extras/temp
Normal file
1
extras/temp
Normal file
@@ -0,0 +1 @@
|
||||
temp
|
||||
29
notify_DSM.sh
Normal file
29
notify_DSM.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 email notifications on synology DSM
|
||||
# Modify to your liking - changing SendMailTo and Subject and content.
|
||||
|
||||
send_notification() {
|
||||
Updates=("$@")
|
||||
UpdToString=$( printf "%s\n" "${Updates[@]}" )
|
||||
# change this to your usual destination for synology DSM notification emails
|
||||
SendMailTo=me@mydomain.com
|
||||
FromHost=$(hostname)
|
||||
|
||||
printf "\nSending email notification\n"
|
||||
|
||||
ssmtp $SendMailTo << __EOF
|
||||
From: "$FromHost" <$SendMailTo>
|
||||
date:$(date -R)
|
||||
To: <$SendMailTo>
|
||||
Subject: [diskstation] Some docker containers need to be updated
|
||||
Content-Type: text/plain; charset=UTF-8; format=flowed
|
||||
Content-Transfer-Encoding: 7bit
|
||||
|
||||
The following docker containers on $FromHost need to be updated:
|
||||
|
||||
$UpdToString
|
||||
|
||||
From $FromHost
|
||||
|
||||
__EOF
|
||||
}
|
||||
13
notify_generic.sh
Normal file
13
notify_generic.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
# Copy/rename this file to notify.sh to enable email/text notifications
|
||||
# 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"
|
||||
}
|
||||
Reference in New Issue
Block a user