Update check image

This commit is contained in:
Shiming Zhang
2024-06-22 19:22:25 +08:00
parent a563464a89
commit 5c3c861f00
3 changed files with 47 additions and 23 deletions

32
hack/correct-image.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
function guess_image() {
local image="${1}"
image="${image# }"
image="${image% }"
if [[ -z "${image}" ]]; then
return
fi
if [[ "${image}" == *"registry.docker.com/r"* ]]; then
image="docker.io/${image##*registry.hub.docker.com\/r\/}"
fi
if [[ "${image}" == *"hub.docker.com/r"* ]]; then
image="docker.io/${image##*hub.docker.com\/r\/}"
fi
if [[ "${image%%/*}" != *"."* ]] || [[ "${image}" != *"/"* ]]; then
image="docker.io/${image}"
fi
if [[ "${image}" != *":"* ]]; then
image="${image}:latest"
fi
if [[ "${image}" == *"//"* ]] || [[ "${image}" == *" "* ]]; then
return
fi
echo "${image}"
}
guess_image "${1}"