mirror of
https://github.com/mag37/dockcheck.git
synced 2026-02-14 23:38:15 +01:00
Removed experimental -z flag and old version check code
This commit is contained in:
parent
3aeee837f9
commit
b2d67c9f52
1 changed files with 50 additions and 79 deletions
129
dockcheck.sh
129
dockcheck.sh
|
|
@ -34,7 +34,6 @@ Help() {
|
|||
echo "-s Include stopped containers in the check. (Logic: docker ps -a)."
|
||||
echo "-t Set a timeout (in seconds) per container for registry checkups, 10 is default."
|
||||
echo "-v Prints current version."
|
||||
echo "-z [Experimental] Check images asynchrously for increased performance."
|
||||
echo
|
||||
echo "Project source: $Github"
|
||||
}
|
||||
|
|
@ -49,7 +48,7 @@ c_reset="\033[0m"
|
|||
|
||||
Timeout=10
|
||||
Stopped=""
|
||||
while getopts "aynpfrhlisvmzc:e:d:t:" options; do
|
||||
while getopts "aynpfrhlisvmc:e:d:t:" options; do
|
||||
case "${options}" in
|
||||
a|y) AutoUp="yes" ;;
|
||||
c) CollectorTextFileDirectory="${OPTARG}"
|
||||
|
|
@ -65,7 +64,6 @@ while getopts "aynpfrhlisvmzc:e:d:t:" options; do
|
|||
s) Stopped="-a" ;;
|
||||
t) Timeout="${OPTARG}" ;;
|
||||
v) printf "%s\n" "$VERSION" ; exit 0 ;;
|
||||
z) ParallelCheck=1 ;;
|
||||
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 ;;
|
||||
|
|
@ -284,90 +282,63 @@ if [[ $t_out ]]; then
|
|||
else t_out=""
|
||||
fi
|
||||
|
||||
if [[ $ParallelCheck -ne 1 ]]; then
|
||||
# Check the image-hash of every running container VS the registry
|
||||
for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}') ; do
|
||||
((RegCheckQue+=1))
|
||||
progress_bar "$RegCheckQue" "$ContCount"
|
||||
# Looping every item over the list of excluded names and skipping
|
||||
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
|
||||
ImageId=$(docker inspect "$i" --format='{{.Image}}')
|
||||
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||
LocalHash=$(docker image inspect "$ImageId" --format '{{.RepoDigests}}')
|
||||
# Checking for errors while setting the variable
|
||||
if RegHash=$(${t_out} $regbin -v error image digest --list "$RepoUrl" 2>&1) ; then
|
||||
if [[ "$LocalHash" = *"$RegHash"* ]] ; then
|
||||
NoUpdates+=("$i")
|
||||
else
|
||||
if [[ -n "$DaysOld" ]] && ! datecheck ; then
|
||||
NoUpdates+=("+$i ${ImageAge}d")
|
||||
else
|
||||
GotUpdates+=("$i")
|
||||
fi
|
||||
fi
|
||||
check_image() {
|
||||
i="$1"
|
||||
local Excludes=($Excludes_string)
|
||||
local skip
|
||||
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && skip=1 ; done
|
||||
|
||||
if [[ $skip -eq 1 ]]; then
|
||||
echo Skip $i
|
||||
return
|
||||
fi
|
||||
|
||||
local NoUpdates GotUpdates GotErrors
|
||||
ImageId=$(docker inspect "$i" --format='{{.Image}}')
|
||||
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||
LocalHash=$(docker image inspect "$ImageId" --format '{{.RepoDigests}}')
|
||||
|
||||
# Checking for errors while setting the variable
|
||||
if RegHash=$(${t_out} $regbin -v error image digest --list "$RepoUrl" 2>&1) ; then
|
||||
if [[ "$LocalHash" = *"$RegHash"* ]] ; then
|
||||
echo NoUpdates "$i"
|
||||
else
|
||||
# Here the RegHash is the result of an error code
|
||||
GotErrors+=("$i - ${RegHash}")
|
||||
fi
|
||||
done
|
||||
else
|
||||
check_image() {
|
||||
i="$1"
|
||||
local Excludes=($Excludes_string)
|
||||
local skip
|
||||
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && skip=1 ; done
|
||||
|
||||
if [[ $skip -eq 1 ]]; then
|
||||
echo Skip $i
|
||||
return
|
||||
fi
|
||||
|
||||
local NoUpdates GotUpdates GotErrors
|
||||
ImageId=$(docker inspect "$i" --format='{{.Image}}')
|
||||
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||
LocalHash=$(docker image inspect "$ImageId" --format '{{.RepoDigests}}')
|
||||
|
||||
# Checking for errors while setting the variable
|
||||
if RegHash=$(${t_out} $regbin -v error image digest --list "$RepoUrl" 2>&1) ; then
|
||||
if [[ "$LocalHash" = *"$RegHash"* ]] ; then
|
||||
echo NoUpdates "$i"
|
||||
if [[ -n "$DaysOld" ]] && ! datecheck ; then
|
||||
echo NoUpdates "+$i ${ImageAge}d"
|
||||
else
|
||||
if [[ -n "$DaysOld" ]] && ! datecheck ; then
|
||||
echo NoUpdates "+$i ${ImageAge}d"
|
||||
else
|
||||
echo GotUpdates "$i"
|
||||
fi
|
||||
echo GotUpdates "$i"
|
||||
fi
|
||||
else
|
||||
# Here the RegHash is the result of an error code
|
||||
echo GotErrors "$i - ${RegHash}"
|
||||
fi
|
||||
}
|
||||
else
|
||||
# Here the RegHash is the result of an error code
|
||||
echo GotErrors "$i - ${RegHash}"
|
||||
fi
|
||||
}
|
||||
|
||||
export -f check_image datecheck
|
||||
export Excludes_string="${Excludes[@]}" # Can only export scalar variables
|
||||
export t_out regbin RepoUrl DaysOld
|
||||
# Make required functions and variables available to subprocesses
|
||||
export -f check_image datecheck
|
||||
export Excludes_string="${Excludes[@]}" # Can only export scalar variables
|
||||
export t_out regbin RepoUrl DaysOld
|
||||
|
||||
# Asynchronously check the image-hash of every running container VS the registry
|
||||
while read -r line; do
|
||||
((RegCheckQue+=1))
|
||||
progress_bar "$RegCheckQue" "$ContCount"
|
||||
# Asynchronously check the image-hash of every running container VS the registry
|
||||
while read -r line; do
|
||||
((RegCheckQue+=1))
|
||||
progress_bar "$RegCheckQue" "$ContCount"
|
||||
|
||||
Got=${line%% *} # Extracts the first word (NoUpdates, GotUpdates, GotErrors)
|
||||
item=${line#* }
|
||||
Got=${line%% *} # Extracts the first word (NoUpdates, GotUpdates, GotErrors)
|
||||
item=${line#* }
|
||||
|
||||
case "$Got" in
|
||||
NoUpdates) NoUpdates+=("$item") ;;
|
||||
GotUpdates) GotUpdates+=("$item") ;;
|
||||
GotErrors) GotErrors+=("$item") ;;
|
||||
Skip) ;;
|
||||
*) echo "Error! Unexpected output from subprocess: ${line}" ;;
|
||||
esac
|
||||
done < <( \
|
||||
docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}' | \
|
||||
xargs -P 32 -I {} bash -c 'check_image "{}"' \
|
||||
)
|
||||
fi
|
||||
case "$Got" in
|
||||
NoUpdates) NoUpdates+=("$item") ;;
|
||||
GotUpdates) GotUpdates+=("$item") ;;
|
||||
GotErrors) GotErrors+=("$item") ;;
|
||||
Skip) ;;
|
||||
*) echo "Error! Unexpected output from subprocess: ${line}" ;;
|
||||
esac
|
||||
done < <( \
|
||||
docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}' | \
|
||||
xargs -P 32 -I {} bash -c 'check_image "{}"' \
|
||||
)
|
||||
|
||||
# Sort arrays alphabetically
|
||||
IFS=$'\n'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue