@@ -9,6 +9,10 @@ assertInPath(){ if [ -z "$(which $1)" ]; then echo "[ERROR] Could not locate '$1
99# # trim whitespace from a string
1010trim () { 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+
1216assertInPath kotlinc
1317assertInPath 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