Created
March 17, 2026 22:11
-
-
Save vgmoose/a6f7564b2f947b45873a1924a6ec37aa to your computer and use it in GitHub Desktop.
Download packages from brew repos directly, without actually installing brew
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # check for curl and jq | |
| if [[ ! -f $(which curl) ]]; then | |
| echo "curl is missing" | |
| exit 1 | |
| fi | |
| if [[ ! -f $(which jq) ]]; then | |
| echo "jq is missing" | |
| exit 2 | |
| fi | |
| # detect the OS version | |
| OS="" | |
| case $(sw_vers -productVersion) in | |
| 26*) OS="tahoe" ;; | |
| 15*) OS="sequoia" ;; | |
| 14*) OS="sonoma" ;; | |
| 13*) OS="ventura" ;; | |
| 12*) OS="monterey" ;; | |
| 11*) OS="big_sur" ;; | |
| esac | |
| # architecture | |
| ARCH=$(machine) | |
| # arm64e -> arm64, I guess? | |
| if [[ "$ARCH" == "arm64e" ]]; then | |
| ARCH="arm64" | |
| fi | |
| PLATFORM=$ARCH"_"$OS | |
| echo "Your platform:" $PLATFORM | |
| # download brew's formula.json, if we don't have it | |
| if [[ ! -f "formula.json" ]]; then | |
| echo "Downloading https://formulae.brew.sh/api/formula.json ..." | |
| curl -s "https://formulae.brew.sh/api/formula.json" --output formula.json | |
| else | |
| echo "Using cached formula.json (delete to refresh)" | |
| fi | |
| # get a flat list of package names | |
| PACKAGES=$(cat formula.json | jq -r ".[] | select(.bottle.stable.files.$PLATFORM.url) | .name") | |
| # figure out operation mode | |
| if [[ "$1" == "list" ]]; then | |
| echo "$PACKAGES" | |
| elif [[ "$1" == "install" ]]; then | |
| PACKAGE="$2" | |
| if [[ "$PACKAGES" == *"$PACKAGE"* ]]; then | |
| URL=$(cat formula.json | jq -r ".[] | select(.name == \"$PACKAGE\") | .bottle.stable.files.$PLATFORM.url") | |
| echo "Downloading $URL ..." | |
| OUT_FILE=$PACKAGE"_"$PLATFORM.tar.gz | |
| curl -L -s -H "Authorization: Bearer QQ==" "$URL" --output $OUT_FILE | |
| echo "Extracting..." | |
| tar xzvf $OUT_FILE | |
| else | |
| echo "Package $PACKAGE not found" | |
| fi | |
| elif [[ "$1" == "remove" ]]; then | |
| echo "TODO" # TODO: list out the contents of the tar file (download it first) and then delete those files | |
| else | |
| echo "Usage: ./brew.sh list" | |
| echo "Usage: ./brew.sh install [package]" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment