macos – How you can get the URL to obtain a Homebrew Bottle?

0
28
macos – How you can get the URL to obtain a Homebrew Bottle?


Sadly, that hyperlink not works.

The hyperlink would not work as a result of Bintray shutdown.

In 2021, the Homebrew mission’s free hosing supplier (JFrog’s Bintray) shutdown. Brew was already internet hosting their code on GitHub, so I suppose somebody checked out “GitHub Packages” and figured it was a great (learn: free) substitute.

Unfortunatly, you possibly can’t merely obtain a file from an OCI Contianer Registry like GitHub Packages. You should:

  1. Generate an authentication token for the API
  2. Make an API name to the registry, requesting to obtain a JSON “Manifest”
  3. Parse the JSON Manifest to determine the hash of the file that you really want
  4. Decide the obtain URL from the hash
  5. Obtain the file with curl

What’s GitHub Packages?

GitHub Packages was launched as a Beta in Could 2019. It allowed customers to publish packages in lots of codecs, together with photographs uploaded to a GitHub Docker Registry. In September 2020, GitHub added a generic Container Registry as a Beta to GitHub Packages. In June 2021, GitHub migrated all photographs uploaded to GitHub Packages’ Docker Registry (on the area ‘docker.pkg.github.com‘) to their Container Registry (on the area ‘ghcr.io‘).

This GitHub Packages Container Registry lets customers (like Brew) add (and obtain) photographs in accordance with the Open Container Initiative (OCI) Specs (described above).

As an example that we need to obtain the ‘vim‘ package deal from the Homebrew mission, which is hosted on GitHub Packages.

Decide Package deal Title

To begin, go the org’s web page on GitHub

https://github.com/Homebrew

Click on on “Packages

Sort the identify of the package deal that you simply need to obtain

Screenshot of the GitHub WUI in firefox, browsing the "Packages" of the "Homebrew" org. The searchbox (populated with 'vim') is highlighted in red. Screenshot of the GitHub WUI in firefox, browsing the search results for the "Packages" of the "Homebrew" org for the query "vim". A package titled "core/vim" is highlighted in red.
Sort the identify of the package deal that you simply’re making an attempt to obtain into the search bar The namespace of our ‘vim’ package deal is ‘homebrew/core/vim’

This may inform you the identify of the package deal, which you’ll need to cross-check with formulae.brew.sh

Screenshot of the GitHub WUI in firefox, browsing the 'Homebrew/homebrew-core' page in GitHub Packages. Screenshot of the Homebrew website in firefox, browsing the 'vim' package.
The itemizing for the brew ‘vim’ package deal on the GitHub Packages web site The itemizing for the brew ‘vim’ package deal on the Brew web site

Decide Package deal Model

To determine which model (tag) we need to obtain from GitHub Packages, we have to verify the Brew “recipe”. All of the brew recipes are discovered within the Homebrew/homebrew-core repo.

Click on the “Formulation” listing, after which click on the “v” listing (which holds all of the brew components information for packages that begin with the letter ‘v’).

Screenshot of the GitHub WUI in firefox, browsing the 'Homebrew/homebrew-core' repo. A directory titled "Formula" is highlighted in red. Screenshot of the GitHub WUI in firefox, browsing the "Formula/" directory of the 'Homebrew/homebrew-core' repo. A subdirectory titled "v" is highlighted in red.
To view the formulation for all brew packages, go to the ‘homebrew-core’ repo, and open the “System/” listing. Click on the ‘v’ listing to view all of the formulation for packages that begin with the letter ‘v’

Lastly, click on the ‘vim.rb‘ file.

Chances are you’ll simply need to obtain the newest model of vim, however for example that we’re utilizing an outdated machine that may’t be up to date past MacOS 11.7.10 (Large Sur). If you happen to verify the newest recipe, you see entries for sonoma (macOS 12), ventura (macOS 13), and monterey (macOS 14). However big_sur is absent as a result of it is not supported.

The best means that I am aware-of to find out what’s the newest brew package deal’s model that helps your OS (with out having to combat with the API) is to view the historical past of the recipe file.

Screenshot of the GitHub WUI in firefox, viewing the contents of the "Formula/v/vim.rb" file of the 'Homebrew/homebrew-core' repo. The "history" button icon is highlighted in red. Screenshot of the GitHub WUI in firefox, showing the history of the "Formula/v/vim.rb" file of the 'Homebrew/homebrew-core' repo.
To seek out the most-recent model to help our OS model, click on the “historical past” icon to view the historical past of the brew recipe Historical past of the ‘vim.rb’ components (for the ‘vim’ brew package deal)

After clicking-through all of the earlier variations, we are able to see that big_sur was eliminated (and never changed) in a commit on Sep 28, 2023 in commit a153795, which has a commit message “vim: replace 9.0.1900_1 bottle”. Due to this fact, it appears to be like like “big_sur” was not supported the vim package deal model ‘9.0.1900_1’. The model instantly earlier than that’s ‘9.0.1900’, and it appears to be like like it does have a package deal for “big_sur”

