#!/bin/bash
USER="admin"
PASS="Harbor12345"
HURL="http://test.aflm.com/"
MTAG=$1
ttoken=$(curl -iksL -X GET -u $USER:$PASS $HURL/service/token?account=${USER}\&service=harbor-registry\&scope=repository:${MTAG}:pull|grep "token" |awk -F '"' '{print $4}')
#echo $ttoken
tlist=$(curl -ksL -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $ttoken" ${HURL}/v2/${MTAG}/tags/list|awk -F '[' '{print $2}'|awk -F ']' '{print $1}'|sed 's/"//g')
echo $tlist|sed 's/,/\n/g' |grep $2 >/dev/null
if [ $? = 0 ];then
echo "images tag "echo $tlist|sed 's/,/\n/g' |grep $2""
echo "image tag already exists,account code not updated"
else
echo "image is not没有找到最新代码镜像"
exit 1
fi