I am trying to build a script that will automatically look for the latest version of curl from https://curl.haxx.se/download/ and install it on local host (Linux x86_64). If I try manually, I can lookup the latest version on website and use the appropriate wget command (with version name in URL). For example, if I want to download curl-8.0.1, the wget command would be
wget https://curl.haxx.se/download/curl-8.0.1.tar.gz
To build this in a script, I will have to first extract the latest version available on Download site.
Is there a simple way to script it out in a way that it automatically checks for the latest version and builds the wget command in script?
If I download the index.html file from the site and grep for "download/curl-" and "tar.gz" with "head -1", I get a line as below. Is there a simple way using awk/sed/grep by which I can get the version number extracted from this line?
# grep -i "download/curl-" index.html | grep "tar.gz" | head -1
<tr class="even"><td>8.0.1</td> <td><a href="download/curl-8.0.1.tar.bz2">2.97MB</a></td><td><a href="download/curl-8.0.1.tar.gz">4.09MB</a></td><td> </td>
I tried with awk to get the version as below. This may not be the best and most efficient way. So I wanted to know if there is a better way to get latest downloadable curl version
# grep -i "download/curl-" index.html | grep "tar.gz" | head -1 | awk -F".tar.gz" '{ print $1 }' | awk -F"download/" '{ print $NF }'
curl-8.0.1
You could also get Curl from the Github repo using the api, if parsing the website's HTML feels too brittle:
curl -s https://api.github.com/repos/curl/curl/releases/latest | grep "browser_download_url.*gz" | cut -d : -f 2,3 | tr -d \" | head -1 | wget -qi -
The head
is because one of the outputs would be a key. You could also use some other tool to get the info from the response, like jq
, if you have that installed — they key point is, /releases/latest
from the GH API will tell you what the most recent tag is.