Skip to content

Commit

Permalink
Merge pull request #15 from DelusionalOptimist/update-install-script
Browse files Browse the repository at this point in the history
chore: add ability to install latest patch version
  • Loading branch information
DelusionalOptimist authored Aug 29, 2024
2 parents 70974e5 + 22a224d commit 4ae58a0
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion content/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ Usage: $this [-b] bindir [-d] [tag]
-b sets bindir or installation directory, Defaults to ./bin
-d turns on debug logging
[tag] is a tag from -
[tag] is a semver tag from -
https://github.com/accuknox/knoxctl-website/releases
[tag] might also be without the patch version.
In this case latest patch version of the given release version
will be fetched.
Example: v0.4
If tag is missing, then the latest will be used.
EOF
Expand Down Expand Up @@ -102,6 +107,17 @@ semver_compare() {
return 1
}

get_patch_version() {
owner_repo=$1
tag=${2#v}
giturl="https://api.github.com/repos/${owner_repo}/releases"
json=$(http_copy "$giturl" "Accept:application/json")
test -z "$json" && return 1
version=$(echo $json | tr -s ',' '\n' | sed -n 's/.*"tag_name"\s*:\s*"\(.*'${tag}'.*\)"/\1/p' | head -n 1)
test -z "$version" && return 1
echo "$version"
}

tag_to_version() {
if [ -z "${TAG}" ]; then
# latest tag will always be fetched from GitHub
Expand All @@ -111,6 +127,14 @@ tag_to_version() {
# check GitHub only if provided tag greater than/equal to v0.3.0
if semver_compare "${TAG#v}" "0.3.0"; then
log_info "checking GitHub for tag '${TAG}'"

# tag doesn't contain patch version
temp_tag=${TAG#v}
tag_length=${#temp_tag}
if [[ $tag_length -le 3 ]]; then
TAG=$(get_patch_version "$OWNER/$REPO" $TAG)
fi

else
log_info "downloading from knoxctl.accuknox.com"
# if version starts with 'v', remove it
Expand Down

0 comments on commit 4ae58a0

Please sign in to comment.