Fetch release with tool when latest one does not

This commit is contained in:
Shivam Mathur
2020-11-02 16:33:14 +05:30
parent 68fbd80105
commit 7de94e6400
4 changed files with 286 additions and 20 deletions

View File

@ -192,6 +192,10 @@ add_tool() {
status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "${urls[1]}")
else
status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
if [ "$status_code" != "200" ] && [[ "$url" =~ .*github.com.*releases.*latest.* ]]; then
url=$(echo $url | sed -e "s|releases/latest/download|releases/download/$(curl "${curl_opts[@]}" "$(echo "$url" | cut -d '/' -f '1-5')/releases" | grep -Eo -m 1 "([0-9]+\.[0-9]+\.[0-9]+)/$(echo "$url" | sed -e "s/.*\///")" | cut -d '/' -f 1)|")
status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
fi
fi
if [ "$status_code" = "200" ]; then
sudo chmod a+x "$tool_path"