簡體   English   中英

如何從 github 下載最新的二進制版本?

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

我想從最新版本下載兩個(.bin 和.zip)二進制文件。

我嘗試使用以下命令

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

但沒有任何反應,output 是SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc

我願意使用任何其他(wget、ecurl 等)命令。

它是否試圖從 HTML 頁面中提取下載鏈接? 這很容易出錯,隨時可能崩潰。

對於此類操作,請先檢查他們是否提供 API。

他們這樣做: https://docs.github.com/en/rest/reference/releases#get-the-latest-release

你可以寫類似的東西(偽代碼):

 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 -

就像評論中建議的那樣,單獨測試每個命令(管道分隔)。

您可以使用GitHub CLI ,特別是release download命令:

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

如果不指定發布標簽,該命令默認為最新版本。

只需在 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>

因此,您很容易立即發現問題所在。 查看 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

第一條線索是響應中的redirect ,然后我們在幫助部分看到有一個標志來處理它。

使用 th -L命令運行它會給出預期的 output。將其通過管道傳輸到grep "browser_download_url.*zip"但是什么也給不了你。 然后,您進行調查以查看正確的匹配項是什么。 但是,讓我們嘗試僅對 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>

從那里您可能可以找到構建命令所需的內容。 如您所見,鏈接與此方法相關,因此您仍然必須向wget (或等效的curl )提供基數 url 才能最終下載您想要的內容。

這更像是一個讓你繼續解決問題的回復。 你已經有了其他答案來實際做你想做的事。 但是如果你不能安裝建議的工具,你可能會這樣做:

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

並不是說這是一個好方法,只是一種方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM