Because it might to be useful for others, I thought I’d share my bash snippet from my Dockerfile (although the code will work in bash scripts outside Docker too, provided the tool jq is installed) that downloads the latest (or a specific version of) Hugo.
curl -sL $(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | jq -r '\
. as $artifacts | .tag_name | ltrimstr("v") as $version | \
$artifacts | .assets | .[] | [.name, .browser_download_url] | \
if (.[0] | contains($version) and contains("extended") and contains("Linux-64bit") and contains(".tar.gz")) \
then .[1] \
else empty \
end') | tar -C /usr/local/bin -xzf - hugo
For a specific version of Hugo one can do something like:
curl -sL $(curl -s https://api.github.com/repos/gohugoio/hugo/releases/tags/v0.80.0 | jq -r '\
. as $artifacts | .tag_name | ltrimstr("v") as $version | \
$artifacts | .assets | .[] | [.name, .browser_download_url] | \
if (.[0] | contains($version) and contains("extended") and contains("Linux-64bit") and contains(".tar.gz")) \
then .[1] \
else empty \
end') | tar -C /usr/local/bin -xzf - hugo \
&& mv /usr/local/bin/hugo /usr/local/bin/hugo-0.80.0
The curl inside $() uses the GitHub REST API to get the release JSON and uses a jq script to extract the download locations.
The outer curl actually downloads the Hugo binary.
This is kind hacky at the moment, but it gets things done for me, for now.
I admit I’ve been avoiding the GitHub CLI. If it’s available via an apt command in 20.04, Bullseye, etc it could be worth it for me, though. (I try to minimize the number of ‘outside’ tools I add).
I reviewed my previous response, and I don’t like what I wrote. Although the statement is accurate, my choice of words was poor, and may convey a tone that I did not intend. I apologize if you were offended.
My revised response:
I don’t know if authentication is required to use gh release download with public repositories. I have never tested the installation without the authentication step because I use the GitHub CLI with both public and private repositories.
I try to adhere to the DBAD code of conduct, and fear that I failed in my previous response. Again, please accept my apology.
@jmooring Thank you! You are awesome. It makes me glad I didn’t overreact to the tone (I was indeed somewhat miffed, but I also know we all have bad days; that it was not even so intended is even better). Now I have to look up DBAD, it sounds like a philosophy I would like to follow (as best possible).
For anyone who might be interested: gh release download requires gh auth login even for public repositories.
Since the use case for my script is a Dockerfile (for creating a VSCode devcontainer) where I’d rather not use credentials to install a public artifact, I will be using my script for that purpose as it seems to me a better fit. YMMV.