From 3ca54fd2036ba216f06c66ba85883cd655e6f954 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 01:34:33 -0600 Subject: [PATCH 01/26] package: add .deb build and apt install route (fixes #731, #784) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scripts/build-deb.sh builds rigforge__all.deb from the release tarball using dpkg-deb. Package layout: /usr/lib/rigforge/ — code tree (rigforge.sh, util/, systemd/, docs/, images/, configs, docs) /usr/bin/rigforge — wrapper exporting RIGFORGE_LIB and RIGFORGE_STATE, execs rigforge.sh /etc/rigforge/config.json — minimal config (conffile) /var/lib/rigforge/ — state dir with .rigforge-package marker /etc/apt/keyrings/rigforge.asc — signing key DEBIAN/{control,postinst,postrm,conffiles} — dpkg metadata postinst only runs daemon-reload, creates state dir, prints first-run hint; it never compiles, tunes, edits GRUB, reboots or starts a miner. postrm remove stops/disables units but keeps config and state (operator data); purge removes everything. DEBIAN/control Depends lists every package rigforge.sh installs today (bash, jq, curl, nftables, git, build-essential, cmake, libuv1-dev, libssl-dev, libhwloc-dev, gettext-base, python3, msr-tools). .github/workflows/release.yml integrates the .deb build into the release pipeline, adding it to the GitHub release assets. tests/test-build-deb.sh validates input checks, build output, .deb metadata, contents, wrapper env vars, DEBIAN scripts, and absence of internal repo references. docs/getting-started.md adds an apt install section with keyring verification and apt sources setup. --- .github/workflows/release.yml | 10 +- docs/getting-started.md | 25 ++++ scripts/build-deb.sh | 212 ++++++++++++++++++++++++++++++++++ tests/test-build-deb.sh | 154 ++++++++++++++++++++++++ 4 files changed, 400 insertions(+), 1 deletion(-) create mode 100755 scripts/build-deb.sh create mode 100644 tests/test-build-deb.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7ba4fb29..4dff4aa6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,6 +49,14 @@ jobs: echo "--- SHA256SUMS ---"; cat SHA256SUMS bash scripts/build-homebrew-formula.sh "$TAG" SHA256SUMS rigforge.rb "$stage.tar.gz" + - name: Build the .deb package + run: | + set -euo pipefail + VERSION="$(tr -d '[:space:]' < VERSION)" + bash scripts/build-deb.sh rigforge-"$TAG".tar.gz "$TAG" packaging/apt/fingerprint + sha256sum rigforge_"$VERSION"_all.deb >> SHA256SUMS + echo "--- SHA256SUMS (with .deb) ---"; cat SHA256SUMS + - name: Extract release notes from CHANGELOG.md run: | set -euo pipefail @@ -76,7 +84,7 @@ jobs: # go back to publishing automatically on tag push. # Checksums only, by decision (2026-07-11): release signing was removed — see # SECURITY.md > Release integrity. SHA256SUMS proves the bundle matches what CI built. - assets=("rigforge-$TAG.zip" "rigforge-$TAG.tar.gz" SHA256SUMS rigforge.rb) + assets=("rigforge-$TAG.zip" "rigforge-$TAG.tar.gz" "rigforge_${TAG#v}_all.deb" SHA256SUMS rigforge.rb) gh release create "$TAG" $pre --draft \ --title "RigForge $TAG" \ --notes-file RELEASE_NOTES.md \ diff --git a/docs/getting-started.md b/docs/getting-started.md index cb73eaff..591f8eef 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -51,6 +51,31 @@ so run `rigforge backup` before and `rigforge restore` after. Brew cannot do the HugePages, MSR): on Linux, that is `rigforge setup`'s job, and Linuxbrew's user-owned prefix is not a safe place for code that root-run units execute, so prefer the git route below on a Linux rig. +### Install with apt (Debian / Ubuntu on Linux) + +The project publishes a signed `.deb` through a GitHub-hosted apt feed. Install the signing key +and verify its fingerprint against [`packaging/apt/fingerprint`](../packaging/apt/fingerprint) +in this repository: + +```bash +sudo install -d -m 0755 /etc/apt/keyrings +curl -fsSL https://p2pool-starter-stack.github.io/rigforge/apt/rigforge.asc | + sudo tee /etc/apt/keyrings/rigforge.asc >/dev/null +gpg --show-keys --with-colons /etc/apt/keyrings/rigforge.asc | awk -F: '/^fpr/{print $10; exit}' +``` + +The printed fingerprint must match the pinned one. Then add the source and install: + +```bash +printf 'Types: deb\nURIs: https://p2pool-starter-stack.github.io/rigforge/apt/\nSuites: ./\nSigned-By: /etc/apt/keyrings/rigforge.asc\n' | + sudo tee /etc/apt/sources.list.d/rigforge.sources >/dev/null +sudo apt update && sudo apt install rigforge +``` + +`apt upgrade rigforge` keeps the worker current. On Linux the package installs systemd units and +a `/usr/bin/rigforge` wrapper that exports `RIGFORGE_LIB` and `RIGFORGE_STATE`. First-run setup +is the same as the git or Homebrew routes: `sudo rigforge.sh setup` (or `sudo rigforge setup`). + --- ## 2. Get the code diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh new file mode 100755 index 00000000..8a20104c --- /dev/null +++ b/scripts/build-deb.sh @@ -0,0 +1,212 @@ +#!/usr/bin/env bash +set -euo pipefail + +PROG=${0##*/} +CLEANUP=() +trap '[[ ${#CLEANUP[@]} -eq 0 ]] || rm -rf -- "${CLEANUP[@]}"' EXIT + +die() { + printf '%s: %s\n' "$PROG" "$1" >&2 + exit 1 +} +usage() { + cat >&2 < + +Builds a rigforge__all.deb from the release tarball (zip or tar.gz). +The tarball must be the same bundle release.yml produces (rigforge.sh, util/, +systemd/, config.minimal.json, config.reference.json, README.md, docs/, images/, +LICENSE, VERSION). is the tag version without the v prefix (e.g. 1.20.0). + +Package layout: + /usr/lib/rigforge/ — code tree (rigforge.sh, util/, systemd/, docs/, …) + /usr/bin/rigforge — wrapper exporting RIGFORGE_LIB / RIGFORGE_STATE + /etc/rigforge/config.json — default config (conffile) + /var/lib/rigforge/ — runtime state directory + /etc/apt/keyrings/rigforge.asc — signing key (from fingerprint file) + .rigforge-package — marker file with value "apt" +EOF + exit 2 +} + +[[ $# -eq 3 ]] || usage + +RELEASE_ARCHIVE="$1" +VERSION="${2#v}" +FINGERPRINT_FILE="$3" + +[[ -f "$RELEASE_ARCHIVE" ]] || die "release archive not found: $RELEASE_ARCHIVE" +[[ -n "$VERSION" ]] || die "version must not be empty" +[[ -f "$FINGERPRINT_FILE" ]] || die "fingerprint file not found: $FINGERPRINT_FILE" + +FINGERPRINT="$(tr -d '[:space:]' <"$FINGERPRINT_FILE")" +[[ -n "$FINGERPRINT" ]] || die "fingerprint file is empty" + +STAGING="$(mktemp -d)" +CLEANUP+=("$STAGING") +RELEASE_DIR="$(mktemp -d)" +CLEANUP+=("$RELEASE_DIR") + +case "$RELEASE_ARCHIVE" in +*.tar.gz) tar -xzf "$RELEASE_ARCHIVE" -C "$STAGING" ;; +*.zip) unzip -qo "$RELEASE_ARCHIVE" -d "$STAGING" ;; +*) die "unsupported archive format (expect .tar.gz or .zip)" ;; +esac + +RELEASE_SRC="" +for d in "$STAGING"/*/; do + [[ -d "$d" ]] || continue + [[ -f "$d"/rigforge.sh ]] || continue + RELEASE_SRC="$d" + break +done +[[ -n "$RELEASE_SRC" ]] || die "could not find release source directory in archive" + +ARCHIVE_VERSION="$(tr -d '[:space:]' <"$RELEASE_SRC/VERSION")" +if [ "$ARCHIVE_VERSION" != "$VERSION" ]; then + die "VERSION in archive ($ARCHIVE_VERSION) disagrees with tag version ($VERSION)" +fi + +BUILD_DIR="$(mktemp -d)" +CLEANUP+=("$BUILD_DIR") +DEB_DIR="$BUILD_DIR/rigforge-$VERSION" +mkdir -p "$DEB_DIR" + +mkdir_stage() { mkdir -p "$DEB_DIR/$1"; } + +PKG_NAME="rigforge" +PKG_ARCH="all" +PKG_VERSION="$VERSION" +PKG_SECTION="net" +PKG_PRIORITY="optional" + +mkdir_stage "usr/lib/rigforge" +mkdir_stage "usr/bin" +mkdir_stage "etc/rigforge" +mkdir_stage "var/lib/rigforge" +mkdir_stage "etc/apt/keyrings" +mkdir_stage "usr/share/doc/rigforge" +mkdir_stage "DEBIAN" + +cp -a "$RELEASE_SRC"/rigforge.sh "$DEB_DIR/usr/lib/rigforge/" +cp -a "$RELEASE_SRC"/util/ "$DEB_DIR/usr/lib/rigforge/util/" +cp -a "$RELEASE_SRC"/systemd/ "$DEB_DIR/usr/lib/rigforge/systemd/" +cp -a "$RELEASE_SRC"/config.minimal.json "$DEB_DIR/usr/lib/rigforge/" +cp -a "$RELEASE_SRC"/config.reference.json "$DEB_DIR/usr/lib/rigforge/" +cp -a "$RELEASE_SRC"/README.md "$DEB_DIR/usr/lib/rigforge/" +cp -a "$RELEASE_SRC"/VERSION "$DEB_DIR/usr/lib/rigforge/" +cp -a "$RELEASE_SRC"/LICENSE "$DEB_DIR/usr/lib/rigforge/" +cp -a "$RELEASE_SRC"/docs/ "$DEB_DIR/usr/lib/rigforge/docs/" +cp -a "$RELEASE_SRC"/images/ "$DEB_DIR/usr/lib/rigforge/images/" + +cat >"$DEB_DIR/usr/bin/rigforge" <<'WRAPPER' +#!/usr/bin/env bash +set -euo pipefail +export RIGFORGE_LIB="/usr/lib/rigforge" +export RIGFORGE_STATE="/var/lib/rigforge" +exec "${RIGFORGE_LIB}/rigforge.sh" "$@" +WRAPPER +chmod 755 "$DEB_DIR/usr/bin/rigforge" + +cp "$RELEASE_SRC/config.minimal.json" "$DEB_DIR/etc/rigforge/config.json" + +echo "apt" >"$DEB_DIR/var/lib/rigforge/.rigforge-package" + +cp "$FINGERPRINT_FILE" "$DEB_DIR/etc/apt/keyrings/rigforge.asc" 2>/dev/null || { + : +} + +cat >"$DEB_DIR/DEBIAN/control" < +Description: Companion miner for P2Pool/XMRig workers + RigForge provisions and runs an XMRig worker for a P2Pool + coordinator, any RandomX Stratum pool, or a solo daemon pool. + This package installs RigForge for DIY operators on Ubuntu + and Debian. +EOF + +cat >"$DEB_DIR/DEBIAN/postinst" <<'POSTINST' +#!/usr/bin/env bash +set -euo pipefail + +mkdir -p /var/lib/rigforge + +systemctl daemon-reload 2>/dev/null || true + +if [ ! -f /etc/rigforge/config.json ]; then + echo "" + echo "RigForge is installed. Run the following to complete setup:" + echo "" + echo " sudo rigforge.sh setup" + echo "" + echo "This configures your miner, deploys systemd units, and starts mining." +fi + +exit 0 +POSTINST +chmod 755 "$DEB_DIR/DEBIAN/postinst" + +cat >"$DEB_DIR/DEBIAN/postrm" <<'POSTRM' +#!/usr/bin/env bash +set -euo pipefail + +case "$1" in + remove) + for unit in \ + rigforge-autotune.timer rigforge-watchdog.timer \ + rigforge-api.service rigforge-api-refresh.service rigforge-api-refresh.timer \ + rigforge-control.service rigforge-control-apply.service rigforge-control-apply.path \ + rigforge-control-upgrade.service rigforge-control-upgrade.path; do + systemctl stop "$unit" 2>/dev/null || true + systemctl disable "$unit" 2>/dev/null || true + done + systemctl daemon-reload 2>/dev/null || true + ;; + purge) + for unit in \ + rigforge-autotune.timer rigforge-watchdog.timer \ + rigforge-api.service rigforge-api-refresh.service rigforge-api-refresh.timer \ + rigforge-control.service rigforge-control-apply.service rigforge-control-apply.path \ + rigforge-control-upgrade.service rigforge-control-upgrade.path; do + systemctl stop "$unit" 2>/dev/null || true + systemctl disable "$unit" 2>/dev/null || true + done + systemctl daemon-reload 2>/dev/null || true + rm -rf /etc/rigforge /var/lib/rigforge + rm -f /usr/bin/rigforge + rm -rf /usr/lib/rigforge + rm -f /etc/apt/keyrings/rigforge.asc + ;; + *) + echo "postrem called with unknown argument: $1" >&2 + exit 1 + ;; +esac + +exit 0 +POSTRM +chmod 755 "$DEB_DIR/DEBIAN/postrm" + +cat >"$DEB_DIR/DEBIAN/conffiles" <<'EOF' +/etc/rigforge/config.json +EOF + +DEB_NAME="rigforge_${VERSION}_all.deb" +DEB_PATH="$(pwd)/$DEB_NAME" +dpkg-deb --build --root-owner-group --zstd \ + "$DEB_DIR" "$DEB_PATH" + +echo "---" +echo "Built: $DEB_PATH" +echo "Size: $(stat -c '%s' "$DEB_PATH" 2>/dev/null || stat -f '%z' "$DEB_PATH") bytes" +echo "Package: $(dpkg-deb -f "$DEB_PATH" Package)" +echo "Version: $(dpkg-deb -f "$DEB_PATH" Version)" +echo "Architecture: $(dpkg-deb -f "$DEB_PATH" Architecture)" +echo "---" diff --git a/tests/test-build-deb.sh b/tests/test-build-deb.sh new file mode 100644 index 00000000..768f394e --- /dev/null +++ b/tests/test-build-deb.sh @@ -0,0 +1,154 @@ +#!/usr/bin/env bash +set -euo pipefail +ROOT=$(cd "$(dirname "$0")/.." && pwd) +cd "$ROOT" + +if [[ $(uname -s) != Linux ]]; then + printf 'SKIP: build-deb needs Linux (dpkg-deb)\n' + exit 0 +fi +for cmd in dpkg-deb dpkg; do + if ! command -v "$cmd" >/dev/null 2>&1; then + printf 'SKIP: missing %s\n' "$cmd" + exit 0 + fi +done + +ok() { printf 'ok: %s\n' "$1"; } +fail() { + printf 'FAIL: %s\n' "$1" >&2 + exit 1 +} +assert_fails() { + local desc=$1 + shift + if "$@" >/dev/null 2>&1; then + printf 'FAIL: %s (unexpectedly succeeded)\n' "$desc" >&2 + exit 1 + fi + ok "$desc" +} +assert_ok() { + local desc=$1 + shift + if ! "$@" >/dev/null 2>&1; then + printf 'FAIL: %s\n' "$desc" >&2 + exit 1 + fi + ok "$desc" +} +assert_eq() { + if [ "$1" != "$2" ]; then + printf 'FAIL: %s (expected [%s], got [%s])\n' "$3" "$2" "$1" >&2 + exit 1 + fi + ok "$3" +} +assert_contains() { + local desc=$1 haystack=$2 needle=$3 + case "$haystack" in + *"$needle"*) ok "$desc" ;; + *) + printf 'FAIL: %s (%s not found)\n' "$desc" "$needle" >&2 + exit 1 + ;; + esac +} +assert_field() { + local desc=$1 deb=$2 field=$3 want=$4 + got=$(dpkg-deb -f "$deb" "$field" 2>/dev/null) || fail "$desc: dpkg-deb -f failed" + assert_eq "$got" "$want" "$desc: $field == $want" +} + +WORK=$(mktemp -d) +trap 'rm -rf "$WORK"' EXIT +mkdir -p "$WORK" + +assert_fails "no args exits non-zero" "$ROOT/scripts/build-deb.sh" +assert_fails "one arg exits non-zero" "$ROOT/scripts/build-deb.sh" "$WORK/missing.tar.gz" "1.0.0" "$ROOT/packaging/apt/fingerprint" + +assert_fails "missing archive exits non-zero" "$ROOT/scripts/build-deb.sh" "$WORK/nope.tar.gz" "1.0.0" "$ROOT/packaging/apt/fingerprint" + +mkdir -p "$WORK/archive" +cp "$ROOT/rigforge.sh" "$WORK/archive/" +cp "$ROOT/util/"* "$WORK/archive/util/" +cp "$ROOT/systemd/"* "$WORK/archive/systemd/" +cp "$ROOT/config.minimal.json" "$WORK/archive/" +cp "$ROOT/config.reference.json" "$WORK/archive/" +cp "$ROOT/README.md" "$WORK/archive/" +cp "$ROOT/docs/"* "$WORK/archive/docs/" +cp "$ROOT/images/"* "$WORK/archive/images/" +cp "$ROOT/LICENSE" "$WORK/archive/" +cp "$ROOT/VERSION" "$WORK/archive/" +tar -czf "$WORK/bundle.tar.gz" -C "$WORK/archive" . +assert_fails "missing fingerprint file exits non-zero" "$ROOT/scripts/build-deb.sh" "$WORK/bundle.tar.gz" "1.0.0" "$WORK/nope" + +printf '0.0.0-mismatch\n' >"$WORK/archive/VERSION" +assert_fails "VERSION mismatch exits non-zero" "$ROOT/scripts/build-deb.sh" "$WORK/bundle.tar.gz" "1.0.0" "$ROOT/packaging/apt/fingerprint" +printf '%s\n' "$(cat "$ROOT/VERSION")" >"$WORK/archive/VERSION" +tar -czf "$WORK/bundle.tar.gz" -C "$WORK/archive" . + +VER="$(tr -d '[:space:]' <"$ROOT/VERSION")" +bash "$ROOT/scripts/build-deb.sh" "$WORK/bundle.tar.gz" "v$VER" "$ROOT/packaging/apt/fingerprint" +DEB="$WORK/rigforge_${VER}_all.deb" +assert_ok "build-deb produces a .deb" test -f "$DEB" + +assert_field "$DEB" Package rigforge +assert_field "$DEB" Version "$VER" +assert_field "$DEB" Architecture all + +CONTENT_DIR=$(mktemp -d) +trap 'rm -rf "$WORK" "$CONTENT_DIR"' EXIT +dpkg-deb --extract "$DEB" "$CONTENT_DIR" + +assert_eq "$([ -f "$CONTENT_DIR/usr/lib/rigforge/rigforge.sh" ] && echo yes || echo no)" "yes" "rigforge.sh in /usr/lib/rigforge/" +assert_eq "$([ -d "$CONTENT_DIR/usr/lib/rigforge/util" ] && echo yes || echo no)" "yes" "util/ in /usr/lib/rigforge/" +assert_eq "$([ -d "$CONTENT_DIR/usr/lib/rigforge/systemd" ] && echo yes || echo no)" "yes" "systemd/ in /usr/lib/rigforge/" +assert_eq "$([ -f "$CONTENT_DIR/usr/bin/rigforge" ] && echo yes || echo no)" "yes" "/usr/bin/rigforge wrapper" +assert_eq "$([ -f "$CONTENT_DIR/etc/rigforge/config.json" ] && echo yes || echo no)" "yes" "config.json as conffile" +assert_eq "$([ -d "$CONTENT_DIR/var/lib/rigforge" ] && echo yes || echo no)" "yes" "state dir /var/lib/rigforge" +assert_eq "$([ -f "$CONTENT_DIR/var/lib/rigforge/.rigforge-package" ] && echo yes || echo no)" "yes" "apt marker" +assert_eq "$(tr -d '[:space:]' <"$CONTENT_DIR/var/lib/rigforge/.rigforge-package")" "apt" "marker value is apt" + +assert_contains "wrapper exports RIGFORGE_LIB" "$(cat "$CONTENT_DIR/usr/bin/rigforge")" "RIGFORGE_LIB" +assert_contains "wrapper exports RIGFORGE_STATE" "$(cat "$CONTENT_DIR/usr/bin/rigforge")" "RIGFORGE_STATE" + +assert_eq "$([ -f "$CONTENT_DIR/DEBIAN/postinst" ] && echo yes || echo no)" "yes" "postinst present" +assert_eq "$([ -f "$CONTENT_DIR/DEBIAN/postrm" ] && echo yes || echo no)" "yes" "postrm present" +assert_eq "$([ -f "$CONTENT_DIR/DEBIAN/conffiles" ] && echo yes || echo no)" "yes" "conffiles present" + +POSTINST="$(cat "$CONTENT_DIR/DEBIAN/postinst")" +assert_contains "postinst runs daemon-reload" "$POSTINST" "daemon-reload" +assert_contains "postinst creates state dir" "$POSTINST" "/var/lib/rigforge" + +POSTRM="$(cat "$CONTENT_DIR/DEBIAN/postrm")" +assert_contains "postrm remove stops units" "$POSTRM" "systemctl stop" +assert_contains "postrm remove disables units" "$POSTRM" "systemctl disable" +assert_contains "postrm purge removes state" "$POSTRM" "/var/lib/rigforge" +assert_contains "postrm purge removes config" "$POSTRM" "/etc/rigforge" + +CONFFILES="$(cat "$CONTENT_DIR/DEBIAN/conffiles")" +assert_contains "conffiles lists config.json" "$CONFFILES" "/etc/rigforge/config.json" + +for f in "$CONTENT_DIR/usr/lib/rigforge/"* "$CONTENT_DIR/DEBIAN/"*; do + [ -f "$f" ] || continue + case "$(cat "$f")" in + *"pithead-developer"*) fail "internal repo reference found: $f" ;; + esac +done +ok "no internal test-runner repo references" + +if command -v apt-ftparchive >/dev/null 2>&1 && command -v gpg >/dev/null 2>&1; then + apt_out="$WORK/apt-feed" + mkdir -p "$apt_out" + FINGERPRINT="$(tr -d '[:space:]' <"$ROOT/packaging/apt/fingerprint")" + if [ "$FINGERPRINT" != "pending-key-generation" ] && [ -n "$FINGERPRINT" ]; then + GNUPGHOME="${GNUPGHOME:-}" apt-ftparchive packages "$apt_out" >/dev/null 2>&1 || true + fi + pkg=$(dpkg-deb -f "$DEB" Package) + ver=$(dpkg-deb -f "$DEB" Version) + assert_eq "$pkg" "rigforge" "build-apt: Package field matches" + assert_eq "$ver" "$VER" "build-apt: Version field matches" +fi + +printf '\nbuild-deb: %s tests passed\n' "$PASS" 2>/dev/null || true From e63102c502967f56c5bba8740a00ade86795c007 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 02:08:46 -0600 Subject: [PATCH 02/26] fix: replace real email with placeholder for topology linter --- scripts/build-deb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh index 8a20104c..e972a8f6 100755 --- a/scripts/build-deb.sh +++ b/scripts/build-deb.sh @@ -124,7 +124,7 @@ Section: ${PKG_SECTION} Priority: ${PKG_PRIORITY} Architecture: ${PKG_ARCH} Depends: bash, jq, curl, nftables, git, build-essential, cmake, libuv1-dev, libssl-dev, libhwloc-dev, gettext-base, python3, msr-tools -Maintainer: RigForge +Maintainer: user@example.com Description: Companion miner for P2Pool/XMRig workers RigForge provisions and runs an XMRig worker for a P2Pool coordinator, any RandomX Stratum pool, or a solo daemon pool. From 941cd8c066ed1f21d7129bf14c5152190d1d1b4f Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 03:52:33 -0600 Subject: [PATCH 03/26] test: register test-build-deb.sh in test-suite; fix stray $PASS reference - Add tests/test-build-deb.sh to Makefile test-suite target - Fix unused $PASS variable in test output line Co-Authored-By: Claude Code --- Makefile | 1 + tests/test-build-deb.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0acbc756..75822038 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ test-suite: ## rigforge test suite: unit + black-box, every CPU/OS profile simul bash tests/test-coverage-cache.sh bash tests/test-revision-key.sh bash tests/test-homebrew-formula.sh + bash tests/test-build-deb.sh test-e2e: ## Full end-to-end run in disposable Linux containers (needs Docker) bash tests/e2e/linux.sh diff --git a/tests/test-build-deb.sh b/tests/test-build-deb.sh index 768f394e..0fe48bcc 100644 --- a/tests/test-build-deb.sh +++ b/tests/test-build-deb.sh @@ -151,4 +151,4 @@ if command -v apt-ftparchive >/dev/null 2>&1 && command -v gpg >/dev/null 2>&1; assert_eq "$ver" "$VER" "build-apt: Version field matches" fi -printf '\nbuild-deb: %s tests passed\n' "$PASS" 2>/dev/null || true +printf '\nbuild-deb: tests passed\n' 2>/dev/null || true From b56e6ae15ad6d41f22775c59118abbf2a057b0f4 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 04:30:53 -0600 Subject: [PATCH 04/26] fix: clean up build-deb.sh and fix docs claim about systemd units MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove unused RELEASE_DIR allocation in build-deb.sh (dead code) - Fix postinst first-install hint: check $2 (package arg) instead of config.json existence — config.json is always placed during build - Correct docs/getting-started.md: the package installs the wrapper, not systemd units (rigforge.sh setup installs units) --- docs/getting-started.md | 7 ++++--- scripts/build-deb.sh | 4 +--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index 591f8eef..dd8a6e4b 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -72,9 +72,10 @@ printf 'Types: deb\nURIs: https://p2pool-starter-stack.github.io/rigforge/apt/\n sudo apt update && sudo apt install rigforge ``` -`apt upgrade rigforge` keeps the worker current. On Linux the package installs systemd units and -a `/usr/bin/rigforge` wrapper that exports `RIGFORGE_LIB` and `RIGFORGE_STATE`. First-run setup -is the same as the git or Homebrew routes: `sudo rigforge.sh setup` (or `sudo rigforge setup`). +`apt upgrade rigforge` keeps the worker current. On Linux the package installs a +`/usr/bin/rigforge` wrapper that exports `RIGFORGE_LIB` and `RIGFORGE_STATE`. First-run setup +is the same as the git or Homebrew routes: `sudo rigforge.sh setup` (or `sudo rigforge setup`), +which installs and enables the systemd units, builds the worker, and tunes the kernel. --- diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh index e972a8f6..6fd53e5b 100755 --- a/scripts/build-deb.sh +++ b/scripts/build-deb.sh @@ -45,8 +45,6 @@ FINGERPRINT="$(tr -d '[:space:]' <"$FINGERPRINT_FILE")" STAGING="$(mktemp -d)" CLEANUP+=("$STAGING") -RELEASE_DIR="$(mktemp -d)" -CLEANUP+=("$RELEASE_DIR") case "$RELEASE_ARCHIVE" in *.tar.gz) tar -xzf "$RELEASE_ARCHIVE" -C "$STAGING" ;; @@ -140,7 +138,7 @@ mkdir -p /var/lib/rigforge systemctl daemon-reload 2>/dev/null || true -if [ ! -f /etc/rigforge/config.json ]; then +if [ -z "${2:-}" ]; then echo "" echo "RigForge is installed. Run the following to complete setup:" echo "" From cd8a08b7b1f6eef30c473c5dd22410ad8133f9e7 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 04:51:32 -0600 Subject: [PATCH 05/26] fix: create archive subdirs in test-build-deb.sh The test copied util/, systemd/, docs/, images/ into archive/ subdirs without creating those directories first, causing cp to fail in CI with 'No such file or directory'. Add mkdir -p for all subdirs. --- tests/test-build-deb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-build-deb.sh b/tests/test-build-deb.sh index 0fe48bcc..c5cf9be7 100644 --- a/tests/test-build-deb.sh +++ b/tests/test-build-deb.sh @@ -69,7 +69,7 @@ assert_fails "one arg exits non-zero" "$ROOT/scripts/build-deb.sh" "$WORK/missin assert_fails "missing archive exits non-zero" "$ROOT/scripts/build-deb.sh" "$WORK/nope.tar.gz" "1.0.0" "$ROOT/packaging/apt/fingerprint" -mkdir -p "$WORK/archive" +mkdir -p "$WORK/archive/util" "$WORK/archive/systemd" "$WORK/archive/docs" "$WORK/archive/images" cp "$ROOT/rigforge.sh" "$WORK/archive/" cp "$ROOT/util/"* "$WORK/archive/util/" cp "$ROOT/systemd/"* "$WORK/archive/systemd/" From 7ff0fb32790ad863ec4818c3ff7d28b2526f6b8e Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:04:09 -0600 Subject: [PATCH 06/26] fix: copy directories recursively in test-build-deb.sh Co-Authored-By: Claude Sonnet 5.5 --- tests/test-build-deb.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test-build-deb.sh b/tests/test-build-deb.sh index c5cf9be7..e33195a0 100644 --- a/tests/test-build-deb.sh +++ b/tests/test-build-deb.sh @@ -71,13 +71,13 @@ assert_fails "missing archive exits non-zero" "$ROOT/scripts/build-deb.sh" "$WOR mkdir -p "$WORK/archive/util" "$WORK/archive/systemd" "$WORK/archive/docs" "$WORK/archive/images" cp "$ROOT/rigforge.sh" "$WORK/archive/" -cp "$ROOT/util/"* "$WORK/archive/util/" -cp "$ROOT/systemd/"* "$WORK/archive/systemd/" +cp -R "$ROOT/util/"* "$WORK/archive/util/" +cp -R "$ROOT/systemd/"* "$WORK/archive/systemd/" cp "$ROOT/config.minimal.json" "$WORK/archive/" cp "$ROOT/config.reference.json" "$WORK/archive/" cp "$ROOT/README.md" "$WORK/archive/" -cp "$ROOT/docs/"* "$WORK/archive/docs/" -cp "$ROOT/images/"* "$WORK/archive/images/" +cp -R "$ROOT/docs/"* "$WORK/archive/docs/" +cp -R "$ROOT/images/"* "$WORK/archive/images/" cp "$ROOT/LICENSE" "$WORK/archive/" cp "$ROOT/VERSION" "$WORK/archive/" tar -czf "$WORK/bundle.tar.gz" -C "$WORK/archive" . From fa735c9f31b58c624a43b1ef311ecf1e9493e2f7 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:18:24 -0600 Subject: [PATCH 07/26] fix: nest the test bundle under a top-level directory like the release tarball Co-Authored-By: Claude Sonnet 5.5 --- tests/test-build-deb.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-build-deb.sh b/tests/test-build-deb.sh index e33195a0..7b1f51c4 100644 --- a/tests/test-build-deb.sh +++ b/tests/test-build-deb.sh @@ -80,13 +80,13 @@ cp -R "$ROOT/docs/"* "$WORK/archive/docs/" cp -R "$ROOT/images/"* "$WORK/archive/images/" cp "$ROOT/LICENSE" "$WORK/archive/" cp "$ROOT/VERSION" "$WORK/archive/" -tar -czf "$WORK/bundle.tar.gz" -C "$WORK/archive" . +tar -czf "$WORK/bundle.tar.gz" -C "$WORK" archive assert_fails "missing fingerprint file exits non-zero" "$ROOT/scripts/build-deb.sh" "$WORK/bundle.tar.gz" "1.0.0" "$WORK/nope" printf '0.0.0-mismatch\n' >"$WORK/archive/VERSION" assert_fails "VERSION mismatch exits non-zero" "$ROOT/scripts/build-deb.sh" "$WORK/bundle.tar.gz" "1.0.0" "$ROOT/packaging/apt/fingerprint" printf '%s\n' "$(cat "$ROOT/VERSION")" >"$WORK/archive/VERSION" -tar -czf "$WORK/bundle.tar.gz" -C "$WORK/archive" . +tar -czf "$WORK/bundle.tar.gz" -C "$WORK" archive VER="$(tr -d '[:space:]' <"$ROOT/VERSION")" bash "$ROOT/scripts/build-deb.sh" "$WORK/bundle.tar.gz" "v$VER" "$ROOT/packaging/apt/fingerprint" From 08f9cb6581002305861b1462f9dfdcff4cf893de Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:18:41 -0600 Subject: [PATCH 08/26] fix: build the test deb in a scratch dir and inspect DEBIAN with raw-extract Co-Authored-By: Claude Sonnet 5.5 --- tests/test-build-deb.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test-build-deb.sh b/tests/test-build-deb.sh index 7b1f51c4..5a180a6a 100644 --- a/tests/test-build-deb.sh +++ b/tests/test-build-deb.sh @@ -55,9 +55,9 @@ assert_contains() { esac } assert_field() { - local desc=$1 deb=$2 field=$3 want=$4 - got=$(dpkg-deb -f "$deb" "$field" 2>/dev/null) || fail "$desc: dpkg-deb -f failed" - assert_eq "$got" "$want" "$desc: $field == $want" + local deb=$1 field=$2 want=$3 got + got=$(dpkg-deb -f "$deb" "$field" 2>/dev/null) || fail "dpkg-deb -f $field failed" + assert_eq "$got" "$want" "control $field == $want" } WORK=$(mktemp -d) @@ -89,7 +89,7 @@ printf '%s\n' "$(cat "$ROOT/VERSION")" >"$WORK/archive/VERSION" tar -czf "$WORK/bundle.tar.gz" -C "$WORK" archive VER="$(tr -d '[:space:]' <"$ROOT/VERSION")" -bash "$ROOT/scripts/build-deb.sh" "$WORK/bundle.tar.gz" "v$VER" "$ROOT/packaging/apt/fingerprint" +(cd "$WORK" && bash "$ROOT/scripts/build-deb.sh" "$WORK/bundle.tar.gz" "v$VER" "$ROOT/packaging/apt/fingerprint" >/dev/null) DEB="$WORK/rigforge_${VER}_all.deb" assert_ok "build-deb produces a .deb" test -f "$DEB" @@ -99,7 +99,7 @@ assert_field "$DEB" Architecture all CONTENT_DIR=$(mktemp -d) trap 'rm -rf "$WORK" "$CONTENT_DIR"' EXIT -dpkg-deb --extract "$DEB" "$CONTENT_DIR" +dpkg-deb --raw-extract "$DEB" "$CONTENT_DIR" assert_eq "$([ -f "$CONTENT_DIR/usr/lib/rigforge/rigforge.sh" ] && echo yes || echo no)" "yes" "rigforge.sh in /usr/lib/rigforge/" assert_eq "$([ -d "$CONTENT_DIR/usr/lib/rigforge/util" ] && echo yes || echo no)" "yes" "util/ in /usr/lib/rigforge/" From 2808fbca7b98ecfdb1beaf268f5dd682f7cc19c3 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:33:03 -0600 Subject: [PATCH 09/26] fix: select xz compression with -Zxz; dpkg-deb has no --zstd option Co-Authored-By: Claude Sonnet 5.5 --- scripts/build-deb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh index 6fd53e5b..5e297d67 100755 --- a/scripts/build-deb.sh +++ b/scripts/build-deb.sh @@ -198,7 +198,7 @@ EOF DEB_NAME="rigforge_${VERSION}_all.deb" DEB_PATH="$(pwd)/$DEB_NAME" -dpkg-deb --build --root-owner-group --zstd \ +dpkg-deb --build --root-owner-group -Zxz \ "$DEB_DIR" "$DEB_PATH" echo "---" From ff69003a867527e788ba8592229e8bd9c54c3b83 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:55:24 -0600 Subject: [PATCH 10/26] package: build the .deb from packaging/debian and test install, upgrade, remove and purge Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 5 +- Makefile | 1 + docs/getting-started.md | 32 ++--- packaging/debian/control | 12 ++ packaging/debian/postinst | 9 +- packaging/debian/postrm | 16 +++ packaging/debian/prerm | 17 +++ scripts/build-deb.sh | 220 +++++----------------------------- tests/README.md | 4 +- tests/test-build-deb.sh | 194 +++++++++--------------------- tests/test-deb-install.sh | 100 ++++++++++++++++ tests/test-package-upgrade.sh | 40 ++++++- 12 files changed, 290 insertions(+), 360 deletions(-) create mode 100644 packaging/debian/control create mode 100755 packaging/debian/postrm create mode 100755 packaging/debian/prerm create mode 100755 tests/test-deb-install.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a628c523..dac7785f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,9 +62,8 @@ jobs: - name: Build the .deb package run: | set -euo pipefail - VERSION="$(tr -d '[:space:]' < VERSION)" - bash scripts/build-deb.sh rigforge-"$TAG".tar.gz "$TAG" packaging/apt/fingerprint - sha256sum rigforge_"$VERSION"_all.deb >> SHA256SUMS + deb=$(bash scripts/build-deb.sh "rigforge-$TAG.tar.gz" "$TAG") + sha256sum "$deb" >> SHA256SUMS echo "--- SHA256SUMS (with .deb) ---"; cat SHA256SUMS - name: Extract release notes from CHANGELOG.md diff --git a/Makefile b/Makefile index 37a4fa82..7c43c887 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ test-suite: ## rigforge test suite: unit + black-box, every CPU/OS profile simul test-e2e: ## Full end-to-end run in disposable Linux containers (needs Docker) bash tests/e2e/linux.sh + bash tests/test-deb-install.sh e2e-docs-replay: ## Replay documented setup and two reboots in an explicitly supplied disposable KVM guest python3 tests/docs_replay.py diff --git a/docs/getting-started.md b/docs/getting-started.md index dd8a6e4b..fe829ff4 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -53,29 +53,15 @@ safe place for code that root-run units execute, so prefer the git route below o ### Install with apt (Debian / Ubuntu on Linux) -The project publishes a signed `.deb` through a GitHub-hosted apt feed. Install the signing key -and verify its fingerprint against [`packaging/apt/fingerprint`](../packaging/apt/fingerprint) -in this repository: - -```bash -sudo install -d -m 0755 /etc/apt/keyrings -curl -fsSL https://p2pool-starter-stack.github.io/rigforge/apt/rigforge.asc | - sudo tee /etc/apt/keyrings/rigforge.asc >/dev/null -gpg --show-keys --with-colons /etc/apt/keyrings/rigforge.asc | awk -F: '/^fpr/{print $10; exit}' -``` - -The printed fingerprint must match the pinned one. Then add the source and install: - -```bash -printf 'Types: deb\nURIs: https://p2pool-starter-stack.github.io/rigforge/apt/\nSuites: ./\nSigned-By: /etc/apt/keyrings/rigforge.asc\n' | - sudo tee /etc/apt/sources.list.d/rigforge.sources >/dev/null -sudo apt update && sudo apt install rigforge -``` - -`apt upgrade rigforge` keeps the worker current. On Linux the package installs a -`/usr/bin/rigforge` wrapper that exports `RIGFORGE_LIB` and `RIGFORGE_STATE`. First-run setup -is the same as the git or Homebrew routes: `sudo rigforge.sh setup` (or `sudo rigforge setup`), -which installs and enables the systemd units, builds the worker, and tunes the kernel. +The apt steps (signing key, source entry, `apt install rigforge`) are in the +[README](../README.md), under **Prefer `apt`?**. Installing changes nothing on the host: the package puts the +code in `/usr/lib/rigforge`, links `/usr/bin/rigforge` to it and adds the one-shot upgrade unit. +Provision with `sudo rigforge setup`. Until `RIGFORGE_STATE` lands (#780), `setup` keeps +`config.json` and the XMRig build inside `/usr/lib/rigforge`; `apt upgrade` and `apt remove` keep +them, and `apt purge` deletes them with `/var/lib/rigforge`. For the same reason the +[queued upgrade](operations.md#upgrading-through-apt), which looks for `/etc/rigforge/config.json`, +does not start yet: run `sudo rigforge upgrade` after `apt upgrade rigforge`. Neither remove nor purge reverts +system tuning; that is `rigforge uninstall`. --- diff --git a/packaging/debian/control b/packaging/debian/control new file mode 100644 index 00000000..7650189e --- /dev/null +++ b/packaging/debian/control @@ -0,0 +1,12 @@ +Package: rigforge +Version: @VERSION@ +Section: net +Priority: optional +Architecture: all +Depends: bash, jq, curl, nftables, git, build-essential, cmake, libuv1-dev, libssl-dev, libhwloc-dev, gettext-base, python3, msr-tools, linux-tools-common | linux-cpupower +Maintainer: RigForge maintainers +Homepage: https://github.com/p2pool-starter-stack/rigforge +Description: Provision and run a tuned XMRig worker for RandomX mining + RigForge provisions and runs an XMRig worker for a Pithead coordinator, + any RandomX Stratum pool, or a solo daemon pool. Installing changes + nothing on the host; run "sudo rigforge setup" to provision. diff --git a/packaging/debian/postinst b/packaging/debian/postinst index 9d909b3b..5997619e 100755 --- a/packaging/debian/postinst +++ b/packaging/debian/postinst @@ -9,10 +9,15 @@ RETRY='sudo rigforge upgrade' case "$1" in configure) old=$2 + install -d -m 0755 "$STATE" + if [ -d "$ROOT/run/systemd/system" ]; then systemctl daemon-reload || true; fi + if [ -z "$old" ]; then + echo "rigforge: installed; nothing on this host changed. Provision with: sudo rigforge setup" + fi new=$(dpkg-query -W -f '${Version}' rigforge 2>/dev/null || true) if [ -n "$old" ] && [ -n "$new" ] && [ -f "$CONFIG" ] && dpkg --compare-versions "$new" gt "$old"; then - if install -d -m 0755 "$STATE" && tmp=$(mktemp "$STATE/.upgrade-pending.XXXXXX") && chmod 0644 "$tmp" && printf '%s\n' "$new" >"$tmp" && mv -f "$tmp" "$STATE/upgrade-pending"; then - if [ -d "$ROOT/run/systemd/system" ] && systemctl daemon-reload && systemctl start --no-block rigforge-upgrade.service; then + if tmp=$(mktemp "$STATE/.upgrade-pending.XXXXXX") && chmod 0644 "$tmp" && printf '%s\n' "$new" >"$tmp" && mv -f "$tmp" "$STATE/upgrade-pending"; then + if [ -d "$ROOT/run/systemd/system" ] && systemctl start --no-block rigforge-upgrade.service; then echo "rigforge: upgrade to $new queued outside dpkg; follow it with: journalctl -u rigforge-upgrade" else echo "rigforge: could not start the upgrade unit; run: $RETRY" >&2 diff --git a/packaging/debian/postrm b/packaging/debian/postrm new file mode 100755 index 00000000..abb4787c --- /dev/null +++ b/packaging/debian/postrm @@ -0,0 +1,16 @@ +#!/bin/sh +set -e + +ROOT=${RIGFORGE_PKG_ROOT:-} + +case "$1" in +purge) + rm -rf "$ROOT/etc/rigforge" "$ROOT/var/lib/rigforge" "$ROOT/usr/lib/rigforge" + if [ -d "$ROOT/run/systemd/system" ]; then systemctl daemon-reload || true; fi + ;; +remove) + if [ -d "$ROOT/run/systemd/system" ]; then systemctl daemon-reload || true; fi + ;; +esac + +exit 0 diff --git a/packaging/debian/prerm b/packaging/debian/prerm new file mode 100755 index 00000000..1a176226 --- /dev/null +++ b/packaging/debian/prerm @@ -0,0 +1,17 @@ +#!/bin/sh +set -e + +ROOT=${RIGFORGE_PKG_ROOT:-} +UNITS="xmrig.service rigforge-upgrade.service rigforge-autotune.timer rigforge-autotune.service rigforge-watchdog.timer rigforge-watchdog.service rigforge-api.service rigforge-api-refresh.timer rigforge-api-refresh.service rigforge-control.service rigforge-control-apply.path rigforge-control-apply.service rigforge-control-upgrade.path rigforge-control-upgrade.service" + +case "$1" in +remove | deconfigure) + if [ -d "$ROOT/run/systemd/system" ]; then + for unit in $UNITS; do + systemctl disable --now "$unit" >/dev/null 2>&1 || true + done + fi + ;; +esac + +exit 0 diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh index 5e297d67..175930a2 100755 --- a/scripts/build-deb.sh +++ b/scripts/build-deb.sh @@ -2,6 +2,7 @@ set -euo pipefail PROG=${0##*/} +PKG_SRC="$(cd "$(dirname "${BASH_SOURCE[0]}")/../packaging/debian" && pwd)" CLEANUP=() trap '[[ ${#CLEANUP[@]} -eq 0 ]] || rm -rf -- "${CLEANUP[@]}"' EXIT @@ -9,202 +10,45 @@ die() { printf '%s: %s\n' "$PROG" "$1" >&2 exit 1 } -usage() { - cat >&2 < -Builds a rigforge__all.deb from the release tarball (zip or tar.gz). -The tarball must be the same bundle release.yml produces (rigforge.sh, util/, -systemd/, config.minimal.json, config.reference.json, README.md, docs/, images/, -LICENSE, VERSION). is the tag version without the v prefix (e.g. 1.20.0). - -Package layout: - /usr/lib/rigforge/ — code tree (rigforge.sh, util/, systemd/, docs/, …) - /usr/bin/rigforge — wrapper exporting RIGFORGE_LIB / RIGFORGE_STATE - /etc/rigforge/config.json — default config (conffile) - /var/lib/rigforge/ — runtime state directory - /etc/apt/keyrings/rigforge.asc — signing key (from fingerprint file) - .rigforge-package — marker file with value "apt" -EOF +[[ $# -eq 2 ]] || { + printf 'usage: %s \n' "$PROG" >&2 exit 2 } -[[ $# -eq 3 ]] || usage - -RELEASE_ARCHIVE="$1" -VERSION="${2#v}" -FINGERPRINT_FILE="$3" - -[[ -f "$RELEASE_ARCHIVE" ]] || die "release archive not found: $RELEASE_ARCHIVE" -[[ -n "$VERSION" ]] || die "version must not be empty" -[[ -f "$FINGERPRINT_FILE" ]] || die "fingerprint file not found: $FINGERPRINT_FILE" +ARCHIVE=$1 +VERSION=${2#v} +[[ -f $ARCHIVE ]] || die "release archive not found: $ARCHIVE" +[[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || die "not a release version: $2" -FINGERPRINT="$(tr -d '[:space:]' <"$FINGERPRINT_FILE")" -[[ -n "$FINGERPRINT" ]] || die "fingerprint file is empty" - -STAGING="$(mktemp -d)" +umask 022 +STAGING=$(mktemp -d) CLEANUP+=("$STAGING") - -case "$RELEASE_ARCHIVE" in -*.tar.gz) tar -xzf "$RELEASE_ARCHIVE" -C "$STAGING" ;; -*.zip) unzip -qo "$RELEASE_ARCHIVE" -d "$STAGING" ;; +case "$ARCHIVE" in +*.tar.gz) tar -xzf "$ARCHIVE" -C "$STAGING" ;; +*.zip) unzip -q "$ARCHIVE" -d "$STAGING" ;; *) die "unsupported archive format (expect .tar.gz or .zip)" ;; esac -RELEASE_SRC="" +SRC="" for d in "$STAGING"/*/; do - [[ -d "$d" ]] || continue - [[ -f "$d"/rigforge.sh ]] || continue - RELEASE_SRC="$d" - break + [[ -f $d/rigforge.sh ]] && SRC=${d%/} && break done -[[ -n "$RELEASE_SRC" ]] || die "could not find release source directory in archive" - -ARCHIVE_VERSION="$(tr -d '[:space:]' <"$RELEASE_SRC/VERSION")" -if [ "$ARCHIVE_VERSION" != "$VERSION" ]; then - die "VERSION in archive ($ARCHIVE_VERSION) disagrees with tag version ($VERSION)" -fi - -BUILD_DIR="$(mktemp -d)" -CLEANUP+=("$BUILD_DIR") -DEB_DIR="$BUILD_DIR/rigforge-$VERSION" -mkdir -p "$DEB_DIR" - -mkdir_stage() { mkdir -p "$DEB_DIR/$1"; } - -PKG_NAME="rigforge" -PKG_ARCH="all" -PKG_VERSION="$VERSION" -PKG_SECTION="net" -PKG_PRIORITY="optional" - -mkdir_stage "usr/lib/rigforge" -mkdir_stage "usr/bin" -mkdir_stage "etc/rigforge" -mkdir_stage "var/lib/rigforge" -mkdir_stage "etc/apt/keyrings" -mkdir_stage "usr/share/doc/rigforge" -mkdir_stage "DEBIAN" - -cp -a "$RELEASE_SRC"/rigforge.sh "$DEB_DIR/usr/lib/rigforge/" -cp -a "$RELEASE_SRC"/util/ "$DEB_DIR/usr/lib/rigforge/util/" -cp -a "$RELEASE_SRC"/systemd/ "$DEB_DIR/usr/lib/rigforge/systemd/" -cp -a "$RELEASE_SRC"/config.minimal.json "$DEB_DIR/usr/lib/rigforge/" -cp -a "$RELEASE_SRC"/config.reference.json "$DEB_DIR/usr/lib/rigforge/" -cp -a "$RELEASE_SRC"/README.md "$DEB_DIR/usr/lib/rigforge/" -cp -a "$RELEASE_SRC"/VERSION "$DEB_DIR/usr/lib/rigforge/" -cp -a "$RELEASE_SRC"/LICENSE "$DEB_DIR/usr/lib/rigforge/" -cp -a "$RELEASE_SRC"/docs/ "$DEB_DIR/usr/lib/rigforge/docs/" -cp -a "$RELEASE_SRC"/images/ "$DEB_DIR/usr/lib/rigforge/images/" - -cat >"$DEB_DIR/usr/bin/rigforge" <<'WRAPPER' -#!/usr/bin/env bash -set -euo pipefail -export RIGFORGE_LIB="/usr/lib/rigforge" -export RIGFORGE_STATE="/var/lib/rigforge" -exec "${RIGFORGE_LIB}/rigforge.sh" "$@" -WRAPPER -chmod 755 "$DEB_DIR/usr/bin/rigforge" - -cp "$RELEASE_SRC/config.minimal.json" "$DEB_DIR/etc/rigforge/config.json" - -echo "apt" >"$DEB_DIR/var/lib/rigforge/.rigforge-package" - -cp "$FINGERPRINT_FILE" "$DEB_DIR/etc/apt/keyrings/rigforge.asc" 2>/dev/null || { - : -} - -cat >"$DEB_DIR/DEBIAN/control" <"$DEB_DIR/DEBIAN/postinst" <<'POSTINST' -#!/usr/bin/env bash -set -euo pipefail - -mkdir -p /var/lib/rigforge - -systemctl daemon-reload 2>/dev/null || true - -if [ -z "${2:-}" ]; then - echo "" - echo "RigForge is installed. Run the following to complete setup:" - echo "" - echo " sudo rigforge.sh setup" - echo "" - echo "This configures your miner, deploys systemd units, and starts mining." -fi - -exit 0 -POSTINST -chmod 755 "$DEB_DIR/DEBIAN/postinst" - -cat >"$DEB_DIR/DEBIAN/postrm" <<'POSTRM' -#!/usr/bin/env bash -set -euo pipefail - -case "$1" in - remove) - for unit in \ - rigforge-autotune.timer rigforge-watchdog.timer \ - rigforge-api.service rigforge-api-refresh.service rigforge-api-refresh.timer \ - rigforge-control.service rigforge-control-apply.service rigforge-control-apply.path \ - rigforge-control-upgrade.service rigforge-control-upgrade.path; do - systemctl stop "$unit" 2>/dev/null || true - systemctl disable "$unit" 2>/dev/null || true - done - systemctl daemon-reload 2>/dev/null || true - ;; - purge) - for unit in \ - rigforge-autotune.timer rigforge-watchdog.timer \ - rigforge-api.service rigforge-api-refresh.service rigforge-api-refresh.timer \ - rigforge-control.service rigforge-control-apply.service rigforge-control-apply.path \ - rigforge-control-upgrade.service rigforge-control-upgrade.path; do - systemctl stop "$unit" 2>/dev/null || true - systemctl disable "$unit" 2>/dev/null || true - done - systemctl daemon-reload 2>/dev/null || true - rm -rf /etc/rigforge /var/lib/rigforge - rm -f /usr/bin/rigforge - rm -rf /usr/lib/rigforge - rm -f /etc/apt/keyrings/rigforge.asc - ;; - *) - echo "postrem called with unknown argument: $1" >&2 - exit 1 - ;; -esac - -exit 0 -POSTRM -chmod 755 "$DEB_DIR/DEBIAN/postrm" - -cat >"$DEB_DIR/DEBIAN/conffiles" <<'EOF' -/etc/rigforge/config.json -EOF - -DEB_NAME="rigforge_${VERSION}_all.deb" -DEB_PATH="$(pwd)/$DEB_NAME" -dpkg-deb --build --root-owner-group -Zxz \ - "$DEB_DIR" "$DEB_PATH" - -echo "---" -echo "Built: $DEB_PATH" -echo "Size: $(stat -c '%s' "$DEB_PATH" 2>/dev/null || stat -f '%z' "$DEB_PATH") bytes" -echo "Package: $(dpkg-deb -f "$DEB_PATH" Package)" -echo "Version: $(dpkg-deb -f "$DEB_PATH" Version)" -echo "Architecture: $(dpkg-deb -f "$DEB_PATH" Architecture)" -echo "---" +[[ -n $SRC ]] || die "no top-level directory with rigforge.sh in the archive" +[[ "$(tr -d '[:space:]' <"$SRC/VERSION")" == "$VERSION" ]] || die "VERSION in archive ($(tr -d '[:space:]' <"$SRC/VERSION")) disagrees with $VERSION" + +export SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-$(stat -c %Y "$SRC/VERSION")} + +ROOT="$STAGING/root" +mkdir -p "$ROOT/usr/lib" "$ROOT/usr/bin" "$ROOT/usr/lib/systemd/system" "$ROOT/var/lib/rigforge" "$ROOT/DEBIAN" +cp -a "$SRC" "$ROOT/usr/lib/rigforge" +rm -rf "$ROOT/usr/lib/rigforge/docs/dev" +printf 'apt\n' >"$ROOT/usr/lib/rigforge/.rigforge-package" +ln -s ../lib/rigforge/rigforge.sh "$ROOT/usr/bin/rigforge" +install -m 0644 "$PKG_SRC/rigforge-upgrade.service" "$ROOT/usr/lib/systemd/system/" +install -m 0755 "$PKG_SRC/postinst" "$PKG_SRC/prerm" "$PKG_SRC/postrm" "$ROOT/DEBIAN/" +sed "s/@VERSION@/$VERSION/" "$PKG_SRC/control" >"$ROOT/DEBIAN/control" + +find "$ROOT" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} + +dpkg-deb --build --root-owner-group -Zxz "$ROOT" "rigforge_${VERSION}_all.deb" >/dev/null +printf '%s\n' "rigforge_${VERSION}_all.deb" diff --git a/tests/README.md b/tests/README.md index 55edb085..172bd045 100644 --- a/tests/README.md +++ b/tests/README.md @@ -52,7 +52,9 @@ CI median/p90, failures and occupied hours; missing evidence leaves rollout acce | **Linux container e2e** | [`e2e/linux.sh`](e2e/linux.sh) → [`e2e/in-container.sh`](e2e/in-container.sh) | Disposable Ubuntu container, **needs Docker**. **In CI.** | The genuine Linux deploy path against a real (throwaway) `/etc` with real GNU tools (`sed -i`, `tee`, `envsubst`) + idempotency on re-run. Only the heavy/privileged bits (compile, package install, `systemctl`/`mount`) are stubbed. A second pass re-runs the container with `RIGFORGE_APPLIANCE=1` (#348) and proves the appliance contracts on that real `/etc`: units land in `/run/systemd/system`, no package installs, no fstab/limits.conf/logrotate writes, every enable carries `--runtime`. A third script, [`e2e/isolation.sh`](e2e/isolation.sh) (#668), puts the rig on a Docker `--internal` network whose only reachable peer is a SOCKS5 proxy fronting a stand-in GitHub (a TLS git smart-HTTP server plus the releases API). With `tor_socks5` set it runs `upgrade --check`, `setup`, a local `upgrade` with an XMRig pin change and the `control-upgrade` oneshot in its own empty environment, and proves from the proxy's log that every connection named a hostname. It also proves the block is real (a direct connection and a keyless `upgrade --check` fail), that an unreachable proxy fails closed without reaching the upstream, and that the live build survives the failed upgrade. | `make test-e2e` | | **Native macOS e2e** | [`e2e/macos.sh`](e2e/macos.sh) | A real Mac, **manual, local only. Not in CI** (macOS is best effort). | The macOS deploy path with genuine BSD tools the Linux CI can only stub: BSD `sed`, the macOS config profile, `mac_*` process control (real `nohup` + PID file), the launchd login agent, `backup`/`restore`. | `make test-e2e-macos` | | **Coverage gate** | [`coverage.sh`](coverage.sh) | kcov in **Docker**. **In CI.** | Line coverage of `rigforge.sh` and its shell helpers by running `run.sh` under kcov; enforces the committed floor ([`coverage-floor.txt`](coverage-floor.txt)) plus a patch-coverage gate (diff-cover) on changed lines. | `make coverage` | -| **Package upgrade** | [`test-package-upgrade.sh`](test-package-upgrade.sh) | Any host, no Docker. **In CI** (`make test-suite`). | [`../packaging/debian/postinst`](../packaging/debian/postinst) queues only on a greater version with a config, never fails dpkg; `package-upgrade` re-renders units and clears the marker on success, and on failure keeps it, records it for status/doctor and does not restart. | `bash tests/test-package-upgrade.sh` | +| **Package upgrade** | [`test-package-upgrade.sh`](test-package-upgrade.sh) | Any host, no Docker. **In CI** (`make test-suite`). | [`../packaging/debian/postinst`](../packaging/debian/postinst) creates the state dir, reloads systemd and prints the first-run step on a first install, and queues only on a greater version with a config, never failing dpkg; `prerm` stops and disables every unit on remove and `postrm` accepts every dpkg action and purges config and state; `package-upgrade` re-renders units and clears the marker on success, and on failure keeps it, records it for status/doctor and does not restart. | `bash tests/test-package-upgrade.sh` | +| **Debian package build** | [`test-build-deb.sh`](test-build-deb.sh) | Linux with `dpkg-deb`, no Docker. **In CI** (`make test-suite`). | [`../scripts/build-deb.sh`](../scripts/build-deb.sh) builds a byte-reproducible `.deb` from the release bundle with the marker where `util/package-mode.sh` reads it, the `packaging/debian` maintainer scripts and upgrade unit, the full `Depends`, and no apt keyring. | `bash tests/test-build-deb.sh` | +| **Debian package install** | [`test-deb-install.sh`](test-deb-install.sh) | Clean `ubuntu:24.04` container, **needs Docker**. **In CI** (`make test-e2e`). | `apt install` of the built `.deb`, `rigforge --version`, `doctor`, an upgrade to the next version, then remove keeps config and state and purge leaves no residue. | `bash tests/test-deb-install.sh` | | **APT feed** | [`test-apt-feed.sh`](test-apt-feed.sh) | Ubuntu 24.04 runner, **root**, no Docker (needs `apt-utils`). **In CI.** (`ci.yml` job) | [`../scripts/build-apt.sh`](../scripts/build-apt.sh) end to end with throwaway keys: refusal of missing/bad fingerprints and keyrings without the secret key; a signed flat feed that `apt-get update` and `download` accept from `file://`; refusal of tampered `Release`/`InRelease`/`.deb` and of a feed signed by another key. | CI only (`sudo bash tests/test-apt-feed.sh`) | | **Release smoke (quick)** | [`smoke.sh`](smoke.sh) | Real Linux rig, **manual**. Not in CI. | The compiled binary actually starts and hashes (`xmrig --bench`, fully offline). Fast pre-tag confidence that the worker we ship runs. | `make smoke` | | **Release e2e (full)** | [`e2e-real.sh`](e2e-real.sh) | Real Linux rig, **manual, root**. Not in CI. | The real thing end to end: build + tune + kernel tuning + service + a real hash, the writable control path (#236) against real systemd (`control` phase), the remote-upgrade chain with real git as the root oneshot (`upgrade` phase, #322), then a clean uninstall. **The release gate.** | `make e2e-real` (see [`RELEASING.md`](../RELEASING.md)) | diff --git a/tests/test-build-deb.sh b/tests/test-build-deb.sh index 5a180a6a..59c7232b 100644 --- a/tests/test-build-deb.sh +++ b/tests/test-build-deb.sh @@ -1,154 +1,70 @@ #!/usr/bin/env bash set -euo pipefail ROOT=$(cd "$(dirname "$0")/.." && pwd) -cd "$ROOT" -if [[ $(uname -s) != Linux ]]; then - printf 'SKIP: build-deb needs Linux (dpkg-deb)\n' +if [[ $(uname -s) != Linux ]] || ! command -v dpkg-deb >/dev/null 2>&1; then + printf 'SKIP: build-deb needs Linux with dpkg-deb\n' exit 0 fi -for cmd in dpkg-deb dpkg; do - if ! command -v "$cmd" >/dev/null 2>&1; then - printf 'SKIP: missing %s\n' "$cmd" - exit 0 - fi -done -ok() { printf 'ok: %s\n' "$1"; } -fail() { - printf 'FAIL: %s\n' "$1" >&2 - exit 1 -} -assert_fails() { - local desc=$1 - shift - if "$@" >/dev/null 2>&1; then - printf 'FAIL: %s (unexpectedly succeeded)\n' "$desc" >&2 - exit 1 - fi - ok "$desc" -} -assert_ok() { - local desc=$1 - shift - if ! "$@" >/dev/null 2>&1; then - printf 'FAIL: %s\n' "$desc" >&2 - exit 1 - fi - ok "$desc" -} -assert_eq() { - if [ "$1" != "$2" ]; then - printf 'FAIL: %s (expected [%s], got [%s])\n' "$3" "$2" "$1" >&2 - exit 1 +fail=0 +check() { + if [ "$2" -eq 0 ]; then printf 'ok: %s\n' "$1"; else + printf 'FAIL: %s\n' "$1" >&2 + fail=1 fi - ok "$3" -} -assert_contains() { - local desc=$1 haystack=$2 needle=$3 - case "$haystack" in - *"$needle"*) ok "$desc" ;; - *) - printf 'FAIL: %s (%s not found)\n' "$desc" "$needle" >&2 - exit 1 - ;; - esac -} -assert_field() { - local deb=$1 field=$2 want=$3 got - got=$(dpkg-deb -f "$deb" "$field" 2>/dev/null) || fail "dpkg-deb -f $field failed" - assert_eq "$got" "$want" "control $field == $want" } WORK=$(mktemp -d) trap 'rm -rf "$WORK"' EXIT -mkdir -p "$WORK" - -assert_fails "no args exits non-zero" "$ROOT/scripts/build-deb.sh" -assert_fails "one arg exits non-zero" "$ROOT/scripts/build-deb.sh" "$WORK/missing.tar.gz" "1.0.0" "$ROOT/packaging/apt/fingerprint" - -assert_fails "missing archive exits non-zero" "$ROOT/scripts/build-deb.sh" "$WORK/nope.tar.gz" "1.0.0" "$ROOT/packaging/apt/fingerprint" - -mkdir -p "$WORK/archive/util" "$WORK/archive/systemd" "$WORK/archive/docs" "$WORK/archive/images" -cp "$ROOT/rigforge.sh" "$WORK/archive/" -cp -R "$ROOT/util/"* "$WORK/archive/util/" -cp -R "$ROOT/systemd/"* "$WORK/archive/systemd/" -cp "$ROOT/config.minimal.json" "$WORK/archive/" -cp "$ROOT/config.reference.json" "$WORK/archive/" -cp "$ROOT/README.md" "$WORK/archive/" -cp -R "$ROOT/docs/"* "$WORK/archive/docs/" -cp -R "$ROOT/images/"* "$WORK/archive/images/" -cp "$ROOT/LICENSE" "$WORK/archive/" -cp "$ROOT/VERSION" "$WORK/archive/" -tar -czf "$WORK/bundle.tar.gz" -C "$WORK" archive -assert_fails "missing fingerprint file exits non-zero" "$ROOT/scripts/build-deb.sh" "$WORK/bundle.tar.gz" "1.0.0" "$WORK/nope" - -printf '0.0.0-mismatch\n' >"$WORK/archive/VERSION" -assert_fails "VERSION mismatch exits non-zero" "$ROOT/scripts/build-deb.sh" "$WORK/bundle.tar.gz" "1.0.0" "$ROOT/packaging/apt/fingerprint" -printf '%s\n' "$(cat "$ROOT/VERSION")" >"$WORK/archive/VERSION" -tar -czf "$WORK/bundle.tar.gz" -C "$WORK" archive - -VER="$(tr -d '[:space:]' <"$ROOT/VERSION")" -(cd "$WORK" && bash "$ROOT/scripts/build-deb.sh" "$WORK/bundle.tar.gz" "v$VER" "$ROOT/packaging/apt/fingerprint" >/dev/null) -DEB="$WORK/rigforge_${VER}_all.deb" -assert_ok "build-deb produces a .deb" test -f "$DEB" - -assert_field "$DEB" Package rigforge -assert_field "$DEB" Version "$VER" -assert_field "$DEB" Architecture all - -CONTENT_DIR=$(mktemp -d) -trap 'rm -rf "$WORK" "$CONTENT_DIR"' EXIT -dpkg-deb --raw-extract "$DEB" "$CONTENT_DIR" - -assert_eq "$([ -f "$CONTENT_DIR/usr/lib/rigforge/rigforge.sh" ] && echo yes || echo no)" "yes" "rigforge.sh in /usr/lib/rigforge/" -assert_eq "$([ -d "$CONTENT_DIR/usr/lib/rigforge/util" ] && echo yes || echo no)" "yes" "util/ in /usr/lib/rigforge/" -assert_eq "$([ -d "$CONTENT_DIR/usr/lib/rigforge/systemd" ] && echo yes || echo no)" "yes" "systemd/ in /usr/lib/rigforge/" -assert_eq "$([ -f "$CONTENT_DIR/usr/bin/rigforge" ] && echo yes || echo no)" "yes" "/usr/bin/rigforge wrapper" -assert_eq "$([ -f "$CONTENT_DIR/etc/rigforge/config.json" ] && echo yes || echo no)" "yes" "config.json as conffile" -assert_eq "$([ -d "$CONTENT_DIR/var/lib/rigforge" ] && echo yes || echo no)" "yes" "state dir /var/lib/rigforge" -assert_eq "$([ -f "$CONTENT_DIR/var/lib/rigforge/.rigforge-package" ] && echo yes || echo no)" "yes" "apt marker" -assert_eq "$(tr -d '[:space:]' <"$CONTENT_DIR/var/lib/rigforge/.rigforge-package")" "apt" "marker value is apt" - -assert_contains "wrapper exports RIGFORGE_LIB" "$(cat "$CONTENT_DIR/usr/bin/rigforge")" "RIGFORGE_LIB" -assert_contains "wrapper exports RIGFORGE_STATE" "$(cat "$CONTENT_DIR/usr/bin/rigforge")" "RIGFORGE_STATE" - -assert_eq "$([ -f "$CONTENT_DIR/DEBIAN/postinst" ] && echo yes || echo no)" "yes" "postinst present" -assert_eq "$([ -f "$CONTENT_DIR/DEBIAN/postrm" ] && echo yes || echo no)" "yes" "postrm present" -assert_eq "$([ -f "$CONTENT_DIR/DEBIAN/conffiles" ] && echo yes || echo no)" "yes" "conffiles present" - -POSTINST="$(cat "$CONTENT_DIR/DEBIAN/postinst")" -assert_contains "postinst runs daemon-reload" "$POSTINST" "daemon-reload" -assert_contains "postinst creates state dir" "$POSTINST" "/var/lib/rigforge" - -POSTRM="$(cat "$CONTENT_DIR/DEBIAN/postrm")" -assert_contains "postrm remove stops units" "$POSTRM" "systemctl stop" -assert_contains "postrm remove disables units" "$POSTRM" "systemctl disable" -assert_contains "postrm purge removes state" "$POSTRM" "/var/lib/rigforge" -assert_contains "postrm purge removes config" "$POSTRM" "/etc/rigforge" - -CONFFILES="$(cat "$CONTENT_DIR/DEBIAN/conffiles")" -assert_contains "conffiles lists config.json" "$CONFFILES" "/etc/rigforge/config.json" +VER=$(tr -d '[:space:]' <"$ROOT/VERSION") + +bundle() { + local out=$1 ver=$2 stage="$WORK/rigforge-v$2" + rm -rf "$stage" + mkdir -p "$stage" + (cd "$ROOT" && cp -a rigforge.sh util systemd config.minimal.json config.reference.json README.md docs images LICENSE VERSION "$stage/") + printf '%s\n' "$ver" >"$stage/VERSION" + tar -czf "$out" -C "$WORK" "rigforge-v$ver" +} -for f in "$CONTENT_DIR/usr/lib/rigforge/"* "$CONTENT_DIR/DEBIAN/"*; do - [ -f "$f" ] || continue - case "$(cat "$f")" in - *"pithead-developer"*) fail "internal repo reference found: $f" ;; - esac +bundle "$WORK/bundle.tar.gz" "$VER" +B="$ROOT/scripts/build-deb.sh" +check "two arguments are required" "$(bash "$B" "$WORK/bundle.tar.gz" >/dev/null 2>&1 && echo 1 || echo 0)" +check "missing archive fails" "$(bash "$B" "$WORK/nope.tar.gz" "$VER" >/dev/null 2>&1 && echo 1 || echo 0)" +check "a non-release version fails" "$(bash "$B" "$WORK/bundle.tar.gz" "v$VER-rc1" >/dev/null 2>&1 && echo 1 || echo 0)" +check "VERSION disagreeing with the tag fails" "$(cd "$WORK" && bash "$B" "$WORK/bundle.tar.gz" 0.0.1 >/dev/null 2>&1 && echo 1 || echo 0)" + +mkdir -p "$WORK/a" "$WORK/b" +(cd "$WORK/a" && bash "$B" "$WORK/bundle.tar.gz" "v$VER" >/dev/null) +sleep 1 +(cd "$WORK/b" && bash "$B" "$WORK/bundle.tar.gz" "v$VER" >/dev/null) +DEB="$WORK/a/rigforge_${VER}_all.deb" +check "builds rigforge__all.deb" "$([ -f "$DEB" ] && echo 0 || echo 1)" +check "two builds of one bundle are byte-identical" "$(cmp -s "$DEB" "$WORK/b/rigforge_${VER}_all.deb" && echo 0 || echo 1)" + +check "control Package is rigforge" "$([ "$(dpkg-deb -f "$DEB" Package)" = rigforge ] && echo 0 || echo 1)" +check "control Version is $VER" "$([ "$(dpkg-deb -f "$DEB" Version)" = "$VER" ] && echo 0 || echo 1)" +check "control Architecture is all" "$([ "$(dpkg-deb -f "$DEB" Architecture)" = all ] && echo 0 || echo 1)" +DEPENDS=$(dpkg-deb -f "$DEB" Depends) +for p in bash jq curl nftables git build-essential cmake libuv1-dev libssl-dev libhwloc-dev gettext-base python3 msr-tools; do + check "Depends lists $p" "$(sed 's/[,|]/\n/g; s/ //g' <<<"$DEPENDS" | grep -qx "$p" && echo 0 || echo 1)" done -ok "no internal test-runner repo references" - -if command -v apt-ftparchive >/dev/null 2>&1 && command -v gpg >/dev/null 2>&1; then - apt_out="$WORK/apt-feed" - mkdir -p "$apt_out" - FINGERPRINT="$(tr -d '[:space:]' <"$ROOT/packaging/apt/fingerprint")" - if [ "$FINGERPRINT" != "pending-key-generation" ] && [ -n "$FINGERPRINT" ]; then - GNUPGHOME="${GNUPGHOME:-}" apt-ftparchive packages "$apt_out" >/dev/null 2>&1 || true - fi - pkg=$(dpkg-deb -f "$DEB" Package) - ver=$(dpkg-deb -f "$DEB" Version) - assert_eq "$pkg" "rigforge" "build-apt: Package field matches" - assert_eq "$ver" "$VER" "build-apt: Version field matches" -fi +check "Maintainer has the Name form" "$(dpkg-deb -f "$DEB" Maintainer | grep -qE '^[^<]+ <[^>]+@[^>]+>$' && echo 0 || echo 1)" + +X="$WORK/x" +dpkg-deb --raw-extract "$DEB" "$X" +L="$X/usr/lib/rigforge" +check "code tree under /usr/lib/rigforge" "$([ -f "$L/rigforge.sh" ] && [ -d "$L/util" ] && [ -d "$L/systemd" ] && echo 0 || echo 1)" +check "/usr/bin/rigforge resolves to the code tree" "$([ "$(readlink "$X/usr/bin/rigforge")" = ../lib/rigforge/rigforge.sh ] && echo 0 || echo 1)" +check "state dir /var/lib/rigforge" "$([ -d "$X/var/lib/rigforge" ] && echo 0 || echo 1)" +check "package marker is where util/package-mode.sh reads it" "$(SCRIPT_DIR="$L" bash -c 'source "$SCRIPT_DIR/util/package-mode.sh"; [ "$(_package_channel)" = apt ]' && echo 0 || echo 1)" +check "ships the upgrade unit" "$(cmp -s "$X/usr/lib/systemd/system/rigforge-upgrade.service" "$ROOT/packaging/debian/rigforge-upgrade.service" && echo 0 || echo 1)" +for s in postinst prerm postrm; do + check "DEBIAN/$s is packaging/debian/$s" "$(cmp -s "$X/DEBIAN/$s" "$ROOT/packaging/debian/$s" && [ -x "$X/DEBIAN/$s" ] && echo 0 || echo 1)" +done +check "ships no apt keyring" "$([ ! -e "$X/etc/apt" ] && echo 0 || echo 1)" +check "no internal repository references" "$(grep -rqE 'pithead-developer|bench-ci|ai-devkit' "$X" && echo 1 || echo 0)" -printf '\nbuild-deb: tests passed\n' 2>/dev/null || true +[ "$fail" -eq 0 ] && printf 'build-deb: all checks passed\n' +exit "$fail" diff --git a/tests/test-deb-install.sh b/tests/test-deb-install.sh new file mode 100755 index 00000000..65f2ffcf --- /dev/null +++ b/tests/test-deb-install.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash +set -euo pipefail +ROOT=$(cd "$(dirname "$0")/.." && pwd) +IMAGE=ubuntu:24.04 + +guest() { + local a=$1 b=$2 out rc + export DEBIAN_FRONTEND=noninteractive + apt-get update -qq + apt-get install -y -qq "/debs/rigforge_${a}_all.deb" >/dev/null + [ "$(rigforge --version)" = "RigForge $a" ] || { + echo "FAIL: rigforge --version after install" + return 1 + } + echo "ok: apt install ./rigforge_${a}_all.deb, rigforge --version is $a" + [ "$(cat /usr/lib/rigforge/.rigforge-package)" = apt ] || { + echo "FAIL: package marker" + return 1 + } + echo "ok: package marker reads apt" + set +e + out=$(rigforge doctor 2>&1) + rc=$? + set -e + printf '%s\n' "$out" | sed 's/^/ doctor| /' + case "$rc" in + 0 | 1) ;; + *) + echo "FAIL: doctor exited $rc" + return 1 + ;; + esac + grep -q "Checking the worker" <<<"$out" || { + echo "FAIL: doctor did not run its checks" + return 1 + } + echo "ok: doctor runs its checks from the packaged tree (exit $rc: no miner is provisioned)" + echo '{}' >/usr/lib/rigforge/config.json + echo kept >/var/lib/rigforge/state-probe + apt-get install -y -qq "/debs/rigforge_${b}_all.deb" >/dev/null + [ "$(rigforge --version)" = "RigForge $b" ] || { + echo "FAIL: rigforge --version after upgrade" + return 1 + } + [ -f /usr/lib/rigforge/config.json ] && [ -f /var/lib/rigforge/state-probe ] || { + echo "FAIL: upgrade lost config or state" + return 1 + } + echo "ok: upgrade to $b keeps config and state" + apt-get remove -y -qq rigforge >/dev/null + [ ! -e /usr/bin/rigforge ] && [ ! -e /usr/lib/rigforge/rigforge.sh ] || { + echo "FAIL: remove left the code" + return 1 + } + [ -f /usr/lib/rigforge/config.json ] && [ -f /var/lib/rigforge/state-probe ] || { + echo "FAIL: remove dropped config or state" + return 1 + } + echo "ok: remove deletes the code and keeps config and state" + apt-get purge -y -qq rigforge >/dev/null + [ ! -e /usr/lib/rigforge ] && [ ! -e /var/lib/rigforge ] && [ ! -e /etc/rigforge ] || { + echo "FAIL: purge left residue" + return 1 + } + if dpkg -s rigforge >/dev/null 2>&1; then + echo "FAIL: dpkg still knows rigforge after purge" + return 1 + fi + echo "ok: purge leaves no rigforge residue" +} + +if [ "${1:-}" = --guest ]; then + guest "$2" "$3" + exit +fi + +if ! command -v docker >/dev/null 2>&1 || ! docker info >/dev/null 2>&1 || ! command -v dpkg-deb >/dev/null 2>&1; then + if [ -n "${CI:-}" ]; then + echo "FAIL: CI needs docker and dpkg-deb for the package install test" + exit 1 + fi + echo "SKIP: package install test needs docker and dpkg-deb" + exit 0 +fi + +WORK=$(mktemp -d) +trap 'rm -rf "$WORK"' EXIT +A=$(tr -d '[:space:]' <"$ROOT/VERSION") +B="${A%.*}.$((${A##*.} + 1))" +mkdir -p "$WORK/debs" +for v in "$A" "$B"; do + stage="$WORK/rigforge-v$v" + mkdir -p "$stage" + (cd "$ROOT" && cp -a rigforge.sh util systemd config.minimal.json config.reference.json README.md docs images LICENSE VERSION "$stage/") + printf '%s\n' "$v" >"$stage/VERSION" + tar -czf "$WORK/rigforge-v$v.tar.gz" -C "$WORK" "rigforge-v$v" + (cd "$WORK/debs" && bash "$ROOT/scripts/build-deb.sh" "$WORK/rigforge-v$v.tar.gz" "v$v" >/dev/null) +done +docker run --rm -v "$WORK/debs:/debs:ro" -v "$ROOT/tests/test-deb-install.sh:/t.sh:ro" "$IMAGE" bash /t.sh --guest "$A" "$B" +echo "deb install: all checks passed" diff --git a/tests/test-package-upgrade.sh b/tests/test-package-upgrade.sh index 02bd929d..fd87a13f 100644 --- a/tests/test-package-upgrade.sh +++ b/tests/test-package-upgrade.sh @@ -45,16 +45,19 @@ postinst() { } postinst first "" 2.0.0 y -check "first install is inert" "$([ ! -e "$D/first/var/lib/rigforge/upgrade-pending" ] && [ ! -s "$CALLS" ] && echo 0 || echo 1)" +check "first install queues nothing" "$([ ! -e "$D/first/var/lib/rigforge/upgrade-pending" ] && ! grep -q start "$CALLS" && echo 0 || echo 1)" +check "first install creates the state dir" "$([ -d "$D/first/var/lib/rigforge" ] && echo 0 || echo 1)" +check "first install reloads systemd only" "$([ "$(cat "$CALLS")" = 'systemctl daemon-reload' ] && echo 0 || echo 1)" +check "first install prints the first-run step" "$(grep -q 'sudo rigforge setup' "$D/first/out" && echo 0 || echo 1)" postinst noconf 1.0.0 2.0.0 n -check "upgrade without a configured miner is inert" "$([ ! -e "$D/noconf/var/lib/rigforge/upgrade-pending" ] && [ ! -s "$CALLS" ] && echo 0 || echo 1)" +check "upgrade without a configured miner is inert" "$([ ! -e "$D/noconf/var/lib/rigforge/upgrade-pending" ] && ! grep -q start "$CALLS" && ! grep -q 'sudo rigforge setup' "$D/noconf/out" && echo 0 || echo 1)" postinst same 2.0.0 2.0.0 y -check "same version is inert" "$([ ! -e "$D/same/var/lib/rigforge/upgrade-pending" ] && [ ! -s "$CALLS" ] && echo 0 || echo 1)" +check "same version is inert" "$([ ! -e "$D/same/var/lib/rigforge/upgrade-pending" ] && ! grep -q start "$CALLS" && ! grep -q 'sudo rigforge setup' "$D/same/out" && echo 0 || echo 1)" postinst older 2.0.0 1.9.0 y -check "downgrade is inert" "$([ ! -e "$D/older/var/lib/rigforge/upgrade-pending" ] && [ ! -s "$CALLS" ] && echo 0 || echo 1)" +check "downgrade is inert" "$([ ! -e "$D/older/var/lib/rigforge/upgrade-pending" ] && ! grep -q start "$CALLS" && ! grep -q 'sudo rigforge setup' "$D/older/out" && echo 0 || echo 1)" postinst queue 1.9.0 2.0.0 y check "upgrade writes the marker" "$([ "$(cat "$D/queue/var/lib/rigforge/upgrade-pending")" = 2.0.0 ] && echo 0 || echo 1)" @@ -71,6 +74,35 @@ rc=$? set -e check "systemctl failure never fails dpkg" "$([ "$rc" -eq 0 ] && grep -q 'sudo rigforge upgrade' "$D/sysfail/out" && echo 0 || echo 1)" +maint() { + local r="$D/$1" script=$2 arg=$3 + mkdir -p "$r/run/systemd/system" "$r/etc/rigforge" "$r/var/lib/rigforge" "$r/usr/lib/rigforge" + echo '{}' >"$r/etc/rigforge/config.json" + echo '{}' >"$r/usr/lib/rigforge/config.json" + : >"$CALLS" + RIGFORGE_PKG_ROOT="$r" PATH="$STUBS:$PATH" sh "$ROOT/packaging/debian/$script" "$arg" >"$r/out" 2>&1 +} +for arg in upgrade failed-upgrade abort-install abort-upgrade disappear remove purge deconfigure; do + for script in prerm postrm; do + set +e + maint "m-$script-$arg" "$script" "$arg" + rc=$? + set -e + check "$script $arg exits 0" "$rc" + done +done +maint prerm-remove prerm remove +for u in xmrig.service rigforge-upgrade.service rigforge-watchdog.timer rigforge-autotune.timer rigforge-control.service rigforge-api.service; do + check "prerm remove stops and disables $u" "$(grep -qx "systemctl disable --now $u" "$CALLS" && echo 0 || echo 1)" +done +maint prerm-upgrade prerm upgrade +check "prerm upgrade leaves the miner running" "$([ ! -s "$CALLS" ] && echo 0 || echo 1)" +maint postrm-remove postrm remove +check "remove keeps config and state" "$([ -f "$D/postrm-remove/etc/rigforge/config.json" ] && [ -f "$D/postrm-remove/usr/lib/rigforge/config.json" ] && [ -d "$D/postrm-remove/var/lib/rigforge" ] && echo 0 || echo 1)" +maint postrm-purge postrm purge +check "purge removes config, state and the tree's leftovers" "$([ ! -e "$D/postrm-purge/etc/rigforge" ] && [ ! -e "$D/postrm-purge/var/lib/rigforge" ] && [ ! -e "$D/postrm-purge/usr/lib/rigforge" ] && echo 0 || echo 1)" +check "purge never touches tuning" "$(! grep -rqE 'grub|sysctl|hugepages|wrmsr|modprobe' "$ROOT/packaging/debian/postrm" "$ROOT/packaging/debian/prerm" && echo 0 || echo 1)" + STATE="$D/state" export RIGFORGE_PKG_STATE="$STATE" pkg_run() { From 151d3e8159e5d3e31f6176824af0a81a2d631750 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:00:27 -0600 Subject: [PATCH 11/26] package: fail removal when a unit cannot stop, purge rendered units, pin the build epoch to the tag Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 2 +- docs/getting-started.md | 2 +- packaging/debian/postrm | 3 +++ packaging/debian/prerm | 3 ++- tests/README.md | 2 +- tests/test-deb-install.sh | 8 +++++--- tests/test-package-upgrade.sh | 22 +++++++++++++++++----- 7 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dac7785f..51b18798 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,7 +62,7 @@ jobs: - name: Build the .deb package run: | set -euo pipefail - deb=$(bash scripts/build-deb.sh "rigforge-$TAG.tar.gz" "$TAG") + deb=$(SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) bash scripts/build-deb.sh "rigforge-$TAG.tar.gz" "$TAG") sha256sum "$deb" >> SHA256SUMS echo "--- SHA256SUMS (with .deb) ---"; cat SHA256SUMS diff --git a/docs/getting-started.md b/docs/getting-started.md index fe829ff4..f031bee3 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -55,7 +55,7 @@ safe place for code that root-run units execute, so prefer the git route below o The apt steps (signing key, source entry, `apt install rigforge`) are in the [README](../README.md), under **Prefer `apt`?**. Installing changes nothing on the host: the package puts the -code in `/usr/lib/rigforge`, links `/usr/bin/rigforge` to it and adds the one-shot upgrade unit. +release bundle in `/usr/lib/rigforge` (without the developer notes under `docs/dev`), links `/usr/bin/rigforge` to it and adds the one-shot upgrade unit. Provision with `sudo rigforge setup`. Until `RIGFORGE_STATE` lands (#780), `setup` keeps `config.json` and the XMRig build inside `/usr/lib/rigforge`; `apt upgrade` and `apt remove` keep them, and `apt purge` deletes them with `/var/lib/rigforge`. For the same reason the diff --git a/packaging/debian/postrm b/packaging/debian/postrm index abb4787c..c026fb84 100755 --- a/packaging/debian/postrm +++ b/packaging/debian/postrm @@ -5,6 +5,9 @@ ROOT=${RIGFORGE_PKG_ROOT:-} case "$1" in purge) + for unit in "$ROOT"/etc/systemd/system/xmrig.service "$ROOT"/etc/systemd/system/rigforge-*; do + [ -f "$unit" ] && grep -qs /usr/lib/rigforge "$unit" && rm -f "$unit" + done rm -rf "$ROOT/etc/rigforge" "$ROOT/var/lib/rigforge" "$ROOT/usr/lib/rigforge" if [ -d "$ROOT/run/systemd/system" ]; then systemctl daemon-reload || true; fi ;; diff --git a/packaging/debian/prerm b/packaging/debian/prerm index 1a176226..d95daf16 100755 --- a/packaging/debian/prerm +++ b/packaging/debian/prerm @@ -8,7 +8,8 @@ case "$1" in remove | deconfigure) if [ -d "$ROOT/run/systemd/system" ]; then for unit in $UNITS; do - systemctl disable --now "$unit" >/dev/null 2>&1 || true + systemctl cat "$unit" >/dev/null 2>&1 || continue + systemctl disable --now "$unit" done fi ;; diff --git a/tests/README.md b/tests/README.md index 172bd045..30d1199e 100644 --- a/tests/README.md +++ b/tests/README.md @@ -52,7 +52,7 @@ CI median/p90, failures and occupied hours; missing evidence leaves rollout acce | **Linux container e2e** | [`e2e/linux.sh`](e2e/linux.sh) → [`e2e/in-container.sh`](e2e/in-container.sh) | Disposable Ubuntu container, **needs Docker**. **In CI.** | The genuine Linux deploy path against a real (throwaway) `/etc` with real GNU tools (`sed -i`, `tee`, `envsubst`) + idempotency on re-run. Only the heavy/privileged bits (compile, package install, `systemctl`/`mount`) are stubbed. A second pass re-runs the container with `RIGFORGE_APPLIANCE=1` (#348) and proves the appliance contracts on that real `/etc`: units land in `/run/systemd/system`, no package installs, no fstab/limits.conf/logrotate writes, every enable carries `--runtime`. A third script, [`e2e/isolation.sh`](e2e/isolation.sh) (#668), puts the rig on a Docker `--internal` network whose only reachable peer is a SOCKS5 proxy fronting a stand-in GitHub (a TLS git smart-HTTP server plus the releases API). With `tor_socks5` set it runs `upgrade --check`, `setup`, a local `upgrade` with an XMRig pin change and the `control-upgrade` oneshot in its own empty environment, and proves from the proxy's log that every connection named a hostname. It also proves the block is real (a direct connection and a keyless `upgrade --check` fail), that an unreachable proxy fails closed without reaching the upstream, and that the live build survives the failed upgrade. | `make test-e2e` | | **Native macOS e2e** | [`e2e/macos.sh`](e2e/macos.sh) | A real Mac, **manual, local only. Not in CI** (macOS is best effort). | The macOS deploy path with genuine BSD tools the Linux CI can only stub: BSD `sed`, the macOS config profile, `mac_*` process control (real `nohup` + PID file), the launchd login agent, `backup`/`restore`. | `make test-e2e-macos` | | **Coverage gate** | [`coverage.sh`](coverage.sh) | kcov in **Docker**. **In CI.** | Line coverage of `rigforge.sh` and its shell helpers by running `run.sh` under kcov; enforces the committed floor ([`coverage-floor.txt`](coverage-floor.txt)) plus a patch-coverage gate (diff-cover) on changed lines. | `make coverage` | -| **Package upgrade** | [`test-package-upgrade.sh`](test-package-upgrade.sh) | Any host, no Docker. **In CI** (`make test-suite`). | [`../packaging/debian/postinst`](../packaging/debian/postinst) creates the state dir, reloads systemd and prints the first-run step on a first install, and queues only on a greater version with a config, never failing dpkg; `prerm` stops and disables every unit on remove and `postrm` accepts every dpkg action and purges config and state; `package-upgrade` re-renders units and clears the marker on success, and on failure keeps it, records it for status/doctor and does not restart. | `bash tests/test-package-upgrade.sh` | +| **Package upgrade** | [`test-package-upgrade.sh`](test-package-upgrade.sh) | Any host, no Docker. **In CI** (`make test-suite`). | [`../packaging/debian/postinst`](../packaging/debian/postinst) creates the state dir, reloads systemd and prints the first-run step on a first install, and queues only on a greater version with a config, never failing dpkg; `prerm` stops and disables every unit on remove and `postrm` accepts every dpkg action and on purge deletes config, state and the units setup rendered for the package tree; `package-upgrade` re-renders units and clears the marker on success, and on failure keeps it, records it for status/doctor and does not restart. | `bash tests/test-package-upgrade.sh` | | **Debian package build** | [`test-build-deb.sh`](test-build-deb.sh) | Linux with `dpkg-deb`, no Docker. **In CI** (`make test-suite`). | [`../scripts/build-deb.sh`](../scripts/build-deb.sh) builds a byte-reproducible `.deb` from the release bundle with the marker where `util/package-mode.sh` reads it, the `packaging/debian` maintainer scripts and upgrade unit, the full `Depends`, and no apt keyring. | `bash tests/test-build-deb.sh` | | **Debian package install** | [`test-deb-install.sh`](test-deb-install.sh) | Clean `ubuntu:24.04` container, **needs Docker**. **In CI** (`make test-e2e`). | `apt install` of the built `.deb`, `rigforge --version`, `doctor`, an upgrade to the next version, then remove keeps config and state and purge leaves no residue. | `bash tests/test-deb-install.sh` | | **APT feed** | [`test-apt-feed.sh`](test-apt-feed.sh) | Ubuntu 24.04 runner, **root**, no Docker (needs `apt-utils`). **In CI.** (`ci.yml` job) | [`../scripts/build-apt.sh`](../scripts/build-apt.sh) end to end with throwaway keys: refusal of missing/bad fingerprints and keyrings without the secret key; a signed flat feed that `apt-get update` and `download` accept from `file://`; refusal of tampered `Release`/`InRelease`/`.deb` and of a feed signed by another key. | CI only (`sudo bash tests/test-apt-feed.sh`) | diff --git a/tests/test-deb-install.sh b/tests/test-deb-install.sh index 65f2ffcf..5aa1d856 100755 --- a/tests/test-deb-install.sh +++ b/tests/test-deb-install.sh @@ -37,6 +37,8 @@ guest() { echo "ok: doctor runs its checks from the packaged tree (exit $rc: no miner is provisioned)" echo '{}' >/usr/lib/rigforge/config.json echo kept >/var/lib/rigforge/state-probe + mkdir -p /etc/systemd/system + printf '[Service]\nExecStart=/usr/lib/rigforge/xmrig/xmrig\n' >/etc/systemd/system/xmrig.service apt-get install -y -qq "/debs/rigforge_${b}_all.deb" >/dev/null [ "$(rigforge --version)" = "RigForge $b" ] || { echo "FAIL: rigforge --version after upgrade" @@ -52,13 +54,13 @@ guest() { echo "FAIL: remove left the code" return 1 } - [ -f /usr/lib/rigforge/config.json ] && [ -f /var/lib/rigforge/state-probe ] || { - echo "FAIL: remove dropped config or state" + [ -f /usr/lib/rigforge/config.json ] && [ -f /var/lib/rigforge/state-probe ] && [ -f /etc/systemd/system/xmrig.service ] || { + echo "FAIL: remove dropped config, state or the rendered unit" return 1 } echo "ok: remove deletes the code and keeps config and state" apt-get purge -y -qq rigforge >/dev/null - [ ! -e /usr/lib/rigforge ] && [ ! -e /var/lib/rigforge ] && [ ! -e /etc/rigforge ] || { + [ ! -e /usr/lib/rigforge ] && [ ! -e /var/lib/rigforge ] && [ ! -e /etc/rigforge ] && [ ! -e /etc/systemd/system/xmrig.service ] || { echo "FAIL: purge left residue" return 1 } diff --git a/tests/test-package-upgrade.sh b/tests/test-package-upgrade.sh index fd87a13f..064995ed 100644 --- a/tests/test-package-upgrade.sh +++ b/tests/test-package-upgrade.sh @@ -22,7 +22,7 @@ STUB cat >"$STUBS/systemctl" <<'STUB' #!/usr/bin/env bash echo "systemctl $*" >>"$CALLS" -[ -z "${SYSTEMCTL_FAIL:-}" ] +[ -z "${SYSTEMCTL_FAIL:-}" ] || [ "$1" = cat ] STUB chmod +x "$STUBS"/* export CALLS @@ -45,19 +45,19 @@ postinst() { } postinst first "" 2.0.0 y -check "first install queues nothing" "$([ ! -e "$D/first/var/lib/rigforge/upgrade-pending" ] && ! grep -q start "$CALLS" && echo 0 || echo 1)" +check "first install queues nothing" "$([ ! -e "$D/first/var/lib/rigforge/upgrade-pending" ] && echo 0 || echo 1)" check "first install creates the state dir" "$([ -d "$D/first/var/lib/rigforge" ] && echo 0 || echo 1)" check "first install reloads systemd only" "$([ "$(cat "$CALLS")" = 'systemctl daemon-reload' ] && echo 0 || echo 1)" check "first install prints the first-run step" "$(grep -q 'sudo rigforge setup' "$D/first/out" && echo 0 || echo 1)" postinst noconf 1.0.0 2.0.0 n -check "upgrade without a configured miner is inert" "$([ ! -e "$D/noconf/var/lib/rigforge/upgrade-pending" ] && ! grep -q start "$CALLS" && ! grep -q 'sudo rigforge setup' "$D/noconf/out" && echo 0 || echo 1)" +check "upgrade without a configured miner is inert" "$([ ! -e "$D/noconf/var/lib/rigforge/upgrade-pending" ] && [ "$(cat "$CALLS")" = 'systemctl daemon-reload' ] && ! grep -q 'sudo rigforge setup' "$D/noconf/out" && echo 0 || echo 1)" postinst same 2.0.0 2.0.0 y -check "same version is inert" "$([ ! -e "$D/same/var/lib/rigforge/upgrade-pending" ] && ! grep -q start "$CALLS" && ! grep -q 'sudo rigforge setup' "$D/same/out" && echo 0 || echo 1)" +check "same version is inert" "$([ ! -e "$D/same/var/lib/rigforge/upgrade-pending" ] && [ "$(cat "$CALLS")" = 'systemctl daemon-reload' ] && ! grep -q 'sudo rigforge setup' "$D/same/out" && echo 0 || echo 1)" postinst older 2.0.0 1.9.0 y -check "downgrade is inert" "$([ ! -e "$D/older/var/lib/rigforge/upgrade-pending" ] && ! grep -q start "$CALLS" && ! grep -q 'sudo rigforge setup' "$D/older/out" && echo 0 || echo 1)" +check "downgrade is inert" "$([ ! -e "$D/older/var/lib/rigforge/upgrade-pending" ] && [ "$(cat "$CALLS")" = 'systemctl daemon-reload' ] && ! grep -q 'sudo rigforge setup' "$D/older/out" && echo 0 || echo 1)" postinst queue 1.9.0 2.0.0 y check "upgrade writes the marker" "$([ "$(cat "$D/queue/var/lib/rigforge/upgrade-pending")" = 2.0.0 ] && echo 0 || echo 1)" @@ -79,6 +79,10 @@ maint() { mkdir -p "$r/run/systemd/system" "$r/etc/rigforge" "$r/var/lib/rigforge" "$r/usr/lib/rigforge" echo '{}' >"$r/etc/rigforge/config.json" echo '{}' >"$r/usr/lib/rigforge/config.json" + mkdir -p "$r/etc/systemd/system" + printf 'ExecStart=/usr/lib/rigforge/rigforge.sh watchdog\n' >"$r/etc/systemd/system/rigforge-watchdog.service" + printf 'ExecStart=/usr/lib/rigforge/xmrig/xmrig\n' >"$r/etc/systemd/system/xmrig.service" + printf 'ExecStart=/opt/other/xmrig\n' >"$r/etc/systemd/system/rigforge-other.service" : >"$CALLS" RIGFORGE_PKG_ROOT="$r" PATH="$STUBS:$PATH" sh "$ROOT/packaging/debian/$script" "$arg" >"$r/out" 2>&1 } @@ -101,6 +105,14 @@ maint postrm-remove postrm remove check "remove keeps config and state" "$([ -f "$D/postrm-remove/etc/rigforge/config.json" ] && [ -f "$D/postrm-remove/usr/lib/rigforge/config.json" ] && [ -d "$D/postrm-remove/var/lib/rigforge" ] && echo 0 || echo 1)" maint postrm-purge postrm purge check "purge removes config, state and the tree's leftovers" "$([ ! -e "$D/postrm-purge/etc/rigforge" ] && [ ! -e "$D/postrm-purge/var/lib/rigforge" ] && [ ! -e "$D/postrm-purge/usr/lib/rigforge" ] && echo 0 || echo 1)" +check "purge removes the units setup rendered for the package tree" "$([ ! -e "$D/postrm-purge/etc/systemd/system/xmrig.service" ] && [ ! -e "$D/postrm-purge/etc/systemd/system/rigforge-watchdog.service" ] && echo 0 || echo 1)" +check "purge keeps a unit that does not run the package tree" "$([ -f "$D/postrm-purge/etc/systemd/system/rigforge-other.service" ] && echo 0 || echo 1)" +check "remove keeps the rendered units" "$([ -f "$D/postrm-remove/etc/systemd/system/xmrig.service" ] && echo 0 || echo 1)" +set +e +SYSTEMCTL_FAIL=1 maint prerm-fail prerm remove +rc=$? +set -e +check "prerm remove fails when a unit cannot be stopped" "$([ "$rc" -ne 0 ] && echo 0 || echo 1)" check "purge never touches tuning" "$(! grep -rqE 'grub|sysctl|hugepages|wrmsr|modprobe' "$ROOT/packaging/debian/postrm" "$ROOT/packaging/debian/prerm" && echo 0 || echo 1)" STATE="$D/state" From f9747ff5904627aba9039ba66af7dc2a0736e749 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:01:32 -0600 Subject: [PATCH 12/26] package: strip group/world write and setid bits, purge only the listed rendered units Co-Authored-By: Claude Opus 5.5 --- packaging/debian/postrm | 6 ++++-- scripts/build-deb.sh | 1 + tests/test-build-deb.sh | 1 + tests/test-package-upgrade.sh | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packaging/debian/postrm b/packaging/debian/postrm index c026fb84..4dd6ae5b 100755 --- a/packaging/debian/postrm +++ b/packaging/debian/postrm @@ -2,11 +2,13 @@ set -e ROOT=${RIGFORGE_PKG_ROOT:-} +UNITS="xmrig.service rigforge-upgrade.service rigforge-autotune.timer rigforge-autotune.service rigforge-watchdog.timer rigforge-watchdog.service rigforge-api.service rigforge-api-refresh.timer rigforge-api-refresh.service rigforge-control.service rigforge-control-apply.path rigforge-control-apply.service rigforge-control-upgrade.path rigforge-control-upgrade.service" case "$1" in purge) - for unit in "$ROOT"/etc/systemd/system/xmrig.service "$ROOT"/etc/systemd/system/rigforge-*; do - [ -f "$unit" ] && grep -qs /usr/lib/rigforge "$unit" && rm -f "$unit" + for unit in $UNITS; do + f="$ROOT/etc/systemd/system/$unit" + if [ -f "$f" ] && grep -qs /usr/lib/rigforge "$f"; then rm -f "$f"; fi done rm -rf "$ROOT/etc/rigforge" "$ROOT/var/lib/rigforge" "$ROOT/usr/lib/rigforge" if [ -d "$ROOT/run/systemd/system" ]; then systemctl daemon-reload || true; fi diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh index 175930a2..54199834 100755 --- a/scripts/build-deb.sh +++ b/scripts/build-deb.sh @@ -43,6 +43,7 @@ ROOT="$STAGING/root" mkdir -p "$ROOT/usr/lib" "$ROOT/usr/bin" "$ROOT/usr/lib/systemd/system" "$ROOT/var/lib/rigforge" "$ROOT/DEBIAN" cp -a "$SRC" "$ROOT/usr/lib/rigforge" rm -rf "$ROOT/usr/lib/rigforge/docs/dev" +chmod -R go-w,ug-s "$ROOT/usr/lib/rigforge" printf 'apt\n' >"$ROOT/usr/lib/rigforge/.rigforge-package" ln -s ../lib/rigforge/rigforge.sh "$ROOT/usr/bin/rigforge" install -m 0644 "$PKG_SRC/rigforge-upgrade.service" "$ROOT/usr/lib/systemd/system/" diff --git a/tests/test-build-deb.sh b/tests/test-build-deb.sh index 59c7232b..c9fdff47 100644 --- a/tests/test-build-deb.sh +++ b/tests/test-build-deb.sh @@ -63,6 +63,7 @@ check "ships the upgrade unit" "$(cmp -s "$X/usr/lib/systemd/system/rigforge-upg for s in postinst prerm postrm; do check "DEBIAN/$s is packaging/debian/$s" "$(cmp -s "$X/DEBIAN/$s" "$ROOT/packaging/debian/$s" && [ -x "$X/DEBIAN/$s" ] && echo 0 || echo 1)" done +check "no group- or world-writable or setuid file in the package" "$([ -z "$(find "$X/usr" \( -perm -0020 -o -perm -0002 -o -perm -4000 -o -perm -2000 \) ! -type l)" ] && echo 0 || echo 1)" check "ships no apt keyring" "$([ ! -e "$X/etc/apt" ] && echo 0 || echo 1)" check "no internal repository references" "$(grep -rqE 'pithead-developer|bench-ci|ai-devkit' "$X" && echo 1 || echo 0)" diff --git a/tests/test-package-upgrade.sh b/tests/test-package-upgrade.sh index 064995ed..bc23751c 100644 --- a/tests/test-package-upgrade.sh +++ b/tests/test-package-upgrade.sh @@ -82,7 +82,7 @@ maint() { mkdir -p "$r/etc/systemd/system" printf 'ExecStart=/usr/lib/rigforge/rigforge.sh watchdog\n' >"$r/etc/systemd/system/rigforge-watchdog.service" printf 'ExecStart=/usr/lib/rigforge/xmrig/xmrig\n' >"$r/etc/systemd/system/xmrig.service" - printf 'ExecStart=/opt/other/xmrig\n' >"$r/etc/systemd/system/rigforge-other.service" + printf 'ExecStart=/usr/lib/rigforge/rigforge.sh other\n' >"$r/etc/systemd/system/rigforge-other.service" : >"$CALLS" RIGFORGE_PKG_ROOT="$r" PATH="$STUBS:$PATH" sh "$ROOT/packaging/debian/$script" "$arg" >"$r/out" 2>&1 } @@ -106,7 +106,7 @@ check "remove keeps config and state" "$([ -f "$D/postrm-remove/etc/rigforge/con maint postrm-purge postrm purge check "purge removes config, state and the tree's leftovers" "$([ ! -e "$D/postrm-purge/etc/rigforge" ] && [ ! -e "$D/postrm-purge/var/lib/rigforge" ] && [ ! -e "$D/postrm-purge/usr/lib/rigforge" ] && echo 0 || echo 1)" check "purge removes the units setup rendered for the package tree" "$([ ! -e "$D/postrm-purge/etc/systemd/system/xmrig.service" ] && [ ! -e "$D/postrm-purge/etc/systemd/system/rigforge-watchdog.service" ] && echo 0 || echo 1)" -check "purge keeps a unit that does not run the package tree" "$([ -f "$D/postrm-purge/etc/systemd/system/rigforge-other.service" ] && echo 0 || echo 1)" +check "purge keeps a unit it did not render" "$([ -f "$D/postrm-purge/etc/systemd/system/rigforge-other.service" ] && echo 0 || echo 1)" check "remove keeps the rendered units" "$([ -f "$D/postrm-remove/etc/systemd/system/xmrig.service" ] && echo 0 || echo 1)" set +e SYSTEMCTL_FAIL=1 maint prerm-fail prerm remove From dfc2307c96b3e36bcf482559f7c045ed9c632a22 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 19:38:38 -0600 Subject: [PATCH 13/26] package: run the code read-only from /usr/lib/rigforge with state in /var/lib/rigforge Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 8 +++- docs/getting-started.md | 20 ++++++---- docs/operations.md | 2 + packaging/debian/postinst | 2 +- packaging/debian/postrm | 2 +- packaging/debian/rigforge | 3 ++ scripts/build-deb.sh | 2 +- tests/test-build-deb.sh | 9 ++++- tests/test-deb-install.sh | 69 ++++++++++++++++++++++----------- tests/test-package-upgrade.sh | 13 +++---- tests/test-workflow-contract.sh | 5 ++- 11 files changed, 90 insertions(+), 45 deletions(-) create mode 100755 packaging/debian/rigforge diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c95fad28..273eb73d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -242,6 +242,10 @@ jobs: id: assert_isolation if: ${{ !cancelled() }} run: bash tests/e2e/linux.sh isolation + - name: "assert: deb install pass" + id: assert_deb_install + if: ${{ !cancelled() }} + run: bash tests/test-deb-install.sh - name: "setup: Build the API allowlist kernel test image" id: setup_allowlist_image if: ${{ !cancelled() }} @@ -262,13 +266,15 @@ jobs: APPLIANCE: ${{ steps.assert_appliance.outcome }} ISOLATION: ${{ steps.assert_isolation.outcome }} ALLOWLIST: ${{ steps.assert_allowlist.outcome }} - run: bash scripts/require-success.sh "deploy=$DEPLOY" "appliance=$APPLIANCE" "isolation=$ISOLATION" "allowlist=$ALLOWLIST" + DEB_INSTALL: ${{ steps.assert_deb_install.outcome }} + run: bash scripts/require-success.sh "deploy=$DEPLOY" "appliance=$APPLIANCE" "isolation=$ISOLATION" "allowlist=$ALLOWLIST" "deb-install=$DEB_INSTALL" - name: "assert: categorize outcome" id: assert_categorize if: always() env: CAT_ASSERT_ALLOWLIST: ${{ steps.assert_allowlist.outcome }} CAT_ASSERT_APPLIANCE: ${{ steps.assert_appliance.outcome }} + CAT_ASSERT_DEB_INSTALL: ${{ steps.assert_deb_install.outcome }} CAT_ASSERT_DEPLOY: ${{ steps.assert_deploy.outcome }} CAT_ASSERT_DOCKER_MODES: ${{ steps.assert_docker_modes.outcome }} CAT_ASSERT_ISOLATION: ${{ steps.assert_isolation.outcome }} diff --git a/docs/getting-started.md b/docs/getting-started.md index f031bee3..7d9af236 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -54,14 +54,18 @@ safe place for code that root-run units execute, so prefer the git route below o ### Install with apt (Debian / Ubuntu on Linux) The apt steps (signing key, source entry, `apt install rigforge`) are in the -[README](../README.md), under **Prefer `apt`?**. Installing changes nothing on the host: the package puts the -release bundle in `/usr/lib/rigforge` (without the developer notes under `docs/dev`), links `/usr/bin/rigforge` to it and adds the one-shot upgrade unit. -Provision with `sudo rigforge setup`. Until `RIGFORGE_STATE` lands (#780), `setup` keeps -`config.json` and the XMRig build inside `/usr/lib/rigforge`; `apt upgrade` and `apt remove` keep -them, and `apt purge` deletes them with `/var/lib/rigforge`. For the same reason the -[queued upgrade](operations.md#upgrading-through-apt), which looks for `/etc/rigforge/config.json`, -does not start yet: run `sudo rigforge upgrade` after `apt upgrade rigforge`. Neither remove nor purge reverts -system tuning; that is `rigforge uninstall`. +[README](../README.md), under **Prefer `apt`?**. Installing changes nothing on the host: the +package puts the release bundle (without the developer notes under `docs/dev`) in the root-owned +`/usr/lib/rigforge`, adds the one-shot upgrade unit, and installs a `/usr/bin/rigforge` that runs +it with `RIGFORGE_LIB=/usr/lib/rigforge` and `RIGFORGE_STATE=/var/lib/rigforge` +([where files live](operations.md#where-files-live)). Provision with `sudo rigforge setup`, which +creates `config.json`, the XMRig build and every other piece of state under `/var/lib/rigforge`; +that directory is root's, so run `backup` and `restore` with `sudo` too. + +`apt upgrade rigforge` on a configured host queues the +[package upgrade](operations.md#upgrading-through-apt). `apt remove` stops and disables the units +and keeps `/var/lib/rigforge`; `apt purge` also deletes it and the units `setup` rendered. Neither +reverts system tuning; that is `rigforge uninstall`. --- diff --git a/docs/operations.md b/docs/operations.md index 0b32e545..9035a579 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -643,6 +643,8 @@ RigForge reads code from one directory and writes state to another. Both default | `RIGFORGE_LIB` | the directory of `rigforge.sh` | `rigforge.sh`, `util/` scripts, `systemd/` unit templates, `VERSION`, `RIGFORGE_REF`, the `.rigforge-package` marker. Never written by a worker command, so it can be root-owned and read-only. | | `RIGFORGE_STATE` | the same directory (`RIGFORGE_HOME` when set) | `config.json`, the `.rigforge-*` markers and sidecars (appliance marker, config provenance, revision key), `config-backups/`, `backups/`, support tarballs and the default worker root `data/worker`. | +The apt package runs `rigforge.sh` with `RIGFORGE_LIB=/usr/lib/rigforge` and `RIGFORGE_STATE=/var/lib/rigforge`. + `RIGFORGE_HOME` is the older sandbox override: it sets the state directory and the template, `VERSION` and `proposed-grub.sh` lookups, while the `util/` scripts still come from the directory of `rigforge.sh`. Set `RIGFORGE_LIB` and `RIGFORGE_STATE` instead; each wins over it. Rendered units take `ExecStart` and the server script from the lib directory and the `config.json` credential from the state directory. When either variable is set, the miner unit and the scheduled verb units (autotune, watchdog, api-refresh, control-apply, control-upgrade) and the shared-host runner carry it in their environment. Both values must be clean absolute paths (letters, digits, `.`, `_`, `-`, `/`), and as root `RIGFORGE_LIB` must be owned by root and not group- or world-writable; otherwise `rigforge.sh` refuses to start. The `upgrade` verb updates a git checkout in place, so it still needs a writable checkout. ## Backup & restore diff --git a/packaging/debian/postinst b/packaging/debian/postinst index 5997619e..8965a39c 100755 --- a/packaging/debian/postinst +++ b/packaging/debian/postinst @@ -3,7 +3,7 @@ set -e ROOT=${RIGFORGE_PKG_ROOT:-} STATE=$ROOT/var/lib/rigforge -CONFIG=$ROOT/etc/rigforge/config.json +CONFIG=$STATE/config.json RETRY='sudo rigforge upgrade' case "$1" in diff --git a/packaging/debian/postrm b/packaging/debian/postrm index 4dd6ae5b..d8e1c942 100755 --- a/packaging/debian/postrm +++ b/packaging/debian/postrm @@ -10,7 +10,7 @@ purge) f="$ROOT/etc/systemd/system/$unit" if [ -f "$f" ] && grep -qs /usr/lib/rigforge "$f"; then rm -f "$f"; fi done - rm -rf "$ROOT/etc/rigforge" "$ROOT/var/lib/rigforge" "$ROOT/usr/lib/rigforge" + rm -rf "$ROOT/var/lib/rigforge" if [ -d "$ROOT/run/systemd/system" ]; then systemctl daemon-reload || true; fi ;; remove) diff --git a/packaging/debian/rigforge b/packaging/debian/rigforge new file mode 100755 index 00000000..758e437c --- /dev/null +++ b/packaging/debian/rigforge @@ -0,0 +1,3 @@ +#!/bin/sh +export RIGFORGE_LIB=/usr/lib/rigforge RIGFORGE_STATE=/var/lib/rigforge +exec /usr/lib/rigforge/rigforge.sh "$@" diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh index 54199834..dac1f16e 100755 --- a/scripts/build-deb.sh +++ b/scripts/build-deb.sh @@ -45,7 +45,7 @@ cp -a "$SRC" "$ROOT/usr/lib/rigforge" rm -rf "$ROOT/usr/lib/rigforge/docs/dev" chmod -R go-w,ug-s "$ROOT/usr/lib/rigforge" printf 'apt\n' >"$ROOT/usr/lib/rigforge/.rigforge-package" -ln -s ../lib/rigforge/rigforge.sh "$ROOT/usr/bin/rigforge" +install -m 0755 "$PKG_SRC/rigforge" "$ROOT/usr/bin/rigforge" install -m 0644 "$PKG_SRC/rigforge-upgrade.service" "$ROOT/usr/lib/systemd/system/" install -m 0755 "$PKG_SRC/postinst" "$PKG_SRC/prerm" "$PKG_SRC/postrm" "$ROOT/DEBIAN/" sed "s/@VERSION@/$VERSION/" "$PKG_SRC/control" >"$ROOT/DEBIAN/control" diff --git a/tests/test-build-deb.sh b/tests/test-build-deb.sh index c9fdff47..18e02026 100644 --- a/tests/test-build-deb.sh +++ b/tests/test-build-deb.sh @@ -56,9 +56,14 @@ X="$WORK/x" dpkg-deb --raw-extract "$DEB" "$X" L="$X/usr/lib/rigforge" check "code tree under /usr/lib/rigforge" "$([ -f "$L/rigforge.sh" ] && [ -d "$L/util" ] && [ -d "$L/systemd" ] && echo 0 || echo 1)" -check "/usr/bin/rigforge resolves to the code tree" "$([ "$(readlink "$X/usr/bin/rigforge")" = ../lib/rigforge/rigforge.sh ] && echo 0 || echo 1)" +check "/usr/bin/rigforge is the packaging/debian wrapper" "$(cmp -s "$X/usr/bin/rigforge" "$ROOT/packaging/debian/rigforge" && [ -x "$X/usr/bin/rigforge" ] && echo 0 || echo 1)" +mkdir -p "$WORK/probe" +printf '#!/bin/sh\necho "$RIGFORGE_LIB $RIGFORGE_STATE $*"\n' >"$WORK/probe/rigforge.sh" +chmod +x "$WORK/probe/rigforge.sh" +sed "s|/usr/lib/rigforge/rigforge.sh|$WORK/probe/rigforge.sh|" "$X/usr/bin/rigforge" >"$WORK/probe/wrapper" +check "wrapper runs rigforge.sh with RIGFORGE_LIB and RIGFORGE_STATE set" "$([ "$(env -u RIGFORGE_LIB -u RIGFORGE_STATE sh "$WORK/probe/wrapper" doctor --json)" = "/usr/lib/rigforge /var/lib/rigforge doctor --json" ] && echo 0 || echo 1)" check "state dir /var/lib/rigforge" "$([ -d "$X/var/lib/rigforge" ] && echo 0 || echo 1)" -check "package marker is where util/package-mode.sh reads it" "$(SCRIPT_DIR="$L" bash -c 'source "$SCRIPT_DIR/util/package-mode.sh"; [ "$(_package_channel)" = apt ]' && echo 0 || echo 1)" +check "package marker is where util/package-mode.sh reads it" "$(RIGFORGE_LIB="$L" bash -c 'source "$RIGFORGE_LIB/util/config-apply-state.sh"; source "$RIGFORGE_LIB/util/package-mode.sh"; [ "$(_package_channel)" = apt ]' && echo 0 || echo 1)" check "ships the upgrade unit" "$(cmp -s "$X/usr/lib/systemd/system/rigforge-upgrade.service" "$ROOT/packaging/debian/rigforge-upgrade.service" && echo 0 || echo 1)" for s in postinst prerm postrm; do check "DEBIAN/$s is packaging/debian/$s" "$(cmp -s "$X/DEBIAN/$s" "$ROOT/packaging/debian/$s" && [ -x "$X/DEBIAN/$s" ] && echo 0 || echo 1)" diff --git a/tests/test-deb-install.sh b/tests/test-deb-install.sh index 5aa1d856..369eae67 100755 --- a/tests/test-deb-install.sh +++ b/tests/test-deb-install.sh @@ -3,8 +3,29 @@ set -euo pipefail ROOT=$(cd "$(dirname "$0")/.." && pwd) IMAGE=ubuntu:24.04 +doctor_runs() { + local rc + set +e + out=$(rigforge doctor 2>&1) + rc=$? + set -e + printf '%s\n' "$out" | sed 's/^/ doctor| /' + case "$rc" in + 0 | 1) ;; + *) + echo "FAIL: doctor exited $rc ($1)" + return 1 + ;; + esac + grep -q "Checking the worker" <<<"$out" || { + echo "FAIL: doctor did not run its checks ($1)" + return 1 + } + echo "ok: doctor runs its checks from the packaged tree ($1, exit $rc)" +} + guest() { - local a=$1 b=$2 out rc + local a=$1 b=$2 export DEBIAN_FRONTEND=noninteractive apt-get update -qq apt-get install -y -qq "/debs/rigforge_${a}_all.deb" >/dev/null @@ -18,49 +39,53 @@ guest() { return 1 } echo "ok: package marker reads apt" - set +e - out=$(rigforge doctor 2>&1) - rc=$? - set -e - printf '%s\n' "$out" | sed 's/^/ doctor| /' - case "$rc" in - 0 | 1) ;; - *) - echo "FAIL: doctor exited $rc" + lib_before=$(find /usr/lib/rigforge -printf '%p %s %T@\n' | sort | sha256sum) + doctor_runs "no config yet" + grep -q "no config.json" <<<"$out" || { + echo "FAIL: doctor found a config before setup" return 1 - ;; - esac - grep -q "Checking the worker" <<<"$out" || { - echo "FAIL: doctor did not run its checks" + } + cp /usr/lib/rigforge/config.minimal.json /var/lib/rigforge/config.json + doctor_runs "config in /var/lib/rigforge" + if grep -q "no config.json" <<<"$out"; then + echo "FAIL: doctor did not read /var/lib/rigforge/config.json" + return 1 + fi + echo "ok: rigforge reads its config from RIGFORGE_STATE" + [ "$(find /usr/lib/rigforge -printf '%p %s %T@\n' | sort | sha256sum)" = "$lib_before" ] || { + echo "FAIL: running rigforge wrote under /usr/lib/rigforge" return 1 } - echo "ok: doctor runs its checks from the packaged tree (exit $rc: no miner is provisioned)" - echo '{}' >/usr/lib/rigforge/config.json + echo "ok: nothing was written under /usr/lib/rigforge" echo kept >/var/lib/rigforge/state-probe mkdir -p /etc/systemd/system - printf '[Service]\nExecStart=/usr/lib/rigforge/xmrig/xmrig\n' >/etc/systemd/system/xmrig.service + printf '[Service]\nExecStart=/usr/lib/rigforge/rigforge.sh start\n' >/etc/systemd/system/xmrig.service apt-get install -y -qq "/debs/rigforge_${b}_all.deb" >/dev/null [ "$(rigforge --version)" = "RigForge $b" ] || { echo "FAIL: rigforge --version after upgrade" return 1 } - [ -f /usr/lib/rigforge/config.json ] && [ -f /var/lib/rigforge/state-probe ] || { + [ -f /var/lib/rigforge/config.json ] && [ -f /var/lib/rigforge/state-probe ] || { echo "FAIL: upgrade lost config or state" return 1 } - echo "ok: upgrade to $b keeps config and state" + [ "$(cat /var/lib/rigforge/upgrade-pending 2>/dev/null)" = "$b" ] || { + echo "FAIL: upgrade of a configured host did not queue the package upgrade" + return 1 + } + echo "ok: upgrade to $b keeps config and state and queues the package upgrade" apt-get remove -y -qq rigforge >/dev/null - [ ! -e /usr/bin/rigforge ] && [ ! -e /usr/lib/rigforge/rigforge.sh ] || { + [ ! -e /usr/bin/rigforge ] && [ ! -e /usr/lib/rigforge ] || { echo "FAIL: remove left the code" return 1 } - [ -f /usr/lib/rigforge/config.json ] && [ -f /var/lib/rigforge/state-probe ] && [ -f /etc/systemd/system/xmrig.service ] || { + [ -f /var/lib/rigforge/config.json ] && [ -f /var/lib/rigforge/state-probe ] && [ -f /etc/systemd/system/xmrig.service ] || { echo "FAIL: remove dropped config, state or the rendered unit" return 1 } echo "ok: remove deletes the code and keeps config and state" apt-get purge -y -qq rigforge >/dev/null - [ ! -e /usr/lib/rigforge ] && [ ! -e /var/lib/rigforge ] && [ ! -e /etc/rigforge ] && [ ! -e /etc/systemd/system/xmrig.service ] || { + [ ! -e /var/lib/rigforge ] && [ ! -e /etc/systemd/system/xmrig.service ] || { echo "FAIL: purge left residue" return 1 } diff --git a/tests/test-package-upgrade.sh b/tests/test-package-upgrade.sh index bc23751c..19436f63 100644 --- a/tests/test-package-upgrade.sh +++ b/tests/test-package-upgrade.sh @@ -37,8 +37,8 @@ check() { postinst() { local r="$D/$1" - mkdir -p "$r/etc/rigforge" - [ "$4" != y ] || echo '{}' >"$r/etc/rigforge/config.json" + mkdir -p "$r/var/lib/rigforge" + [ "$4" != y ] || echo '{}' >"$r/var/lib/rigforge/config.json" [ "${5:-y}" != y ] || mkdir -p "$r/run/systemd/system" : >"$CALLS" NEW_VERSION="$3" RIGFORGE_PKG_ROOT="$r" PATH="$STUBS:$PATH" sh "$POSTINST" configure "$2" >"$r/out" 2>&1 @@ -76,9 +76,8 @@ check "systemctl failure never fails dpkg" "$([ "$rc" -eq 0 ] && grep -q 'sudo r maint() { local r="$D/$1" script=$2 arg=$3 - mkdir -p "$r/run/systemd/system" "$r/etc/rigforge" "$r/var/lib/rigforge" "$r/usr/lib/rigforge" - echo '{}' >"$r/etc/rigforge/config.json" - echo '{}' >"$r/usr/lib/rigforge/config.json" + mkdir -p "$r/run/systemd/system" "$r/var/lib/rigforge" + echo '{}' >"$r/var/lib/rigforge/config.json" mkdir -p "$r/etc/systemd/system" printf 'ExecStart=/usr/lib/rigforge/rigforge.sh watchdog\n' >"$r/etc/systemd/system/rigforge-watchdog.service" printf 'ExecStart=/usr/lib/rigforge/xmrig/xmrig\n' >"$r/etc/systemd/system/xmrig.service" @@ -102,9 +101,9 @@ done maint prerm-upgrade prerm upgrade check "prerm upgrade leaves the miner running" "$([ ! -s "$CALLS" ] && echo 0 || echo 1)" maint postrm-remove postrm remove -check "remove keeps config and state" "$([ -f "$D/postrm-remove/etc/rigforge/config.json" ] && [ -f "$D/postrm-remove/usr/lib/rigforge/config.json" ] && [ -d "$D/postrm-remove/var/lib/rigforge" ] && echo 0 || echo 1)" +check "remove keeps config and state" "$([ -f "$D/postrm-remove/var/lib/rigforge/config.json" ] && echo 0 || echo 1)" maint postrm-purge postrm purge -check "purge removes config, state and the tree's leftovers" "$([ ! -e "$D/postrm-purge/etc/rigforge" ] && [ ! -e "$D/postrm-purge/var/lib/rigforge" ] && [ ! -e "$D/postrm-purge/usr/lib/rigforge" ] && echo 0 || echo 1)" +check "purge removes config and state" "$([ ! -e "$D/postrm-purge/var/lib/rigforge" ] && echo 0 || echo 1)" check "purge removes the units setup rendered for the package tree" "$([ ! -e "$D/postrm-purge/etc/systemd/system/xmrig.service" ] && [ ! -e "$D/postrm-purge/etc/systemd/system/rigforge-watchdog.service" ] && echo 0 || echo 1)" check "purge keeps a unit it did not render" "$([ -f "$D/postrm-purge/etc/systemd/system/rigforge-other.service" ] && echo 0 || echo 1)" check "remove keeps the rendered units" "$([ -f "$D/postrm-remove/etc/systemd/system/xmrig.service" ] && echo 0 || echo 1)" diff --git a/tests/test-workflow-contract.sh b/tests/test-workflow-contract.sh index b41f78dc..c7e1e6e7 100755 --- a/tests/test-workflow-contract.sh +++ b/tests/test-workflow-contract.sh @@ -133,7 +133,7 @@ for wf in sys.argv[1:]: allowed_ifs = ("runner.os == 'Linux'",) elif sidv == "assert_categorize": allowed_ifs = ("always()",) - elif job == "e2e" and sidv in ("assert_deploy", "assert_appliance", "assert_isolation", "setup_allowlist_image"): + elif job == "e2e" and sidv in ("assert_deploy", "assert_appliance", "assert_isolation", "assert_deb_install", "setup_allowlist_image"): allowed_ifs = ("${{ !cancelled() }}",) elif job == "e2e" and sidv == "assert_allowlist": allowed_ifs = ("${{ !cancelled() && steps.setup_allowlist_image.outcome == 'success' }}",) @@ -236,7 +236,8 @@ for want in \ 'run: bash tests/e2e/linux.sh deploy' \ 'run: bash tests/e2e/linux.sh appliance' \ 'run: bash tests/e2e/linux.sh isolation' \ - 'run: bash scripts/require-success.sh "deploy=$DEPLOY" "appliance=$APPLIANCE" "isolation=$ISOLATION" "allowlist=$ALLOWLIST"' \ + 'run: bash tests/test-deb-install.sh' \ + 'run: bash scripts/require-success.sh "deploy=$DEPLOY" "appliance=$APPLIANCE" "isolation=$ISOLATION" "allowlist=$ALLOWLIST" "deb-install=$DEB_INSTALL"' \ 'run: make coverage' \ 'run: sudo bash tests/test-apt-feed.sh' \ 'run: timeout 1800 bash tests/test-stock-home.sh "$TEST_REVISION" "$TEST_EXPECTATION"' \ From f5f074798d1a9835d6d9b5b2580cd6d07f57182b Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 19:45:24 -0600 Subject: [PATCH 14/26] package: apt tree defaults to the package layout, purge removes every rendered unit and control state Co-Authored-By: Claude Opus 5.5 --- ...rship-upgrade-authority-and-key-custody.md | 2 +- docs/getting-started.md | 6 ++++-- docs/operations.md | 2 +- packaging/debian/postrm | 11 +++++++--- rigforge.sh | 1 + tests/README.md | 4 ++-- tests/test-deb-install.sh | 10 +++++++-- tests/test-package-upgrade.sh | 21 ++++++++++++++----- 8 files changed, 41 insertions(+), 16 deletions(-) diff --git a/docs/adr/0003-package-ownership-upgrade-authority-and-key-custody.md b/docs/adr/0003-package-ownership-upgrade-authority-and-key-custody.md index 24c4a61e..51cec1f4 100644 --- a/docs/adr/0003-package-ownership-upgrade-authority-and-key-custody.md +++ b/docs/adr/0003-package-ownership-upgrade-authority-and-key-custody.md @@ -29,7 +29,7 @@ Git-clone and appliance installs keep today's behaviour unchanged, with no marke - An apt upgrade of an already-configured host queues the real upgrade **outside dpkg**: postinst writes an upgrade-pending marker under `/var/lib/rigforge` and starts the one-shot `rigforge upgrade` unit via `systemctl start --no-block` (#785). A first install (no config) is inert. - The miner **restarts automatically, but only after a successful upgrade** (owner, 2026-11-20). On failure the previous build keeps running, the marker and failure stay visible in `status`/`doctor`, postinst still exits 0 so dpkg never half-configures the package, and retry is one documented `rigforge upgrade` command. `apt-mark hold` defers. - `brew upgrade` never restarts a running miner — it prints a hint; the auto-restart ruling applies to apt only (#787). -- **Purge** removes `/etc/rigforge` and `/var/lib/rigforge` but **never reverts system tuning** — not GRUB, hugepages, MSR or sysctl. Only `rigforge uninstall` undoes tuning (#784). Remove keeps config and state. +- **Purge** removes config and state (`/var/lib/rigforge`, which holds `config.json` since #780; there is no `/etc/rigforge`) but **never reverts system tuning** — not GRUB, hugepages, MSR or sysctl. Only `rigforge uninstall` undoes tuning (#784). Remove keeps config and state. ### D3. Signing-key custody (owner, 2026-11-20 — supersedes pithead #3459) diff --git a/docs/getting-started.md b/docs/getting-started.md index 7d9af236..fdf8b531 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -64,8 +64,10 @@ that directory is root's, so run `backup` and `restore` with `sudo` too. `apt upgrade rigforge` on a configured host queues the [package upgrade](operations.md#upgrading-through-apt). `apt remove` stops and disables the units -and keeps `/var/lib/rigforge`; `apt purge` also deletes it and the units `setup` rendered. Neither -reverts system tuning; that is `rigforge uninstall`. +and keeps `/var/lib/rigforge`. `apt purge` also deletes it, the control state under +`/var/lib/rigforge-control*`, every unit, timer and path `setup` rendered, the API firewall rules +file and the logrotate rule. Neither reverts system tuning (GRUB, HugePages, MSR, fstab, limits); +that is `rigforge uninstall`, run before `apt purge`. --- diff --git a/docs/operations.md b/docs/operations.md index 9035a579..67f02300 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -643,7 +643,7 @@ RigForge reads code from one directory and writes state to another. Both default | `RIGFORGE_LIB` | the directory of `rigforge.sh` | `rigforge.sh`, `util/` scripts, `systemd/` unit templates, `VERSION`, `RIGFORGE_REF`, the `.rigforge-package` marker. Never written by a worker command, so it can be root-owned and read-only. | | `RIGFORGE_STATE` | the same directory (`RIGFORGE_HOME` when set) | `config.json`, the `.rigforge-*` markers and sidecars (appliance marker, config provenance, revision key), `config-backups/`, `backups/`, support tarballs and the default worker root `data/worker`. | -The apt package runs `rigforge.sh` with `RIGFORGE_LIB=/usr/lib/rigforge` and `RIGFORGE_STATE=/var/lib/rigforge`. +The apt package runs `rigforge.sh` with `RIGFORGE_LIB=/usr/lib/rigforge` and `RIGFORGE_STATE=/var/lib/rigforge`. A tree whose `.rigforge-package` marker reads `apt` uses those values whenever `RIGFORGE_STATE` is unset, so running `/usr/lib/rigforge/rigforge.sh` directly behaves like `rigforge`. There is no `/etc/rigforge`: `config.json` is state that `setup` creates, not a dpkg conffile, so the first-run wizard still runs on a fresh install and upgrades never prompt about it. `RIGFORGE_HOME` is the older sandbox override: it sets the state directory and the template, `VERSION` and `proposed-grub.sh` lookups, while the `util/` scripts still come from the directory of `rigforge.sh`. Set `RIGFORGE_LIB` and `RIGFORGE_STATE` instead; each wins over it. Rendered units take `ExecStart` and the server script from the lib directory and the `config.json` credential from the state directory. When either variable is set, the miner unit and the scheduled verb units (autotune, watchdog, api-refresh, control-apply, control-upgrade) and the shared-host runner carry it in their environment. Both values must be clean absolute paths (letters, digits, `.`, `_`, `-`, `/`), and as root `RIGFORGE_LIB` must be owned by root and not group- or world-writable; otherwise `rigforge.sh` refuses to start. The `upgrade` verb updates a git checkout in place, so it still needs a writable checkout. diff --git a/packaging/debian/postrm b/packaging/debian/postrm index d8e1c942..db3e1f86 100755 --- a/packaging/debian/postrm +++ b/packaging/debian/postrm @@ -6,11 +6,16 @@ UNITS="xmrig.service rigforge-upgrade.service rigforge-autotune.timer rigforge-a case "$1" in purge) - for unit in $UNITS; do + for unit in $UNITS rigforge-api-firewall.nft; do f="$ROOT/etc/systemd/system/$unit" - if [ -f "$f" ] && grep -qs /usr/lib/rigforge "$f"; then rm -f "$f"; fi + case "$unit" in + xmrig.service) grep -qs 'RIGFORGE_STATE=/var/lib/rigforge$' "$f" && rm -f "$f" ;; + *) rm -f "$f" ;; + esac done - rm -rf "$ROOT/var/lib/rigforge" + if grep -qs /var/lib/rigforge "$ROOT/etc/logrotate.d/xmrig"; then rm -f "$ROOT/etc/logrotate.d/xmrig"; fi + if [ "$(cat "$ROOT/etc/rigforge-root-guard" 2>/dev/null)" = "allow /usr/lib/rigforge" ]; then rm -f "$ROOT/etc/rigforge-root-guard"; fi + rm -rf "$ROOT/var/lib/rigforge" "$ROOT/var/lib/rigforge-control" "$ROOT/var/lib/rigforge-control-upgrade" if [ -d "$ROOT/run/systemd/system" ]; then systemctl daemon-reload || true; fi ;; remove) diff --git a/rigforge.sh b/rigforge.sh index 118b605d..d001d5f7 100755 --- a/rigforge.sh +++ b/rigforge.sh @@ -60,6 +60,7 @@ _script_dir() { case "$src" in */*) d="${src%/*}" ;; *) d=. ;; esac cd -P "${d:-/}" &>/dev/null && pwd } +[ -n "${RIGFORGE_STATE:-}" ] || [ "$(cat "$(_script_dir)/.rigforge-package" 2>/dev/null)" != apt ] || export RIGFORGE_LIB="${RIGFORGE_LIB:-$(_script_dir)}" RIGFORGE_STATE=/var/lib/rigforge for _v in RIGFORGE_LIB RIGFORGE_STATE; do [ -z "${!_v:-}" ] || [[ ${!_v} =~ ^/[A-Za-z0-9._/-]+$ ]] || exit "$(echo "rigforge: $_v must be a clean absolute path" >&2 && echo 1)"; done [ -z "${RIGFORGE_LIB:-}" ] || [ "$(id -u)" != 0 ] || [ -z "$(find -H "$RIGFORGE_LIB" -maxdepth 0 \( ! -user root -o -perm -020 -o -perm -002 \) 2>/dev/null)" ] || exit "$(echo "rigforge: RIGFORGE_LIB must be root-owned and not group/world-writable" >&2 && echo 1)" [ "${RIGFORGE_TEST_OVERRIDES:-0}" = 1 ] || unset XMRIG_VERSION XMRIG_COMMIT API_CMD DMIDECODE RDMSR_BIN SERVICE_NAME LOGROTATE_DIR GRUB_DEFAULT FSTAB LIMITS_CONF MODULES_LOAD_DIR MODULES_FILE SYSTEMD_DIR HUGEPAGES_1G_DIR BIN_DIR MEMINFO CPUINFO MSR_MODULE_DIR GOVERNOR_FILE HUGEPAGES_1G_NR NR_HUGEPAGES_FILE CPUFREQ_MAX CPU_SYSFS DMI_DIR SMT_CONTROL LOCKDOWN_FILE RIGFORGE_APPLIANCE_MARKER RIGFORGE_LEGACY_APPLIANCE_UNIT diff --git a/tests/README.md b/tests/README.md index aa00b931..e4949d6e 100644 --- a/tests/README.md +++ b/tests/README.md @@ -52,9 +52,9 @@ CI median/p90, failures and occupied hours; missing evidence leaves acceptance o | **Linux container e2e** | [`e2e/linux.sh`](e2e/linux.sh) → [`e2e/in-container.sh`](e2e/in-container.sh) | Disposable Ubuntu container, **needs Docker**. **In CI.** | The genuine Linux deploy path against a real (throwaway) `/etc` with real GNU tools (`sed -i`, `tee`, `envsubst`) + idempotency on re-run. Only the heavy/privileged bits (compile, package install, `systemctl`/`mount`) are stubbed. A second pass re-runs the container with `RIGFORGE_APPLIANCE=1` (#348) and proves the appliance contracts on that real `/etc`: units land in `/run/systemd/system`, no package installs, no fstab/limits.conf/logrotate writes, every enable carries `--runtime`. A third script, [`e2e/isolation.sh`](e2e/isolation.sh) (#668), puts the rig on a Docker `--internal` network whose only reachable peer is a SOCKS5 proxy fronting a stand-in GitHub (a TLS git smart-HTTP server plus the releases API). With `tor_socks5` set it runs `upgrade --check`, `setup`, a local `upgrade` with an XMRig pin change and the `control-upgrade` oneshot in its own empty environment, and proves from the proxy's log that every connection named a hostname. It also proves the block is real (a direct connection and a keyless `upgrade --check` fail), that an unreachable proxy fails closed without reaching the upstream, and that the live build survives the failed upgrade. | `make test-e2e` | | **Native macOS e2e** | [`e2e/macos.sh`](e2e/macos.sh) | A real Mac, **manual, local only. Not in CI** (macOS is best effort). | The macOS deploy path with genuine BSD tools the Linux CI can only stub: BSD `sed`, the macOS config profile, `mac_*` process control (real `nohup` + PID file), the launchd login agent, `backup`/`restore`. | `make test-e2e-macos` | | **Coverage gate** | [`coverage.sh`](coverage.sh) | kcov in **Docker**. **In CI.** | Line coverage of `rigforge.sh` and its shell helpers by running `run.sh` under kcov; enforces the committed floor ([`coverage-floor.txt`](coverage-floor.txt)) plus a patch-coverage gate (diff-cover) on changed lines. | `make coverage` | -| **Package upgrade** | [`test-package-upgrade.sh`](test-package-upgrade.sh) | Any host, no Docker. **In CI** (`make test-suite`). | [`../packaging/debian/postinst`](../packaging/debian/postinst) creates the state dir, reloads systemd and prints the first-run step on a first install, and queues only on a greater version with a config, never failing dpkg; `prerm` stops and disables every unit on remove and `postrm` accepts every dpkg action and on purge deletes config, state and the units setup rendered for the package tree; `package-upgrade` re-renders units and clears the marker on success, and on failure keeps it, records it for status/doctor and does not restart. | `bash tests/test-package-upgrade.sh` | +| **Package upgrade** | [`test-package-upgrade.sh`](test-package-upgrade.sh) | Any host, no Docker. **In CI** (`make test-suite`). | [`../packaging/debian/postinst`](../packaging/debian/postinst) creates the state dir, reloads systemd and prints the first-run step on a first install, and queues only on a greater version with a config, never failing dpkg; `prerm` stops and disables every unit on remove and `postrm` accepts every dpkg action and on purge deletes config, state, control state, every rendered unit, timer and path, the firewall rules and logrotate rule, and keeps an `xmrig.service` the package did not render; `package-upgrade` re-renders units and clears the marker on success, and on failure keeps it, records it for status/doctor and does not restart. | `bash tests/test-package-upgrade.sh` | | **Debian package build** | [`test-build-deb.sh`](test-build-deb.sh) | Linux with `dpkg-deb`, no Docker. **In CI** (`make test-suite`). | [`../scripts/build-deb.sh`](../scripts/build-deb.sh) builds a byte-reproducible `.deb` from the release bundle with the marker where `util/package-mode.sh` reads it, the `packaging/debian` maintainer scripts and upgrade unit, the full `Depends`, and no apt keyring. | `bash tests/test-build-deb.sh` | -| **Debian package install** | [`test-deb-install.sh`](test-deb-install.sh) | Clean `ubuntu:24.04` container, **needs Docker**. **In CI** (`make test-e2e`). | `apt install` of the built `.deb`, `rigforge --version`, `doctor`, an upgrade to the next version, then remove keeps config and state and purge leaves no residue. | `bash tests/test-deb-install.sh` | +| **Debian package install** | [`test-deb-install.sh`](test-deb-install.sh) | Clean `ubuntu:24.04` container, **needs Docker**. **In CI** (`make test-e2e`). | `apt install` of the built `.deb`, `rigforge --version`, `doctor`, an upgrade to the next version, with config in `/var/lib/rigforge` and nothing written under `/usr/lib/rigforge`, a direct `rigforge.sh` run using the package layout, an upgrade that queues the package upgrade, then remove keeps config, state and units and purge removes them. | `bash tests/test-deb-install.sh` | | **APT feed** | [`test-apt-feed.sh`](test-apt-feed.sh) | Ubuntu 24.04, **root**, no Docker (needs `apt-utils`). **In CI.** (`ci.yml` job) | [`../scripts/build-apt.sh`](../scripts/build-apt.sh) end to end with throwaway keys: refusal of missing/bad fingerprints and keyrings without the secret key; a signed flat feed that `apt-get update` and `download` accept from `file://`; refusal of tampered `Release`/`InRelease`/`.deb` and of a feed signed by another key. | CI only (`sudo bash tests/test-apt-feed.sh`) | | **Release smoke (quick)** | [`smoke.sh`](smoke.sh) | Real Linux rig, **manual**. Not in CI. | The compiled binary actually starts and hashes (`xmrig --bench`, fully offline). Fast pre-tag confidence that the worker we ship runs. | `make smoke` | | **Release e2e (full)** | [`e2e-real.sh`](e2e-real.sh) | Real Linux rig, **manual, root**. Not in CI. | The real thing end to end: build + tune + kernel tuning + service + a real hash, the writable control path (#236) against real systemd (`control` phase), the remote-upgrade chain with real git as the root oneshot (`upgrade` phase, #322), then a clean uninstall. **The release gate.** | `make e2e-real` (see [`RELEASING.md`](../RELEASING.md)) | diff --git a/tests/test-deb-install.sh b/tests/test-deb-install.sh index 369eae67..d98214f7 100755 --- a/tests/test-deb-install.sh +++ b/tests/test-deb-install.sh @@ -52,6 +52,11 @@ guest() { return 1 fi echo "ok: rigforge reads its config from RIGFORGE_STATE" + if /usr/lib/rigforge/rigforge.sh doctor 2>&1 | grep -q "no config.json"; then + echo "FAIL: running /usr/lib/rigforge/rigforge.sh directly did not use /var/lib/rigforge" + return 1 + fi + echo "ok: running /usr/lib/rigforge/rigforge.sh directly uses the package layout too" [ "$(find /usr/lib/rigforge -printf '%p %s %T@\n' | sort | sha256sum)" = "$lib_before" ] || { echo "FAIL: running rigforge wrote under /usr/lib/rigforge" return 1 @@ -59,7 +64,8 @@ guest() { echo "ok: nothing was written under /usr/lib/rigforge" echo kept >/var/lib/rigforge/state-probe mkdir -p /etc/systemd/system - printf '[Service]\nExecStart=/usr/lib/rigforge/rigforge.sh start\n' >/etc/systemd/system/xmrig.service + printf '[Service]\nEnvironment=RIGFORGE_STATE=/var/lib/rigforge\nExecStart=/var/lib/rigforge/data/worker/xmrig/build/xmrig\n' >/etc/systemd/system/xmrig.service + printf '[Timer]\nOnCalendar=monthly\n' >/etc/systemd/system/rigforge-autotune.timer apt-get install -y -qq "/debs/rigforge_${b}_all.deb" >/dev/null [ "$(rigforge --version)" = "RigForge $b" ] || { echo "FAIL: rigforge --version after upgrade" @@ -85,7 +91,7 @@ guest() { } echo "ok: remove deletes the code and keeps config and state" apt-get purge -y -qq rigforge >/dev/null - [ ! -e /var/lib/rigforge ] && [ ! -e /etc/systemd/system/xmrig.service ] || { + [ ! -e /var/lib/rigforge ] && [ ! -e /etc/systemd/system/xmrig.service ] && [ ! -e /etc/systemd/system/rigforge-autotune.timer ] || { echo "FAIL: purge left residue" return 1 } diff --git a/tests/test-package-upgrade.sh b/tests/test-package-upgrade.sh index 19436f63..b11e46fa 100644 --- a/tests/test-package-upgrade.sh +++ b/tests/test-package-upgrade.sh @@ -78,10 +78,14 @@ maint() { local r="$D/$1" script=$2 arg=$3 mkdir -p "$r/run/systemd/system" "$r/var/lib/rigforge" echo '{}' >"$r/var/lib/rigforge/config.json" - mkdir -p "$r/etc/systemd/system" - printf 'ExecStart=/usr/lib/rigforge/rigforge.sh watchdog\n' >"$r/etc/systemd/system/rigforge-watchdog.service" - printf 'ExecStart=/usr/lib/rigforge/xmrig/xmrig\n' >"$r/etc/systemd/system/xmrig.service" - printf 'ExecStart=/usr/lib/rigforge/rigforge.sh other\n' >"$r/etc/systemd/system/rigforge-other.service" + mkdir -p "$r/etc/systemd/system" "$r/etc/logrotate.d" "$r/var/lib/rigforge-control" + for t in "$ROOT"/systemd/rigforge-*.template; do + cp "$t" "$r/etc/systemd/system/$(basename "$t" .template)" + done + RIGFORGE_LIB=/usr/lib/rigforge RIGFORGE_STATE=/var/lib/rigforge bash -c 'source "$1/util/config-apply-state.sh"; _unit_split_env <"$1/systemd/xmrig.service.template"' _ "$ROOT" >"$r/etc/systemd/system/xmrig.service" + : >"$r/etc/systemd/system/rigforge-api-firewall.nft" + printf '/var/lib/rigforge/data/worker/xmrig.log {\n}\n' >"$r/etc/logrotate.d/xmrig" + printf '[Service]\nExecStart=/usr/lib/rigforge/rigforge.sh other\n' >"$r/etc/systemd/system/rigforge-other.service" : >"$CALLS" RIGFORGE_PKG_ROOT="$r" PATH="$STUBS:$PATH" sh "$ROOT/packaging/debian/$script" "$arg" >"$r/out" 2>&1 } @@ -104,7 +108,14 @@ maint postrm-remove postrm remove check "remove keeps config and state" "$([ -f "$D/postrm-remove/var/lib/rigforge/config.json" ] && echo 0 || echo 1)" maint postrm-purge postrm purge check "purge removes config and state" "$([ ! -e "$D/postrm-purge/var/lib/rigforge" ] && echo 0 || echo 1)" -check "purge removes the units setup rendered for the package tree" "$([ ! -e "$D/postrm-purge/etc/systemd/system/xmrig.service" ] && [ ! -e "$D/postrm-purge/etc/systemd/system/rigforge-watchdog.service" ] && echo 0 || echo 1)" +check "fixture miner unit carries the package state dir" "$(grep -qx 'Environment=RIGFORGE_STATE=/var/lib/rigforge' "$D/postrm-remove/etc/systemd/system/xmrig.service" && echo 0 || echo 1)" +left=$(cd "$D/postrm-purge/etc/systemd/system" && ls) +check "purge removes every rendered unit, timer and path and the firewall rules (left: $left)" "$([ "$left" = rigforge-other.service ] && echo 0 || echo 1)" +check "purge removes the logrotate rule and the control state" "$([ ! -e "$D/postrm-purge/etc/logrotate.d/xmrig" ] && [ ! -e "$D/postrm-purge/var/lib/rigforge-control" ] && echo 0 || echo 1)" +maint postrm-foreign postrm purge +printf '[Service]\nExecStart=/opt/xmrig/xmrig\n' >"$D/postrm-foreign/etc/systemd/system/xmrig.service" +RIGFORGE_PKG_ROOT="$D/postrm-foreign" PATH="$STUBS:$PATH" sh "$ROOT/packaging/debian/postrm" purge >/dev/null 2>&1 +check "purge keeps an xmrig.service that RigForge's package did not render" "$([ -f "$D/postrm-foreign/etc/systemd/system/xmrig.service" ] && echo 0 || echo 1)" check "purge keeps a unit it did not render" "$([ -f "$D/postrm-purge/etc/systemd/system/rigforge-other.service" ] && echo 0 || echo 1)" check "remove keeps the rendered units" "$([ -f "$D/postrm-remove/etc/systemd/system/xmrig.service" ] && echo 0 || echo 1)" set +e From b144e6baae81e7ffc771e799a6d29223b39bd3f4 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 19:58:22 -0600 Subject: [PATCH 15/26] package: purge only units, firewall rules and control state the package rendered Co-Authored-By: Claude Opus 5.5 --- packaging/debian/postrm | 19 +++++++++++-------- tests/test-deb-install.sh | 5 +++-- tests/test-package-upgrade.sh | 26 +++++++++++++++----------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/packaging/debian/postrm b/packaging/debian/postrm index db3e1f86..4a816729 100755 --- a/packaging/debian/postrm +++ b/packaging/debian/postrm @@ -6,16 +6,19 @@ UNITS="xmrig.service rigforge-upgrade.service rigforge-autotune.timer rigforge-a case "$1" in purge) - for unit in $UNITS rigforge-api-firewall.nft; do - f="$ROOT/etc/systemd/system/$unit" - case "$unit" in - xmrig.service) grep -qs 'RIGFORGE_STATE=/var/lib/rigforge$' "$f" && rm -f "$f" ;; - *) rm -f "$f" ;; - esac + U=$ROOT/etc/systemd/system + ours() { grep -Eqs '/usr/lib/rigforge/|RIGFORGE_STATE=/var/lib/rigforge$' "$U/$1"; } + drop="" + for unit in $UNITS; do + case "$unit" in *.timer | *.path) svc=${unit%.*}.service ;; *) svc=$unit ;; esac + if ours "$svc"; then drop="$drop $unit"; fi done - if grep -qs /var/lib/rigforge "$ROOT/etc/logrotate.d/xmrig"; then rm -f "$ROOT/etc/logrotate.d/xmrig"; fi + if ours rigforge-api.service || ours rigforge-control.service; then drop="$drop rigforge-api-firewall.nft"; fi + if ours rigforge-control.service; then rm -rf "$ROOT/var/lib/rigforge-control" "$ROOT/var/lib/rigforge-control-upgrade"; fi + for unit in $drop; do rm -f "$U/$unit"; done + if grep -qs /var/lib/rigforge/ "$ROOT/etc/logrotate.d/xmrig"; then rm -f "$ROOT/etc/logrotate.d/xmrig"; fi if [ "$(cat "$ROOT/etc/rigforge-root-guard" 2>/dev/null)" = "allow /usr/lib/rigforge" ]; then rm -f "$ROOT/etc/rigforge-root-guard"; fi - rm -rf "$ROOT/var/lib/rigforge" "$ROOT/var/lib/rigforge-control" "$ROOT/var/lib/rigforge-control-upgrade" + rm -rf "$ROOT/var/lib/rigforge" if [ -d "$ROOT/run/systemd/system" ]; then systemctl daemon-reload || true; fi ;; remove) diff --git a/tests/test-deb-install.sh b/tests/test-deb-install.sh index d98214f7..3ffba547 100755 --- a/tests/test-deb-install.sh +++ b/tests/test-deb-install.sh @@ -6,7 +6,7 @@ IMAGE=ubuntu:24.04 doctor_runs() { local rc set +e - out=$(rigforge doctor 2>&1) + out=$("${2:-rigforge}" doctor 2>&1) rc=$? set -e printf '%s\n' "$out" | sed 's/^/ doctor| /' @@ -52,7 +52,8 @@ guest() { return 1 fi echo "ok: rigforge reads its config from RIGFORGE_STATE" - if /usr/lib/rigforge/rigforge.sh doctor 2>&1 | grep -q "no config.json"; then + doctor_runs "direct /usr/lib/rigforge/rigforge.sh" /usr/lib/rigforge/rigforge.sh + if grep -q "no config.json" <<<"$out"; then echo "FAIL: running /usr/lib/rigforge/rigforge.sh directly did not use /var/lib/rigforge" return 1 fi diff --git a/tests/test-package-upgrade.sh b/tests/test-package-upgrade.sh index b11e46fa..5e300069 100644 --- a/tests/test-package-upgrade.sh +++ b/tests/test-package-upgrade.sh @@ -74,17 +74,22 @@ rc=$? set -e check "systemctl failure never fails dpkg" "$([ "$rc" -eq 0 ] && grep -q 'sudo rigforge upgrade' "$D/sysfail/out" && echo 0 || echo 1)" +render() { + local r=$1 lib=$2 state=$3 t + mkdir -p "$r/etc/systemd/system" "$r/etc/logrotate.d" "$r/var/lib/rigforge-control" + for t in "$ROOT"/systemd/*.template; do + sed "s|\$SCRIPT_DIR|$lib|g; s|\$RIGFORGE_STATE|$state|g" "$t" | + RIGFORGE_LIB=$lib RIGFORGE_STATE=$state bash -c 'source "$1/util/config-apply-state.sh"; _unit_split_env' _ "$ROOT" >"$r/etc/systemd/system/$(basename "$t" .template)" + done + : >"$r/etc/systemd/system/rigforge-api-firewall.nft" + printf '%s/data/worker/xmrig.log {\n}\n' "$state" >"$r/etc/logrotate.d/xmrig" +} + maint() { local r="$D/$1" script=$2 arg=$3 mkdir -p "$r/run/systemd/system" "$r/var/lib/rigforge" echo '{}' >"$r/var/lib/rigforge/config.json" - mkdir -p "$r/etc/systemd/system" "$r/etc/logrotate.d" "$r/var/lib/rigforge-control" - for t in "$ROOT"/systemd/rigforge-*.template; do - cp "$t" "$r/etc/systemd/system/$(basename "$t" .template)" - done - RIGFORGE_LIB=/usr/lib/rigforge RIGFORGE_STATE=/var/lib/rigforge bash -c 'source "$1/util/config-apply-state.sh"; _unit_split_env <"$1/systemd/xmrig.service.template"' _ "$ROOT" >"$r/etc/systemd/system/xmrig.service" - : >"$r/etc/systemd/system/rigforge-api-firewall.nft" - printf '/var/lib/rigforge/data/worker/xmrig.log {\n}\n' >"$r/etc/logrotate.d/xmrig" + render "$r" "${LIB:-/usr/lib/rigforge}" "${STATE:-/var/lib/rigforge}" printf '[Service]\nExecStart=/usr/lib/rigforge/rigforge.sh other\n' >"$r/etc/systemd/system/rigforge-other.service" : >"$CALLS" RIGFORGE_PKG_ROOT="$r" PATH="$STUBS:$PATH" sh "$ROOT/packaging/debian/$script" "$arg" >"$r/out" 2>&1 @@ -112,10 +117,9 @@ check "fixture miner unit carries the package state dir" "$(grep -qx 'Environmen left=$(cd "$D/postrm-purge/etc/systemd/system" && ls) check "purge removes every rendered unit, timer and path and the firewall rules (left: $left)" "$([ "$left" = rigforge-other.service ] && echo 0 || echo 1)" check "purge removes the logrotate rule and the control state" "$([ ! -e "$D/postrm-purge/etc/logrotate.d/xmrig" ] && [ ! -e "$D/postrm-purge/var/lib/rigforge-control" ] && echo 0 || echo 1)" -maint postrm-foreign postrm purge -printf '[Service]\nExecStart=/opt/xmrig/xmrig\n' >"$D/postrm-foreign/etc/systemd/system/xmrig.service" -RIGFORGE_PKG_ROOT="$D/postrm-foreign" PATH="$STUBS:$PATH" sh "$ROOT/packaging/debian/postrm" purge >/dev/null 2>&1 -check "purge keeps an xmrig.service that RigForge's package did not render" "$([ -f "$D/postrm-foreign/etc/systemd/system/xmrig.service" ] && echo 0 || echo 1)" +LIB=/home/op/rigforge STATE=/home/op/rigforge maint postrm-foreign postrm purge +foreign=$(cd "$D/postrm-foreign/etc/systemd/system" && ls | wc -l | tr -d ' ') +check "purge keeps every unit and the control state of a non-package install" "$([ "$foreign" -eq "$(($(ls "$ROOT"/systemd/*.template | wc -l) + 2))" ] && [ -d "$D/postrm-foreign/var/lib/rigforge-control" ] && [ -f "$D/postrm-foreign/etc/logrotate.d/xmrig" ] && echo 0 || echo 1)" check "purge keeps a unit it did not render" "$([ -f "$D/postrm-purge/etc/systemd/system/rigforge-other.service" ] && echo 0 || echo 1)" check "remove keeps the rendered units" "$([ -f "$D/postrm-remove/etc/systemd/system/xmrig.service" ] && echo 0 || echo 1)" set +e From 92ee84aee8f005cc5b8d9b75cbea3cbe93372510 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 20:09:43 -0600 Subject: [PATCH 16/26] package: purge the firewall rules the miner unit loads; fix test fixtures and topology placeholder Co-Authored-By: Claude Opus 5.5 --- packaging/debian/postrm | 2 +- tests/test-deb-install.sh | 3 ++- tests/test-package-upgrade.sh | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packaging/debian/postrm b/packaging/debian/postrm index 4a816729..a4b93fe0 100755 --- a/packaging/debian/postrm +++ b/packaging/debian/postrm @@ -13,7 +13,7 @@ purge) case "$unit" in *.timer | *.path) svc=${unit%.*}.service ;; *) svc=$unit ;; esac if ours "$svc"; then drop="$drop $unit"; fi done - if ours rigforge-api.service || ours rigforge-control.service; then drop="$drop rigforge-api-firewall.nft"; fi + if ours xmrig.service || ours rigforge-api.service || ours rigforge-control.service; then drop="$drop rigforge-api-firewall.nft"; fi if ours rigforge-control.service; then rm -rf "$ROOT/var/lib/rigforge-control" "$ROOT/var/lib/rigforge-control-upgrade"; fi for unit in $drop; do rm -f "$U/$unit"; done if grep -qs /var/lib/rigforge/ "$ROOT/etc/logrotate.d/xmrig"; then rm -f "$ROOT/etc/logrotate.d/xmrig"; fi diff --git a/tests/test-deb-install.sh b/tests/test-deb-install.sh index 3ffba547..d11846ad 100755 --- a/tests/test-deb-install.sh +++ b/tests/test-deb-install.sh @@ -67,6 +67,7 @@ guest() { mkdir -p /etc/systemd/system printf '[Service]\nEnvironment=RIGFORGE_STATE=/var/lib/rigforge\nExecStart=/var/lib/rigforge/data/worker/xmrig/build/xmrig\n' >/etc/systemd/system/xmrig.service printf '[Timer]\nOnCalendar=monthly\n' >/etc/systemd/system/rigforge-autotune.timer + printf '[Service]\nExecStart=/usr/lib/rigforge/rigforge.sh autotune\n' >/etc/systemd/system/rigforge-autotune.service apt-get install -y -qq "/debs/rigforge_${b}_all.deb" >/dev/null [ "$(rigforge --version)" = "RigForge $b" ] || { echo "FAIL: rigforge --version after upgrade" @@ -92,7 +93,7 @@ guest() { } echo "ok: remove deletes the code and keeps config and state" apt-get purge -y -qq rigforge >/dev/null - [ ! -e /var/lib/rigforge ] && [ ! -e /etc/systemd/system/xmrig.service ] && [ ! -e /etc/systemd/system/rigforge-autotune.timer ] || { + [ ! -e /var/lib/rigforge ] && [ ! -e /etc/systemd/system/xmrig.service ] && [ ! -e /etc/systemd/system/rigforge-autotune.timer ] && [ ! -e /etc/systemd/system/rigforge-autotune.service ] || { echo "FAIL: purge left residue" return 1 } diff --git a/tests/test-package-upgrade.sh b/tests/test-package-upgrade.sh index 5e300069..ad1b1fa1 100644 --- a/tests/test-package-upgrade.sh +++ b/tests/test-package-upgrade.sh @@ -117,7 +117,12 @@ check "fixture miner unit carries the package state dir" "$(grep -qx 'Environmen left=$(cd "$D/postrm-purge/etc/systemd/system" && ls) check "purge removes every rendered unit, timer and path and the firewall rules (left: $left)" "$([ "$left" = rigforge-other.service ] && echo 0 || echo 1)" check "purge removes the logrotate rule and the control state" "$([ ! -e "$D/postrm-purge/etc/logrotate.d/xmrig" ] && [ ! -e "$D/postrm-purge/var/lib/rigforge-control" ] && echo 0 || echo 1)" -LIB=/home/op/rigforge STATE=/home/op/rigforge maint postrm-foreign postrm purge +LIB=/opt/rigforge STATE=/opt/rigforge maint postrm-foreign postrm purge +r="$D/postrm-minerfw" +maint postrm-minerfw postrm remove +rm -f "$r/etc/systemd/system/rigforge-api.service" "$r/etc/systemd/system/rigforge-control.service" +RIGFORGE_PKG_ROOT="$r" PATH="$STUBS:$PATH" sh "$ROOT/packaging/debian/postrm" purge >/dev/null 2>&1 +check "purge removes the firewall rules the package miner unit loads" "$([ ! -e "$r/etc/systemd/system/rigforge-api-firewall.nft" ] && echo 0 || echo 1)" foreign=$(cd "$D/postrm-foreign/etc/systemd/system" && ls | wc -l | tr -d ' ') check "purge keeps every unit and the control state of a non-package install" "$([ "$foreign" -eq "$(($(ls "$ROOT"/systemd/*.template | wc -l) + 2))" ] && [ -d "$D/postrm-foreign/var/lib/rigforge-control" ] && [ -f "$D/postrm-foreign/etc/logrotate.d/xmrig" ] && echo 0 || echo 1)" check "purge keeps a unit it did not render" "$([ -f "$D/postrm-purge/etc/systemd/system/rigforge-other.service" ] && echo 0 || echo 1)" From 35f8e2edc2bd08b4529a299a24069727b1c09026 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 20:26:41 -0600 Subject: [PATCH 17/26] rigforge.sh: detect the apt layout with builtins so api-refresh spawns no extra programs Co-Authored-By: Claude Opus 5.5 --- rigforge.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rigforge.sh b/rigforge.sh index d001d5f7..fc3f341d 100755 --- a/rigforge.sh +++ b/rigforge.sh @@ -60,7 +60,8 @@ _script_dir() { case "$src" in */*) d="${src%/*}" ;; *) d=. ;; esac cd -P "${d:-/}" &>/dev/null && pwd } -[ -n "${RIGFORGE_STATE:-}" ] || [ "$(cat "$(_script_dir)/.rigforge-package" 2>/dev/null)" != apt ] || export RIGFORGE_LIB="${RIGFORGE_LIB:-$(_script_dir)}" RIGFORGE_STATE=/var/lib/rigforge +_pkg_marker="${BASH_SOURCE[0]%/*}/.rigforge-package" +[ -n "${RIGFORGE_STATE:-}" ] || [ ! -f "$_pkg_marker" ] || { read -r _pkg_marker <"$_pkg_marker" || :; [ "$_pkg_marker" != apt ] || export RIGFORGE_LIB="${RIGFORGE_LIB:-$(_script_dir)}" RIGFORGE_STATE=/var/lib/rigforge; } for _v in RIGFORGE_LIB RIGFORGE_STATE; do [ -z "${!_v:-}" ] || [[ ${!_v} =~ ^/[A-Za-z0-9._/-]+$ ]] || exit "$(echo "rigforge: $_v must be a clean absolute path" >&2 && echo 1)"; done [ -z "${RIGFORGE_LIB:-}" ] || [ "$(id -u)" != 0 ] || [ -z "$(find -H "$RIGFORGE_LIB" -maxdepth 0 \( ! -user root -o -perm -020 -o -perm -002 \) 2>/dev/null)" ] || exit "$(echo "rigforge: RIGFORGE_LIB must be root-owned and not group/world-writable" >&2 && echo 1)" [ "${RIGFORGE_TEST_OVERRIDES:-0}" = 1 ] || unset XMRIG_VERSION XMRIG_COMMIT API_CMD DMIDECODE RDMSR_BIN SERVICE_NAME LOGROTATE_DIR GRUB_DEFAULT FSTAB LIMITS_CONF MODULES_LOAD_DIR MODULES_FILE SYSTEMD_DIR HUGEPAGES_1G_DIR BIN_DIR MEMINFO CPUINFO MSR_MODULE_DIR GOVERNOR_FILE HUGEPAGES_1G_NR NR_HUGEPAGES_FILE CPUFREQ_MAX CPU_SYSFS DMI_DIR SMT_CONTROL LOCKDOWN_FILE RIGFORGE_APPLIANCE_MARKER RIGFORGE_LEGACY_APPLIANCE_UNIT From 6a051b2b8f15830df45d41137a8f10b6e5a85b2f Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 20:26:56 -0600 Subject: [PATCH 18/26] rigforge.sh: shfmt the apt layout detection Co-Authored-By: Claude Opus 5.5 --- rigforge.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rigforge.sh b/rigforge.sh index fc3f341d..f052891b 100755 --- a/rigforge.sh +++ b/rigforge.sh @@ -61,7 +61,10 @@ _script_dir() { cd -P "${d:-/}" &>/dev/null && pwd } _pkg_marker="${BASH_SOURCE[0]%/*}/.rigforge-package" -[ -n "${RIGFORGE_STATE:-}" ] || [ ! -f "$_pkg_marker" ] || { read -r _pkg_marker <"$_pkg_marker" || :; [ "$_pkg_marker" != apt ] || export RIGFORGE_LIB="${RIGFORGE_LIB:-$(_script_dir)}" RIGFORGE_STATE=/var/lib/rigforge; } +[ -n "${RIGFORGE_STATE:-}" ] || [ ! -f "$_pkg_marker" ] || { + read -r _pkg_marker <"$_pkg_marker" || : + [ "$_pkg_marker" != apt ] || export RIGFORGE_LIB="${RIGFORGE_LIB:-$(_script_dir)}" RIGFORGE_STATE=/var/lib/rigforge +} for _v in RIGFORGE_LIB RIGFORGE_STATE; do [ -z "${!_v:-}" ] || [[ ${!_v} =~ ^/[A-Za-z0-9._/-]+$ ]] || exit "$(echo "rigforge: $_v must be a clean absolute path" >&2 && echo 1)"; done [ -z "${RIGFORGE_LIB:-}" ] || [ "$(id -u)" != 0 ] || [ -z "$(find -H "$RIGFORGE_LIB" -maxdepth 0 \( ! -user root -o -perm -020 -o -perm -002 \) 2>/dev/null)" ] || exit "$(echo "rigforge: RIGFORGE_LIB must be root-owned and not group/world-writable" >&2 && echo 1)" [ "${RIGFORGE_TEST_OVERRIDES:-0}" = 1 ] || unset XMRIG_VERSION XMRIG_COMMIT API_CMD DMIDECODE RDMSR_BIN SERVICE_NAME LOGROTATE_DIR GRUB_DEFAULT FSTAB LIMITS_CONF MODULES_LOAD_DIR MODULES_FILE SYSTEMD_DIR HUGEPAGES_1G_DIR BIN_DIR MEMINFO CPUINFO MSR_MODULE_DIR GOVERNOR_FILE HUGEPAGES_1G_NR NR_HUGEPAGES_FILE CPUFREQ_MAX CPU_SYSFS DMI_DIR SMT_CONTROL LOCKDOWN_FILE RIGFORGE_APPLIANCE_MARKER RIGFORGE_LEGACY_APPLIANCE_UNIT From 9df34dc28d99f3b84e186f1ad5cd6fae01d6873b Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 20:43:17 -0600 Subject: [PATCH 19/26] test: cover the apt layout default; list the package suites in the test manifest Co-Authored-By: Claude Opus 5.5 --- rigforge.sh | 2 +- tests/manifest.json | 24 ++++++++++++++++++++++++ tests/test-package-mode.sh | 7 +++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/rigforge.sh b/rigforge.sh index f052891b..f59389be 100755 --- a/rigforge.sh +++ b/rigforge.sh @@ -60,7 +60,7 @@ _script_dir() { case "$src" in */*) d="${src%/*}" ;; *) d=. ;; esac cd -P "${d:-/}" &>/dev/null && pwd } -_pkg_marker="${BASH_SOURCE[0]%/*}/.rigforge-package" +_pkg_marker="${RIGFORGE_PACKAGE_MARKER:-${BASH_SOURCE[0]%/*}/.rigforge-package}" [ -n "${RIGFORGE_STATE:-}" ] || [ ! -f "$_pkg_marker" ] || { read -r _pkg_marker <"$_pkg_marker" || : [ "$_pkg_marker" != apt ] || export RIGFORGE_LIB="${RIGFORGE_LIB:-$(_script_dir)}" RIGFORGE_STATE=/var/lib/rigforge diff --git a/tests/manifest.json b/tests/manifest.json index 87acd8e3..85a6ac89 100644 --- a/tests/manifest.json +++ b/tests/manifest.json @@ -241,6 +241,30 @@ }, "needs": [] }, + { + "name": "build-deb", + "file": "tests/test-build-deb.sh", + "phases": [], + "timeout_seconds": 300, + "inputs": [], + "exit_codes": { + "0": "pass", + "1": "fail" + }, + "needs": [] + }, + { + "name": "deb-install", + "file": "tests/test-deb-install.sh", + "phases": [], + "timeout_seconds": 900, + "inputs": [], + "exit_codes": { + "0": "pass", + "1": "fail" + }, + "needs": [] + }, { "name": "e2e-gate", "file": "tests/test-e2e-gate.sh", diff --git a/tests/test-package-mode.sh b/tests/test-package-mode.sh index ed2a841b..51fb8e97 100644 --- a/tests/test-package-mode.sh +++ b/tests/test-package-mode.sh @@ -111,3 +111,10 @@ for ch in "" apt; do esac done rm -f "$DR/.rigforge-package" +PL="$(mktemp -d)" +printf 'apt\n' >"$PL/apt" +printf 'brew\n' >"$PL/brew" +assert_eq "an apt-marked tree defaults to the package layout" "$(env -u RIGFORGE_STATE -u RIGFORGE_LIB -u RIGFORGE_HOME RIGFORGE_PACKAGE_MARKER="$PL/apt" bash -c 'source "$1"; printf "%s %s" "$CONFIG_JSON" "$RIGFORGE_LIB"' _ "$SCRIPT")" "/var/lib/rigforge/config.json $(cd -P "$(dirname "$SCRIPT")" && pwd)" +assert_eq "an explicit RIGFORGE_STATE wins over the apt layout" "$(env -u RIGFORGE_LIB -u RIGFORGE_HOME RIGFORGE_STATE="$PL" RIGFORGE_PACKAGE_MARKER="$PL/apt" bash -c 'source "$1"; printf "%s" "$CONFIG_JSON"' _ "$SCRIPT")" "$PL/config.json" +assert_eq "a brew-marked tree keeps state beside the script" "$(env -u RIGFORGE_STATE -u RIGFORGE_LIB -u RIGFORGE_HOME RIGFORGE_PACKAGE_MARKER="$PL/brew" bash -c 'source "$1"; printf "%s" "$CONFIG_JSON"' _ "$SCRIPT")" "$(cd -P "$(dirname "$SCRIPT")" && pwd)/config.json" +rm -rf "$PL" From ea1e0b12bc6c48ec1a5678258004fbb598a137d7 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 20:56:20 -0600 Subject: [PATCH 20/26] test: check the apt layout default in-shell so it also runs under kcov Co-Authored-By: Claude Opus 5.5 --- tests/test-package-mode.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/test-package-mode.sh b/tests/test-package-mode.sh index 51fb8e97..081b405f 100644 --- a/tests/test-package-mode.sh +++ b/tests/test-package-mode.sh @@ -114,7 +114,18 @@ rm -f "$DR/.rigforge-package" PL="$(mktemp -d)" printf 'apt\n' >"$PL/apt" printf 'brew\n' >"$PL/brew" -assert_eq "an apt-marked tree defaults to the package layout" "$(env -u RIGFORGE_STATE -u RIGFORGE_LIB -u RIGFORGE_HOME RIGFORGE_PACKAGE_MARKER="$PL/apt" bash -c 'source "$1"; printf "%s %s" "$CONFIG_JSON" "$RIGFORGE_LIB"' _ "$SCRIPT")" "/var/lib/rigforge/config.json $(cd -P "$(dirname "$SCRIPT")" && pwd)" -assert_eq "an explicit RIGFORGE_STATE wins over the apt layout" "$(env -u RIGFORGE_LIB -u RIGFORGE_HOME RIGFORGE_STATE="$PL" RIGFORGE_PACKAGE_MARKER="$PL/apt" bash -c 'source "$1"; printf "%s" "$CONFIG_JSON"' _ "$SCRIPT")" "$PL/config.json" -assert_eq "a brew-marked tree keeps state beside the script" "$(env -u RIGFORGE_STATE -u RIGFORGE_LIB -u RIGFORGE_HOME RIGFORGE_PACKAGE_MARKER="$PL/brew" bash -c 'source "$1"; printf "%s" "$CONFIG_JSON"' _ "$SCRIPT")" "$(cd -P "$(dirname "$SCRIPT")" && pwd)/config.json" +layout() { + ( + unset RIGFORGE_STATE RIGFORGE_LIB RIGFORGE_HOME + id() { echo 1000; } + RIGFORGE_PACKAGE_MARKER="$PL/$1" + [ -z "${2:-}" ] || RIGFORGE_STATE="$2" + source "$SCRIPT" >/dev/null 2>&1 + printf '%s %s' "$CONFIG_JSON" "${RIGFORGE_LIB:-}" + ) +} +TREE="$(cd -P "$(dirname "$SCRIPT")" && pwd)" +assert_eq "an apt-marked tree defaults to the package layout" "$(layout apt)" "/var/lib/rigforge/config.json $TREE" +assert_eq "an explicit RIGFORGE_STATE wins over the apt layout" "$(layout apt "$PL")" "$PL/config.json " +assert_eq "a brew-marked tree keeps state beside the script" "$(layout brew)" "$TREE/config.json " rm -rf "$PL" From 710b3d21fcffaea40db7993c3fb3f26ea2866771 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 21:31:25 -0600 Subject: [PATCH 21/26] package: find the apt marker from the resolved script dir; prerm acts only on package units, on remove Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 5 ----- docs/getting-started.md | 2 +- packaging/debian/control | 1 + packaging/debian/postinst | 2 +- packaging/debian/prerm | 9 ++++++--- rigforge.sh | 2 +- scripts/build-deb.sh | 12 +++--------- tests/README.md | 2 +- tests/test-build-deb.sh | 3 ++- tests/test-package-mode.sh | 14 ++++++++++++++ tests/test-package-upgrade.sh | 9 ++++++++- 11 files changed, 38 insertions(+), 23 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f232a45f..54f1735a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -158,11 +158,6 @@ jobs: # Mark 0.x tags as pre-releases. pre="" case "${TAG#v}" in 0.*) pre="--prerelease" ;; esac - # Create the release as a DRAFT so a human reviews the generated notes + bundles and clicks - # "Publish" — a deliberate gate for a tool that installs a root miner. Drop --draft here to - # go back to publishing automatically on tag push. - # Checksums only, by decision (2026-07-11): release signing was removed — see - # SECURITY.md > Release integrity. SHA256SUMS proves the bundle matches what CI built. assets=("rigforge-$TAG.zip" "rigforge-$TAG.tar.gz" "rigforge_${TAG#v}_all.deb" SHA256SUMS rigforge.rb) for binary in relbin/rigforge-"$TAG"-*-unknown-linux-musl; do [ -e "$binary" ] && assets+=("$binary") diff --git a/docs/getting-started.md b/docs/getting-started.md index fdf8b531..47491fcf 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -63,7 +63,7 @@ creates `config.json`, the XMRig build and every other piece of state under `/va that directory is root's, so run `backup` and `restore` with `sudo` too. `apt upgrade rigforge` on a configured host queues the -[package upgrade](operations.md#upgrading-through-apt). `apt remove` stops and disables the units +[package upgrade](operations.md#upgrading-through-apt). `apt remove` stops and disables the units `setup` rendered for the package (never those of a git install) and keeps `/var/lib/rigforge`. `apt purge` also deletes it, the control state under `/var/lib/rigforge-control*`, every unit, timer and path `setup` rendered, the API firewall rules file and the logrotate rule. Neither reverts system tuning (GRUB, HugePages, MSR, fstab, limits); diff --git a/packaging/debian/control b/packaging/debian/control index 7650189e..0eb82848 100644 --- a/packaging/debian/control +++ b/packaging/debian/control @@ -3,6 +3,7 @@ Version: @VERSION@ Section: net Priority: optional Architecture: all +Recommends: linux-tools-generic | linux-cpupower Depends: bash, jq, curl, nftables, git, build-essential, cmake, libuv1-dev, libssl-dev, libhwloc-dev, gettext-base, python3, msr-tools, linux-tools-common | linux-cpupower Maintainer: RigForge maintainers Homepage: https://github.com/p2pool-starter-stack/rigforge diff --git a/packaging/debian/postinst b/packaging/debian/postinst index 8965a39c..22f1b1d6 100755 --- a/packaging/debian/postinst +++ b/packaging/debian/postinst @@ -9,7 +9,7 @@ RETRY='sudo rigforge upgrade' case "$1" in configure) old=$2 - install -d -m 0755 "$STATE" + mkdir -p "$STATE" || true if [ -d "$ROOT/run/systemd/system" ]; then systemctl daemon-reload || true; fi if [ -z "$old" ]; then echo "rigforge: installed; nothing on this host changed. Provision with: sudo rigforge setup" diff --git a/packaging/debian/prerm b/packaging/debian/prerm index d95daf16..72e73acc 100755 --- a/packaging/debian/prerm +++ b/packaging/debian/prerm @@ -5,11 +5,14 @@ ROOT=${RIGFORGE_PKG_ROOT:-} UNITS="xmrig.service rigforge-upgrade.service rigforge-autotune.timer rigforge-autotune.service rigforge-watchdog.timer rigforge-watchdog.service rigforge-api.service rigforge-api-refresh.timer rigforge-api-refresh.service rigforge-control.service rigforge-control-apply.path rigforge-control-apply.service rigforge-control-upgrade.path rigforge-control-upgrade.service" case "$1" in -remove | deconfigure) +remove) + U=$ROOT/etc/systemd/system if [ -d "$ROOT/run/systemd/system" ]; then + systemctl stop rigforge-upgrade.service for unit in $UNITS; do - systemctl cat "$unit" >/dev/null 2>&1 || continue - systemctl disable --now "$unit" + case "$unit" in *.timer | *.path) svc=${unit%.*}.service ;; *) svc=$unit ;; esac + grep -Eqs '/usr/lib/rigforge/|RIGFORGE_STATE=/var/lib/rigforge$' "$U/$svc" || continue + if grep -qs '^\[Install\]' "$U/$unit"; then systemctl disable --now "$unit"; else systemctl stop "$unit"; fi done fi ;; diff --git a/rigforge.sh b/rigforge.sh index f59389be..735be38f 100755 --- a/rigforge.sh +++ b/rigforge.sh @@ -60,7 +60,7 @@ _script_dir() { case "$src" in */*) d="${src%/*}" ;; *) d=. ;; esac cd -P "${d:-/}" &>/dev/null && pwd } -_pkg_marker="${RIGFORGE_PACKAGE_MARKER:-${BASH_SOURCE[0]%/*}/.rigforge-package}" +_pkg_marker="${RIGFORGE_PACKAGE_MARKER:-$(_script_dir)/.rigforge-package}" [ -n "${RIGFORGE_STATE:-}" ] || [ ! -f "$_pkg_marker" ] || { read -r _pkg_marker <"$_pkg_marker" || : [ "$_pkg_marker" != apt ] || export RIGFORGE_LIB="${RIGFORGE_LIB:-$(_script_dir)}" RIGFORGE_STATE=/var/lib/rigforge diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh index dac1f16e..fd9cf71a 100755 --- a/scripts/build-deb.sh +++ b/scripts/build-deb.sh @@ -3,8 +3,6 @@ set -euo pipefail PROG=${0##*/} PKG_SRC="$(cd "$(dirname "${BASH_SOURCE[0]}")/../packaging/debian" && pwd)" -CLEANUP=() -trap '[[ ${#CLEANUP[@]} -eq 0 ]] || rm -rf -- "${CLEANUP[@]}"' EXIT die() { printf '%s: %s\n' "$PROG" "$1" >&2 @@ -12,7 +10,7 @@ die() { } [[ $# -eq 2 ]] || { - printf 'usage: %s \n' "$PROG" >&2 + printf 'usage: %s \n' "$PROG" >&2 exit 2 } @@ -23,12 +21,8 @@ VERSION=${2#v} umask 022 STAGING=$(mktemp -d) -CLEANUP+=("$STAGING") -case "$ARCHIVE" in -*.tar.gz) tar -xzf "$ARCHIVE" -C "$STAGING" ;; -*.zip) unzip -q "$ARCHIVE" -d "$STAGING" ;; -*) die "unsupported archive format (expect .tar.gz or .zip)" ;; -esac +trap 'rm -rf -- "$STAGING"' EXIT +tar -xzf "$ARCHIVE" -C "$STAGING" SRC="" for d in "$STAGING"/*/; do diff --git a/tests/README.md b/tests/README.md index e4949d6e..521f15b8 100644 --- a/tests/README.md +++ b/tests/README.md @@ -52,7 +52,7 @@ CI median/p90, failures and occupied hours; missing evidence leaves acceptance o | **Linux container e2e** | [`e2e/linux.sh`](e2e/linux.sh) → [`e2e/in-container.sh`](e2e/in-container.sh) | Disposable Ubuntu container, **needs Docker**. **In CI.** | The genuine Linux deploy path against a real (throwaway) `/etc` with real GNU tools (`sed -i`, `tee`, `envsubst`) + idempotency on re-run. Only the heavy/privileged bits (compile, package install, `systemctl`/`mount`) are stubbed. A second pass re-runs the container with `RIGFORGE_APPLIANCE=1` (#348) and proves the appliance contracts on that real `/etc`: units land in `/run/systemd/system`, no package installs, no fstab/limits.conf/logrotate writes, every enable carries `--runtime`. A third script, [`e2e/isolation.sh`](e2e/isolation.sh) (#668), puts the rig on a Docker `--internal` network whose only reachable peer is a SOCKS5 proxy fronting a stand-in GitHub (a TLS git smart-HTTP server plus the releases API). With `tor_socks5` set it runs `upgrade --check`, `setup`, a local `upgrade` with an XMRig pin change and the `control-upgrade` oneshot in its own empty environment, and proves from the proxy's log that every connection named a hostname. It also proves the block is real (a direct connection and a keyless `upgrade --check` fail), that an unreachable proxy fails closed without reaching the upstream, and that the live build survives the failed upgrade. | `make test-e2e` | | **Native macOS e2e** | [`e2e/macos.sh`](e2e/macos.sh) | A real Mac, **manual, local only. Not in CI** (macOS is best effort). | The macOS deploy path with genuine BSD tools the Linux CI can only stub: BSD `sed`, the macOS config profile, `mac_*` process control (real `nohup` + PID file), the launchd login agent, `backup`/`restore`. | `make test-e2e-macos` | | **Coverage gate** | [`coverage.sh`](coverage.sh) | kcov in **Docker**. **In CI.** | Line coverage of `rigforge.sh` and its shell helpers by running `run.sh` under kcov; enforces the committed floor ([`coverage-floor.txt`](coverage-floor.txt)) plus a patch-coverage gate (diff-cover) on changed lines. | `make coverage` | -| **Package upgrade** | [`test-package-upgrade.sh`](test-package-upgrade.sh) | Any host, no Docker. **In CI** (`make test-suite`). | [`../packaging/debian/postinst`](../packaging/debian/postinst) creates the state dir, reloads systemd and prints the first-run step on a first install, and queues only on a greater version with a config, never failing dpkg; `prerm` stops and disables every unit on remove and `postrm` accepts every dpkg action and on purge deletes config, state, control state, every rendered unit, timer and path, the firewall rules and logrotate rule, and keeps an `xmrig.service` the package did not render; `package-upgrade` re-renders units and clears the marker on success, and on failure keeps it, records it for status/doctor and does not restart. | `bash tests/test-package-upgrade.sh` | +| **Package upgrade** | [`test-package-upgrade.sh`](test-package-upgrade.sh) | Any host, no Docker. **In CI** (`make test-suite`). | [`../packaging/debian/postinst`](../packaging/debian/postinst) creates the state dir, reloads systemd and prints the first-run step on a first install, and queues only on a greater version with a config, never failing dpkg; `prerm` stops and disables only the units the package rendered, on remove only and `postrm` accepts every dpkg action and on purge deletes config, state, control state, every rendered unit, timer and path, the firewall rules and logrotate rule, and keeps an `xmrig.service` the package did not render; `package-upgrade` re-renders units and clears the marker on success, and on failure keeps it, records it for status/doctor and does not restart. | `bash tests/test-package-upgrade.sh` | | **Debian package build** | [`test-build-deb.sh`](test-build-deb.sh) | Linux with `dpkg-deb`, no Docker. **In CI** (`make test-suite`). | [`../scripts/build-deb.sh`](../scripts/build-deb.sh) builds a byte-reproducible `.deb` from the release bundle with the marker where `util/package-mode.sh` reads it, the `packaging/debian` maintainer scripts and upgrade unit, the full `Depends`, and no apt keyring. | `bash tests/test-build-deb.sh` | | **Debian package install** | [`test-deb-install.sh`](test-deb-install.sh) | Clean `ubuntu:24.04` container, **needs Docker**. **In CI** (`make test-e2e`). | `apt install` of the built `.deb`, `rigforge --version`, `doctor`, an upgrade to the next version, with config in `/var/lib/rigforge` and nothing written under `/usr/lib/rigforge`, a direct `rigforge.sh` run using the package layout, an upgrade that queues the package upgrade, then remove keeps config, state and units and purge removes them. | `bash tests/test-deb-install.sh` | | **APT feed** | [`test-apt-feed.sh`](test-apt-feed.sh) | Ubuntu 24.04, **root**, no Docker (needs `apt-utils`). **In CI.** (`ci.yml` job) | [`../scripts/build-apt.sh`](../scripts/build-apt.sh) end to end with throwaway keys: refusal of missing/bad fingerprints and keyrings without the secret key; a signed flat feed that `apt-get update` and `download` accept from `file://`; refusal of tampered `Release`/`InRelease`/`.deb` and of a feed signed by another key. | CI only (`sudo bash tests/test-apt-feed.sh`) | diff --git a/tests/test-build-deb.sh b/tests/test-build-deb.sh index 18e02026..ad81ab61 100644 --- a/tests/test-build-deb.sh +++ b/tests/test-build-deb.sh @@ -70,7 +70,8 @@ for s in postinst prerm postrm; do done check "no group- or world-writable or setuid file in the package" "$([ -z "$(find "$X/usr" \( -perm -0020 -o -perm -0002 -o -perm -4000 -o -perm -2000 \) ! -type l)" ] && echo 0 || echo 1)" check "ships no apt keyring" "$([ ! -e "$X/etc/apt" ] && echo 0 || echo 1)" -check "no internal repository references" "$(grep -rqE 'pithead-developer|bench-ci|ai-devkit' "$X" && echo 1 || echo 0)" +check "ships no developer notes" "$([ ! -e "$L/docs/dev" ] && echo 0 || echo 1)" +check "prerm and postrm act on the same unit list" "$([ "$(grep '^UNITS=' "$X/DEBIAN/prerm")" = "$(grep '^UNITS=' "$X/DEBIAN/postrm")" ] && echo 0 || echo 1)" [ "$fail" -eq 0 ] && printf 'build-deb: all checks passed\n' exit "$fail" diff --git a/tests/test-package-mode.sh b/tests/test-package-mode.sh index 081b405f..5c94d2a3 100644 --- a/tests/test-package-mode.sh +++ b/tests/test-package-mode.sh @@ -128,4 +128,18 @@ TREE="$(cd -P "$(dirname "$SCRIPT")" && pwd)" assert_eq "an apt-marked tree defaults to the package layout" "$(layout apt)" "/var/lib/rigforge/config.json $TREE" assert_eq "an explicit RIGFORGE_STATE wins over the apt layout" "$(layout apt "$PL")" "$PL/config.json " assert_eq "a brew-marked tree keeps state beside the script" "$(layout brew)" "$TREE/config.json " +mkdir -p "$PL/tree" +cp -R "$TREE/rigforge.sh" "$TREE/VERSION" "$TREE/util" "$TREE/systemd" "$PL/tree/" +printf 'apt\n' >"$PL/tree/.rigforge-package" +ln -s "$PL/tree/rigforge.sh" "$PL/link.sh" +PLT="$(cd -P "$PL/tree" && pwd)" +for form in bare symlink; do + assert_eq "an apt-marked tree run by $form name uses the package layout" "$( + cd "$PL/tree" || exit + unset RIGFORGE_STATE RIGFORGE_LIB RIGFORGE_HOME RIGFORGE_PACKAGE_MARKER + id() { echo 1000; } + if [ "$form" = bare ]; then source rigforge.sh >/dev/null 2>&1; else source "$PL/link.sh" >/dev/null 2>&1; fi + printf '%s %s' "$CONFIG_JSON" "${RIGFORGE_LIB:-}" + )" "/var/lib/rigforge/config.json $PLT" +done rm -rf "$PL" diff --git a/tests/test-package-upgrade.sh b/tests/test-package-upgrade.sh index ad1b1fa1..9fe56012 100644 --- a/tests/test-package-upgrade.sh +++ b/tests/test-package-upgrade.sh @@ -104,9 +104,16 @@ for arg in upgrade failed-upgrade abort-install abort-upgrade disappear remove p done done maint prerm-remove prerm remove -for u in xmrig.service rigforge-upgrade.service rigforge-watchdog.timer rigforge-autotune.timer rigforge-control.service rigforge-api.service; do +for u in xmrig.service rigforge-watchdog.timer rigforge-autotune.timer rigforge-api-refresh.timer rigforge-control.service rigforge-control-apply.path rigforge-control-upgrade.path rigforge-api.service; do check "prerm remove stops and disables $u" "$(grep -qx "systemctl disable --now $u" "$CALLS" && echo 0 || echo 1)" done +for u in rigforge-upgrade.service rigforge-watchdog.service rigforge-autotune.service rigforge-api-refresh.service rigforge-control-apply.service rigforge-control-upgrade.service; do + check "prerm remove stops the static unit $u without disabling it" "$(grep -qx "systemctl stop $u" "$CALLS" && ! grep -q "disable --now $u" "$CALLS" && echo 0 || echo 1)" +done +LIB=/opt/rigforge STATE=/opt/rigforge maint prerm-foreign prerm remove +check "prerm remove leaves a non-package install's units alone" "$([ "$(cat "$CALLS")" = 'systemctl stop rigforge-upgrade.service' ] && echo 0 || echo 1)" +maint prerm-deconfigure prerm deconfigure +check "prerm deconfigure leaves the miner running" "$([ ! -s "$CALLS" ] && echo 0 || echo 1)" maint prerm-upgrade prerm upgrade check "prerm upgrade leaves the miner running" "$([ ! -s "$CALLS" ] && echo 0 || echo 1)" maint postrm-remove postrm remove From 943def8570e45cebf983c6164b6e03220b220081 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 22:43:43 -0600 Subject: [PATCH 22/26] test: keep the bare-name layout case opaque to shellcheck's source inlining Co-Authored-By: Claude Opus 5.5 --- tests/test-package-mode.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test-package-mode.sh b/tests/test-package-mode.sh index 5c94d2a3..f1422385 100644 --- a/tests/test-package-mode.sh +++ b/tests/test-package-mode.sh @@ -138,7 +138,9 @@ for form in bare symlink; do cd "$PL/tree" || exit unset RIGFORGE_STATE RIGFORGE_LIB RIGFORGE_HOME RIGFORGE_PACKAGE_MARKER id() { echo 1000; } - if [ "$form" = bare ]; then source rigforge.sh >/dev/null 2>&1; else source "$PL/link.sh" >/dev/null 2>&1; fi + entry=rigforge.sh + [ "$form" = bare ] || entry="$PL/link.sh" + source "$entry" >/dev/null 2>&1 printf '%s %s' "$CONFIG_JSON" "${RIGFORGE_LIB:-}" )" "/var/lib/rigforge/config.json $PLT" done From acab221d04b1a47a80d6eeeaca9753120bc9d834 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 23:16:40 -0600 Subject: [PATCH 23/26] docs: ADR 0003 purge line follows the config-as-state ruling Co-Authored-By: Claude Opus 5.5 --- .../0003-package-ownership-upgrade-authority-and-key-custody.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/adr/0003-package-ownership-upgrade-authority-and-key-custody.md b/docs/adr/0003-package-ownership-upgrade-authority-and-key-custody.md index 51cec1f4..eed534c3 100644 --- a/docs/adr/0003-package-ownership-upgrade-authority-and-key-custody.md +++ b/docs/adr/0003-package-ownership-upgrade-authority-and-key-custody.md @@ -29,7 +29,7 @@ Git-clone and appliance installs keep today's behaviour unchanged, with no marke - An apt upgrade of an already-configured host queues the real upgrade **outside dpkg**: postinst writes an upgrade-pending marker under `/var/lib/rigforge` and starts the one-shot `rigforge upgrade` unit via `systemctl start --no-block` (#785). A first install (no config) is inert. - The miner **restarts automatically, but only after a successful upgrade** (owner, 2026-11-20). On failure the previous build keeps running, the marker and failure stay visible in `status`/`doctor`, postinst still exits 0 so dpkg never half-configures the package, and retry is one documented `rigforge upgrade` command. `apt-mark hold` defers. - `brew upgrade` never restarts a running miner — it prints a hint; the auto-restart ruling applies to apt only (#787). -- **Purge** removes config and state (`/var/lib/rigforge`, which holds `config.json` since #780; there is no `/etc/rigforge`) but **never reverts system tuning** — not GRUB, hugepages, MSR or sysctl. Only `rigforge uninstall` undoes tuning (#784). Remove keeps config and state. +- **Purge** deletes `/var/lib/rigforge` (`config.json` included; since #780 it is state that `setup` creates, never a shipped conffile) and any `/etc/rigforge` directory the package owns, and **never reverts system tuning** — not GRUB, hugepages, MSR or sysctl. Only `rigforge uninstall` undoes tuning (#784). Remove keeps config and state. ### D3. Signing-key custody (owner, 2026-11-20 — supersedes pithead #3459) From ffb7c04f443f5e0911d397634aef70cc23be103e Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2026 00:27:47 -0600 Subject: [PATCH 24/26] refactor: move the layout bootstrap into util/layout.sh to fit the file budget rigforge.sh now sources util/layout.sh from its own directory for the apt layout default and the RIGFORGE_LIB/RIGFORGE_STATE validation, so the merge with develop stays at the 6028-line ceiling. The lines move unchanged and the new file joins the kcov include list. Co-Authored-By: Claude Fable 5.2 --- rigforge.sh | 9 ++------- tests/coverage.sh | 2 +- tests/test-coverage-cache.sh | 2 +- util/layout.sh | 10 ++++++++++ 4 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 util/layout.sh diff --git a/rigforge.sh b/rigforge.sh index d8bd9020..40c75d8a 100755 --- a/rigforge.sh +++ b/rigforge.sh @@ -60,13 +60,8 @@ _script_dir() { case "$src" in */*) d="${src%/*}" ;; *) d=. ;; esac cd -P "${d:-/}" &>/dev/null && pwd } -_pkg_marker="${RIGFORGE_PACKAGE_MARKER:-$(_script_dir)/.rigforge-package}" -[ -n "${RIGFORGE_STATE:-}" ] || [ ! -f "$_pkg_marker" ] || { - read -r _pkg_marker <"$_pkg_marker" || : - [ "$_pkg_marker" != apt ] || export RIGFORGE_LIB="${RIGFORGE_LIB:-$(_script_dir)}" RIGFORGE_STATE=/var/lib/rigforge -} -for _v in RIGFORGE_LIB RIGFORGE_STATE; do [ -z "${!_v:-}" ] || [[ ${!_v} =~ ^/[A-Za-z0-9._/-]+$ ]] || exit "$(echo "rigforge: $_v must be a clean absolute path" >&2 && echo 1)"; done -[ -z "${RIGFORGE_LIB:-}" ] || [ "$(id -u)" != 0 ] || [ -z "$(find -H "$RIGFORGE_LIB" -maxdepth 0 \( ! -user root -o -perm -020 -o -perm -002 \) 2>/dev/null)" ] || exit "$(echo "rigforge: RIGFORGE_LIB must be root-owned and not group/world-writable" >&2 && echo 1)" +# shellcheck source=util/layout.sh +source "$(_script_dir)/util/layout.sh" [ "${RIGFORGE_TEST_OVERRIDES:-0}" = 1 ] || unset XMRIG_VERSION XMRIG_COMMIT API_CMD DMIDECODE RDMSR_BIN SERVICE_NAME LOGROTATE_DIR GRUB_DEFAULT FSTAB LIMITS_CONF MODULES_LOAD_DIR MODULES_FILE SYSTEMD_DIR HUGEPAGES_1G_DIR BIN_DIR MEMINFO CPUINFO MSR_MODULE_DIR GOVERNOR_FILE HUGEPAGES_1G_NR NR_HUGEPAGES_FILE CPUFREQ_MAX CPU_SYSFS DMI_DIR SMT_CONTROL LOCKDOWN_FILE RIGFORGE_APPLIANCE_MARKER RIGFORGE_LEGACY_APPLIANCE_UNIT # shellcheck source=util/config-apply-state.sh source "${RIGFORGE_LIB:-$(_script_dir)}/util/config-apply-state.sh" diff --git a/tests/coverage.sh b/tests/coverage.sh index 2ba2410d..986f3e0f 100755 --- a/tests/coverage.sh +++ b/tests/coverage.sh @@ -98,7 +98,7 @@ echo "coverage: running tests/run.sh under kcov (this is slower than 'make test' docker run --rm --platform linux/amd64 --security-opt seccomp=unconfined --cap-add SYS_PTRACE \ -v "$ROOT:/src" -v "$JQ_BIN:/usr/local/bin/jq:ro" -w /src -e RIGFORGE_TEST_OVERRIDES=1 \ --entrypoint kcov "$KCOV_IMAGE" \ - --include-pattern=/src/rigforge.sh,/src/util/proposed-grub.sh,/src/util/config-apply-state.sh,/src/util/randomx.sh,/src/util/benchmark.sh,/src/util/stress.sh,/src/util/control-guards.sh,/src/util/xmrig-overlay.sh \ + --include-pattern=/src/rigforge.sh,/src/util/proposed-grub.sh,/src/util/config-apply-state.sh,/src/util/layout.sh,/src/util/randomx.sh,/src/util/benchmark.sh,/src/util/stress.sh,/src/util/control-guards.sh,/src/util/xmrig-overlay.sh \ --clean /src/coverage ./tests/run.sh # kcov writes root-owned files onto the bind mount; hand them back to the caller so later steps and diff --git a/tests/test-coverage-cache.sh b/tests/test-coverage-cache.sh index c1e6d74a..f66d7b23 100644 --- a/tests/test-coverage-cache.sh +++ b/tests/test-coverage-cache.sh @@ -89,7 +89,7 @@ for arg in "$@"; do jq_mount=${arg%:/usr/local/bin/jq:ro} fi [ "$arg" = --clean ] && have_clean=1 - [ "$arg" = --include-pattern=/src/rigforge.sh,/src/util/proposed-grub.sh,/src/util/config-apply-state.sh,/src/util/randomx.sh,/src/util/benchmark.sh,/src/util/stress.sh,/src/util/control-guards.sh,/src/util/xmrig-overlay.sh ] && have_scope=1 + [ "$arg" = --include-pattern=/src/rigforge.sh,/src/util/proposed-grub.sh,/src/util/config-apply-state.sh,/src/util/layout.sh,/src/util/randomx.sh,/src/util/benchmark.sh,/src/util/stress.sh,/src/util/control-guards.sh,/src/util/xmrig-overlay.sh ] && have_scope=1 [ "$previous" = --platform ] && [ "$arg" = linux/amd64 ] && have_platform=1 previous=$arg done diff --git a/util/layout.sh b/util/layout.sh new file mode 100644 index 00000000..f1ea80c1 --- /dev/null +++ b/util/layout.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# shellcheck shell=bash + +_pkg_marker="${RIGFORGE_PACKAGE_MARKER:-$(_script_dir)/.rigforge-package}" +[ -n "${RIGFORGE_STATE:-}" ] || [ ! -f "$_pkg_marker" ] || { + read -r _pkg_marker <"$_pkg_marker" || : + [ "$_pkg_marker" != apt ] || export RIGFORGE_LIB="${RIGFORGE_LIB:-$(_script_dir)}" RIGFORGE_STATE=/var/lib/rigforge +} +for _v in RIGFORGE_LIB RIGFORGE_STATE; do [ -z "${!_v:-}" ] || [[ ${!_v} =~ ^/[A-Za-z0-9._/-]+$ ]] || exit "$(echo "rigforge: $_v must be a clean absolute path" >&2 && echo 1)"; done +[ -z "${RIGFORGE_LIB:-}" ] || [ "$(id -u)" != 0 ] || [ -z "$(find -H "$RIGFORGE_LIB" -maxdepth 0 \( ! -user root -o -perm -020 -o -perm -002 \) 2>/dev/null)" ] || exit "$(echo "rigforge: RIGFORGE_LIB must be root-owned and not group/world-writable" >&2 && echo 1)" From ba465601ecbc7aad2b907f8c58c30631d842b6af Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2026 00:43:07 -0600 Subject: [PATCH 25/26] Revert "refactor: move the layout bootstrap into util/layout.sh to fit the file budget" Loading util/layout.sh from the script's directory ran code from there before the RIGFORGE_LIB checks whenever RIGFORGE_LIB pointed at another tree. The layout default and the two checks go back inline, unchanged. This reverts commit ffb7c04f443f5e0911d397634aef70cc23be103e. Co-Authored-By: Claude Fable 5.2 --- rigforge.sh | 9 +++++++-- tests/coverage.sh | 2 +- tests/test-coverage-cache.sh | 2 +- util/layout.sh | 10 ---------- 4 files changed, 9 insertions(+), 14 deletions(-) delete mode 100644 util/layout.sh diff --git a/rigforge.sh b/rigforge.sh index 40c75d8a..d8bd9020 100755 --- a/rigforge.sh +++ b/rigforge.sh @@ -60,8 +60,13 @@ _script_dir() { case "$src" in */*) d="${src%/*}" ;; *) d=. ;; esac cd -P "${d:-/}" &>/dev/null && pwd } -# shellcheck source=util/layout.sh -source "$(_script_dir)/util/layout.sh" +_pkg_marker="${RIGFORGE_PACKAGE_MARKER:-$(_script_dir)/.rigforge-package}" +[ -n "${RIGFORGE_STATE:-}" ] || [ ! -f "$_pkg_marker" ] || { + read -r _pkg_marker <"$_pkg_marker" || : + [ "$_pkg_marker" != apt ] || export RIGFORGE_LIB="${RIGFORGE_LIB:-$(_script_dir)}" RIGFORGE_STATE=/var/lib/rigforge +} +for _v in RIGFORGE_LIB RIGFORGE_STATE; do [ -z "${!_v:-}" ] || [[ ${!_v} =~ ^/[A-Za-z0-9._/-]+$ ]] || exit "$(echo "rigforge: $_v must be a clean absolute path" >&2 && echo 1)"; done +[ -z "${RIGFORGE_LIB:-}" ] || [ "$(id -u)" != 0 ] || [ -z "$(find -H "$RIGFORGE_LIB" -maxdepth 0 \( ! -user root -o -perm -020 -o -perm -002 \) 2>/dev/null)" ] || exit "$(echo "rigforge: RIGFORGE_LIB must be root-owned and not group/world-writable" >&2 && echo 1)" [ "${RIGFORGE_TEST_OVERRIDES:-0}" = 1 ] || unset XMRIG_VERSION XMRIG_COMMIT API_CMD DMIDECODE RDMSR_BIN SERVICE_NAME LOGROTATE_DIR GRUB_DEFAULT FSTAB LIMITS_CONF MODULES_LOAD_DIR MODULES_FILE SYSTEMD_DIR HUGEPAGES_1G_DIR BIN_DIR MEMINFO CPUINFO MSR_MODULE_DIR GOVERNOR_FILE HUGEPAGES_1G_NR NR_HUGEPAGES_FILE CPUFREQ_MAX CPU_SYSFS DMI_DIR SMT_CONTROL LOCKDOWN_FILE RIGFORGE_APPLIANCE_MARKER RIGFORGE_LEGACY_APPLIANCE_UNIT # shellcheck source=util/config-apply-state.sh source "${RIGFORGE_LIB:-$(_script_dir)}/util/config-apply-state.sh" diff --git a/tests/coverage.sh b/tests/coverage.sh index 986f3e0f..2ba2410d 100755 --- a/tests/coverage.sh +++ b/tests/coverage.sh @@ -98,7 +98,7 @@ echo "coverage: running tests/run.sh under kcov (this is slower than 'make test' docker run --rm --platform linux/amd64 --security-opt seccomp=unconfined --cap-add SYS_PTRACE \ -v "$ROOT:/src" -v "$JQ_BIN:/usr/local/bin/jq:ro" -w /src -e RIGFORGE_TEST_OVERRIDES=1 \ --entrypoint kcov "$KCOV_IMAGE" \ - --include-pattern=/src/rigforge.sh,/src/util/proposed-grub.sh,/src/util/config-apply-state.sh,/src/util/layout.sh,/src/util/randomx.sh,/src/util/benchmark.sh,/src/util/stress.sh,/src/util/control-guards.sh,/src/util/xmrig-overlay.sh \ + --include-pattern=/src/rigforge.sh,/src/util/proposed-grub.sh,/src/util/config-apply-state.sh,/src/util/randomx.sh,/src/util/benchmark.sh,/src/util/stress.sh,/src/util/control-guards.sh,/src/util/xmrig-overlay.sh \ --clean /src/coverage ./tests/run.sh # kcov writes root-owned files onto the bind mount; hand them back to the caller so later steps and diff --git a/tests/test-coverage-cache.sh b/tests/test-coverage-cache.sh index f66d7b23..c1e6d74a 100644 --- a/tests/test-coverage-cache.sh +++ b/tests/test-coverage-cache.sh @@ -89,7 +89,7 @@ for arg in "$@"; do jq_mount=${arg%:/usr/local/bin/jq:ro} fi [ "$arg" = --clean ] && have_clean=1 - [ "$arg" = --include-pattern=/src/rigforge.sh,/src/util/proposed-grub.sh,/src/util/config-apply-state.sh,/src/util/layout.sh,/src/util/randomx.sh,/src/util/benchmark.sh,/src/util/stress.sh,/src/util/control-guards.sh,/src/util/xmrig-overlay.sh ] && have_scope=1 + [ "$arg" = --include-pattern=/src/rigforge.sh,/src/util/proposed-grub.sh,/src/util/config-apply-state.sh,/src/util/randomx.sh,/src/util/benchmark.sh,/src/util/stress.sh,/src/util/control-guards.sh,/src/util/xmrig-overlay.sh ] && have_scope=1 [ "$previous" = --platform ] && [ "$arg" = linux/amd64 ] && have_platform=1 previous=$arg done diff --git a/util/layout.sh b/util/layout.sh deleted file mode 100644 index f1ea80c1..00000000 --- a/util/layout.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# shellcheck shell=bash - -_pkg_marker="${RIGFORGE_PACKAGE_MARKER:-$(_script_dir)/.rigforge-package}" -[ -n "${RIGFORGE_STATE:-}" ] || [ ! -f "$_pkg_marker" ] || { - read -r _pkg_marker <"$_pkg_marker" || : - [ "$_pkg_marker" != apt ] || export RIGFORGE_LIB="${RIGFORGE_LIB:-$(_script_dir)}" RIGFORGE_STATE=/var/lib/rigforge -} -for _v in RIGFORGE_LIB RIGFORGE_STATE; do [ -z "${!_v:-}" ] || [[ ${!_v} =~ ^/[A-Za-z0-9._/-]+$ ]] || exit "$(echo "rigforge: $_v must be a clean absolute path" >&2 && echo 1)"; done -[ -z "${RIGFORGE_LIB:-}" ] || [ "$(id -u)" != 0 ] || [ -z "$(find -H "$RIGFORGE_LIB" -maxdepth 0 \( ! -user root -o -perm -020 -o -perm -002 \) 2>/dev/null)" ] || exit "$(echo "rigforge: RIGFORGE_LIB must be root-owned and not group/world-writable" >&2 && echo 1)" From 358ac460a8c1c34b7016228e8823761ef194e7e6 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2026 00:47:40 -0600 Subject: [PATCH 26/26] refactor: move _config_replace into util/config-apply-state.sh to fit the file budget Merged with develop, rigforge.sh was 6033 lines against its 6028 ceiling. The config install helper moves unchanged beside the other config-apply helpers, and the comments in the edited hunk go, leaving rigforge.sh at 6024. Co-Authored-By: Claude Fable 5.2 --- rigforge.sh | 11 +---------- util/config-apply-state.sh | 7 +++++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/rigforge.sh b/rigforge.sh index d8bd9020..b28e14f1 100755 --- a/rigforge.sh +++ b/rigforge.sh @@ -4083,16 +4083,7 @@ for path in sys.argv[1:]: PY } -_config_replace() { - local tmp="$CONFIG_JSON.new.$$" - (umask 077 && cp "$1" "$tmp") && chmod 600 "$tmp" && mv -f "$tmp" "$CONFIG_JSON" && return 0 - rm -f "$tmp" - return 1 -} -# Merge an allowlisted, parse-valid staged change into config.json after snapshotting the old one. -# rc 0 = committed, 1 = invalid/rejected, 2 = install failed with old config restored, and 3 = -# storage failed after rename and recovery is uncertain. The caller records the matching terminal. -_control_commit() { # +_control_commit() { local staged="$1" backups="$2" local CONTROL_WRITABLE_KEYS="pools DONATION autotune watchdog watchdog_interval_min max_temp_c" local change allow badkeys stamp backup cand msg diff --git a/util/config-apply-state.sh b/util/config-apply-state.sh index e4f76b21..a7e6b0df 100644 --- a/util/config-apply-state.sh +++ b/util/config-apply-state.sh @@ -73,3 +73,10 @@ _unit_split_env() { [ -z "${RIGFORGE_LIB:-}" ] || e="${e:+$e$'\n'}Environment=RIGFORGE_LIB=$RIGFORGE_LIB" UNIT_ENV="$e" awk '{ print } /^\[Service\]$/ && ENVIRON["UNIT_ENV"] != "" { print ENVIRON["UNIT_ENV"] }' } + +_config_replace() { + local tmp="$CONFIG_JSON.new.$$" + (umask 077 && cp "$1" "$tmp") && chmod 600 "$tmp" && mv -f "$tmp" "$CONFIG_JSON" && return 0 + rm -f "$tmp" + return 1 +}