Update dockcheck.sh

Did some changes to the logic, cleaned some whitespace.
This commit is contained in:
mag37 2023-08-28 21:24:23 +02:00 committed by GitHub
parent f91ca08d54
commit 5dc9af9874
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
VERSION="v0.2.4"
### ChangeNotes: Fixes to the Exclude-option to only exclude exact matches. +cleaning
VERSION="v0.2.5"
### ChangeNotes: Added an -s option to include stopped contianers in the check.
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
@ -25,10 +25,11 @@ Help() {
echo "-n No updates, only checking availability."
echo "-e Exclude containers, separated by comma."
echo "-p Auto-Prune dangling images after update."
echo "-s Check stopped containers"
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
case "${options}" in
a|y) UpdYes="yes" ;;
@ -36,7 +37,7 @@ while getopts "aynprhse:" options; do
r) DrUp="yes" ;;
p) PruneQ="yes" ;;
e) Exclude=${OPTARG} ;;
s) Stopped="yes" ;;
s) Stopped="-a" ;;
h|*) Help ; exit 0 ;;
esac
done
@ -163,17 +164,8 @@ if [[ -n ${Excludes[*]} ]] ; then
printf "\n"
fi
if [ "$Stopped" == "yes" ]; then
Cadena="$(docker ps -a --filter "name=$SearchName" --format '{{.Names}}')";
else
Cadena="$(docker ps --filter "name=$SearchName" --format '{{.Names}}')";
fi
### Check the image-hash of every running container VS the registry
for i in ${Cadena} ; do
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 ". "
@ -187,10 +179,6 @@ for i in ${Cadena} ; do
fi
done
### Sort arrays alphabetically
IFS=$'\n'
NoUpdates=($(sort <<<"${NoUpdates[*]}"))