Files
ArchiveBox/bin/build_brew.sh
Claude 36b4055304 Add caveats block to Homebrew formula showing data directory
The post_install initializes var/archivebox as the data directory,
but users need to know where it is for subsequent commands. The
caveats block is shown after brew install/upgrade to guide users.

https://claude.ai/code/session_01Vx1EsNrNySgsc8Y67dGzCn
2026-03-15 04:56:25 +00:00

113 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
### Bash Environment Setup
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
# set -o xtrace
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
IFS=$'\n'
REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && cd .. && pwd )"
cd "$REPO_DIR"
VERSION="$(grep '^version = ' "${REPO_DIR}/pyproject.toml" | awk -F'"' '{print $2}')"
FORMULA_FILE="$REPO_DIR/brew_dist/archivebox.rb"
echo "[+] Building Homebrew formula for archivebox==${VERSION}..."
# Create a temporary virtualenv for generating the formula
TMPDIR="$(mktemp -d)"
trap "rm -rf $TMPDIR" EXIT
python3 -m venv "$TMPDIR/venv"
source "$TMPDIR/venv/bin/activate"
pip install --quiet "archivebox==${VERSION}" homebrew-pypi-poet 2>/dev/null
echo "[+] Generating resource stanzas with homebrew-pypi-poet..."
RESOURCES="$(poet archivebox)"
# Get the sdist URL and SHA256 from PyPI JSON API (works on macOS and Linux)
SDIST_URL=""
SDIST_SHA256=""
PYPI_JSON="$(curl -fsSL "https://pypi.org/pypi/archivebox/${VERSION}/json" 2>/dev/null || echo '')"
if [ -n "$PYPI_JSON" ]; then
SDIST_URL="$(echo "$PYPI_JSON" | python3 -c "import sys,json; d=json.load(sys.stdin); print(next((u['url'] for u in d['urls'] if u['packagetype']=='sdist'), ''))" 2>/dev/null || echo '')"
SDIST_SHA256="$(echo "$PYPI_JSON" | python3 -c "import sys,json; d=json.load(sys.stdin); print(next((u['digests']['sha256'] for u in d['urls'] if u['packagetype']=='sdist'), ''))" 2>/dev/null || echo '')"
fi
if [ -z "$SDIST_URL" ]; then
SDIST_URL="https://files.pythonhosted.org/packages/source/a/archivebox/archivebox-${VERSION}.tar.gz"
fi
if [ -z "$SDIST_SHA256" ]; then
# Fallback: download and compute locally
mkdir -p "$TMPDIR/sdist"
pip download --no-binary :all: --no-deps -d "$TMPDIR/sdist" "archivebox==${VERSION}" 2>/dev/null || true
SDIST_SHA256="$(shasum -a 256 "$TMPDIR/sdist/"*.tar.gz 2>/dev/null | awk '{print $1}' || echo '')"
fi
deactivate
echo "[+] Updating formula file: $FORMULA_FILE"
# Build the formula from the template
cat > "$FORMULA_FILE" << RUBY
# Auto-generated by bin/build_brew.sh using homebrew-pypi-poet.
# Users install with: brew tap archivebox/archivebox && brew install archivebox
class Archivebox < Formula
include Language::Python::Virtualenv
desc "Self-hosted internet archiving solution"
homepage "https://github.com/ArchiveBox/ArchiveBox"
url "${SDIST_URL}"
sha256 "${SDIST_SHA256}"
license "MIT"
head "https://github.com/ArchiveBox/ArchiveBox.git", branch: "dev"
depends_on "python@3.13"
# All other runtime deps (node, chrome, yt-dlp, etc.) are installed
# on-demand by \`archivebox install\` and should NOT be declared here.
# Python dependency resource blocks auto-generated by homebrew-pypi-poet
# AUTOGENERATED_RESOURCES_START
${RESOURCES}
# AUTOGENERATED_RESOURCES_END
def install
virtualenv_install_with_resources
end
def post_install
# Initialize ArchiveBox data in the Homebrew-managed var directory
data_dir = var/"archivebox"
data_dir.mkpath
ENV["DATA_DIR"] = data_dir.to_s
system bin/"archivebox", "init"
end
def caveats
<<~EOS
ArchiveBox data is stored in:
#{var}/archivebox
To start archiving, run:
cd #{var}/archivebox && archivebox add 'https://example.com'
To start the web UI:
cd #{var}/archivebox && archivebox server 0.0.0.0:8000
EOS
end
test do
assert_match version.to_s, shell_output("#{bin}/archivebox version")
end
end
RUBY
echo "[√] Formula updated: $FORMULA_FILE"
echo " Version: ${VERSION}"
echo " URL: ${SDIST_URL}"