Skip to content

Commit

Permalink
v3.0 big commit, added date-check function
Browse files Browse the repository at this point in the history
  • Loading branch information
mag37 committed Dec 13, 2023
1 parent 488669b commit 886379d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions dockcheck.sh
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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. 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))"
Expand Down Expand Up @@ -102,6 +105,17 @@ choosecontainers() {
printf "\n"
}

datecheck() {
DaysAgo=$(date -d "$DaysOld days ago" +"%Y-%m-%d")
ImageDate=$($regbin image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 )
if [ $(date -d "$ImageDate" +%s) -le $(date -d "$DaysAgo" +%s) ] ; 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 ; }

Expand Down Expand Up @@ -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")
else
GotUpdates+=("$i")
fi
fi
else
GotErrors+=("$i")
fi
Expand Down
Binary file modified extras/example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 886379d

Please sign in to comment.