7

I am trying to download an installation script of a project that is in a Github protected repo.

user and repo below are replaced by the correct info.

I have tried curl:

curl -u gabipetrovay -L -o install.sh "https://raw.github.com/user/repo/master/admin/scripts/install.sh"

Curl prompts for the password but as soon as I type the first character it goes further and downloads something (a lot of JS probably from Github)

I also tried wget:

wget --user=gabipetrovay --ask-password "https://raw.github.com/user/repo/master/admin/scripts/install.sh"

With wget I can enter my complete password but then I get a 503 error:

Resolving raw.github.com (raw.github.com)... 199.27.73.133
Connecting to raw.github.com (raw.github.com)|199.27.73.133|:443... connected.
HTTP request sent, awaiting response... 503 Connection timed out
2013-10-14 10:18:45 ERROR 503: Connection timed out.

How can I get the install.sh file? (I am running this from an Ubuntu server 13.04)

Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168
  • 1
    possible duplicate of [How can I download a single raw file from a private github repo using the command line?](http://stackoverflow.com/questions/18126559/how-can-i-download-a-single-raw-file-from-a-private-github-repo-using-the-comman) – Ciro Santilli OurBigBook.com Jan 30 '15 at 13:25

4 Answers4

7

And the official response from the Github guys is:

Thanks for getting in touch! For this case, you'll want to use our API to download individual files:

http://developer.github.com/v3/repos/contents/#get-contents

With this endpoint, you can get a specific file like this:

curl -u gabipetrovay -H "Accept: application/vnd.github.raw" "https://api.github.com/repos/user/repo/contents/filename"

You'll just be prompted for your GitHub account password in this case, or you can also use an OAuth token as well. For reference, our API Getting Started Guide has a nice section on authentication:

http://developer.github.com/guides/getting-started/#authentication

And this works like a charm!

Thanks Robert@Github

Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168
3

You can use the V3 API to get a raw file like this (you'll need an OAuth token):

curl -H 'Authorization: token INSERTACCESSTOKENHERE' -H 'Accept: application/vnd.github.v3.raw' -O -L https://api.github.com/repos/owner/repo/contents/path

All of this has to go on one line. The -O option saves the file in the current directory. You can use -o filename to specify a different filename.

To get the OAuth token follow the instructions here: https://help.github.com/articles/creating-an-access-token-for-command-line-use

This allows better automation if you, say, need to do this from a shell script.

I've written this up as a gist as well: https://gist.github.com/madrobby/9476733

thomasfuchs
  • 5,386
  • 2
  • 18
  • 38
  • if you want to retrieve a file stored in a specific tag (say: my_unit_rest) you would specify the curl command as follows (as in a bash script): `USER="me"; PASSWD="mypasswd"; OUTPUT_FILEPATH="./foo"; OWNER="mycompany"; REPOSITORY="boo"; RESOURCE_PATH="project-x/a/b/c.py"; TAG="my_unit_test"; curl -u "$USER:$PASSWD" -H 'Accept: application/vnd.github.v4.raw' -o $OUTPUT_FILEPATH" -L "https://api.github.com/repos/$OWNER/$REPOSITORY/contents/$RESOURCE_PATH?ref=$TAG";` – ksridhar Jan 23 '19 at 09:54
0

I'm working with GitHub with API, so only one solution is working for me for private repos:

https://api.github.com/repos/<owner>/<repo>/contents/<path/to/file>

with sending the login:token in CURLOPT_USERPWD

It returns the array where download_url have desired url with token in it which is generated dynamically and differ from your access token (so it's the key to solve it).

Acuna
  • 1,741
  • 17
  • 20
-1

You need to create an oauth token as explained there : Github basic authentication

then you can use the following command, curl get a temporary url so you need to use '-L' in curl to follow the redirection :

curl -L -u <your token>:x-oauth-basic https://raw.github.com/user/repo/master/admin/scripts/install.sh

You can also use -o "filename" to save it on disk

davidonet
  • 660
  • 4
  • 17