Skip to content

Commit 071b51d

Browse files
author
fmoko
authored
Check if python is available while checking for git, rustc and cargo (#376)
2 parents 32721bb + 9cfb617 commit 071b51d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

install.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ else
3030
exit 1
3131
fi
3232

33+
# Look up python installations, starting with 3 with a fallback of 2
34+
if [ -x "$(command -v python3)" ]
35+
then
36+
PY="$(command -v python3)"
37+
elif [ -x "$(command -v python)" ]
38+
then
39+
PY="$(command -v python)"
40+
elif [ -x "$(command -v python2)" ]
41+
then
42+
PY="$(command -v python2)"
43+
else
44+
echo "ERROR: No working python installation was found"
45+
echo "Please install python and add it to the PATH variable"
46+
exit 1
47+
fi
48+
3349
# Function that compares two versions strings v1 and v2 given in arguments (e.g 1.31 and 1.33.0).
3450
# Returns 1 if v1 > v2, 0 if v1 == v2, 2 if v1 < v2.
3551
function vercomp() {
@@ -86,7 +102,7 @@ Path=${1:-rustlings/}
86102
echo "Cloning Rustlings at $Path..."
87103
git clone -q https://github.com/rust-lang/rustlings $Path
88104

89-
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']);")
105+
Version=$(curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | ${PY} -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);")
90106
CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin"
91107

92108
echo "Checking out version $Version..."

0 commit comments

Comments
 (0)