diff --git a/.github/workflows/apt-repo.yml b/.github/workflows/apt-repo.yml index dd9330d..9e12c78 100644 --- a/.github/workflows/apt-repo.yml +++ b/.github/workflows/apt-repo.yml @@ -2,7 +2,7 @@ # # Consumes the .deb produced by the `release` workflow and publishes it to a # signed apt repo hosted on GitHub Pages (https://UserJoo9.github.io/Netrex/) -# so Linux users can `apt-get install quota-manager` and upgrade via +# so Linux users can `apt-get install netrex` and upgrade via # `apt-get update && apt-get upgrade`. # # Triggered: @@ -11,6 +11,11 @@ # * workflow_dispatch with a `version` input — used once to backfill the # already-released v0.1.2 .deb. # +# Two packages are published per release: the real `netrex` package and a tiny +# transitional `quota-manager` (no files, Depends: netrex) so boxes that installed +# the old name move over on a plain `apt upgrade`. Older quota-manager versions +# stay in the pool untouched. +# # The signing key is the armored PRIVATE key in the APT_REPO_GPG_KEY secret # (user-generated, empty passphrase). The matching PUBLIC key is committed at # the repo root as quota-manager.gpg and copied into the published repo so @@ -85,14 +90,35 @@ jobs: echo "tag=$TAG" >> "$GITHUB_OUTPUT" - name: Download the .deb from GitHub Releases + id: debs run: | set -euo pipefail VER="${{ steps.version.outputs.version }}" TAG="${{ steps.version.outputs.tag }}" mkdir -p "$RUNNER_TEMP/deb" - gh release download "$TAG" --pattern "quota-manager_${VER}_all.deb" \ - --dir "$RUNNER_TEMP/deb" --clobber - test -f "$RUNNER_TEMP/deb/quota-manager_${VER}_all.deb" # fail loudly if absent + if gh release download "$TAG" --pattern "netrex_${VER}_all.deb" \ + --dir "$RUNNER_TEMP/deb" --clobber 2>/dev/null; then + test -f "$RUNNER_TEMP/deb/netrex_${VER}_all.deb" + echo "name=netrex" >> "$GITHUB_OUTPUT" + else + # A backfill of a release from before the rename (<= 0.5.x) ships the + # old name; publish it as it was, with no transitional package. + gh release download "$TAG" --pattern "quota-manager_${VER}_all.deb" \ + --dir "$RUNNER_TEMP/deb" --clobber + test -f "$RUNNER_TEMP/deb/quota-manager_${VER}_all.deb" # fail loudly if absent + echo "name=quota-manager" >> "$GITHUB_OUTPUT" + fi + + - name: Build the transitional quota-manager package + if: steps.debs.outputs.name == 'netrex' + run: | + set -euo pipefail + VER="${{ steps.version.outputs.version }}" + T="$RUNNER_TEMP/transitional" + rm -rf "$T"; mkdir -p "$T/DEBIAN" + sed -e "s/__VERSION__/${VER}/g" -e '/^#/d' packaging/DEBIAN/transitional.control.template > "$T/DEBIAN/control" + dpkg-deb --build --root-owner-group "$T" "$RUNNER_TEMP/deb/quota-manager_${VER}_all.deb" + dpkg-deb --info "$RUNNER_TEMP/deb/quota-manager_${VER}_all.deb" - name: Install repo tooling (apt-ftparchive + gpg) run: | @@ -135,13 +161,14 @@ jobs: cp "$RUNNER_TEMP/quota-manager.gpg" ./quota-manager.gpg test -s quota-manager.gpg touch .nojekyll # REQUIRED: else Jekyll strips pool/ and dists/ - mkdir -p "pool/main/q/quota-manager" "dists/stable/main/binary-all" + mkdir -p "pool/main/q/quota-manager" "pool/main/n/netrex" "dists/stable/main/binary-all" + [ -f "$RUNNER_TEMP/deb/netrex_${VER}_all.deb" ] && cp "$RUNNER_TEMP/deb/netrex_${VER}_all.deb" "pool/main/n/netrex/" cp "$RUNNER_TEMP/deb/quota-manager_${VER}_all.deb" "pool/main/q/quota-manager/" - name: Generate Packages + Release run: | set -euo pipefail - # From the repo root so Filename: is pool/main/q/quota-manager/... + # From the repo root so Filename: is pool/main///... apt-ftparchive packages pool > "dists/stable/main/binary-all/Packages" gzip -9n -c "dists/stable/main/binary-all/Packages" > "dists/stable/main/binary-all/Packages.gz" apt-ftparchive release \ @@ -174,7 +201,7 @@ jobs: else git -c user.name="github-actions[bot]" \ -c user.email="41898282+github-actions[bot]@users.noreply.github.com" \ - commit -m "apt repo: publish quota-manager ${VER}" + commit -m "apt repo: publish netrex ${VER}" git push origin gh-pages fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f911a64..9ba1bee 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -69,12 +69,12 @@ jobs: - name: Inspect the artifact (sanity) run: | - dpkg-deb --info "dist/quota-manager_${{ steps.version.outputs.version }}_all.deb" - dpkg-deb --contents "dist/quota-manager_${{ steps.version.outputs.version }}_all.deb" | head -40 + dpkg-deb --info "dist/netrex_${{ steps.version.outputs.version }}_all.deb" + dpkg-deb --contents "dist/netrex_${{ steps.version.outputs.version }}_all.deb" | head -40 V="${{ steps.version.outputs.version }}" - tar -tzf "dist/quota-manager-${V}.tar.gz" | head -8 - rpm -qpl "dist/quota-manager-${V}-1.noarch.rpm" | head -8 - tar --zstd -tf "dist/quota-manager-${V}-1-any.pkg.tar.zst" | head -8 + tar -tzf "dist/netrex-${V}.tar.gz" | head -8 + rpm -qpl "dist/netrex-${V}-1.noarch.rpm" | head -8 + tar --zstd -tf "dist/netrex-${V}-1-any.pkg.tar.zst" | head -8 ls -l dist # The release description = a short install note + this version's @@ -88,13 +88,13 @@ jobs: VER="${{ steps.version.outputs.version }}" { printf 'Netrex **v%s**.\n\n' "${VER}" printf 'Install on the gateway laptop:\n\n' - printf '```bash\nsudo apt install ./quota-manager_%s_all.deb\n```\n\n' "${VER}" + printf '```bash\nsudo apt install ./netrex_%s_all.deb\n```\n\n' "${VER}" printf 'Or, with the apt repository configured (see README):\n' - printf '```bash\nsudo apt-get update && sudo apt-get install quota-manager\n```\n\n' + printf '```bash\nsudo apt-get update && sudo apt-get install netrex\n```\n\n' printf 'Other distros:\n\n' - printf '```bash\n# Fedora / RHEL family\nsudo dnf install ./quota-manager-%s-1.noarch.rpm\n\n' "${VER}" - printf '# Arch / Manjaro\nsudo pacman -U quota-manager-%s-1-any.pkg.tar.zst\n\n' "${VER}" - printf '# Any other systemd distro\ntar xzf quota-manager-%s.tar.gz && cd quota-manager-%s && sudo ./install.sh\n```\n\n' "${VER}" "${VER}" + printf '```bash\n# Fedora / RHEL family\nsudo dnf install ./netrex-%s-1.noarch.rpm\n\n' "${VER}" + printf '# Arch / Manjaro\nsudo pacman -U netrex-%s-1-any.pkg.tar.zst\n\n' "${VER}" + printf '# Any other systemd distro\ntar xzf netrex-%s.tar.gz && cd netrex-%s && sudo ./install.sh\n```\n\n' "${VER}" "${VER}" printf 'The package configures the network stack, installs the Python\n' printf 'dependencies into `/opt/quota-manager/.venv`, wires the\n' printf '`quota-gateway` systemd service and starts it. See the README for\n' @@ -137,8 +137,8 @@ jobs: uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2.6.2 with: files: | - release-assets/dist/quota-manager_*.deb - release-assets/dist/quota-manager-*.tar.gz - release-assets/dist/quota-manager-*.rpm - release-assets/dist/quota-manager-*.pkg.tar.zst + release-assets/dist/netrex_*.deb + release-assets/dist/netrex-*.tar.gz + release-assets/dist/netrex-*.rpm + release-assets/dist/netrex-*.pkg.tar.zst body_path: release-assets/release_body.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 3215d5a..1a33f4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Added: - **Internet schedule** (new page). Turn the internet off at set times of the week for chosen people (all their devices) or single devices: bedtime on school nights, study time, meal times. One click starts from a ready plan ("School nights", "Every night", "Study time", "Meal times"); a schedule can have several times, a time can run past midnight, and dates can be marked as days off (holidays, Eid). **Bonus time** gives a few extra minutes without changing the schedule. **Always allowed** sites (a school platform, a study site) keep working during every schedule. While a schedule is on, the device's card shows when the internet comes back, the home network (printer, shared drives, the dashboard) keeps working, and the cut is done by the gateway itself, so it works on any phone, tablet, TV or console with no app. Each device gets its end time in the system kernel, so it comes back online on time even if the gateway service restarts or stops. Sites on the "always allowed" list only open on devices that look names up through the gateway; a phone with Private DNS (or a browser with secure DNS) turned on keeps them blocked during a schedule. Contributed by @amr-elgharip2006. Closes #32. Changed: +- **The packages are now named Netrex.** The files are `netrex__all.deb`, `netrex--1.noarch.rpm`, `netrex--1-any.pkg.tar.zst` and `netrex-.tar.gz`, and the apt command is `sudo apt-get install netrex`. If you installed it as `quota-manager`, the dashboard updater, `apt-get install netrex` and `dnf install` move you over by themselves: the old package is replaced, and your settings, data and users stay where they were. Nothing else was renamed (service, folders and database are unchanged). - A new version is now published only after all the tests and the install checks on Debian, Ubuntu, Fedora and Arch pass on exactly that version. Contributed by @compnew2006. Fixed: diff --git a/CLAUDE.md b/CLAUDE.md index b2e5444..12c89ba 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -9,11 +9,15 @@ belongs, and which mistakes already cost a real outage. Deep technical detail li The user-facing name is **Netrex** (UI, titles, READMEs, release notes, TOTP issuer, passkey display name). Internal identifiers deliberately KEEP the old name so -existing installs, packages and the apt repo keep working: package `quota-manager`, -`/opt/quota-manager`, services `quota-gateway`/`quota-wan-ppp`, `/etc/quota-gateway`, -`/var/lib/quota-gateway`, nft tables `quota_*`, release asset names -`quota-manager_*`, the apt key `quota-manager.gpg`, apt `Origin`/`Label: Quota Manager` +existing installs and the apt repo keep working: `/opt/quota-manager`, services +`quota-gateway`/`quota-wan-ppp`, `/etc/quota-gateway`, `/var/lib/quota-gateway`, nft +tables `quota_*`, the apt key `quota-manager.gpg`, apt `Origin`/`Label: Quota Manager` (changing them makes apt refuse the repo), and the passkey `USER_ID`. Don't rename those. +**Packages and release assets ARE named `netrex`** since 0.6.0 (`netrex__all.deb`, ...); +the deb/rpm metadata declares `quota-manager` as replaced (Breaks/Replaces, Obsoletes; the +Arch pacman package keeps the name `quota-manager`, only its file is `netrex-*`) and the apt repo also carries a tiny transitional `quota-manager` +(`Depends: netrex`, built by `apt-repo.yml`, never a release asset). Updaters find assets by +SUFFIX (every version since 0.2), so the file names can change; keep it that way. ## 1. What this is diff --git a/README.md b/README.md index 19d9c02..63ce6e0 100644 --- a/README.md +++ b/README.md @@ -99,22 +99,22 @@ curl -fsSL https://UserJoo9.github.io/Netrex/quota-manager.gpg | \ echo "deb [signed-by=/etc/apt/keyrings/quota-manager.gpg] https://UserJoo9.github.io/Netrex stable main" | \ sudo tee /etc/apt/sources.list.d/quota-manager.list sudo apt-get update -sudo apt-get install quota-manager +sudo apt-get install netrex ``` -Prefer a single file? Download `quota-manager__all.deb` from [Releases](https://github.com/UserJoo9/Netrex/releases) and run `sudo apt install ./quota-manager_*_all.deb`. +Prefer a single file? Download `netrex__all.deb` from [Releases](https://github.com/UserJoo9/Netrex/releases) and run `sudo apt install ./netrex_*_all.deb`. **Other distros** - download the matching file from [Releases](https://github.com/UserJoo9/Netrex/releases): ```bash # Fedora / RHEL family -sudo dnf install ./quota-manager--1.noarch.rpm +sudo dnf install ./netrex--1.noarch.rpm # Arch / Manjaro -sudo pacman -U quota-manager--1-any.pkg.tar.zst +sudo pacman -U netrex--1-any.pkg.tar.zst # Any other systemd distro -tar xzf quota-manager-.tar.gz && cd quota-manager- && sudo ./install.sh +tar xzf netrex-.tar.gz && cd netrex- && sudo ./install.sh ``` The in-app updater picks the right file for how you installed. Fedora and Arch support is new: if your box runs SELinux or firewalld and forwarded traffic is blocked, set `QUOTA_DISABLE_FIREWALLD=1` before installing, or open an issue with the output. @@ -243,11 +243,14 @@ Handy to know: The dashboard checks for updates itself (**System → Updates**) and can install them in one click. Your settings and data are kept. ```bash -sudo apt-get update && sudo apt-get install --only-upgrade quota-manager # update -sudo apt remove quota-manager # remove, keep data -sudo apt purge quota-manager # remove everything +sudo apt-get update && sudo apt-get install --only-upgrade netrex # update +sudo apt remove netrex # remove, keep data +sudo apt purge netrex # remove everything ``` +> Installed it earlier as `quota-manager`? Run `sudo apt-get update && sudo apt-get install netrex` once (or update from the dashboard). The old package is removed automatically; your settings and data stay. Use `apt-get install`, not `apt-get upgrade`: `upgrade` skips packages it has to newly install. + + Your data lives in `/var/lib/quota-gateway/quota.db`. To back it up (safe while the gateway is running): ```bash diff --git a/README_AR.md b/README_AR.md index e81046d..4d7adee 100644 --- a/README_AR.md +++ b/README_AR.md @@ -107,12 +107,12 @@ curl -fsSL https://UserJoo9.github.io/Netrex/quota-manager.gpg | \ echo "deb [signed-by=/etc/apt/keyrings/quota-manager.gpg] https://UserJoo9.github.io/Netrex stable main" | \ sudo tee /etc/apt/sources.list.d/quota-manager.list sudo apt-get update -sudo apt-get install quota-manager +sudo apt-get install netrex ```
-تفضّل ملف واحد؟ نزّل `quota-manager__all.deb` من [الإصدارات](https://github.com/UserJoo9/Netrex/releases) ونفّذ `sudo apt install ./quota-manager_*_all.deb`. +تفضّل ملف واحد؟ نزّل `netrex__all.deb` من [الإصدارات](https://github.com/UserJoo9/Netrex/releases) ونفّذ `sudo apt install ./netrex_*_all.deb`. بعدها كمّل على [الإعداد الأول](#الإعداد-الأول). @@ -250,11 +250,18 @@ http://192.168.2.1:8080
```bash -sudo apt-get update && sudo apt-get install --only-upgrade quota-manager # تحديث -sudo apt remove quota-manager # إزالة مع الاحتفاظ بالبيانات -sudo apt purge quota-manager # إزالة كاملة +sudo apt-get update && sudo apt-get install --only-upgrade netrex # تحديث +sudo apt remove netrex # إزالة مع الاحتفاظ بالبيانات +sudo apt purge netrex # إزالة كاملة ``` +
+ +> لو كنت مثبّت النسخة القديمة باسم `quota-manager`، نفّذ `sudo apt-get update && sudo apt-get install netrex` مرة واحدة (أو حدّث من اللوحة). الحزمة القديمة بتتشال لوحدها وإعداداتك وبياناتك بتفضل زي ما هي. استخدم `apt-get install` مش `apt-get upgrade` لأن `upgrade` بيتجاهل الحزم الجديدة. + +
+ +
بياناتك موجودة في `/var/lib/quota-gateway/quota.db`. عشان تاخد نسخة احتياطية منها (آمن والبوابة شغالة): diff --git a/Structure_README.md b/Structure_README.md index 34530e8..72f00a0 100644 --- a/Structure_README.md +++ b/Structure_README.md @@ -2,10 +2,9 @@ > **Naming.** The project was called *Quota Manager* until the Netrex rename. > Only user-facing names changed. Every internal identifier keeps the old name -> on purpose: the `quota-manager` package, `/opt/quota-manager`, the +> on purpose: `/opt/quota-manager`, the > `quota-gateway` / `quota-wan-ppp` services, `/etc/quota-gateway`, -> `/var/lib/quota-gateway`, the `quota_*` nftables tables, release asset names -> (`quota-manager__all.deb`, which every updater since 0.2 looks for), the +> `/var/lib/quota-gateway`, the `quota_*` nftables tables, the > apt key file `quota-manager.gpg` and the signing key itself, the apt > `Origin`/`Label: Quota Manager` (apt refuses a repo whose Origin/Label changed > without `--allow-releaseinfo-change`), and the passkey `USER_ID` (changing it @@ -13,6 +12,23 @@ > falls back to `UserJoo9/QuotaManager`; `quota/apt_source.py` moves 0.5.8+ > boxes from `UserJoo9.github.io/QuotaManager` to `UserJoo9.github.io/Netrex` > once the new Pages site serves the repo. +> +> **Packages (0.6.0).** The packages and release assets are named `netrex` +> (`netrex__all.deb`, `netrex--1.noarch.rpm`, +> `netrex--1-any.pkg.tar.zst`, `netrex-.tar.gz`) and still install into +> `/opt/quota-manager`. Updaters pick an asset by its SUFFIX (`.deb`, `.rpm`, +> `.pkg.tar.zst`, `.tar.gz`) and have done so since 0.2, so the rename needs no +> old-name copy in the release. Upgrade from `quota-manager`: deb `Breaks`+`Replaces: +> quota-manager (<< 0.6.0)` (never `Conflicts`, which would make the transitional +> package unsatisfiable); rpm `Obsoletes` + a `%posttrans` that restarts the service +> (the old `%preun` stops/disables it after the new `%post`); Arch keeps the pacman name +> `quota-manager` (only the file is `netrex-*`): `pacman -U --noconfirm` answers NO to a +> conflict prompt, so a renamed conflicting package could not replace it (proven in CI). The apt repo also publishes a files-free transitional `quota-manager` +> (`packaging/DEBIAN/transitional.control.template`, built in `apt-repo.yml`, never a +> release asset: old updaters take the first `.deb`). `packaging/ci/smoke.sh` installs the +> real 0.5.11 package and upgrades it in Debian, Ubuntu, Fedora and Arch containers. +> `apt-get upgrade` keeps the new dependency back; the documented command is +> `apt-get install netrex`. How the app actually works: the topology, the packet path, the maintenance loop, the quota model, and every subsystem — plus configuration, the REST API, @@ -2156,11 +2172,12 @@ QuotaManager/ │ └── release.yml # builds the .deb on a version tag -> GitHub Releases ├── packaging/DEBIAN/ │ ├── control.template # Debian control file (Version rendered from quota/version.py) +│ ├── transitional.control.template # files-free quota-manager -> netrex (built by apt-repo.yml) │ ├── postinst # thin wrapper -> scripts/post_install.sh deb │ └── prerm # stop + disable the gateway service on remove/upgrade ├── packaging/generic/install.sh # tarball installer for any systemd distro (--no-deps, --uninstall) -├── packaging/rpm/quota-manager.spec.template # Fedora/RHEL (noarch; %preun acts only on erase) -├── packaging/arch/{PKGBUILD,quota-manager.install} # Arch (CI builds the .pkg.tar.zst with tar --zstd) +├── packaging/rpm/netrex.spec.template # Fedora/RHEL (noarch; %preun acts only on erase) +├── packaging/arch/{PKGBUILD,netrex.install} # Arch (CI builds the .pkg.tar.zst with tar --zstd) ├── packaging/build_packages.sh # builds deb+tarball+rpm+arch into dist/ (release.yml AND packaging-smoke.yml use it) ├── packaging/ci/smoke.sh # installs/upgrades/removes a package inside a distro container ├── scripts/install_openwrt.sh # OpenWrt installer (apk on 25.12+, opkg before; experimental) @@ -2413,7 +2430,7 @@ git push origin v0.2.1 ``` The `release` workflow (`.github/workflows/release.yml`) builds -`quota-manager_0.2.1_all.deb` and uploads it to a GitHub Release named +`netrex_0.2.1_all.deb` (plus the rpm, Arch and tarball) and uploads it to a GitHub Release named `v0.2.1`. GitHub Releases are immutable, so each version needs a **new** tag. The release description is auto-composed from the `CHANGELOG.md` section for the released version (plus the install note), so keep the CHANGELOG current — @@ -2422,7 +2439,7 @@ it IS the release notes. Tagging also **auto-publishes the `.deb` to a signed apt repository** (`.github/workflows/apt-repo.yml`, a `workflow_run` on the `release` workflow) hosted on GitHub Pages. Once a box has the repo configured, `apt-get update && -apt-get install quota-manager` installs/upgrades to the newest published +apt-get install netrex` installs/upgrades to the newest published version; old versions stay installable. > Version tags are what trigger the release — pushing a commit to `main` alone diff --git a/packaging/DEBIAN/control.template b/packaging/DEBIAN/control.template index 07c603f..a33768f 100644 --- a/packaging/DEBIAN/control.template +++ b/packaging/DEBIAN/control.template @@ -3,11 +3,13 @@ # NOTE: any comment line (starting with '#') here is STRIPPED by the render # step — Debian control files don't allow comments, so don't comment out a # field as a "disabled" placeholder: it would never reach the built .deb. -Package: quota-manager +Package: netrex Version: __VERSION__ Section: net Priority: optional Architecture: all +Breaks: quota-manager (<< 0.6.0) +Replaces: quota-manager (<< 0.6.0) Depends: python3 (>= 3.10), python3-venv, python3-pip, dnsmasq, nftables, iproute2, kmod, ppp, ca-certificates Maintainer: Youssef Alkhodary diff --git a/packaging/DEBIAN/transitional.control.template b/packaging/DEBIAN/transitional.control.template new file mode 100644 index 0000000..4877768 --- /dev/null +++ b/packaging/DEBIAN/transitional.control.template @@ -0,0 +1,17 @@ +# Transitional package for boxes that installed the old `quota-manager` name. +# Built by .github/workflows/apt-repo.yml (never attached to a GitHub release, +# whose .deb is the real `netrex` package). It has no files: it only pulls in +# `netrex`, so `apt upgrade` moves existing installs over. Keep it published for +# several months. Comment lines (#) are stripped when rendered. +Package: quota-manager +Version: __VERSION__ +Section: oldlibs +Priority: optional +Architecture: all +Depends: netrex (>= __VERSION__) +Maintainer: Youssef Alkhodary +Homepage: https://github.com/UserJoo9/Netrex +Description: transitional package - Quota Manager is now Netrex + This empty package only exists so that existing installs of quota-manager + upgrade to the renamed netrex package. It can be removed once netrex is + installed. diff --git a/packaging/arch/PKGBUILD b/packaging/arch/PKGBUILD index ef6764a..8b21b4a 100644 --- a/packaging/arch/PKGBUILD +++ b/packaging/arch/PKGBUILD @@ -1,7 +1,12 @@ # Maintainer: Youssef Alkhodary # Local build from the release tarball: -# makepkg -si (with quota-manager-VER.tar.gz next to this file) +# makepkg -si (with netrex-VER.tar.gz next to this file) # The release workflow also publishes a ready-made .pkg.tar.zst. +# The pacman package keeps the name quota-manager for now: updaters older than 0.6.0 +# run `pacman -U --noconfirm`, which answers NO to a package-conflict prompt, so a +# renamed (conflicting) package could not replace the installed one. Only the +# release FILE is named netrex-*. Rename the package itself once every box updates +# with 0.6.0+ (the updater can then pass --ask=4). pkgname=quota-manager pkgver=0.0.0 pkgrel=1 @@ -10,12 +15,12 @@ arch=('any') url='https://github.com/UserJoo9/Netrex' license=('MIT') depends=('python>=3.10' 'python-pip' 'dnsmasq' 'nftables' 'iproute2' 'kmod' 'ppp' 'ca-certificates') -install=quota-manager.install -source=("quota-manager-${pkgver}.tar.gz") +install=netrex.install +source=("netrex-${pkgver}.tar.gz") sha256sums=('SKIP') package() { - cd "$srcdir/quota-manager-${pkgver}" + cd "$srcdir/netrex-${pkgver}" install -d "$pkgdir/opt/quota-manager" for item in run.py requirements-linux.txt LICENSE core quota api web scripts bin; do [ -e "$item" ] && cp -a "$item" "$pkgdir/opt/quota-manager/" diff --git a/packaging/arch/quota-manager.install b/packaging/arch/netrex.install similarity index 92% rename from packaging/arch/quota-manager.install rename to packaging/arch/netrex.install index 91217a3..d27e69d 100644 --- a/packaging/arch/quota-manager.install +++ b/packaging/arch/netrex.install @@ -1,4 +1,4 @@ -# Arch pacman install hooks for Quota Manager. +# Arch pacman install hooks for Netrex. post_install() { bash /opt/quota-manager/scripts/post_install.sh arch || true } diff --git a/packaging/build_packages.sh b/packaging/build_packages.sh index a6576a6..943c571 100644 --- a/packaging/build_packages.sh +++ b/packaging/build_packages.sh @@ -1,7 +1,11 @@ #!/usr/bin/env bash # Build every release package from the working tree into ./dist: -# quota-manager_VER_all.deb, quota-manager-VER.tar.gz, -# quota-manager-VER-1.noarch.rpm, quota-manager-VER-1-any.pkg.tar.zst +# netrex_VER_all.deb, netrex-VER.tar.gz, +# netrex-VER-1.noarch.rpm, netrex-VER-1-any.pkg.tar.zst +# The packages are named `netrex`; they install into /opt/quota-manager (the +# on-disk path is deliberately unchanged) and replace the old `quota-manager` +# package on upgrade (Arch keeps the pacman package name quota-manager for now, +# only its file is named netrex-*; see packaging/arch/PKGBUILD). # Used by BOTH the release workflow and the packaging smoke-test workflow, so # what gets tested is byte-for-byte what gets released. # Needs: dpkg-deb, tar, zstd, rpmbuild. Usage: packaging/build_packages.sh [workdir] @@ -27,41 +31,41 @@ find "$STAGE/opt/quota-manager" -name __pycache__ -type d -prune -exec rm -rf {} # ---- .deb ---- sed -e "s/__VERSION__/${VERSION}/g" -e '/^#/d' packaging/DEBIAN/control.template > "$STAGE/DEBIAN/control" -printf 'quota-manager (%s) stable; urgency=medium\n\n * Linux-only metered-internet quota gateway.\n\n -- Quota Manager Maintainer Tue, 05 Aug 2026 00:00:00 +0000\n' \ +printf 'netrex (%s) stable; urgency=medium\n\n * Linux-only metered-internet quota gateway.\n\n -- Netrex Maintainer Tue, 05 Aug 2026 00:00:00 +0000\n' \ "${VERSION}" > "$STAGE/DEBIAN/changelog" cp packaging/DEBIAN/postinst packaging/DEBIAN/prerm "$STAGE/DEBIAN/" chmod 755 "$STAGE/DEBIAN/postinst" "$STAGE/DEBIAN/prerm" -dpkg-deb --build --root-owner-group "$STAGE" "dist/quota-manager_${VERSION}_all.deb" +dpkg-deb --build --root-owner-group "$STAGE" "dist/netrex_${VERSION}_all.deb" # the DEBIAN dir must not leak into the other formats' payload mv "$STAGE/DEBIAN" "$W/DEBIAN.keep" # ---- tarball ---- -T="$W/tarball/quota-manager-${VERSION}" +T="$W/tarball/netrex-${VERSION}" mkdir -p "$T" cp -a "$STAGE/opt/quota-manager/." "$T/" cp packaging/generic/install.sh "$T/install.sh" chmod 755 "$T/install.sh" if find "$T" -type l | grep -q .; then echo "symlink in tarball payload" >&2; exit 1; fi tar -C "$W/tarball" --owner=0 --group=0 --numeric-owner \ - -czf "dist/quota-manager-${VERSION}.tar.gz" "quota-manager-${VERSION}" + -czf "dist/netrex-${VERSION}.tar.gz" "netrex-${VERSION}" # ---- rpm ---- TOP="$W/rpmbuild" mkdir -p "$TOP"/{BUILD,RPMS,SPECS,SRPMS} sed -e "s/__VERSION__/${VERSION}/g" -e "s#__PAYLOAD__#${STAGE}#g" \ - packaging/rpm/quota-manager.spec.template > "$TOP/SPECS/quota-manager.spec" -rpmbuild -bb --define "_topdir $TOP" "$TOP/SPECS/quota-manager.spec" >/dev/null -cp "$TOP/RPMS/noarch/quota-manager-${VERSION}-1.noarch.rpm" dist/ + packaging/rpm/netrex.spec.template > "$TOP/SPECS/netrex.spec" +rpmbuild -bb --define "_topdir $TOP" "$TOP/SPECS/netrex.spec" >/dev/null +cp "$TOP/RPMS/noarch/netrex-${VERSION}-1.noarch.rpm" dist/ # ---- arch ---- A="$W/archpkg" mkdir -p "$A/opt" cp -a "$STAGE/opt/quota-manager" "$A/opt/" SIZE="$(du -sb "$A/opt" | cut -f1)" -printf 'pkgname = quota-manager\npkgbase = quota-manager\npkgver = %s-1\npkgdesc = Fair-split metered-internet quota gateway\nurl = https://github.com/UserJoo9/Netrex\nbuilddate = %s\npackager = Quota Manager CI\nsize = %s\narch = any\nlicense = MIT\ndepend = python>=3.10\ndepend = python-pip\ndepend = dnsmasq\ndepend = nftables\ndepend = iproute2\ndepend = kmod\ndepend = ppp\ndepend = ca-certificates\n' \ +printf 'pkgname = quota-manager\npkgbase = quota-manager\npkgver = %s-1\npkgdesc = Fair-split metered-internet quota gateway\nurl = https://github.com/UserJoo9/Netrex\nbuilddate = %s\npackager = Netrex CI\nsize = %s\narch = any\nlicense = MIT\ndepend = python>=3.10\ndepend = python-pip\ndepend = dnsmasq\ndepend = nftables\ndepend = iproute2\ndepend = kmod\ndepend = ppp\ndepend = ca-certificates\n' \ "${VERSION}" "$(date +%s)" "${SIZE}" > "$A/.PKGINFO" -cp packaging/arch/quota-manager.install "$A/.INSTALL" +cp packaging/arch/netrex.install "$A/.INSTALL" tar -C "$A" --owner=0 --group=0 --numeric-owner --zstd \ - -cf "dist/quota-manager-${VERSION}-1-any.pkg.tar.zst" .PKGINFO .INSTALL opt + -cf "dist/netrex-${VERSION}-1-any.pkg.tar.zst" .PKGINFO .INSTALL opt echo "built:"; ls -l dist diff --git a/packaging/ci/smoke.sh b/packaging/ci/smoke.sh index 5c0acd2..a69fc52 100644 --- a/packaging/ci/smoke.sh +++ b/packaging/ci/smoke.sh @@ -60,10 +60,84 @@ ok "upgrade keeps the venv" echo "== remove" case "$KIND" in - deb) DEBIAN_FRONTEND=noninteractive apt-get remove -y -qq quota-manager ;; - rpm) dnf remove -y -q quota-manager ;; + deb) DEBIAN_FRONTEND=noninteractive apt-get remove -y -qq netrex ;; + rpm) dnf remove -y -q netrex ;; arch) pacman -R --noconfirm quota-manager ;; esac || fail "remove failed" [ ! -e /opt/quota-manager/run.py ] || fail "files left after remove" ok "removed cleanly" + +# --------------------------------------------------------------------------- +# Rename migration: a box that installed the OLD package name (the real, published +# quota-manager 0.5.11) must move to netrex without losing its files/venv, and the +# old package must be gone afterwards. This is the path every existing install takes. +# --------------------------------------------------------------------------- +OLD_VER=0.5.11 +BASE="https://github.com/UserJoo9/Netrex/releases/download/v${OLD_VER}" +case "$KIND" in + deb) OLD_FILE="quota-manager_${OLD_VER}_all.deb" ;; + rpm) OLD_FILE="quota-manager-${OLD_VER}-1.noarch.rpm" ;; + arch) OLD_FILE="quota-manager-${OLD_VER}-1-any.pkg.tar.zst" ;; +esac +echo "== migration: old quota-manager ${OLD_VER} -> netrex" +if ! command -v curl >/dev/null 2>&1; then + case "$KIND" in + deb) apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq curl ca-certificates ;; + rpm) dnf install -y -q curl ;; + esac +fi +mkdir -p /tmp/old +curl -fsSL -o "/tmp/old/$OLD_FILE" "$BASE/$OLD_FILE" || fail "could not download the old $OLD_FILE" +install_pkg "/tmp/old/$OLD_FILE" || fail "old package install failed" +[ -x /opt/quota-manager/.venv/bin/python ] || fail "old package left no venv" +touch /opt/quota-manager/.venv/KEEP-MIGRATION +mkdir -p /etc/quota-gateway && echo "# keep me" > /etc/quota-gateway/KEEP-CONFIG + +case "$KIND" in + deb) DEBIAN_FRONTEND=noninteractive apt-get install -y -qq "$PKG" ;; + rpm) dnf install -y -q "$PKG" ;; + arch) pacman -U --noconfirm "$PKG" ;; +esac || fail "installing netrex over quota-manager failed" + +case "$KIND" in + deb) dpkg -s netrex >/dev/null 2>&1 || fail "netrex not installed after migration" + if dpkg -s quota-manager 2>/dev/null | grep -q '^Status: install ok installed'; then + fail "old quota-manager still installed next to netrex" + fi ;; + rpm) rpm -q netrex >/dev/null || fail "netrex not installed after migration" + ! rpm -q quota-manager >/dev/null 2>&1 || fail "old quota-manager still installed" ;; + arch) # same pacman package name on purpose (see packaging/arch/PKGBUILD), so + # the installed package is simply upgraded in place + pacman -Q quota-manager >/dev/null || fail "package missing after migration" ;; +esac +ok "old package replaced by netrex" +[ -e /opt/quota-manager/.venv/KEEP-MIGRATION ] || fail "migration wiped the venv" +[ -e /etc/quota-gateway/KEEP-CONFIG ] || fail "migration touched /etc/quota-gateway" +[ -f /opt/quota-manager/run.py ] || fail "app files missing after migration" +(cd /opt/quota-manager && .venv/bin/python -c "import api.app, quota.service") || fail "app does not import after migration" +ok "venv, config and app survive the migration" + +if [ "$KIND" = deb ]; then + echo "== migration through an apt repository (the documented upgrade command)" + DEBIAN_FRONTEND=noninteractive apt-get remove -y -qq netrex >/dev/null + DEBIAN_FRONTEND=noninteractive apt-get install -y -qq "/tmp/old/$OLD_FILE" >/dev/null || fail "old deb reinstall failed" + touch /opt/quota-manager/.venv/KEEP-APT + NEWVER="$(dpkg-deb -f "$PKG" Version)" + # The real transitional package carries the release version (>= 0.6.0, the + # version netrex Breaks below). Pin 0.6.0 so this also runs before the bump. + DUMMYVER=0.6.0 + DUMMY=/tmp/dummy; rm -rf "$DUMMY"; mkdir -p "$DUMMY/DEBIAN" + printf 'Package: quota-manager\nVersion: %s\nSection: oldlibs\nPriority: optional\nArchitecture: all\nDepends: netrex (>= %s)\nMaintainer: ci \nDescription: transitional\n x\n' \ + "$DUMMYVER" "$NEWVER" > "$DUMMY/DEBIAN/control" + mkdir -p /tmp/repo && cp "$PKG" /tmp/repo/ && dpkg-deb --build --root-owner-group "$DUMMY" /tmp/repo/quota-manager_"$DUMMYVER"_all.deb >/dev/null + DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-utils >/dev/null + (cd /tmp/repo && apt-ftparchive packages . > Packages) + echo "deb [trusted=yes] file:/tmp/repo ./" > /etc/apt/sources.list.d/netrex-test.list + apt-get update -qq >/dev/null 2>&1 + DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --only-upgrade quota-manager || fail "apt upgrade of quota-manager failed" + dpkg -s netrex 2>/dev/null | grep -q '^Status: install ok installed' || fail "apt did not pull in netrex" + [ -e /opt/quota-manager/.venv/KEEP-APT ] || fail "apt migration wiped the venv" + [ -f /opt/quota-manager/run.py ] || fail "app files missing after apt migration" + ok "apt upgrade quota-manager -> netrex" +fi echo "SMOKE PASSED ($KIND)" diff --git a/packaging/generic/install.sh b/packaging/generic/install.sh index 317774d..591434f 100644 --- a/packaging/generic/install.sh +++ b/packaging/generic/install.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Quota Manager - generic installer for any systemd-based Linux distro. +# Netrex - generic installer for any systemd-based Linux distro. # Run as root from inside the unpacked release tarball: # sudo ./install.sh # install / upgrade (installs distro deps) # sudo ./install.sh --no-deps # skip the package-manager step @@ -40,7 +40,7 @@ if [ "$UNINSTALL" -eq 1 ]; then exit 0 fi -[ -f "$HERE/run.py" ] && [ -d "$HERE/quota" ] || die "run this from the unpacked quota-manager tarball" +[ -f "$HERE/run.py" ] && [ -d "$HERE/quota" ] || die "run this from the unpacked netrex tarball" # shellcheck source=/dev/null . "$HERE/scripts/distro.sh" diff --git a/packaging/rpm/quota-manager.spec.template b/packaging/rpm/netrex.spec.template similarity index 73% rename from packaging/rpm/quota-manager.spec.template rename to packaging/rpm/netrex.spec.template index b129ede..45b7598 100644 --- a/packaging/rpm/quota-manager.spec.template +++ b/packaging/rpm/netrex.spec.template @@ -1,4 +1,4 @@ -# RPM spec for Quota Manager (Fedora / RHEL family). __VERSION__ and __PAYLOAD__ +# RPM spec for Netrex (Fedora / RHEL family). __VERSION__ and __PAYLOAD__ # are substituted by the release workflow; the payload is the same staged tree # the .deb ships (/opt/quota-manager). # The payload ships the bundled sing-box binary; the .deb is "all" the same way. @@ -6,13 +6,14 @@ %global debug_package %{nil} %global __strip /bin/true -Name: quota-manager +Name: netrex Version: __VERSION__ Release: 1 Summary: Fair-split metered-internet quota gateway License: MIT URL: https://github.com/UserJoo9/Netrex BuildArch: noarch +Obsoletes: quota-manager < 0.6.0 AutoReqProv: no Requires: python3 >= 3.10 Requires: python3-pip @@ -54,6 +55,16 @@ if [ "$1" -eq 0 ]; then fi exit 0 +# The OLD quota-manager package is erased by this transaction and its %preun +# (written before the rename) stops + disables the service AFTER our %post has +# started it. %posttrans runs once the whole transaction is done, so bring the +# gateway back up here. Harmless on a normal install/upgrade (already running). +%posttrans +systemctl daemon-reload 2>/dev/null || true +systemctl enable quota-gateway 2>/dev/null || true +systemctl start quota-gateway 2>/dev/null || true +exit 0 + %postun if [ "$1" -eq 0 ]; then systemctl daemon-reload 2>/dev/null || true diff --git a/quota/updater.py b/quota/updater.py index 147621d..6a0a3b9 100644 --- a/quota/updater.py +++ b/quota/updater.py @@ -59,12 +59,14 @@ def repo_candidates(configured: str) -> list[str]: #: package type -> (asset suffix, deterministic asset name). The release #: pipeline names every asset this way, so a release with an empty asset list -#: still resolves to a download URL. +#: still resolves to a download URL. Assets are found by SUFFIX, never by name +#: (every updater since 0.2 does the same), which is why the files could be +#: renamed from ``quota-manager_*`` to ``netrex_*`` without breaking old boxes. ASSET_KINDS: dict[str, tuple[str, str]] = { - "deb": (".deb", "quota-manager_{v}_all.deb"), - "rpm": (".rpm", "quota-manager-{v}-1.noarch.rpm"), - "arch": (".pkg.tar.zst", "quota-manager-{v}-1-any.pkg.tar.zst"), - "tarball": (".tar.gz", "quota-manager-{v}.tar.gz"), + "deb": (".deb", "netrex_{v}_all.deb"), + "rpm": (".rpm", "netrex-{v}-1.noarch.rpm"), + "arch": (".pkg.tar.zst", "netrex-{v}-1-any.pkg.tar.zst"), + "tarball": (".tar.gz", "netrex-{v}.tar.gz"), } #: written by every installer (deb postinst, rpm %post, PKGBUILD, install.sh) so diff --git a/tests/test_packaging.py b/tests/test_packaging.py index 5a13792..a801e0f 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -107,7 +107,7 @@ def test_release_workflow_exists_and_parses_as_yaml(): def test_release_workflow_publishes_to_github_releases(): text = _read(WORKFLOW) assert "softprops/action-gh-release" in text, "the .deb must go to GitHub Releases" - assert "dist/quota-manager_*.deb" in text + assert "dist/netrex_*.deb" in text assert "permissions:" in text and "contents: write" in text @@ -180,8 +180,8 @@ def test_apt_repo_workflow_downloads_the_deb_from_releases(): text = _read(APT_WORKFLOW) assert "gh release download" in text, \ "the .deb must come from the GitHub Release asset (not a local build)" - assert "quota-manager_" in text and "_all.deb" in text, \ - "the download must target quota-manager__all.deb" + assert "netrex_" in text and "_all.deb" in text, \ + "the download must target netrex__all.deb" assert "GH_TOKEN" in text or "GITHUB_TOKEN" in text, \ "gh must be authenticated with the Actions token" @@ -243,7 +243,7 @@ def test_public_key_file_exists_and_is_not_ignored(): def test_control_template_fields(): text = _read(PACKAGING / "DEBIAN" / "control.template") fields = { - "Package": "quota-manager", + "Package": "netrex", "Version": "__VERSION__", # rendered by the workflow "Architecture": "all", "Section": "net", @@ -385,7 +385,7 @@ def test_generic_installer_is_safe_and_calls_shared_post_install(): def test_rpm_spec_only_stops_service_on_real_erase(): - text = _read(PACKAGING / "rpm" / "quota-manager.spec.template") + text = _read(PACKAGING / "rpm" / "netrex.spec.template") assert "BuildArch: noarch" in text assert "post_install.sh rpm" in text pre = text.split("%preun", 1)[1].split("%postun", 1)[0] @@ -395,26 +395,26 @@ def test_rpm_spec_only_stops_service_on_real_erase(): def test_arch_install_hooks_and_pkgbuild(): - hooks = _read(PACKAGING / "arch" / "quota-manager.install") + hooks = _read(PACKAGING / "arch" / "netrex.install") for fn in ("post_install", "post_upgrade", "pre_upgrade", "pre_remove"): assert fn + "()" in hooks assert "post_install.sh arch" in hooks pkgbuild = _read(PACKAGING / "arch" / "PKGBUILD") assert "arch=('any')" in pkgbuild - assert "install=quota-manager.install" in pkgbuild + assert "install=netrex.install" in pkgbuild assert "iproute2" in pkgbuild and "python-pip" in pkgbuild def test_release_workflow_builds_and_uploads_every_package_kind(): wf = _read(REPO / ".github" / "workflows" / "release.yml") build = _read(PACKAGING / "build_packages.sh") - for needle in ("quota-manager-${VERSION}.tar.gz", "rpmbuild -bb", + for needle in ("netrex-${VERSION}.tar.gz", "rpmbuild -bb", ".pkg.tar.zst", "dpkg-deb --build", "find \"$T\" -type l", "chmod 755 \"$STAGE/DEBIAN/postinst\""): assert needle in build, needle - for needle in ("packaging/build_packages.sh", "dist/quota-manager_*.deb", - "dist/quota-manager-*.tar.gz", "dist/quota-manager-*.rpm", - "dist/quota-manager-*.pkg.tar.zst"): + for needle in ("packaging/build_packages.sh", "dist/netrex_*.deb", + "dist/netrex-*.tar.gz", "dist/netrex-*.rpm", + "dist/netrex-*.pkg.tar.zst"): assert needle in wf, needle @@ -557,3 +557,61 @@ def test_download_step_nothing_works_reports_not_finished(tmp_path): r, calls = _run_download_step(tmp_path, probe_ok=False, pip_ok=False, systemd_ok=False) assert r.returncode == 1 and "CONTINUED" not in r.stdout assert "SETUP IS NOT FINISHED" in r.stderr + + +# --------------------------------------------------------------------------- # +# Package rename: quota-manager -> netrex (0.6.0). Existing installs must move +# over without losing anything, so every format declares the replacement. +# --------------------------------------------------------------------------- # + +def test_deb_replaces_the_old_package_name(): + text = _read(PACKAGING / "DEBIAN" / "control.template") + # versioned, so the transitional quota-manager 0.6.0+ (which Depends: netrex) + # is not itself broken by netrex + assert re.search(r"^Breaks:\s*quota-manager \(<< 0\.6\.0\)", text, re.M) + assert re.search(r"^Replaces:\s*quota-manager \(<< 0\.6\.0\)", text, re.M) + assert "Conflicts:" not in text, "Conflicts would make the transitional package unsatisfiable" + + +def test_transitional_quota_manager_package_pulls_in_netrex(): + text = _read(PACKAGING / "DEBIAN" / "transitional.control.template") + assert re.search(r"^Package:\s*quota-manager$", text, re.M) + assert re.search(r"^Depends:\s*netrex \(>= __VERSION__\)", text, re.M) + assert re.search(r"^Version:\s*__VERSION__$", text, re.M) + apt = _read(APT_WORKFLOW) + assert "transitional.control.template" in apt + assert "pool/main/n/netrex" in apt, "the real package goes into its own pool dir" + assert "quota-manager_${VER}_all.deb" in apt, "the transitional deb keeps the old pool entry" + release = _read(REPO / ".github" / "workflows" / "release.yml") + assert "transitional" not in release, \ + "the transitional deb must never be a release asset (old updaters pick the first .deb)" + + +def test_rpm_obsoletes_the_old_package_and_restarts_after_its_erase(): + text = _read(PACKAGING / "rpm" / "netrex.spec.template") + assert re.search(r"^Name:\s+netrex$", text, re.M) + assert re.search(r"^Obsoletes:\s+quota-manager < 0\.6\.0$", text, re.M) + # the old package's %preun stops + disables the service after our %post ran + post = text.split("%posttrans", 1)[1].split("%postun", 1)[0] + assert "systemctl enable quota-gateway" in post and "systemctl start quota-gateway" in post + + +def test_arch_package_keeps_its_pacman_name_so_old_updaters_can_upgrade_it(): + """`pacman -U --noconfirm` (every updater before 0.6.0) answers NO to a + package-conflict prompt, so a renamed Arch package could not replace the old + one. Only the release file is renamed.""" + pkgbuild = _read(PACKAGING / "arch" / "PKGBUILD") + assert "pkgname=quota-manager" in pkgbuild + assert "conflicts=" not in pkgbuild + build = _read(PACKAGING / "build_packages.sh") + assert "pkgname = quota-manager" in build and "conflict" not in build + assert "dist/netrex-${VERSION}-1-any.pkg.tar.zst" in build + + +def test_every_asset_is_named_netrex_but_installs_to_the_old_path(): + build = _read(PACKAGING / "build_packages.sh") + for needle in ("dist/netrex_${VERSION}_all.deb", "dist/netrex-${VERSION}.tar.gz", + "netrex-${VERSION}-1.noarch.rpm", "dist/netrex-${VERSION}-1-any.pkg.tar.zst"): + assert needle in build, needle + assert "dist/quota-manager" not in build + assert 'mkdir -p dist "$STAGE/DEBIAN" "$STAGE/opt/quota-manager"' in build diff --git a/tests/test_updater.py b/tests/test_updater.py index af41be0..9c2dc20 100644 --- a/tests/test_updater.py +++ b/tests/test_updater.py @@ -255,7 +255,7 @@ def test_install_uses_release_asset_url(): # no assets -> constructed URL fallback assert up._find_deb_url({}, "0.3.1") == ( "https://github.com/UserJoo9/Netrex/releases/download/" - "v0.3.1/quota-manager_0.3.1_all.deb") + "v0.3.1/netrex_0.3.1_all.deb") def test_check_now_refuses_when_disabled(): @@ -315,10 +315,10 @@ def test_detect_install_kind_marker_then_package_manager(tmp_path): @pytest.mark.parametrize("kind,name", [ - ("deb", "quota-manager_0.3.1_all.deb"), - ("rpm", "quota-manager-0.3.1-1.noarch.rpm"), - ("arch", "quota-manager-0.3.1-1-any.pkg.tar.zst"), - ("tarball", "quota-manager-0.3.1.tar.gz")]) + ("deb", "netrex_0.3.1_all.deb"), + ("rpm", "netrex-0.3.1-1.noarch.rpm"), + ("arch", "netrex-0.3.1-1-any.pkg.tar.zst"), + ("tarball", "netrex-0.3.1.tar.gz")]) def test_asset_url_per_kind(kind, name): up = Updater(FakeDb(), current_version="0.2.0", install_kind=kind) release = {"assets": [ @@ -460,3 +460,15 @@ def test_custom_repo_is_the_only_one_asked(): fetch_text=lambda url, timeout=20: CHANGELOG) run(up.check_now()) assert fetch.asked == ["me/fork"] and up.repo == "me/fork" + + +@pytest.mark.parametrize("names", [ + # what a release published before the rename carries ... + ["quota-manager_0.5.11_all.deb"], + # ... and after it: the real asset is found by its suffix, whatever it is called + ["netrex_0.6.0_all.deb"], +]) +def test_asset_is_found_by_suffix_not_by_name(names): + up = Updater(FakeDb(), current_version="0.5.0", install_kind="deb") + release = {"assets": [{"name": n, "browser_download_url": f"https://x/{n}"} for n in names]} + assert up._find_asset_url(release, "0.6.0", "deb") == f"https://x/{names[0]}"