Skip to content

Commit 91dce31

Browse files
authored
Merge pull request #131 from ColinPitrat/master
Verify that rust version is recent enough to install rustlings.
2 parents 040ca18 + f07703e commit 91dce31

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

install.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,58 @@ else
3030
echo "SUCCESS: Cargo is installed"
3131
fi
3232

33+
# Function that compares two versions strings v1 and v2 given in arguments (e.g 1.31 and 1.33.0).
34+
# Returns 1 if v1 > v2, 0 if v1 == v2, 2 if v1 < v2.
35+
function vercomp() {
36+
if [[ $1 == $2 ]]
37+
then
38+
return 0
39+
fi
40+
v1=( ${1//./ } )
41+
v2=( ${2//./ } )
42+
len1=${#v1[@]}
43+
len2=${#v2[@]}
44+
max_len=$len1
45+
if [[ $max_len -lt $len2 ]]
46+
then
47+
max_len=$len2
48+
fi
49+
for i in `seq 0 $max_len`
50+
do
51+
# Fill empty fields with zeros in v1
52+
if [ -z "${v1[$i]}" ]
53+
then
54+
v1[$i]=0
55+
fi
56+
# And in v2
57+
if [ -z "${v2[$i]}" ]
58+
then
59+
v2[$i]=0
60+
fi
61+
if [ ${v1[$i]} -gt ${v2[$i]} ]
62+
then
63+
return 1
64+
fi
65+
if [ ${v1[$i]} -lt ${v2[$i]} ]
66+
then
67+
return 2
68+
fi
69+
done
70+
return 0
71+
}
72+
73+
RustVersion=$(rustc --version | cut -d " " -f 2)
74+
MinRustVersion=1.31
75+
vercomp $RustVersion $MinRustVersion
76+
if [ $? -eq 2 ]
77+
then
78+
echo "WARNING: Rust version is too old: $RustVersion - needs at least $MinRustVersion"
79+
echo "Please update Rust with 'rustup update'"
80+
exit 1
81+
else
82+
echo "SUCCESS: Rust is up to date"
83+
fi
84+
3385
Path=${1:-rustlings/}
3486
echo "Cloning Rustlings at $Path..."
3587
git clone -q https://github.com/rust-lang/rustlings $Path

0 commit comments

Comments
 (0)