v3.0 big commit, added date-check function
This commit is contained in:
parent
488669b99a
commit
886379dc7d
36
dockcheck.sh
36
dockcheck.sh
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
VERSION="v0.2.6"
|
VERSION="v0.3.0"
|
||||||
### ChangeNotes: Logic change on regctl check/download. Will match the scripts workdir.
|
### ChangeNotes: Added feature (-d N) to only update to new images that are N+ days old.
|
||||||
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"
|
||||||
|
|
||||||
@ -17,20 +17,21 @@ LatestChanges="$(curl -s -r 0-200 $RawUrl | sed -n "/ChangeNotes/s/### ChangeNot
|
|||||||
### Help Function:
|
### Help Function:
|
||||||
Help() {
|
Help() {
|
||||||
echo "Syntax: dockcheck.sh [OPTION] [part of name to filter]"
|
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
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo "-h Print this Help."
|
echo "-h Print this Help."
|
||||||
echo "-a|y Automatic updates, without interaction."
|
echo "-a|y Automatic updates, without interaction."
|
||||||
echo "-n No updates, only checking availability."
|
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 "-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)"
|
||||||
}
|
}
|
||||||
|
|
||||||
Stopped=""
|
Stopped=""
|
||||||
while getopts "aynprhse:" options; do
|
while getopts "aynprhse:d:" options; do
|
||||||
case "${options}" in
|
case "${options}" in
|
||||||
a|y) UpdYes="yes" ;;
|
a|y) UpdYes="yes" ;;
|
||||||
n) UpdYes="no" ;;
|
n) UpdYes="no" ;;
|
||||||
@ -38,7 +39,9 @@ while getopts "aynprhse:" options; do
|
|||||||
p) PruneQ="yes" ;;
|
p) PruneQ="yes" ;;
|
||||||
e) Exclude=${OPTARG} ;;
|
e) Exclude=${OPTARG} ;;
|
||||||
s) Stopped="-a" ;;
|
s) Stopped="-a" ;;
|
||||||
h|*) Help ; exit 0 ;;
|
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
|
esac
|
||||||
done
|
done
|
||||||
shift "$((OPTIND-1))"
|
shift "$((OPTIND-1))"
|
||||||
@ -102,6 +105,17 @@ choosecontainers() {
|
|||||||
printf "\n"
|
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 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 ; }
|
[[ "$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}}')
|
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>/dev/null) ; then
|
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
|
else
|
||||||
GotErrors+=("$i")
|
GotErrors+=("$i")
|
||||||
fi
|
fi
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 333 KiB After Width: | Height: | Size: 404 KiB |
Loading…
Reference in New Issue
Block a user