From a90743a09c1a0940ac3bdf7f0142ea0c272c0946 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Sun, 21 Apr 2024 14:56:41 +0300 Subject: [PATCH] feat(bin): x-gh-get-latest-* release and version helpers --- local/bin/x-gh-get-latest-release-targz | 17 +++++++++++++++++ local/bin/x-gh-get-latest-version | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 local/bin/x-gh-get-latest-release-targz create mode 100755 local/bin/x-gh-get-latest-version diff --git a/local/bin/x-gh-get-latest-release-targz b/local/bin/x-gh-get-latest-release-targz new file mode 100755 index 0000000..bf5d968 --- /dev/null +++ b/local/bin/x-gh-get-latest-release-targz @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +REPO=$1 + +if [ -z "$REPO" ]; then + echo "Usage: $0 (e.g. ivuorinen/dotfiles)" + exit 1 +fi + +LOCATION=$(curl -s "https://api.github.com/repos/${REPO}/releases/latest" \ + | sed -Ene '/^[[:blank:]]+"tarball_url":[[:blank:]]"(https:[^"]+)",/s//\1/p') + +echo "Downloading and extracting from: $LOCATION" + +curl --location --silent "$LOCATION" | tar --extract --gzip --file=- + +# vim: set ts=2 sw=2 ft=sh et: diff --git a/local/bin/x-gh-get-latest-version b/local/bin/x-gh-get-latest-version new file mode 100755 index 0000000..d1f2a18 --- /dev/null +++ b/local/bin/x-gh-get-latest-version @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +REPO=$1 + +if [ -z "$REPO" ]; then + echo "Usage: $0 (e.g. ivuorinen/dotfiles)" + exit 1 +fi + +VERSION=$( + curl -s "https://api.github.com/repos/${REPO}/releases/latest" \ + | grep "tag_name" \ + | awk '{print substr($2, 2, length($2)-3)}' +) + +echo "$VERSION" + +# vim: set ts=2 sw=2 ft=sh et: