Skip to content

Commit 67cad59

Browse files
committed
removed bc dependency (fixes #35)
1 parent 0b25d25 commit 67cad59

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

kscript

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ assertInPath(){ if [ -z "$(which $1)" ]; then echo "[ERROR] Could not locate '$1
99
## trim whitespace from a string
1010
trim() { while read -r line; do echo "$line"; done; }
1111

12+
## pad version with 0s. From https://stackoverflow.com/questions/18668556/comparing-numbers-in-bash
13+
function pad_version { printf "%03d" $(echo "$1" | tr '.' ' '); }
14+
15+
1216
assertInPath kotlinc
1317
assertInPath mvn
1418

@@ -52,14 +56,14 @@ if [ $# == 0 ] || [ "$1" == "-v" ] || [ "$1" == "--version" ] || [ "$1" == "-h"
5256
echo "Website : https://github.com/holgerbrandl/kscript" >&2
5357

5458
## determine the latest version
55-
latestVersion=$(kurl https://git.io/v9R73 | grep '^KSCRIPT_VERSION' | cut -f2 -d'=' | tr -d '.')
56-
installedVersion=$(echo $KSCRIPT_VERSION | tr -d '.')
59+
latestVersion=$(kurl https://git.io/v9R73 | grep '^KSCRIPT_VERSION' | cut -f2 -d'=')
60+
installedVersion=$(echo $KSCRIPT_VERSION | cut -f1 -d'-')
5761

5862
## http://stackoverflow.com/questions/15224581/floating-point-comparison-with-variable-in-bash
59-
## fixme bc is a dependency, use a kscriptlet here
60-
if [ $(echo " ${latestVersion} > ${installedVersion}" | bc) -eq 1 ]; then
61-
bold=$(tput bold); normal=$(tput sgr0) ## http://stackoverflow.com/questions/2924697/how-does-one-output-bold-text-in-bash
62-
echo -e "\n${bold}A new version of kscript is available. Use 'kscript --self-update' to update your local kscript installation" >&2
63+
if (( $(pad_version ${latestVersion}) > $(pad_version ${installedVersion}) )); then
64+
## http://stackoverflow.com/questions/2924697/how-does-one-output-bold-text-in-bash
65+
bold=$(tput bold); normal=$(tput sgr0)
66+
echo -e "\n${bold}A new version (v${latestVersion}) of kscript is available. Use 'kscript --self-update' to update your local kscript installation" >&2
6367
fi
6468

6569
exit 0;

0 commit comments

Comments
 (0)