mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-18 02:17:46 +00:00
re-ordering, cleaning.
Moved where the `options` function got called, and replaced the "Containers with updates available:" -listing with the numbered list straight away. Instead of having the question "want updates?" before listing with numbers. Cleaner this way.
This commit is contained in:
@@ -58,38 +58,7 @@ else
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### Check the image-hash of every running container VS the registry
|
### Numbered List -function:
|
||||||
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}}')
|
|
||||||
RegHash=$($regbin image digest --list "$RepoUrl" 2>/dev/null)
|
|
||||||
# Check if regtcl produces errors - add to GotErrors if so.
|
|
||||||
if [ $? -eq 0 ] ; then
|
|
||||||
if [[ "$LocalHash" = *"$RegHash"* ]] ; then NoUpdates+=("$i"); else GotUpdates+=("$i"); fi
|
|
||||||
else
|
|
||||||
GotErrors+=("$i")
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
### List what containers got updates or not
|
|
||||||
if [ -n "$NoUpdates" ] ; then
|
|
||||||
printf "\n\033[32;1mContainers on latest version:\033[0m\n"
|
|
||||||
printf "%s\n" "${NoUpdates[@]}"
|
|
||||||
fi
|
|
||||||
if [ -n "$GotUpdates" ] ; then
|
|
||||||
printf "\n\033[31;1mContainers with updates available:\033[0m\n"
|
|
||||||
printf "%s\n" "${GotUpdates[@]}"
|
|
||||||
fi
|
|
||||||
if [ -n "$GotErrors" ] ; then
|
|
||||||
printf "\n\033[33;1mContainers with errors, wont get updated:\033[0m\n"
|
|
||||||
printf "%s\n" "${GotErrors[@]}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
### SELECTION definitions and functions:
|
|
||||||
NumberedUpdates=(all "${GotUpdates[@]}")
|
|
||||||
|
|
||||||
options() {
|
options() {
|
||||||
num=0
|
num=0
|
||||||
for i in "${NumberedUpdates[@]}"; do
|
for i in "${NumberedUpdates[@]}"; do
|
||||||
@@ -98,10 +67,11 @@ for i in "${NumberedUpdates[@]}"; do
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
### Choose from list -function:
|
||||||
choosecontainers() {
|
choosecontainers() {
|
||||||
while [[ "$ChoiceClean" =~ [A-Za-z] || -z "$ChoiceClean" ]]; do
|
while [[ "$ChoiceClean" =~ [A-Za-z] || -z "$ChoiceClean" ]]; do
|
||||||
printf "What containers do you like to update? \n"
|
printf "What containers do you like to update? \n"
|
||||||
options
|
# options
|
||||||
read -p 'Enter number(s) separated by , : ' Choice
|
read -p 'Enter number(s) separated by , : ' Choice
|
||||||
if [ "$Choice" == "0" ] ; then
|
if [ "$Choice" == "0" ] ; then
|
||||||
SelectedUpdates=( ${NumberedUpdates[@]:1} )
|
SelectedUpdates=( ${NumberedUpdates[@]:1} )
|
||||||
@@ -117,6 +87,37 @@ printf "\nYou've SelectedUpdates:\n"
|
|||||||
printf "%s\n" "${SelectedUpdates[@]}"
|
printf "%s\n" "${SelectedUpdates[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
### Check the image-hash of every running container VS the registry
|
||||||
|
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}}')
|
||||||
|
RegHash=$($regbin image digest --list "$RepoUrl" 2>/dev/null)
|
||||||
|
# Check if regtcl produces errors - add to GotErrors if so.
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
if [[ "$LocalHash" = *"$RegHash"* ]] ; then NoUpdates+=("$i"); else GotUpdates+=("$i"); fi
|
||||||
|
else
|
||||||
|
GotErrors+=("$i")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
### Create new Array to use for the numbered list:
|
||||||
|
NumberedUpdates=(ALL "${GotUpdates[@]}")
|
||||||
|
|
||||||
|
### List what containers got updates or not
|
||||||
|
if [ -n "$NoUpdates" ] ; then
|
||||||
|
printf "\n\033[32;1mContainers on latest version:\033[0m\n"
|
||||||
|
printf "%s\n" "${NoUpdates[@]}"
|
||||||
|
fi
|
||||||
|
if [ -n "$GotErrors" ] ; then
|
||||||
|
printf "\n\033[33;1mContainers with errors, wont get updated:\033[0m\n"
|
||||||
|
printf "%s\n" "${GotErrors[@]}"
|
||||||
|
fi
|
||||||
|
if [ -n "$GotUpdates" ] ; then
|
||||||
|
printf "\n\033[31;1mContainers with updates available:\033[0m\n"
|
||||||
|
options
|
||||||
|
fi
|
||||||
|
|
||||||
### Optionally get updates if there's any
|
### Optionally get updates if there's any
|
||||||
if [ -n "$GotUpdates" ] ; then
|
if [ -n "$GotUpdates" ] ; then
|
||||||
if [ -z "$UpdYes" ] ; then
|
if [ -z "$UpdYes" ] ; then
|
||||||
|
|||||||
Reference in New Issue
Block a user