minor edits

safer code, encapsulation etc.
This commit is contained in:
mag37
2023-01-18 19:13:45 +01:00
committed by GitHub
parent b5c3588aec
commit 9efbca8bb1

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
### Check arch: ### Check arch:
case "`uname --machine`" in case "$(uname --machine)" in
x86_64|amd64) x86_64|amd64)
architecture="amd64";; architecture="amd64";;
arm64|aarch64) arm64|aarch64)
@ -31,9 +31,9 @@ fi
for i in $(docker ps --format '{{.Names}}') for i in $(docker ps --format '{{.Names}}')
do do
printf ". " printf ". "
RepoUrl=$(docker inspect $i --format='{{.Config.Image}}') RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
LocalHash=$(docker image inspect $RepoUrl --format '{{.RepoDigests}}' | sed -e 's/.*sha256/sha256/' -e 's/\]$//') LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}' | sed -e 's/.*sha256/sha256/' -e 's/\]$//')
RegHash=$(./regctl image digest --list $RepoUrl) RegHash=$($regbin image digest --list "$RepoUrl")
if [[ "$LocalHash" != "$RegHash" ]] ; then if [[ "$LocalHash" != "$RegHash" ]] ; then
GotUpdates+=("$i") GotUpdates+=("$i")
else else
@ -42,11 +42,11 @@ printf ". "
done done
### List what containers got updates or not ### List what containers got updates or not
if [ ! -z $GotUpdates ] ; then if [ -n "$GotUpdates" ] ; then
printf "\n\033[31;1mContainers with updates available:\033[0m\n" printf "\n\033[31;1mContainers with updates available:\033[0m\n"
printf "%s\n" "${GotUpdates[@]}" printf "%s\n" "${GotUpdates[@]}"
fi fi
if [ ! -z $NoUpdates ] ; then if [ -n "$NoUpdates" ] ; then
printf "\n\033[32;1mContainers on latest version:\033[0m\n" printf "\n\033[32;1mContainers on latest version:\033[0m\n"
printf "%s\n" "${NoUpdates[@]}" printf "%s\n" "${NoUpdates[@]}"
fi fi
@ -59,7 +59,7 @@ if [ "$UpdYes" != "${UpdYes#[Yy]}" ] ; then
do do
# Check what compose-type is installed: # Check what compose-type is installed:
if docker compose &> /dev/null ; then DockerBin="docker compose" ; else DockerBin="docker-compose" ; fi if docker compose &> /dev/null ; then DockerBin="docker compose" ; else DockerBin="docker-compose" ; fi
ContPath=$(docker inspect $i --format '{{ index .Config.Labels "com.docker.compose.project.working_dir"}}') ContPath=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.working_dir"}}')
$DockerBin -f "$ContPath/docker-compose.yml" pull $DockerBin -f "$ContPath/docker-compose.yml" pull
$DockerBin -f "$ContPath/docker-compose.yml" up -d $DockerBin -f "$ContPath/docker-compose.yml" up -d
done done