File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 30
30
echo " SUCCESS: Cargo is installed"
31
31
fi
32
32
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
+
33
85
Path=${1:- rustlings/ }
34
86
echo " Cloning Rustlings at $Path ..."
35
87
git clone -q https://github.com/rust-lang/rustlings $Path
You can’t perform that action at this time.
0 commit comments