From 8ae13837f17741aa8ed35f4577d54f8be39c2a61 Mon Sep 17 00:00:00 2001 From: mag37 Date: Thu, 2 Feb 2023 13:17:15 +0100 Subject: [PATCH 1/5] cleaning Securing some variable calls with quoting. Minor cleaning. --- dockcheck.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/dockcheck.sh b/dockcheck.sh index 346b8a5..680b499 100644 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -1,5 +1,5 @@ #!/bin/bash -### VERSION v.0.1.1 +### VERSION v.0.1.3 ### Help Function: Help() { @@ -21,7 +21,7 @@ while getopts "aynh" options; do done shift "$((OPTIND-1))" -### Set $1 to a variable for later +### Set $1 to a variable for name filtering later. SearchName="$1" ### Check if required binary exists in PATH or directory: @@ -70,15 +70,14 @@ done choosecontainers() { while [[ "$ChoiceClean" =~ [A-Za-z] || -z "$ChoiceClean" ]]; do printf "What containers do you like to update? \n" - # options read -p 'Enter number(s) separated by comma (eg. 1,3,4): ' Choice if [ "$Choice" == "0" ] ; then - SelectedUpdates=( ${NumberedUpdates[@]:1} ) - ChoiceClean=$(echo $Choice|sed 's/[,.:;]/ /g') + SelectedUpdates=( "${NumberedUpdates[@]:1}" ) + ChoiceClean=$(echo "$Choice" |sed 's/[,.:;]/ /g') else - ChoiceClean=$(echo $Choice|sed 's/[,.:;]/ /g') - for s in $ChoiceClean; do - SelectedUpdates+=( ${NumberedUpdates[$s]} ) + ChoiceClean=$(echo "$Choice" |sed 's/[,.:;]/ /g') + for s in "$ChoiceClean"; do + SelectedUpdates+=( "${NumberedUpdates[$s]}" ) done fi done @@ -92,7 +91,7 @@ for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do 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. + # Add container to GotErrors if regctl encounter problems. if [ $? -eq 0 ] ; then if [[ "$LocalHash" = *"$RegHash"* ]] ; then NoUpdates+=("$i"); else GotUpdates+=("$i"); fi else From a7bfb49fadf5b6bcea23182da8800ea6cc286902 Mon Sep 17 00:00:00 2001 From: mag37 Date: Thu, 2 Feb 2023 21:29:10 +0100 Subject: [PATCH 2/5] version-format Changed Version-format to a variable instead of comment, for future use with version-checking. --- dockcheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockcheck.sh b/dockcheck.sh index 680b499..cd2960c 100644 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -1,5 +1,5 @@ #!/bin/bash -### VERSION v.0.1.3 +VERSION="v0.1.3" ### Help Function: Help() { From 08175c87ab1c91a471fee8a618b14686c95cd8c1 Mon Sep 17 00:00:00 2001 From: mag37 Date: Thu, 2 Feb 2023 22:02:41 +0100 Subject: [PATCH 3/5] added ugly version-check curl-check on the version in local VS raw on github to let the user know there's a new release. --- dockcheck.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dockcheck.sh b/dockcheck.sh index cd2960c..bfdc7e0 100644 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -1,5 +1,10 @@ #!/bin/bash VERSION="v0.1.3" +Github="https://github.com/mag37/dockcheck" + +### Check if there's a new release of the script: +LatestRelease="$(curl -s -r 0-30 https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')" +[ $VERSION != $LatestRelease ] && printf "New version available! Latest: $LatestRelease - Local: $VERSION \nGrab it here: $Github \n" ### Help Function: Help() { From bde81aad22f41300d55981861618e1ca1938cedd Mon Sep 17 00:00:00 2001 From: mag37 Date: Thu, 2 Feb 2023 22:07:33 +0100 Subject: [PATCH 4/5] forgot quoting. Quote the variables... again. --- dockcheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockcheck.sh b/dockcheck.sh index bfdc7e0..7f6b1bc 100644 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -4,7 +4,7 @@ Github="https://github.com/mag37/dockcheck" ### Check if there's a new release of the script: LatestRelease="$(curl -s -r 0-30 https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')" -[ $VERSION != $LatestRelease ] && printf "New version available! Latest: $LatestRelease - Local: $VERSION \nGrab it here: $Github \n" +[ "$VERSION" != "$LatestRelease" ] && printf "New version available! Latest: "$LatestRelease" - Local: "$VERSION" \nGrab it here: "$Github" \n\n" ### Help Function: Help() { From dd42100a3d0935d3a9ede99c179a99a63eb32c0a Mon Sep 17 00:00:00 2001 From: mag37 Date: Sat, 4 Feb 2023 12:35:08 +0100 Subject: [PATCH 5/5] added new update from main Added the fix to only update the service chosen, not the whole stack. thanx to @maanoobh --- dockcheck.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dockcheck.sh b/dockcheck.sh index 7f6b1bc..6033c95 100644 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -139,9 +139,10 @@ if [ -n "$GotUpdates" ] ; then if [ "$UpdYes" != "${UpdYes#[Yy]}" ] ; then for i in "${SelectedUpdates[@]}" do - ContPath=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.config_files"}}') - $DockerBin -f "$ContPath" pull - $DockerBin -f "$ContPath" up -d + ContPath=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.config_files" }}') + ContName=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.service" }}') + $DockerBin -f "$ContPath" pull "$ContName" + $DockerBin -f "$ContPath" up -d "$ContName" done else printf "\nNo updates installed, exiting.\n"