Hi everyone. I have a documentation page instruction my users on how to set up the Hugo environment for their contributions:
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:
wget https://github.com`wget -qO- https://github.com/gohugoio/hugo/releases/latest | grep -oE -m 1 ''\/gohugoio\/hugo\/releases\/download\/v[0-9]+.[0-9]+\/hugo_[0-9]+.[0-9]+_Linux-64bit.deb'`
Interesting things for geeks:
- 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
While that will work for now, after bep has been busy, it will eventually fail
Releases > v9 such as
10.01 or any with more than 99 point releases such as
0.100 would fail.
I will add a separate thread to show how to do the same thing using PowerShell for Windows users.
Thanks for pushing me to improve! - I’ve edited the expression to match more version numbers.
For anybody interested in the Powershell version, here’s a link
There was an extra apostrpohe breaking the command I gave above. Also, it wasn’t able to handle the minor versions, like the latest
So here is a new command with both of these issues fixed:
wget https://github.com`wget -qO- https://github.com/gohugoio/hugo/releases/latest | grep -oE -m 1 '\/gohugoio\/hugo\/releases\/download\/v[0-9]+.[0-9]+.[0-9]*\/hugo_[0-9]+.[0-9]+.[0-9]*_Linux-64bit.deb'`
If you want the latest extended Sass/SCSS version use this one instead:
wget https://github.com`wget -qO- https://github.com/gohugoio/hugo/releases/latest | grep -oE -m 1 '\/gohugoio\/hugo\/releases\/download\/v[0-9]+.[0-9]+.[0-9]*\/hugo_extended_[0-9]+.[0-9]+.[0-9]*_Linux-64bit.deb'`