Update dockcheck.sh

Fixed formatting.
This commit is contained in:
Alex
2023-02-09 12:03:27 +00:00
committed by GitHub
parent d5c90fb98d
commit 8b8ac84a44

View File

@@ -1,5 +1,5 @@
#!/bin/bash
VERSION="v0.1.4"
VERSION="v0.1.5"
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 @@ Help() {
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 @@ Help() {
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 @@ Help() {
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