2019-03-06 14:16:31 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
echo "Let's get you set up with Rustlings!"
|
|
|
|
|
|
|
|
echo "Checking requirements..."
|
2019-03-28 05:51:54 -04:00
|
|
|
if [ -x "$(command -v git)" ]
|
2019-03-06 14:16:31 -05:00
|
|
|
then
|
2019-03-28 06:53:29 -04:00
|
|
|
echo "SUCCESS: Git is installed"
|
|
|
|
else
|
2020-02-21 12:52:47 -05:00
|
|
|
echo "ERROR: Git does not seem to be installed."
|
2019-03-06 14:16:31 -05:00
|
|
|
echo "Please download Git using your package manager or over https://git-scm.com/!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-03-28 05:51:54 -04:00
|
|
|
if [ -x "$(command -v rustc)" ]
|
2019-03-06 14:16:31 -05:00
|
|
|
then
|
2019-03-28 06:53:29 -04:00
|
|
|
echo "SUCCESS: Rust is installed"
|
|
|
|
else
|
2020-02-21 12:52:47 -05:00
|
|
|
echo "ERROR: Rust does not seem to be installed."
|
2019-03-06 14:16:31 -05:00
|
|
|
echo "Please download Rust using https://rustup.rs!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-03-28 05:51:54 -04:00
|
|
|
if [ -x "$(command -v cargo)" ]
|
2019-03-06 14:16:31 -05:00
|
|
|
then
|
2019-03-28 06:53:29 -04:00
|
|
|
echo "SUCCESS: Cargo is installed"
|
|
|
|
else
|
2020-02-21 12:52:47 -05:00
|
|
|
echo "ERROR: Cargo does not seem to be installed."
|
2019-03-06 14:16:31 -05:00
|
|
|
echo "Please download Rust and Cargo using https://rustup.rs!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-03-20 07:18:39 -04:00
|
|
|
# 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
|
2019-03-20 07:21:15 -04:00
|
|
|
# And in v2
|
2019-03-20 07:18:39 -04:00
|
|
|
if [ -z "${v2[$i]}" ]
|
|
|
|
then
|
|
|
|
v2[$i]=0
|
|
|
|
fi
|
|
|
|
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
|
2020-02-21 12:52:47 -05:00
|
|
|
echo "ERROR: Rust version is too old: $RustVersion - needs at least $MinRustVersion"
|
2019-03-20 07:18:39 -04:00
|
|
|
echo "Please update Rust with 'rustup update'"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "SUCCESS: Rust is up to date"
|
|
|
|
fi
|
|
|
|
|
2019-03-06 14:16:31 -05:00
|
|
|
Version=$(curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | python -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);")
|
2020-02-14 09:25:03 -05:00
|
|
|
CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin"
|
2019-03-06 14:16:31 -05:00
|
|
|
|
|
|
|
echo "Installing the 'rustlings' executable..."
|
2020-02-14 09:25:03 -05:00
|
|
|
cargo install --force --git https://github.com/rust-lang/rustlings --tag $Version
|
2019-03-06 14:16:31 -05:00
|
|
|
|
2019-06-06 21:59:59 -04:00
|
|
|
if ! [ -x "$(command -v rustlings)" ]
|
2019-03-06 14:16:31 -05:00
|
|
|
then
|
2020-02-14 09:25:03 -05:00
|
|
|
echo "WARNING: Please check that you have '$CargoBin' in your PATH environment variable!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Checking whether Clippy is installed.
|
|
|
|
# Due to a bug in Cargo, this must be done with Rustup: https://github.com/rust-lang/rustup/issues/1514
|
|
|
|
Clippy=$(rustup component list | grep "clippy" | grep "installed")
|
|
|
|
if [ -z "$Clippy" ]
|
|
|
|
then
|
|
|
|
echo "Installing the 'cargo-clippy' executable..."
|
|
|
|
rustup component add clippy
|
2019-03-06 14:16:31 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "All done! Run 'rustlings' to get started."
|