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 #!/bin/bash
VERSION="v0.1.4" VERSION="v0.1.5"
Github="https://github.com/mag37/dockcheck" Github="https://github.com/mag37/dockcheck"
### Check if there's a new release of the script: ### Check if there's a new release of the script:
@@ -15,26 +15,26 @@ Help() {
echo "-h Print this Help." echo "-h Print this Help."
echo "-a|y Automatic updates, without interaction." echo "-a|y Automatic updates, without interaction."
echo "-n No updates, only checking availability." echo "-n No updates, only checking availability."
} }
while getopts "aynh" options; do while getopts "aynh" options; do
case "${options}" in case "${options}" in
a|y) UpdYes="yes" ;; a|y) UpdYes="yes" ;;
n) UpdYes="no" ;; n) UpdYes="no" ;;
h|*) Help ; exit 0 ;; h|*) Help ; exit 0 ;;
esac esac
done done
shift "$((OPTIND-1))" shift "$((OPTIND-1))"
### Set $1 to a variable for name filtering later. ### Set $1 to a variable for name filtering later.
SearchName="$1" SearchName="$1"
### Check if required binary exists in PATH or directory: ### Check if required binary exists in PATH or directory:
if [[ $(builtin type -P "regctl") ]]; then if [[ $(builtin type -P "regctl") ]]; then
regbin="regctl" regbin="regctl"
elif [[ -f "./regctl" ]]; then elif [[ -f "./regctl" ]]; then
regbin="./regctl" regbin="./regctl"
else else
printf "Required dependency 'regctl' missing, do you want it downloaded? y/[n] " printf "Required dependency 'regctl' missing, do you want it downloaded? y/[n] "
read GetDep read GetDep
if [ "$GetDep" != "${GetDep#[Yy]}" ]; then if [ "$GetDep" != "${GetDep#[Yy]}" ]; then
@@ -51,28 +51,28 @@ Help() {
printf "%s\n" "Dependency missing, quitting." printf "%s\n" "Dependency missing, quitting."
exit exit
fi fi
fi fi
### Check docker compose binary: ### Check docker compose binary:
if docker compose &> /dev/null ; then if docker compose &> /dev/null ; then
DockerBin="docker compose" DockerBin="docker compose"
elif docker-compose -v &> /dev/null; then elif docker-compose -v &> /dev/null; then
DockerBin="docker-compose" DockerBin="docker-compose"
else else
printf "%s\n" "No docker compose binary available, quitting." printf "%s\n" "No docker compose binary available, quitting."
exit exit
fi fi
### Numbered List -function: ### Numbered List -function:
options() { options() {
num=0 num=0
for i in "${NumberedUpdates[@]}"; do for i in "${NumberedUpdates[@]}"; do
echo "$num) $i" echo "$num) $i"
((num++)) ((num++))
done done
} }
### Choose from list -function: ### Choose from list -function:
choosecontainers() { choosecontainers() {
while [[ "$ChoiceClean" =~ [A-Za-z] || -z "$ChoiceClean" ]]; do while [[ "$ChoiceClean" =~ [A-Za-z] || -z "$ChoiceClean" ]]; do
read -p "Enter number(s) separated by comma, [q] to quit: " Choice read -p "Enter number(s) separated by comma, [q] to quit: " Choice
if [[ "$Choice" =~ [qQnN] ]] ; then if [[ "$Choice" =~ [qQnN] ]] ; then
@@ -90,10 +90,10 @@ Help() {
printf "\nUpdating containers:\n" printf "\nUpdating containers:\n"
printf "%s\n" "${SelectedUpdates[@]}" printf "%s\n" "${SelectedUpdates[@]}"
printf "\n" printf "\n"
} }
### Check the image-hash of every running container VS the registry ### Check the image-hash of every running container VS the registry
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
printf ". " printf ". "
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}') RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}') LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
@@ -104,11 +104,11 @@ Help() {
else else
GotErrors+=("$i") GotErrors+=("$i")
fi fi
done done
### Sort arrays alphabetically ### Sort arrays alphabetically
IFS=$'\n' IFS=$'\n'
NoUpdates=($(sort <<<"${NoUpdates[*]}")) NoUpdates=($(sort <<<"${NoUpdates[*]}"))
GotUpdates=($(sort <<<"${GotUpdates[*]}")) GotUpdates=($(sort <<<"${GotUpdates[*]}"))
GotErrors=($(sort <<<"${GotErrors[*]}")) GotErrors=($(sort <<<"${GotErrors[*]}"))
unset IFS unset IFS