#!/bin/bash make_tag () { local DIR DIR=$(cd "$(dirname "$BASH_SOURCE")" >/dev/null 2>&1 ; pwd -P ) # 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 'daht:r:u:' OPTION; do # echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND} case "$OPTION" in d) delete=true ;; 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)) # image 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 $@