Merge pull request #47 from mag37/agecheck

datecheck merge.
This commit is contained in:
mag37 2023-12-14 13:28:39 +01:00 committed by GitHub
commit 15d3a96b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 25 deletions

View File

@ -16,6 +16,7 @@
### :pushpin: Recent changes:
- **v0.3.0**: Added a flag `-d N` to choose how many days old 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.
@ -39,17 +40,18 @@ ___
## `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.
-e Exclude containers, separated by comma.
-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).
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:
@ -90,8 +92,7 @@ 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/DCW](https://github.com/Palleri/DCW) for a WebUI-front with exporters and notifications.
### Check out a spinoff project: [Palleri/DCW](https://github.com/Palleri/DCW) for a WebUI-front with exporters and notifications.
## Special Thanks:
- :bison: [t0rnis](https://github.com/t0rnis)

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
VERSION="v0.2.6"
### ChangeNotes: Logic change on regctl check/download. Will match the scripts workdir.
VERSION="v0.3.0"
### ChangeNotes: Added feature (-d N) to only update to new images that are N+ days old.
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
@ -17,28 +17,31 @@ LatestChanges="$(curl -s -r 0-200 $RawUrl | sed -n "/ChangeNotes/s/### ChangeNot
### 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 "-n No updates, only checking availability."
echo "-e Exclude containers, separated by comma."
echo "-e X Exclude containers, separated by comma."
echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower."
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)"
}
Stopped=""
while getopts "aynprhse:" options; do
while getopts "aynprhse:d:" options; do
case "${options}" in
a|y) UpdYes="yes" ;;
n) UpdYes="no" ;;
r) DrUp="yes" ;;
p) PruneQ="yes" ;;
e) Exclude=${OPTARG} ;;
s) Stopped="-a" ;;
h|*) Help ; exit 0 ;;
n) UpdYes="no" ;;
r) DrUp="yes" ;;
p) PruneQ="yes" ;;
e) Exclude=${OPTARG} ;;
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))"
@ -102,6 +105,17 @@ 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 "$UpdYes" ]] && self_update_select ; }
@ -172,7 +186,15 @@ for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}')
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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 333 KiB

After

Width:  |  Height:  |  Size: 404 KiB