aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xautotag.sh45
1 files changed, 23 insertions, 22 deletions
diff --git a/autotag.sh b/autotag.sh
index d3de206..4f443c5 100755
--- a/autotag.sh
+++ b/autotag.sh
@@ -1,40 +1,41 @@
#!/usr/bin/env bash
#Clyhtsuriva
-PURPLE='\033[1;35m'
-RED='\033[0;31m'
-NC='\033[0m'
+PURPLE=$(tput setaf 5)
+RED=$(tput setaf 1)
+NC=$(tput sgr0)
#just for aesthetic when printing on stdout
-[ -z "$1" ] && printf "${RED}Image name required${NC}\n" && exit 1 #the user should give us the image name
+[ -z "$1" ] && printf "%s\n" "${RED}Image name required${NC}" && exit 1 #the user should give us the image name
image="$1"
host="localhost"
port=5000
-request="curl -s "$host":"$port"/v2/"$image"/tags/list"
+request="curl -s $host:$port/v2/$image/tags/list"
json=$($request) #actually do the request
-printf "${PURPLE}request: $request\n"
-printf "json response: $json${NC}\n"
+printf "%s\n" "${PURPLE}request: $request"
+printf "%s\n" "json response: $json${NC}"
-[ -n "$(grep "error" <<< $json)" ] && printf "${RED}Image not found${NC}\n" && exit 1
+grep -q "error" <<< "$json" && printf "%s\n" "${RED}Image not found${NC}" && exit 1
-parsed=$(cut -d: -f3 <<< $json) #only takes what's after "tags"
+parsed=$(cut -d: -f3 <<< "$json") #only takes what's after "tags"
i=1
max_found=0
buffer=0
-while [ $max_found -eq 0 ]; do
+while [ $max_found -eq 0 ]; do
- if [ ! -z $(grep "v" <<< $(cut -d'"' -f$i <<< $parsed)) ]; then
+ if ! grep -q "v" <<< "$(cut -d'"' -f$i <<< "$parsed")" ; then
#if there is a v when cutting with the delimiter "
- latest=$(cut -d'"' -f$i <<< $parsed) #since it's ok, we're saving it
- [ $(sed 's/v//g' <<< $latest) -gt $buffer ] && buffer=$(sed 's/v//g' <<< $latest)
- #save in buffer in greater than anything else
+ latest=$(cut -d'"' -f$i <<< "$parsed") #since it's ok, we're saving it
+ [ "$(sed 's/v//g' <<< "$latest")" -gt $buffer ] && \
+ buffer=$(sed 's/v//g' <<< "$latest")
+ #save in buffer in greater than anything else
fi
((i++)) # incrementing
- if [ -z $(cut -d'"' -f$i <<< $parsed) ]; then
+ if [ -z "$(cut -d'"' -f"$i" <<< "$parsed")" ]; then
max_found=1 #if it's empty, it means we are out of tags
fi
done
@@ -43,13 +44,13 @@ done
latest=$buffer
version=$latest
((version++))
-printf "${PURPLE}latest version: v$latest\n"
-printf "new tag: v$version\n"
+printf "%s\n" "${PURPLE}latest version: v$latest"
+printf "%s\n" "new tag: v$version"
-printf "Tagging ...${NC}\n"
-docker tag $image localhost/$image:v$version
-printf "${PURPLE}Pushing ...${NC}\n"
-docker push localhost/$image:v$version
+printf "%s\n" "Tagging ...${NC}"
+docker tag "$image" localhost/"$image":v"$version"
+printf "%s\n" "${PURPLE}Pushing ...${NC}"
+docker push localhost/"$image":v"$version"
-printf "${PURPLE}Looking at the registry ...${NC}\n"
+printf "%s\n" "${PURPLE}Looking at the registry ...${NC}"
$request