2

I'm trying to download a tar.gz file from a github repo with curl, but it's evidently downloading plain ASCII and so I can't unzip or untar the file (as evidenced by the file command - see the third line of my stack trace below).

One other important detail is that this is running inside an AWS CodeBuild instance. However, I can download this with curl just fine on my mac and it is a proper tar.gz file.

Here's the command I'm running:

curl -Lk0s https://github.com/gohugoio/hugo/releases/download/v0.49/hugo_0.49_Linux-64bit.tar.gz -o /tmp/hugo.tar.gz

The full stack trace is:

[Container] 2018/12/03 05:39:44 Running command curl -Lk0s https://github.com/gohugoio/hugo/releases/download/v0.49/hugo_0.49_Linux-64bit.tar.gz -o /tmp/hugo.tar.gz
[Container] 2018/12/03 05:39:45 Running command file /tmp/hugo.tar.gz
/tmp/hugo.tar.gz: ASCII text, with no line terminators ***[NB. This is the output of the file command]***
[Container] 2018/12/03 05:39:45 Running command tar xvf /tmp/hugo.tar.gz -C /tmp
tar: This does not look like a tar archive
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
[Container] 2018/12/03 05:39:45 Command did not exit successfully tar xvf /tmp/hugo.tar.gz -C /tmp exit status 2
[Container] 2018/12/03 05:39:45 Phase complete: INSTALL Success: false
[Container] 2018/12/03 05:39:45 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: tar xvf /tmp/hugo.tar.gz -C /tmp. Reason: exit status 2

What am I doing wrong here?

hobscrk777
  • 2,347
  • 4
  • 23
  • 29
  • I belive you want capital O, `curl -O `. It's currently outputting the entire response from curl instead of the file being downloaded. Look at little o vs big O https://curl.haxx.se/docs/manpage.html – jmoney Dec 03 '18 at 05:59
  • 1
    Possible duplicate of [How do I preserve the remote filename when Downloading a file using curl](https://stackoverflow.com/q/7451299/608639), [Is there a way to give a specific file name when saving a file via cURL?](https://stackoverflow.com/q/9744973/608639) – jww Dec 03 '18 at 08:46
  • 1
    Check the file contents. It is probably a 500 error or something like that. – Daniel Stenberg Dec 03 '18 at 08:49

1 Answers1

4

-L works for me:

curl -L https://github.com/gohugoio/hugo/releases/download/v0.49/hugo_0.49_Linux-64bit.tar.gz -o /tmp/hugo.tar.gz

I tried it without any flags first and it downloaded the redirection page.

Added -L to follow redirects and the result was a well-formed, complete .tar.gz file that decompressed perfectly. The result was a folder with a few files in it:

$ ls -l
total 41704
-rw-r--r--  1 xxxxxxxxxxx  staff     11357 Sep 24 05:54 LICENSE
-rw-r--r--  1 xxxxxxxxxxx  staff      6414 Sep 24 05:54 README.md
-rwxr-xr-x  1 xxxxxxxxxxx  staff  21328256 Sep 24 06:03 hugo

UPDATE: I didn't at first try your set of params (-Lk0s) assuming it wouldn't work for me either. But I just now tried it and it works for me. I get the same .tar.gz that I got with -L and it decompresses accurately. Please cat the contents of the text file that gets downloaded and show at least some of it here. It's probably an error of some sort being sent back as plain text or html.

Craig
  • 51
  • 2