Screenshot of the GitHub WUI in firefox, browsing a diff of the 'Formula/v/vim.rb' file in the 'Homebrew/homebrew-core' repo. The diff shows a bunch of hashes being removed and a bunch of hashes being added. The hash for 'big_sur' was not re-added, however. Screenshot of the GitHub WUI in firefox, browsing the contents of the 'Formula/v/vim.rb' file in the 'Homebrew/homebrew-core' repo. A line showing a sha256sum hash for "big_sur" is highlighted in red.
The diff reveals many of the hashes being up to date, however the “big_sur” line was eliminated (and never changed) Essentially the most-recent model that helps ‘big_sur’ is the most-recent model of the ‘vim.rb’ file that comprises a sha256sum for “big_sur”

Now that we all know that we need to obtain ‘9.0.1900’ model of the ‘vim’ package deal, we are able to return to the GitHub Packages web page and discover the tag for this model.

Click on on “View all tagged variations” after which scroll-down to the tag that corresponds to the model we wish (9.0.1900).

Screenshot of the GitHub WUI in firefox, browsing the 'Homebrew/homebrew-core' page in GitHub Packages for the 'core/vim' package. The "View all tagged versions" link is highlighted in red. Screenshot of the GitHub WUI in firefox, browsing the 'Homebrew/homebrew-core' page in GitHub Packages, browsing "All versions" of the 'core/vim' package. The tag '9.0.1900' is highlighted in red.
To view a listing of all the variations for the package deal, click on “View all tagged variations” Scroll down to seek out the tag for the model that you really want. In our case, it is “9.0.1900”

Get an Auth Token

Execute the next command to get an authentication token from GitHub Packages.

# get a JSON with an nameless token
curl -so "token.json" "https://ghcr.io/token?service=ghcr.io&scope=://:";

# extract token from JSON
token=$(cat token.json | jq -jr ".token")

The above instructions will get a free/non permanent token that you should use in subsequent API calls. If all went effectively, there will likely be no output from these instructions. This is an instance execution

consumer@disp7456:~$ curl -so "token.json" "https://ghcr.io/token?service=ghcr.io&scope=repository:homebrew/core/go:pull";
consumer@disp7456:~$

consumer@disp7456:~$ token=$(cat token.json | jq -jr ".token")
consumer@disp7456:~$ 

Record the Tags

We will record all the out there tags for the ‘vim‘ package deal with the ‘GET /v2//tags/record‘ API endpoint, as proven within the desk above

curl -i -H "Authorization: Bearer $" https://ghcr.io/v2/homebrew/core//tags/record

This is an instance execution. Be aware that it affirms the existence of the ‘9.0.1900‘ tag that we discovered above.

consumer@disp7456:~$ curl -i -H "Authorization: Bearer $" https://ghcr.io/v2/homebrew/core/vim/tags/record
HTTP/2 200 
content-type: software/json
docker-distribution-api-version: registry/2.0
hyperlink: ; rel="subsequent"
date: Mon, 06 Could 2024 01:06:25 GMT
content-length: 1164
x-github-request-id: CD4E:29D249:57F4C1F:5A244F1:66382D11


consumer@disp7456:~$ 

Obtain the Manifest

We will obtain the manifest for the ‘9.0.1900‘ tag of the ‘vim‘ package deal with the ‘GET /v2//manifests/‘ API endpoint, as proven within the desk above

curl -o manifest.json -s -H "Authorization: Bearer $" -H 'Settle for: software/vnd.oci.picture.index.v1+json' https://ghcr.io/v2/homebrew/core//manifests/

And this is an instance execution that downloads the manifest for the ‘9.0.1900‘ tag of the ‘vim‘ package deal


consumer@disp7456:~$ curl -o manifest.json -s -H "Authorization: Bearer $" -H 'Settle for: software/vnd.oci.picture.index.v1+json' https://ghcr.io/v2/homebrew/core/vim/manifests/9.0.1900
consumer@disp7456:~$ 

consumer@disp7456:~$ ls
manifest.json
consumer@disp7456:~$ 

⚠ Be aware that we MUST specify the Settle for header right here. If we do not, then the registry will reply with the next error message

For extra info on the OCI media varieties and their MIME varieties, see the record of OCI Picture Media Sorts.

Parse the Manifest

The earlier step downloaded a file named ‘manifest.json‘. This ‘manifest.json‘ file lists all the many information out there for the ‘9.0.1900‘ model of the ‘vim‘ package deal — spanning many OS variations and processor architectures.

As a way to proceed and obtain our precise brew bottle file, we have to extract the ‘sh.brew.bottle.digest‘ for our goal system, which is a sha256sum hash that we’ll use within the ‘GET /v2//blobs/‘ API name to really obtain the file from the container registry.

There’s just one dictionary within the ‘manifests‘ array that has a ‘platform‘ dict with the next keys:

  1. "structure": "amd64", and
  2. "os.model": "macOS 11.7"

…And that is the one we wish:

