#!/bin/bash make_tag () { local tag # generate a full image name with tag # $1 name, $2 user(or repo), $3 repo [[ $# -lt 1 ]] && echo "image base name required" && exit declare OPTION; declare OPTARG; declare OPTIND while getopts 'at:r:u:' OPTION; do # echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND} case "$OPTION" in r) REPO=$OPTARG ;; u) RUSER=$OPTARG ;; t) TAG=$OPTARG ;; a) # add -arm64 to image arm=arm64 ;; *) echo unknown run option -$OPTARG echo "USAGE: tag " echo "available options: -a add -arm64 to tag, -d delete tag " ;; esac done shift $((OPTIND - 1)) tag=$( echo $1 | cut -s -d ":" -f2) tag=${tag:-$TAG} name=${1%:*} user=${2:-$RUSER} repo=${3:-$REPO} tag=$([[ $repo ]] && echo ${repo}/)$([[ $user ]] && echo ${user}/)$name$([[ $arm ]] && echo -arm64):${tag:-latest} echo $tag } # if script was executed then call the function (return 0 2>/dev/null) || make_tag $@