Commit a2a4e3e7 authored by Ivan Mazhukin's avatar Ivan Mazhukin

fix normalize function

parent f6173497
......@@ -97,14 +97,32 @@ sanitize_name() {
normalize_system_name() {
local raw="$1"
local normalized
#TODO сделать в одну строку и убрать башизм.
local image_name
local image_tag
normalized="${raw// /}"
normalized="${normalized,,}"
normalized="${normalized//\//:}"
[[ -n "$normalized" ]] || fatal "Target system is empty"
if [[ "$normalized" != *:* ]]; then
if [[ "$normalized" == *:* ]]; then
if [[ "$normalized" =~ ^[a-z0-9._/-]+:[a-z0-9._-]+$ ]]; then
printf '%s\n' "$normalized"
return 0
fi
fatal "Unsupported system format: $raw"
fi
if [[ "$normalized" == */* ]]; then
image_name="${normalized%/*}"
image_tag="${normalized##*/}"
if [[ "$image_tag" =~ ^v?[0-9][a-z0-9._-]*$ ]]; then
normalized="${image_name}:${image_tag}"
else
normalized="${normalized}:latest"
fi
else
normalized="${normalized}:latest"
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment