Skip to content

Commit

Permalink
enh: Optimize get_last_netbox_version
Browse files Browse the repository at this point in the history
  • Loading branch information
amhn committed Sep 4, 2022
1 parent b761180 commit 7b0dd96
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions utils/netbox_generate_client
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,17 @@ get_last_netbox_version() {

while [ "$NEXT" != "null" ]
do
i=$((i+1))
JSON=$(curl https://registry.hub.docker.com/v2/repositories/netboxcommunity/netbox/tags/?page=$i 2>/dev/null)
tags="$tags $(echo $JSON | jq '."results"[]["name"]')"
NEXT=$(echo $JSON | jq '."next"')
i=$((i+1))
JSON=$(curl https://registry.hub.docker.com/v2/repositories/netboxcommunity/netbox/tags/?page=$i\&page_size=1000 2>/dev/null)
tags="$tags $(echo $JSON | jq -r '."results"[]["name"]' | grep $version | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+-[0-9]+\.[0-9]+\.[0-9]+$")"
NEXT=$(echo $JSON | jq '."next"')
done

for t in $tags; do
tag="$(echo $t | xargs)"
if [ "$(echo $tag | grep "$version")" == "$tag" -a "$(echo $tag | grep -v "ldap")" == "$tag" -a "$(echo $tag | grep -v "develop")" == "$tag" ]; then
tags_list="$tags_list $tag"
fi
done

for t in $tags_list; do
if [[ $t =~ ^v[0-9]+\.[0-9]+\.[0-9]+-[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
MAJOR=$(echo $t | cut -d"-" -f1 | cut -d"." -f3)
if [ "$MAJOR" != "" ]; then
if [ $MAJOR -gt $max ]; then
max=$MAJOR
docker="$(echo $t | cut -d"-" -f2)"
fi
fi
MAJOR=$(echo $t | cut -d"-" -f1 | cut -d"." -f3)
if [ "$MAJOR" != "" -a $MAJOR -gt $max ]; then
max=$MAJOR
docker="$(echo $t | cut -d"-" -f2)"
fi
done

Expand Down

0 comments on commit 7b0dd96

Please sign in to comment.