Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Github releases generate archive filenames?

Tags:

git

github

curl

I just created releases for my NFQL software on github.
Here is the releases page: https://github.com/vbajpai/nfql/releases

For the latest release, v0.7. If I click on the tarball button, it saves a nfql-0.7.tar.gz. This is great and exactly how I want my release archives to be named.

enter image description here

However, I need the download link of the tarball itself. So that I can create a MacPorts/Homebrew file for the tarball. If I look at the download link, it is:

a) https://github.com/vbajpai/nfql/archive/v0.7.tar.gz or
b) https://codeload.github.com/vbajpai/nfql/tar.gz/v0.7

now if I use curl/wget it saves the tarball as v0.7.tar.gz. I know I can specify a filename while downloading using curl/wget. I want to know is there is a reliable github URL I can use to fetch my tarball as nfql-0.7.tar.gz.

PS: What is github doing there anyway? How is the filename altered by the browsers when I directly click the source code link?

like image 335
Vaibhav Bajpai Avatar asked Dec 25 '13 16:12

Vaibhav Bajpai


2 Answers

The first link gives a redirection to the second one:

curl --head https://github.com/vbajpai/nfql/archive/v0.7.tar.gz
HTTP/1.1 302 Found
Location: https://codeload.github.com/vbajpai/nfql/tar.gz/v0.7
...

How is the filename altered by the browsers when I directly click the source code link?

The filename is defined via a custom Content-Disposition HTTP header:

curl --head https://codeload.github.com/vbajpai/nfql/tar.gz/v0.7
HTTP/1.1 200 OK
Content-Disposition: attachment; filename=nfql-0.7.tar.gz
...

So you can use curl's -O, --remote-name, -L, --location and -J, --remote-header-name to (resp.) write output to a file named as the remote file, follow redirects and use the header-provided filename:

curl -LOJ https://github.com/vbajpai/nfql/archive/v0.7.tar.gz
like image 138
deltheil Avatar answered Nov 11 '22 18:11

deltheil


Not sure if this worked when the question was originally posted, but now you can use https://github.com/vbajpai/nfql/archive/v0.7/nfql-0.7.tar.gz to get the correct filename directly without looking at headers. This is very nice when using wget as you need no flags, just simply wget https://github.com/vbajpai/nfql/archive/v0.7/nfql-0.7.tar.gz

Note that it is the next-to-last path component that selects the release to use - you can put whatever filename you want to have as the last path component.

like image 20
Marcus Avatar answered Nov 11 '22 19:11

Marcus