aboutsummaryrefslogtreecommitdiffstats
path: root/dfly-update
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-01-24 13:46:20 +0800
committerAaron LI <aly@aaronly.me>2018-01-24 13:46:20 +0800
commitf5f12eed551f6fcbf0040b13268c054c1d8786c6 (patch)
tree35b98b1a1791a11c14270471fc2a4d1f51dd2c8c /dfly-update
parent0eee6e2c664fe8ad4e4cf63e02d8f7bd21065201 (diff)
downloaddfly-update-f5f12eed551f6fcbf0040b13268c054c1d8786c6.tar.bz2
dfly-update: implement compare_version() using "sort -V"
Diffstat (limited to 'dfly-update')
-rwxr-xr-xdfly-update19
1 files changed, 15 insertions, 4 deletions
diff --git a/dfly-update b/dfly-update
index 04cec61..7b8744e 100755
--- a/dfly-update
+++ b/dfly-update
@@ -129,12 +129,23 @@ get_version_filename() {
}
# Compare between two version strings
+# Parameters: ver1 ver2
# Returns values:
-# * 0 : The two versions are the same
-# * 1 : The first version is older than the other one
-# * 2 : The first version is newer than the other one
+# * 0 : ver1 = ver2
+# * 1 : ver1 < ver2
+# * 2 : ver1 > ver2
compare_version() {
- echo 1
+ lcal ver1 ver2 ver_low
+ ver1="$1"
+ ver2="$2"
+ ver_low=$(echo -e "${ver1}\n${ver2}" | sort -V | head -n 1)
+ if [ "${ver1}" = "${ver2}" ]; then
+ echo 0
+ elif [ "${ver1}" = "${ver_low}" ]; then
+ echo 1
+ else
+ echo 2
+ fi
}