Update dockcheck.sh

Added condition based on the contents of the `com.docker.compose.project.config_files` label.
This commit is contained in:
Alex
2023-02-09 12:00:29 +00:00
committed by GitHub
parent 4302d45033
commit d5c90fb98d
+40 -35
View File
@@ -1,5 +1,5 @@
#!/bin/bash
VERSION="v0.1.5"
VERSION="v0.1.4"
Github="https://github.com/mag37/dockcheck"
### Check if there's a new release of the script:
@@ -15,26 +15,26 @@ Help() {
echo "-h Print this Help."
echo "-a|y Automatic updates, without interaction."
echo "-n No updates, only checking availability."
}
}
while getopts "aynh" options; do
while getopts "aynh" options; do
case "${options}" in
a|y) UpdYes="yes" ;;
n) UpdYes="no" ;;
h|*) Help ; exit 0 ;;
esac
done
shift "$((OPTIND-1))"
done
shift "$((OPTIND-1))"
### Set $1 to a variable for name filtering later.
SearchName="$1"
### Set $1 to a variable for name filtering later.
SearchName="$1"
### Check if required binary exists in PATH or directory:
if [[ $(builtin type -P "regctl") ]]; then
### Check if required binary exists in PATH or directory:
if [[ $(builtin type -P "regctl") ]]; then
regbin="regctl"
elif [[ -f "./regctl" ]]; then
elif [[ -f "./regctl" ]]; then
regbin="./regctl"
else
else
printf "Required dependency 'regctl' missing, do you want it downloaded? y/[n] "
read GetDep
if [ "$GetDep" != "${GetDep#[Yy]}" ]; then
@@ -51,28 +51,28 @@ else
printf "%s\n" "Dependency missing, quitting."
exit
fi
fi
### Check docker compose binary:
if docker compose &> /dev/null ; then
fi
### Check docker compose binary:
if docker compose &> /dev/null ; then
DockerBin="docker compose"
elif docker-compose -v &> /dev/null; then
elif docker-compose -v &> /dev/null; then
DockerBin="docker-compose"
else
else
printf "%s\n" "No docker compose binary available, quitting."
exit
fi
fi
### Numbered List -function:
options() {
num=0
for i in "${NumberedUpdates[@]}"; do
### Numbered List -function:
options() {
num=0
for i in "${NumberedUpdates[@]}"; do
echo "$num) $i"
((num++))
done
}
done
}
### Choose from list -function:
choosecontainers() {
### Choose from list -function:
choosecontainers() {
while [[ "$ChoiceClean" =~ [A-Za-z] || -z "$ChoiceClean" ]]; do
read -p "Enter number(s) separated by comma, [q] to quit: " Choice
if [[ "$Choice" =~ [qQnN] ]] ; then
@@ -90,10 +90,10 @@ choosecontainers() {
printf "\nUpdating containers:\n"
printf "%s\n" "${SelectedUpdates[@]}"
printf "\n"
}
}
### Check the image-hash of every running container VS the registry
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
### 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}}')
@@ -104,11 +104,11 @@ for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
else
GotErrors+=("$i")
fi
done
done
### Sort arrays alphabetically
IFS=$'\n'
NoUpdates=($(sort <<<"${NoUpdates[*]}"))
### Sort arrays alphabetically
IFS=$'\n'
NoUpdates=($(sort <<<"${NoUpdates[*]}"))
GotUpdates=($(sort <<<"${GotUpdates[*]}"))
GotErrors=($(sort <<<"${GotErrors[*]}"))
unset IFS
@@ -143,8 +143,14 @@ if [ -n "$GotUpdates" ] ; then
ContPath=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.working_dir" }}')
ContConfigFile=$(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/$ContConfigFile" pull "$ContName"
$DockerBin -f "$ContPath/$ContConfigFile" up -d "$ContName"
### Checking if "com.docker.compose.project.config_files" returns the full path to the config file or just the file name
if [[ $ContConfigFile = '/'* ]] ; then
ComposeFile="$ContConfigFile"
else
ComposeFile="$ContPath/$ContConfigFile"
fi
$DockerBin -f "$ComposeFile" pull "$ContName"
$DockerBin -f "$ComposeFile" up -d "$ContName"
done
else
printf "\nNo updates installed, exiting.\n"
@@ -154,4 +160,3 @@ else
fi
exit 0