7

我正在尝试下载受 Github 保护的存储库中的项目的安装脚本。

userrepo以下被正确的信息取代。

我试过卷曲:

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

Curl 提示输入密码,但只要我输入第一个字符,它就会进一步下载一些东西(很多 JS 可能来自 Github)

我也试过wget:

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

使用 wget 我可以输入完整的密码,但随后出现 503 错误:

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.

如何获取 install.sh 文件?(我从 Ubuntu 服务器 13.04 运行它)

4

4 回答 4

7

来自 Github 的官方回应是:

感谢您的联系!对于这种情况,您需要使用我们的 API 下载单个文件:

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

使用此端点,您可以获得如下特定文件:

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

在这种情况下,系统只会提示您输入 GitHub 帐户密码,或者您也可以使用 OAuth 令牌。作为参考,我们的 API Getting Started Guide 有一个很好的关于身份验证的部分:

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

这就像一个魅力!

谢谢罗伯特@Github

于 2013-10-15T09:16:14.497 回答
3

您可以使用 V3 API 来获取这样的原始文件(您需要一个 OAuth 令牌):

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

所有这些都必须在一条线上进行。该-O选项将文件保存在当前目录中。您可以使用-o filename来指定不同的文件名。

要获取 OAuth 令牌,请按照此处的说明操作: https ://help.github.com/articles/creating-an-access-token-for-command-line-use

如果您需要从 shell 脚本执行此操作,这可以实现更好的自动化。

我也把它写成了一个要点: https ://gist.github.com/madrobby/9476733

于 2014-03-11T00:46:18.647 回答
0

我正在使用带有 API 的 GitHub,因此只有一种解决方案适用于我的私人存储库:

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

login:token与发送CURLOPT_USERPWD

它返回download_url具有所需 url 的数组,其中包含动态生成的令牌,并且与您的访问令牌不同(因此它是解决它的关键)。

于 2021-02-23T02:45:15.030 回答
-1

您需要按照那里的说明创建一个 oauth 令牌:Github 基本身份验证

然后您可以使用以下命令,curl 获取一个临时 url,因此您需要在 curl 中使用 '-L' 来跟踪重定向:

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

您也可以使用 -o "filename" 将其保存在磁盘上

于 2013-10-15T05:11:58.973 回答