summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbdou Seck <djily02016@gmail.com>2020-06-05 16:33:14 -0400
committerAbdou Seck <djily02016@gmail.com>2020-06-05 16:33:14 -0400
commit9e4fb1009f1c9e3433915c03e22c2af422e5c5fe (patch)
tree879ec8b5233d483053d8a598af2f38d55562149e
parent8ad5f9bf531a4848b1104b7b389a20171624c82f (diff)
fix(installation): Provide a backup git reference when tag can't be curl
closes #423 If the parsed JSON data curled during a bash installation is not valid, use the repository's tag files as a backup. If those files don't exist somehow, then checkout the master branch and install it.
-rwxr-xr-xinstall.sh22
1 files changed, 20 insertions, 2 deletions
diff --git a/install.sh b/install.sh
index 532728e..c32f512 100755
--- a/install.sh
+++ b/install.sh
@@ -102,12 +102,30 @@ Path=${1:-rustlings/}
echo "Cloning Rustlings at $Path..."
git clone -q https://github.com/rust-lang/rustlings $Path
+cd $Path
+
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']);")
CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin"
+if [[ -z ${Version} ]]
+then
+ echo "The latest tag version could not be fetched remotely."
+ echo "Using the local git repository..."
+ Version=$(ls -tr .git/refs/tags/ | tail -1)
+ if [[ -z ${Version} ]]
+ then
+ echo "No valid tag version found"
+ echo "Rustlings will be installed using the master branch"
+ Version="master"
+ else
+ Version="tags/${Version}"
+ fi
+else
+ Version="tags/${Version}"
+fi
+
echo "Checking out version $Version..."
-cd $Path
-git checkout -q tags/$Version
+git checkout -q ${Version}
echo "Installing the 'rustlings' executable..."
cargo install --force --path .