Update dupc_function.sh

re-wrote it some to followe the changes in the main script.
This commit is contained in:
mag37 2023-01-23 12:05:22 +01:00 committed by GitHub
parent 98b6074723
commit 17e6bd4dcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,25 +1,29 @@
#!/bin/bash #!/bin/bash
### Requires the regctl binary, either in PATH or as an alias ### Requires the regctl binary.
### Get it here: https://github.com/regclient/regclient/releases ### Get it here: https://github.com/regclient/regclient/releases
### Preferably placed in .bashrc or similar ### Preferably placed in .bashrc or similar
### if regctl is not in PATH, set the alias: ### Set the full path to the binary or just regctl if in PATH:
alias regctl="/path/to/regctl" regctl="/home/gw-tdc/dockers/regctl"
dupc () { dupc () {
if [[ -z "$1" ]]; then if [[ "$@" == "help" ]]; then
echo "No container name given, here's the list of currently running containers:" echo "No container name given, here's the list of currently running containers:"
docker ps --format '{{.Names}}' docker ps --format '{{.Names}}'
else else
for i in $(docker ps --filter "name=$1" --format '{{.Names}}') for i in $(docker ps --filter "name=$@" --format '{{.Names}}')
do do
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}}')
RegHash=$(regctl image digest --list $RepoUrl) RegHash=$($regctl image digest --list $RepoUrl 2>/dev/null)
if [[ "$LocalHash" != "$RegHash" ]] ; then printf "Updates available for $i.\n" ; else printf "$i is already latest.\n" ; fi if [ $? -eq 0 ] ; then
if [[ "$LocalHash" = *"$RegHash"* ]] ; then printf "$i is already latest.\n" ; else printf "$i got updates.\n" ; fi
else
printf "$i got errors, no check possible.\n"
fi
done done
fi fi
} }
dupc $1