Metadata-Version: 2.5
Name: arch-mirror-downloader
Version: 0.1.1
Summary: Ships consistent Arch Linux repo snapshots, plus AUR builds, as size-limited chunks through a one-way path
Project-URL: Repository, https://github.com/arch-mirror-krdp/arch-mirror
Author: arch-mirror-krdp
License-Expression: MIT
License-File: LICENSE
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: System :: Archiving :: Mirroring
Requires-Python: >=3.14
Requires-Dist: httpx>=0.27
Requires-Dist: pydantic>=2
Requires-Dist: pyyaml>=6
Requires-Dist: typer>=0.12
Description-Content-Type: text/markdown

# arch-mirror-downloader

Ships consistent snapshots of the Arch Linux repos, plus packages built from the AUR, local or
git PKGBUILDs, to an airgapped mirror through a one-way path, from a host with a small disk.
The other side is [arch-mirror-receiver](https://pypi.org/project/arch-mirror-receiver/).

Each `sync`:

1. Builds the AUR/local/git packages first, in throwaway docker containers, against live upstream.
2. Fetches all repo databases until a round starts and ends on the same upstream `lastupdate`.
3. Downloads (over http(s), as pacman, 5 at a time) every package version not moved before,
   checks each against its database sha256, and appends it to the chunk being filled.
4. A full chunk (`chunk_limit`) is closed and moved to the outbox; the last one adds the AUR
   repo, the databases and the snapshot's file list.

A chunk is `chunk_magic` (4 bytes) + a tar whose last member, `message.json`, lists every file
with its sha256. Files are named `<chunk_prefix><YYYYmmdd-HHMMSS>-<seq><chunk_suffix>` (UTC; unique even after a
reset). A sqlite db in `root`
records the newest version of each package that has left (written only after its chunk moved),
so reruns fetch only what's new, and an interrupted run continues the open chunk.

Local disk needed: `chunk_limit` + `batch_size` + about 1 GB of databases + docker storage for
the builds.

## Install

```sh
sudo useradd --system --home-dir /var/lib/arch-mirror-downloader --groups docker arch-mirror
sudo UV_TOOL_DIR=/opt/uv-tools UV_TOOL_BIN_DIR=/usr/local/bin uv tool install arch-mirror-downloader
arch-mirror-downloader default-config | sudo install -Dm644 /dev/stdin /etc/arch-mirror-downloader/config.yaml   # then edit
sudo install -m644 systemd/arch-mirror-downloader.{service,timer} /etc/systemd/system/
sudo systemctl daemon-reload && sudo systemctl enable --now arch-mirror-downloader.timer
```

`default-config` prints every setting with its default and what it does. The units in `systemd/`
are in the [repository](https://github.com/arch-mirror-krdp/arch-mirror/tree/main/packages/downloader).
The outbox must be writable by the `arch-mirror` user.

## Use

```sh
arch-mirror-downloader sync            # what the timer runs; progress bars on a terminal
arch-mirror-downloader status          # last snapshot shipped, packages moved, open chunk
arch-mirror-downloader rank            # which upstreams carry every repo, fastest first
arch-mirror-downloader reset           # forget what was shipped; next sync sends everything
arch-mirror-downloader default-config  # commented default config (YAML) on stdout
arch-mirror-downloader --install-completion   # tab completion for your shell (bash, zsh, fish)
```

`-c/--config` (or `ARCH_MIRROR_DOWNLOADER_CONFIG`) picks another config. Exit status: 0 shipped
or nothing new, 2 shipped but an AUR build failed (that package keeps its previous build), 1 no
upstream could deliver.

`arch-mirror-downloader reset` forgets what was shipped: the next sync downloads and ships the
whole mirror again, and the receiver takes it as a fresh snapshot. Use it if a chunk was lost on
the way, or to test. `--aur` also drops the AUR builds, so all are rebuilt.
