Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading a tarball from github without curl

I have an embedded system where I cannot install anything and the only tool I could potentially use to fetch something is wget. It turns out you cannot do the same things with wget that you can with curl. I cannot cross-compile for this system either, so I need to resort to Python or shell scripts. There pure-Python implementation of git called Dulwich actually has some C code that I'd need to cross-compile... So I even resorted looking into that, FYI.

What I need is get code from github repository, and the obvious solution to that is using tarballs they provide. I usually copy the link to download zip button from the repository page and use an authorization token instead of username and password. It works pretty simply with curl like so:

curl -L https://<token>@github.com/<org|user>/<repo>/archive/master.tar.gz | tar xz

Turns out wget is somewhat more awkward and whatever I tried just does work.

like image 864
errordeveloper Avatar asked Apr 28 '14 17:04

errordeveloper


People also ask

How do I download a folder directly from GitHub?

To download a folder from GitHub, navigate to your desired repository, select the folder you want to download from GitHub, copy the URL, navigate to https://download-directory.github.io/ and paste the URL into the text box, and hit enter .

How do I download an entire code from GitHub?

On GitHub.com, navigate to the main page of the repository. Above the list of files, click Code. Click Open with GitHub Desktop to clone and open the repository with GitHub Desktop. Follow the prompts in GitHub Desktop to complete the clone.

How do I download a database from GitHub?

In the upper-right corner of any page, click your profile photo, then click Settings. In the left sidebar, click Account. Under "Export account data", click Start export or New export. Once the export is ready to download, GitHub will send you a download link to your primary email address.


1 Answers

After beating my head on various combination of wget flags involving either:

  • --post-data; or
  • --user= with and without --pasword= as well as vice versa; or
  • --header="Authorization: token <token>"

I looked back at the documentation and found that there are alternative endpoints in releases API. Looks like firstly I just cannot use the Authorization header with the server that hosts tarballs and secondly curl (or github front-end, based on the agent string) seem to be doing a different thing with <token>@github.com vs wget's --user=<token>, and it's not the most pleasant thing to figure out.

So what works is this:

wget \
  --header='Authorization: token <token>' \
  https://api.github.com/repos/<org|user>/<repo>/tarball/<ref>
like image 100
errordeveloper Avatar answered Oct 06 '22 01:10

errordeveloper