From cb65d78075266fe90c3bdfc3a7943cdf0fc9f1e4 Mon Sep 17 00:00:00 2001 From: mag37 Date: Tue, 21 Feb 2023 21:08:50 +0100 Subject: [PATCH] Create dc_brief.sh A brief version of the script, just checking and listing all running containers with updates / no updates / errors. --- dc_brief.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 dc_brief.sh diff --git a/dc_brief.sh b/dc_brief.sh new file mode 100644 index 0000000..4c4a85a --- /dev/null +++ b/dc_brief.sh @@ -0,0 +1,36 @@ +### If not in PATH, set full path. Else just "regctl" +regbin="regctl" +SearchName="$1" + +for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do + printf ". " + RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}') + 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 + else + GotErrors+=("$i") + fi +done + +### Sort arrays alphabetically +IFS=$'\n' +NoUpdates=($(sort <<<"${NoUpdates[*]}")) +GotUpdates=($(sort <<<"${GotUpdates[*]}")) +GotErrors=($(sort <<<"${GotErrors[*]}")) +unset IFS + +### List what containers got updates or not +if [[ -n ${NoUpdates[*]} ]] ; then + printf "\n\033[0;32mContainers on latest version:\033[0m\n" + printf "%s\n" "${NoUpdates[@]}" +fi +if [[ -n ${GotErrors[*]} ]] ; then + printf "\n\033[0;31mContainers with errors, wont get updated:\033[0m\n" + printf "%s\n" "${GotErrors[@]}" +fi +if [[ -n ${GotUpdates[*]} ]] ; then + printf "\n\033[0;33mContainers with updates available:\033[0m\n" + printf "%s\n" "${GotUpdates[@]}" +fi