From f91ca08d54d1bec54e6c71d02d091045807b013f Mon Sep 17 00:00:00 2001 From: elchanly <49251727+elchanly@users.noreply.github.com> Date: Mon, 21 Aug 2023 23:56:03 +0200 Subject: [PATCH 1/2] Update dockcheck.sh to include stopped containers as suggested in reddit, this is proposed to include stopped containers take into account im not skilled in this programming language but i wanted to contribute. --- dockcheck.sh | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/dockcheck.sh b/dockcheck.sh index bc8673b..9c1cdfa 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -25,16 +25,18 @@ Help() { echo "-n No updates, only checking availability." echo "-e Exclude containers, separated by comma." echo "-p Auto-Prune dangling images after update." - echo "-r Allow updating images for docker run, wont update the container" + echo "-s Check stopped containers" + echo "-r Allow updating images for docker run, wont update the container" } -while getopts "aynprhe:" options; do +while getopts "aynprhse:" options; do case "${options}" in a|y) UpdYes="yes" ;; n) UpdYes="no" ;; r) DrUp="yes" ;; p) PruneQ="yes" ;; e) Exclude=${OPTARG} ;; + s) Stopped="yes" ;; h|*) Help ; exit 0 ;; esac done @@ -161,9 +163,18 @@ 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 $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do - ### Looping every item over the list of excluded names and skipping: +for i in ${Cadena} ; do + ### Looping every item over the list of excluded names and skipping: for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done printf ". " RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}') @@ -176,6 +187,10 @@ for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do fi done + + + + ### Sort arrays alphabetically IFS=$'\n' NoUpdates=($(sort <<<"${NoUpdates[*]}")) From 5dc9af9874223f2ed78c1914bb17a8809b7d8de4 Mon Sep 17 00:00:00 2001 From: mag37 Date: Mon, 28 Aug 2023 21:24:23 +0200 Subject: [PATCH 2/2] Update dockcheck.sh Did some changes to the logic, cleaned some whitespace. --- dockcheck.sh | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/dockcheck.sh b/dockcheck.sh index 9c1cdfa..4939e66 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -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,18 +25,19 @@ 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 "-r Allow updating images for docker run, wont update the container" + echo "-s Include stopped containers in the check. (Logic: docker ps -a)" } -while getopts "aynprhse:" options; do +Stopped="" +while getopts "aynprhse:" options; do case "${options}" in a|y) UpdYes="yes" ;; n) UpdYes="no" ;; r) DrUp="yes" ;; p) PruneQ="yes" ;; e) Exclude=${OPTARG} ;; - s) Stopped="yes" ;; + s) Stopped="-a" ;; h|*) Help ; exit 0 ;; esac done @@ -163,18 +164,9 @@ 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 - ### Looping every item over the list of excluded names and skipping: +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 ". " RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}') @@ -187,10 +179,6 @@ for i in ${Cadena} ; do fi done - - - - ### Sort arrays alphabetically IFS=$'\n' NoUpdates=($(sort <<<"${NoUpdates[*]}"))