#!/bin/bash image_name () { local tag; local efile # 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 'e:ag:r:u:' OPTION; do # echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND} case "$OPTION" in e) efile=$OPTARG ;; r) REPO=$OPTARG ;; u) RUSER=$OPTARG ;; g) 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)) echo $efile if [[ $efile ]]; then [[ ! -f $efile ]] && efile=$SDIR/$efile if [[ -f $efile ]]; then source $efile [[ ! $? -eq 0 ]] && echo source of $efile failed, exiting && return 2 else echo no environment file at $efile, exiting return 2 fi echo "----------" echo loaded environment filen $efile cat $efile echo "----------" fi 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) || image_name $@