{
  "schemaVersion": 2,
  "manifests": [
    ...
    {
      "mediaType": "application/vnd.oci.image.manifest.v1+json",
      "digest": "sha256:5b538ff92ab00c3658b152dee240e30f9ffa65d817540b6a461460b02b93ceda",
      "size": 5357,
      "platform": {
        "architecture": "amd64",
        "os": "darwin",
        "os.version": "macOS 11.7"
      },
      "annotations": {
        "org.opencontainers.image.ref.name": "9.0.1900.big_sur",
        "sh.brew.bottle.digest": "6cbad503034158806227128743d2acc08773c90890cea12efee25c4a53399d02",
        "sh.brew.bottle.size": "13598246",
        "sh.brew.tab": ""
      }
    },
    ...
  ],
  "annotations": {
    "com.github.package deal.sort": "homebrew_bottle",
    "org.opencontainers.picture.created": "2023-09-16",
    "org.opencontainers.picture.description": "Vi 'workalike' with many extra options",
    "org.opencontainers.picture.documentation": "https://formulae.brew.sh/components/vim",
    "org.opencontainers.picture.license": "Vim",
    "org.opencontainers.picture.ref.identify": "9.0.1900",
    "org.opencontainers.picture.revision": "a78712b62dd7fba03243de22c20e4858d0fd1802",
    "org.opencontainers.picture.supply": "https://github.com/homebrew/homebrew-core/blob/a78712b62dd7fba03243de22c20e4858d0fd1802/System/v/vim.rb",
    "org.opencontainers.picture.title": "vim",
    "org.opencontainers.picture.url": "https://www.vim.org/",
    "org.opencontainers.picture.vendor": "homebrew",
    "org.opencontainers.picture.model": "9.0.1900"
  }
}

And, voilà, the block above reveals us the ‘sh.brew.bottle.digest‘ that we want within the subsequent step

You’ll be able to both decide by the file in your fav editor of-choice, however I discovered (when downloading many information from GitHub Packages) it was a lot simpler to make use of ‘jq

cat manifest.json | jq '.manifests[] | choose(.platform."os.model" | startswith("macOS ")) | choose(.platform.structure=="")' | jq -r '.annotations."sh.brew.bottle.digest"'

For instance, this is an execution that makes use of ‘jq‘ to extract the bottle digest hash for the blob for macOS 11 on a system with an amd64 processor.

consumer@disp7456:~$ cat manifest.json | jq '.manifests[] | choose(.platform."os.model" | startswith("macOS 11")) | choose(.platform.structure=="amd64")' | jq -r '.annotations."sh.brew.bottle.digest"'
6cbad503034158806227128743d2acc08773c90890cea12efee25c4a53399d02
consumer@disp7456:~$ 

Obtain the file

Now, we are able to lastly obtain our file if we simply move the ‘sh.brew.bottle.digest‘ hash discovered above into the GET /v2//blobs/‘ API endpoint, as proven within the desk above

curl -Lo -.bottle.tar.gz -H "Authorization: Bearer $" -H 'Settle for: software/vnd.oci.picture.layer.v1.tar+gzip' https://ghcr.io/v2/homebrew/core//blobs/sha256:

For instance, the next command downloads ‘vim-9.0.1900.bottle.tar.gz

consumer@disp7456:~$ curl -Lo vim-9.0.1900.bottle.tar.gz -H "Authorization: Bearer $" -H 'Settle for: software/vnd.oci.picture.layer.v1.tar+gzip' https://ghcr.io/v2/homebrew/core/vim/blobs/sha256:6cbad503034158806227128743d2acc08773c90890cea12efee25c4a53399d02
  % Complete    % Acquired % Xferd  Common Velocity   Time    Time     Time  Present
                                 Dload  Add   Complete   Spent    Left  Velocity
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 12.9M  100 12.9M    0     0  1450k      0  0:00:09  0:00:09 --:--:-- 2798k
consumer@disp7456:~$ 

consumer@disp7456:~$ ls
 vim-9.0.1900.bottle.tar.gz
consumer@disp7456:~$ 

Set up the file

Lastly, now you can switch the file ‘vim-9.0.1900.bottle.tar.gz‘ to your macOS system and set up it with brew.

brew reinstall --verbose --debug path/to/-.tar.gz

This is an instance execution

consumer@host ~ % /usr/native/bin/brew reinstall --debug --verbose construct/deps/vim-9.0.1900.bottle.tar.gz
/usr/native/Homebrew/Library/Homebrew/brew.rb (Formulary::FromNameLoader): loading vim
/usr/native/Homebrew/Library/Homebrew/brew.rb (Formulary::FromBottleLoader): loading construct/deps/vim-9.0.1900.bottle.tar.gz
...
␛[34m==>␛[0m ␛[1mSummary␛[0m
🍺  /usr/local/Cellar/vim/9.0.1900: 2,220 files, 40.3MB
...
user@host ~ % 

The package ‘vim‘ is now installed.

For more details describing how to download a Brew bottle from GitHub packages, see Manually Downloading Container Images (Docker, Github Packages), from which the examples above were copied.

LEAVE A REPLY

Please enter your comment!
Please enter your name here