简体   繁体   English

如何从 github 下载最新的二进制版本?

[英]How to download the latest binary release from github?

I want to download the two (.bin and.zip) binaries from the latest releases.我想从最新版本下载两个(.bin 和.zip)二进制文件。

I tried using the following command我尝试使用以下命令

curl -s https://github.com/Atmosphere-NX/Atmosphere/releases/latest | grep "browser_download_url.*zip" | cut -d : -f 2,3 | tr -d "\" | wget -qi -

but nothing happens, output being SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc但没有任何反应,output 是SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc

I'm open to using any other (wget, ecurl etc) commands.我愿意使用任何其他(wget、ecurl 等)命令。

Is it trying to extract the download link from the HTML page?它是否试图从 HTML 页面中提取下载链接? That's error prone and may break any time.这很容易出错,随时可能崩溃。

For such operations, check if they offer an API first.对于此类操作,请先检查他们是否提供 API。

They do: https://docs.github.com/en/rest/reference/releases#get-the-latest-release他们这样做: https://docs.github.com/en/rest/reference/releases#get-the-latest-release

You could write something like (pseudo code):你可以写类似的东西(伪代码):

 curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/Atmosphere-NX/Atmosphere/releases/latest \
    | jq .assets[0].browser_download_url \
    | xargs wget -qi -

Like suggested in the comments, test each command (pipe separated) individually.就像评论中建议的那样,单独测试每个命令(管道分隔)。

You can use the GitHub CLI , specifically the release download command:您可以使用GitHub CLI ,特别是release download命令:

gh release download --repo Atmosphere-NX/Atmosphere --pattern '*.bin'
gh release download --repo Atmosphere-NX/Atmosphere --archive zip

Without specifying a release tag, the command defaults to the latest release.如果不指定发布标签,该命令默认为最新版本。

Just running curl on the url gives this:只需在 url 上运行 curl 即可得到:

curl https://github.com/Atmosphere-NX/Atmosphere/releases/latest
<html><body>You are being <a href="https://github.com/Atmosphere-NX/Atmosphere/releases/tag/1.2.6">redirected</a>.</body>

So, you easily see something is amiss straight off.因此,您很容易立即发现问题所在。 Checking the curl help, you find options, command below to pinpoint what you need:查看 curl 帮助,您可以在下面找到选项、命令来确定您需要什么:

curl --help | grep redirect
 -L, --location      Follow redirects
     --max-redirs <num> Maximum number of redirects allowed
     --proto-redir <protocols> Enable/disable PROTOCOLS on redirect
     --stderr        Where to redirect stderr

First clue is redirect in the response and then we see in the help section that there is a flag to handle that.第一条线索是响应中的redirect ,然后我们在帮助部分看到有一个标志来处理它。

Running it with th -L command gives the expected output. Pipeing it to grep "browser_download_url.*zip" however gives you nothing.使用 th -L命令运行它会给出预期的 output。将其通过管道传输到grep "browser_download_url.*zip"但是什么也给不了你。 You then investigate to see what the right match would be.然后,您进行调查以查看正确的匹配项是什么。 But let's try mathing just html link with zip, just to see what happens.但是,让我们尝试仅对 html 与 zip 进行数学运算,看看会发生什么。

curl -sL https://github.com/Atmosphere-NX/Atmosphere/releases/latest | grep "href=.*zip"
          <a href="/Atmosphere-NX/Atmosphere/releases/download/1.2.6/atmosphere-1.2.6-master-173d5c2d3+hbl-2.4.1+hbmenu-3.5.0.zip" rel="nofollow" data-skip-pjax>
          <a href="/Atmosphere-NX/Atmosphere/archive/refs/tags/1.2.6.zip" rel="nofollow" data-skip-pjax>

From there you can probably find what you are after to construct your command.从那里您可能可以找到构建命令所需的内容。 As you see, links are relative with this method, so you still have to provide the base url to wget (or a curl equivalent) to finally be able to dowload what you are after.如您所见,链接与此方法相关,因此您仍然必须向wget (或等效的curl )提供基数 url 才能最终下载您想要的内容。

This is more a reply to get you going on trouble shooting.这更像是一个让你继续解决问题的回复。 You already have other answers to actually do what you want.你已经有了其他答案来实际做你想做的事。 But if you can't install the tools suggested, you could probably do something like this:但是如果你不能安装建议的工具,你可能会这样做:

curl -sL https://github.com/Atmosphere-NX/Atmosphere/releases/latest |
    awk '/releases\/download/ && done != 1 {
        sub(/.*href="/, "https://github.com")
        sub(/".*/, "")
        print
        done = 1
    }' |
    xargs curl -LsO

Not suggesting this is a good way, just a way.并不是说这是一个好方法,只是一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM