From fd4eda8bda87fb5efe4c0e99a042d095a40c6b90 Mon Sep 17 00:00:00 2001 From: Colin Pitrat Date: Wed, 20 Mar 2019 11:18:39 +0000 Subject: [PATCH 1/2] Verify that rust version is recent enough to install rustlings. I would have liked to write some tests for the vercomp function I introduce, but there doesn't seem to be any CI setup yet? --- install.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/install.sh b/install.sh index b2860252..05cc635d 100755 --- a/install.sh +++ b/install.sh @@ -30,6 +30,58 @@ else echo "SUCCESS: Cargo is installed" fi +# Function that compares two versions strings v1 and v2 given in arguments (e.g 1.31 and 1.33.0). +# Returns 1 if v1 > v2, 0 if v1 == v2, 2 if v1 < v2. +function vercomp() { + if [[ $1 == $2 ]] + then + return 0 + fi + v1=( ${1//./ } ) + v2=( ${2//./ } ) + len1=${#v1[@]} + len2=${#v2[@]} + max_len=$len1 + if [[ $max_len -lt $len2 ]] + then + max_len=$len2 + fi + for i in `seq 0 $max_len` + do + # Fill empty fields with zeros in v1 + if [ -z "${v1[$i]}" ] + then + v1[$i]=0 + fi + if [ -z "${v2[$i]}" ] + then + v2[$i]=0 + fi + # And in v2 + if [ ${v1[$i]} -gt ${v2[$i]} ] + then + return 1 + fi + if [ ${v1[$i]} -lt ${v2[$i]} ] + then + return 2 + fi + done + return 0 +} + +RustVersion=$(rustc --version | cut -d " " -f 2) +MinRustVersion=1.31 +vercomp $RustVersion $MinRustVersion +if [ $? -eq 2 ] +then + echo "WARNING: Rust version is too old: $RustVersion - needs at least $MinRustVersion" + echo "Please update Rust with 'rustup update'" + exit 1 +else + echo "SUCCESS: Rust is up to date" +fi + Path=${1:-rustlings/} echo "Cloning Rustlings at $Path..." git clone -q https://github.com/rust-lang/rustlings $Path From f07703eb7ae347345d1553aff26b1387fa6d858f Mon Sep 17 00:00:00 2001 From: Colin Pitrat Date: Wed, 20 Mar 2019 11:21:15 +0000 Subject: [PATCH 2/2] Fix comment position --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 05cc635d..b07a6a73 100755 --- a/install.sh +++ b/install.sh @@ -53,11 +53,11 @@ function vercomp() { then v1[$i]=0 fi + # And in v2 if [ -z "${v2[$i]}" ] then v2[$i]=0 fi - # And in v2 if [ ${v1[$i]} -gt ${v2[$i]} ] then return 1