如何使用 cURL 从 GitHub 下载 tarball?

发布于 2024-11-02 14:12:04 字数 871 浏览 4 评论 0原文

我正在尝试使用 cURL 从 GitHub 下载 tarball,但它似乎没有重定向:

$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2
<html><body>You are being <a href="https://nodeload.github.com/pinard/Pymacs/tarball/v0.24-beta2">redirected</a>.</body></html>

注意:wget对我有用:

$ wget --no-check-certificate https://github.com/pinard/Pymacs/tarball/v0.24-beta2

但是我想使用cURL,因为最终我想用类似的内容解压它:

$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx

我发现重定向后的URL变成了 https://download.github.com/pinard-Pymacs-v0.24-beta1-0-gcebc80b.tar .gz,但我希望 cURL 足够聪明来解决这个问题。

I am trying to download a tarball from GitHub using cURL, but it does not seem to be redirecting:

$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2
<html><body>You are being <a href="https://nodeload.github.com/pinard/Pymacs/tarball/v0.24-beta2">redirected</a>.</body></html>

Note: wget works for me:

$ wget --no-check-certificate https://github.com/pinard/Pymacs/tarball/v0.24-beta2

However I want to use cURL because ultimately I want to untar it inline with something like:

$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx

I found that the URL after redirecting turned out to be https://download.github.com/pinard-Pymacs-v0.24-beta1-0-gcebc80b.tar.gz, but I would like cURL to be smart enough to figure this out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

尛丟丟 2024-11-09 14:12:04

使用 -L 选项来跟踪重定向:

curl -L https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx

Use the -L option to follow redirects:

curl -L https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx
帅气称霸 2024-11-09 14:12:04

现代化的方法是:

curl -sL https://github.com/user-or-org/repo/archive/sha1-or-ref.tar.gz | tar xz

相应地替换 user-or-orgreposha1-or-ref

如果您想要 zip 文件而不是 tarball,请指定 .zip 而不是 .tar.gz 后缀。

您还可以通过为curl指定-u token:x-oauth-basic选项来检索私有存储库的存档。将 token 替换为 个人访问令牌。

The modernized way of doing this is:

curl -sL https://github.com/user-or-org/repo/archive/sha1-or-ref.tar.gz | tar xz

Replace user-or-org, repo, and sha1-or-ref accordingly.

If you want a zip file instead of a tarball, specify .zip instead of .tar.gz suffix.

You can also retrieve the archive of a private repo, by specifying -u token:x-oauth-basic option to curl. Replace token with a personal access token.

甜点 2024-11-09 14:12:04

您还可以使用 wget 来“内联解压”。只需将 stdout 指定为输出文件 (-O -):

wget --no-check-certificate https://github.com/pinard/Pymacs/tarball/v0.24-beta2 -O - | tar xz

You can also use wget to »untar it inline«. Simply specify stdout as the output file (-O -):

wget --no-check-certificate https://github.com/pinard/Pymacs/tarball/v0.24-beta2 -O - | tar xz
ぽ尐不点ル 2024-11-09 14:12:04

所有其他解决方案都需要指定发布/版本号,这显然会破坏自动化。

此解决方案 - 目前经过测试,已知可与 Github API v3 配合使用 - 但可以通过编程方式使用来获取 最新 版本,而无需指定任何标签或版本号并将二进制文件解压缩为您在开关 --one-top-level="pi-ap" 中指定的任意名称。只需在下面的示例中使用您自己的详细信息交换用户 f1linux 和存储库 pi-ap ,而 Bob 是您的叔叔:

curl -L https://api.github.com/repos/f1linux/pi-ap/tarball | tar xzvf - --one-top-level="pi-ap" --strip-components 1

All the other solutions require specifying a release/version number which obviously breaks automation.

This solution- currently tested and known to work with Github API v3- however can be used programmatically to grab the LATEST release without specifying any tag or release number and un-TARs the binary to an arbitrary name you specify in switch --one-top-level="pi-ap". Just swap-out user f1linux and repo pi-ap in below example with your own details and Bob's your uncle:

curl -L https://api.github.com/repos/f1linux/pi-ap/tarball | tar xzvf - --one-top-level="pi-ap" --strip-components 1
够钟 2024-11-09 14:12:04

具有特定的目录:

cd your_dir && curl -L https://download.calibre-ebook.com/3.19.0/calibre-3.19.0-x86_64.txz | tar zx

with a specific dir:

cd your_dir && curl -L https://download.calibre-ebook.com/3.19.0/calibre-3.19.0-x86_64.txz | tar zx
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文