Skip to content

Commit

Permalink
add update checker and fix compact version name error
Browse files Browse the repository at this point in the history
  • Loading branch information
TuxVinyards committed Dec 16, 2024
1 parent 881ee8e commit 03e37fa
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 19 deletions.
45 changes: 38 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Point separated, multi-point separated or [semantic](http://semver.org/) version

Use as standalone or embedded (~90 lines)

- Check GitHub Latest Release or Tag
## Check GitHub Latest Release or Tag

```bash
floatversion -M "$(curl -sf "https://github.com/TuxVinyards/floatversion/releases" | grep 's/tag')"
1.0.0
1.1.0

floatversion -r "$(curl -sf https://github.com/qemu/qemu/tags | grep 's/tag')"
9.1.1 9.1.0 9.0.3 8.2.7 7.2.14
Expand Down Expand Up @@ -144,10 +144,21 @@ Requires up-to-date versions of Bash, Grep and JQ. On MacOS install these via Ho

### Standalone

Copy to `$PATH` eg `sudo cp floatversion /usr/bin` or place the script in with your program.
Copy to `$PATH` eg `sudo cp floatversion /usr/bin` or `/usr/local/bin`

Make sure that it has execute permissions `sudo chmod +x /usr/bin/floatversion`

Add a short link?

```bash
cd /usr/bin
sudo ln -s floatversion fv
fv -V
1.0.01
```

### Within a program

The following simple wrapper can be used in Bash to call an includes folder full script:

```bash
Expand All @@ -157,7 +168,7 @@ floatversion () {
}
```

For Non-Bash, see below
For Non-Bash, see [below](#use-in-different-shells)

### Embedding

Expand Down Expand Up @@ -207,7 +218,25 @@ Up to Date

### Updates

The script snippets, above, show how to check `floatversion` releases and how to compare versions.
The script snippets, [above,](#check-github-latest-release-or-tag) show how to check `floatversion` releases and how to compare versions.

Version 1.1 now has an auto-update checker that will run on request:

```txt
floatversion -V
CurrentVersion: 1.1.0
Checking for updates.... LatestVersion: 1.0.01 Up-to-Date
(c) Alex Genovese https://github.com/TuxVinyards/floatversion
OR ....
if floatversion -V | grep -sq 'Up-to-Date' ; then echo OK ; fi
OK
```

Alternatively see GitHub's dependabot docs for setting up alerts ....

Expand All @@ -223,7 +252,7 @@ For example:
/usr/bin/fish
╭─xxx@garuda in repo: floatversion on  main [$]
╰─λ floatversion -F 10 -M -n non-pad-test.txt
╰─λ floatversion -F 10 -M -n "non-pad-test.txt"
1.10.3
```

Expand Down Expand Up @@ -286,6 +315,8 @@ yes

### Limitations

The input _must resemble_ semantic versioning to _some_ extent. The version number must be _dot separated_. Integers are ignored.
The input must resemble [semantic versioning](http://semver.org/) to _some_ extent, or decimal floating points.

Plain integers are ignored. The version number must be _dot separated_. Only _one_ single _hyphenated_ suffix is permitted.

Some pre-filtering may be required.
38 changes: 26 additions & 12 deletions floatversion
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ float_version_from_string () {
local Verbose=
local UseSortV=
local NoSortVfallback=
local CurrentVersion=
local LatestVersion=
declare -a NumArrTemp
declare -a NumArrSorted
declare -a FilterArr
Expand All @@ -130,8 +132,20 @@ float_version_from_string () {
case "$1" in
-h|--help)
show_help ; return 0 ;;
-V|--version)
echo "1.0.01" ; return 0 ;;
-V|--version)
CurrentVersion="1.1.0"
printf "\n CurrentVersion: %s" "$CurrentVersion"
printf "\n\n Checking for updates.... "
LatestVersion="$(floatversion -M "$(curl -sf --max-time 5 "https://github.com/TuxVinyards/floatversion/releases" | grep 's/tag')" 2>/dev/null)"
if [[ $LatestVersion ]]; then
printf "LatestVersion: %s " "$LatestVersion"
if floatversion --gt "$LatestVersion $CurrentVersion" 2>/dev/null; then printf " UPGRADEABLE "
else printf " Up-to-Date "
fi
else printf "connection/data not available"
fi
printf "\n\n (c) Alex Genovese https://github.com/TuxVinyards/floatversion \n\n"
return 0 ;;
-c|--col)
ShowAsCol=1 ; shift ;;
-r|--rev)
Expand Down Expand Up @@ -360,9 +374,9 @@ float_version_from_string () {
# COMPACT VERSION, suitable for embedding into other scripts, if preferred (help and annotation removed)
# # NB make sure that locale is set in the main script. See notes at start.

float_version () {
floatversion () {
# floatversion --options "quoted-input-string-or-text-file"
# (c) Alex Genovese - version 1.0.0 (compact) - Usage/Help/Details @ https://github.com/TuxVinyards/floatversion
# (c) Alex Genovese - version 1.1.0 (compact) - Usage/Help/Details @ https://github.com/TuxVinyards/floatversion
local ShowAsStr= ; local ShowAsCol= ; local ShowMax= ; local ShowRev= ; local ShowAll= ; local SortNum= ; local GrepFull=
local InputText= ; local Nums= ; local NumsCount= ; local FilterString= ; local StartString= ; local DeleteString= ; local GTcompare=
local UseSortV= ; local NoSortVfallback= ; declare -a NumArrTemp ; declare -a NumArrSorted ; declare -a SelectArrTemp
Expand All @@ -381,27 +395,27 @@ float_version () {
-g|--gt) GTcompare=1 ; shift ;;
--sort-v) UseSortV=1 ; shift ;;
--no-svb) NoSortVfallback=1 ; shift ;;
*) if [[ "$1" == '-'* ]]; then printf "\n ERROR: '%s' not recognised \n" "$1" >&2 ; return 1
elif [[ $InputText ]]; then printf "\n ERROR: QUOTED Input String or Text File Name should be given only once \n" >&2 ; return 1
*) if [[ "$1" == '-'* ]]; then printf "\n ERROR: '%s' not recognised \n\n" "$1" >&2 ; return 1
elif [[ $InputText ]]; then printf "\n ERROR: QUOTED Input String or Text File Name should be given only once \n\n" >&2 ; return 1
else InputText="$1" ; shift ; fi ;;
esac
done
[[ -e "$InputText" ]] && InputText="$(cat -A "$InputText")"
InputText="$(tr -cd '[:print:]' <<< "$InputText" | tr ';' ' ' | tr '$' ' ' | tr ' ' '\n' | grep -sE '[[:print:]]')"
[[ ! $InputText ]] && printf "\n ERROR: no input found. Is '-i' or '-g' the last parameter plus input the last quoted element? \n" >&2 && return 1
[[ ! $InputText ]] && printf "\n ERROR: no input found. Is '-i' or '-g' the last parameter plus input the last quoted element? \n\n" >&2 && return 1
[[ $FilterString ]] && mapfile -t FilterArr <<< "$(tr ' ' '\n' <<< "$FilterString")"
[[ $StartString ]] && mapfile -t StartArr <<< "$(tr ' ' '\n' <<< "$StartString")"
[[ $DeleteString ]] && mapfile -t DeleteArr <<< "$(tr ' ' '\n' <<< "$DeleteString")"
if [[ $ShowMax ]]; then ShowAsStr= ; ShowAsCol= ; elif [[ $ShowAsCol ]]; then ShowAsStr= ; else ShowAsStr=1 ; fi
if [[ $UseSortV ]] && ! sort --help | grep -sq -o 'version-sort' ; then
if [[ $NoSortVfallback ]]; then printf "\n Sorry, 'sort -V' is not available, you need 'jq' to run this script. \n" >&2 ; else UseSortV= ; fi
if [[ $NoSortVfallback ]]; then printf "\n Sorry, 'sort -V' is not available, you need 'jq' to run this script. \n\n" >&2 ; else UseSortV= ; fi
fi
if [[ ! $UseSortV ]] && [[ ! "$(command -v jq)" ]]; then printf "\n Sorry, you need to install 'jq' to run this script. \n" >&2 ; fi
if [[ ! $UseSortV ]] && [[ ! "$(command -v jq)" ]]; then printf "\n Sorry, you need to install 'jq' to run this script. \n\n" >&2 ; fi
[[ $GTcompare ]] && GrepFull=1
if [[ $GrepFull ]]; then Nums="$(grep -sEo '[0-9]+([.][0-9]+)+([.][0-9]+)?+([.][0-9]+)?+([.][0-9]+)?+([-][[:alnum:]]+)?+([.][[:digit:]]+)?' <<< "$InputText" )"
else Nums="$(grep -sEo '[0-9]+([.][0-9]+)+([.][0-9]+)?+([.][0-9]+)?+([.][0-9]+)?' <<< "$InputText" )"; fi ; printf -v Nums "%s\n" "$Nums"
Nums="$(grep -s '[[:print:]]' <<< "$Nums")" ; NumsCount="$(grep -sc '[[:print:]]' <<< "$Nums")"
if [[ $GTcompare ]] && [[ "$NumsCount" != 2 ]]; then printf "\n ERROR: two floating point or semantic version values should be supplied" >&2 ; return 1 ; fi
if [[ $GTcompare ]] && [[ "$NumsCount" != 2 ]]; then printf "\n ERROR: two floating point or semantic version values should be supplied \n\n" >&2 ; return 1 ; fi
[[ ! $Nums ]] && return 1
mapfile -t NumArrTemp <<< "$(tr ' ' '\n' <<< "$Nums")"
if [[ $ShowAll ]]; then mapfile -t NumArrSorted <<< "$(printf "%s\n" "${NumArrTemp[@]}")"
Expand Down Expand Up @@ -453,8 +467,8 @@ float_version () {
##

# script call, developer option
if [[ $1 == "-C" ]] || [[ $1 == "--compact" ]]; then shift ; float_version "$@"
elif [[ $CompactVersion ]]; then float_version "$@"
if [[ $1 == "-C" ]] || [[ $1 == "--compact" ]]; then shift ; floatversion "$@"
elif [[ $CompactVersion ]]; then floatversion "$@"
else float_version_from_string "$@"
fi

Expand Down

0 comments on commit 03e37fa

Please sign in to comment.