From 367df5046c8ef01257c9a1b976ebf048ab4c7353 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Thu, 11 Jan 2024 01:53:19 +0000 Subject: [PATCH 1/4] gh_releases: default to only show latest stable --- .../usr/local/bin/gh_releases | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases b/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases index 2b3f8ed5..2fee7cd4 100755 --- a/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases +++ b/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases @@ -2,7 +2,6 @@ [[ -n $DEBUG ]] && set -x -repo_path="$1" # user/repo_name tmp_dir=/tmp/gh_releases rm -rf $tmp_dir mkdir -p $tmp_dir @@ -12,14 +11,19 @@ warning() { echo -e "[WARNING] $@" 1>&2; } usage() { cat >&2 </ +Usage: $(basename $0) [OPTIONS] / + +Options: + -a|--all show all (stable) versions, not just the most recent + -p|--inc-pre-release + include alpha, beta and rc versions Env Vars: # used for github api GITHUB_USER GITHUB_USER_TOKEN - # retain temp files and set x if set + # retain temp files and set x DEBUG # omit tags or releases in output respectively if set @@ -31,6 +35,24 @@ Note: Setting GITHUB_USER and GITHUB_USER_TOKEN environment variables are EOF } +unset show_all pre_release repo_path +while [[ "$#" -gt 0 ]]; do + case $1 in + -a|--all) + show_all=true;; + -p|--inc-pre-release) + pre_release=true;; + *) + if [[ -z "$repo_path" ]]; then + repo_path="$1" + else + usage + fatal "Unknown option: $1" + fi;; + esac + shift +done + if [[ -z "$repo_path" ]]; then usage fatal "user/repo not provided!" @@ -89,5 +111,12 @@ get_all_pages() { [[ -z $NO_TAGS ]] && get_all_pages "https://api.github.com/repos/${repo_path}/tags" "name" echo "Done!" 1>&2 -cat $tmp_dir/releases | sort --version-sort --unique +versions=$(cat $tmp_dir/releases | sort --version-sort --unique) +if [[ -z "$pre_release" ]]; then + versions=$(grep -vi 'alpha\|beta\|rc' <<<"$versions") +fi +if [[ -z "$show_all" ]]; then + versions=$(tail -1 <<<"$versions") +fi +echo "$versions" [[ -z $DEBUG ]] && rm -rf $tmp_dir From f5e415f91cc604a131d02a69d7076b02195b90ad Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Thu, 11 Jan 2024 03:53:37 +0000 Subject: [PATCH 2/4] Add -h|--help --- .../turnkey.d/github-latest-release/usr/local/bin/gh_releases | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases b/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases index 2fee7cd4..78bfa511 100755 --- a/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases +++ b/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases @@ -14,6 +14,7 @@ usage() { Usage: $(basename $0) [OPTIONS] / Options: + -h|--help show this help and exit -a|--all show all (stable) versions, not just the most recent -p|--inc-pre-release include alpha, beta and rc versions @@ -42,6 +43,9 @@ while [[ "$#" -gt 0 ]]; do show_all=true;; -p|--inc-pre-release) pre_release=true;; + -h|--help) + usage + exit;; *) if [[ -z "$repo_path" ]]; then repo_path="$1" From 5d276bd33b0156e63733e470318b9b923ea516be Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Thu, 11 Jan 2024 04:10:39 +0000 Subject: [PATCH 3/4] Actually --pre-release makes more sense --- .../turnkey.d/github-latest-release/usr/local/bin/gh_releases | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases b/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases index 78bfa511..1fd3db0b 100755 --- a/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases +++ b/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases @@ -16,7 +16,7 @@ Usage: $(basename $0) [OPTIONS] / Options: -h|--help show this help and exit -a|--all show all (stable) versions, not just the most recent - -p|--inc-pre-release + -p|--pre-release include alpha, beta and rc versions Env Vars: @@ -41,7 +41,7 @@ while [[ "$#" -gt 0 ]]; do case $1 in -a|--all) show_all=true;; - -p|--inc-pre-release) + -p|--pre-release) pre_release=true;; -h|--help) usage From 0b6a082b1bb8535ca7de1f96c47d6111c6f6d01d Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Thu, 25 Jan 2024 19:58:21 +1100 Subject: [PATCH 4/4] Apply shellcheck suggestions --- .../usr/local/bin/gh_releases | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases b/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases index 1fd3db0b..40de3938 100755 --- a/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases +++ b/overlays/turnkey.d/github-latest-release/usr/local/bin/gh_releases @@ -6,12 +6,12 @@ tmp_dir=/tmp/gh_releases rm -rf $tmp_dir mkdir -p $tmp_dir -fatal() { echo -e "\n[FATAL] $@" 1>&2; exit 1; } -warning() { echo -e "[WARNING] $@" 1>&2; } +fatal() { echo -e "\n[FATAL] $*" 1>&2; exit 1; } +warning() { echo -e "[WARNING] $*" 1>&2; } usage() { cat >&2 </ +Usage: $(basename "$0") [OPTIONS] / Options: -h|--help show this help and exit @@ -70,7 +70,7 @@ fi if [[ -n "$GITHUB_USER" ]] && [[ -n "$GITHUB_USER_TOKEN" ]]; then USER="-u $GITHUB_USER:$GITHUB_USER_TOKEN" else - warning $warn "Authentication won't be used." + warning "$warn Authentication won't be used." USER="" fi @@ -88,12 +88,12 @@ get_page() { key=$2 page=$3 tmp_file=$(mktemp $tmp_dir/XXXX.tmp) - curl $USER -b /tmp/cookies.txt -c /tmp/cookies.txt -s "${url}?page=${page}&per_page=100" > $tmp_file || true - if grep "Bad credentials" $tmp_file >/dev/null ; then + curl "$USER" -b /tmp/cookies.txt -c /tmp/cookies.txt -s "${url}?page=${page}&per_page=100" > "$tmp_file" || true + if grep "Bad credentials" "$tmp_file" >/dev/null ; then fatal "Bad GitHub credentials" else - grep -oP "\"$key\": \"\\K(.*)(?=\")" $tmp_file - rm -f $tmp_file + grep -oP "\"$key\": \"\\K(.*)(?=\")" "$tmp_file" + rm -f "$tmp_file" fi }