Now, you can see that is outdated, but I don’t want to have to change this every time there is a Hugo release. Does any one know of a clever way to link to the latest Hugo release for Ubuntu 64-bit?
How can I get the bit that should read 0.41 at the moment?
Answering myself, I found out that GitHub keeps a tag called latest so here’s a clever (if I may say so) bash thing to get the latest Hugo for Ubuntu 64bit:
the inner wget uses the -qO- option to redirect downloaded output to stdout so I can handle it directly by piping, without writing to any file on disk.
so that gives me a GitHub HTML page which I can parse for the first (-m 1) reference to a 64bit deb package. That will be the latest.
grep -oE uses a regular expression to get what I want, and tells grep to give me just that part of the line
the outer wget concatenates this path+filename with the domain and downloads the file
Of course, I knew none of these things ten minutes ago, one learns as one goes along
EDIT: improved regular expression to match version numbers in an even cleverer fashion
There’s been a few changes in the format of the release links since the last post here, but the following should download the latest release of April 2023.
Replace windows-amd64.zip with your preferred release, and be mindful about the extension of the output:
The last one is not bulletproof: it can fail if you go over the GitHub API limit (60 calls every hour) or if hugo.exe is somehow not the first file in the archive.
Adaption for Linux. The example will extract hugo to the /bin directory, which is not really recommended outside of “throw-away” pipeline docker containers. Change as you need.
curl --silent --follow -N "$(curl -s --silent -N "https://api.github.com/repos/gohugoio/hugo/releases/latest" | jq '.assets[] | select(.name | contains("linux-amd64.tar.gz") and contains("extended") and (contains("withdeploy")|not))' | jq -r .browser_download_url)" | tar -xz -C /bin hugo