From b3c5d50c293b16ab1ce6e8ba25fedbfcdb493daf Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 21 Oct 2026 10:32:12 +0200 Subject: slackrepo_setup: build in .new and swap; sbshadow --yes A failed clone no longer leaves the VM without a tree: the new tree is built in $REPO.new and swapped in only when clone and subtree adds succeed. sbshadow runs with --yes, since sb-builder runs this script as a job with no stdin and the bare prompt would read EOF as "no". The old tree is deleted once shadowing succeeds and kept as $REPO.old if it fails. SBO_REPO overrides the path, as in sbshadow. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 6 ++++-- README.md | 8 +++++--- slackrepo_setup_SBo-danix.sh | 47 ++++++++++++++++++++++++++------------------ 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 5bf3ac3..ffe1953 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -65,8 +65,10 @@ the config with `/usr/local/bin/` rewritten to a stub dir (stub `sb-publish`, ./slackrepo_setup_SBo-danix.sh ``` -Destructive: `rm -rf`s `$REPO` on every run to start clean, then re-clones upstream. Interactive -`read` prompt inside `sbshadow` is the only confirmation (declining exits 0, run continues). +Destructive: builds a fresh tree in `$REPO.new`, swaps it in (old tree to `$REPO.old`), runs +`sbshadow --yes`, then deletes `$REPO.old`. A failed clone or subtree add leaves `$REPO` untouched; +a failed `sbshadow` keeps `$REPO.old` for a manual rollback. Non-interactive: sb-builder runs it +as a job with no stdin. `SBO_REPO` overrides the path, for trying it on a throwaway repo. ## Architecture diff --git a/README.md b/README.md index 04e525e..06a8b45 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,11 @@ upstream tree), so the overlay version wins. ## Files -- `slackrepo_setup_SBo-danix.sh`: full rebuild. Wipes the repo, clones upstream, - adds the subtrees, then runs `sbshadow`. **Destructive**: `rm -rf`s the repo - on every run. +- `slackrepo_setup_SBo-danix.sh`: full rebuild. Clones upstream and adds the + subtrees in `$REPO.new`, swaps it in, then runs `sbshadow --yes`. + **Destructive**: the old tree is deleted once shadowing succeeds; a failed + clone leaves it untouched, a failed `sbshadow` leaves it as `$REPO.old`. + sb-builder runs it as the `rebuild-tree` job. - `sbshadow`: reconciles shadowing both ways. Shadows upstream packages now carried in an overlay, and restores (unshadows) upstream packages no longer carried, from the pristine `current` branch. Asks once before changing diff --git a/slackrepo_setup_SBo-danix.sh b/slackrepo_setup_SBo-danix.sh index be2b1dd..f54e947 100644 --- a/slackrepo_setup_SBo-danix.sh +++ b/slackrepo_setup_SBo-danix.sh @@ -5,45 +5,54 @@ # under the terms of the GNU General Public License version 2 as published # by the Free Software Foundation. See the LICENSE file for details. +# Rebuild the SBo-danix tree: fresh clone of upstream plus the personal and +# pentesting subtrees, built beside the live tree and swapped in, then shadowed. +# Run by sb-builder as the rebuild-tree job (no stdin). +# SBO_REPO overrides the repo path (used to test against a throwaway repo). set -euo pipefail -REPO="/var/lib/sbopkg/SBo-danix" +REPO="${SBO_REPO:-/var/lib/sbopkg/SBo-danix}" +NEW="$REPO.new" +OLD="$REPO.old" +export SBO_REPO="$REPO" # sbshadow reads the same override # ── safety guard ────────────────────────────────────────────────────────────── -if [[ -z "$REPO" ]]; then - echo "ERROR: REPO is unset or empty. Aborting." >&2 +if [[ -z "$REPO" || "$REPO" == / ]]; then + echo "ERROR: REPO is unset, empty or /. Aborting." >&2 exit 1 fi -# ── clean slate ─────────────────────────────────────────────────────────────── -if [[ -d "$REPO" ]]; then - echo "Removing existing repo at $REPO..." - rm -rf "$REPO" -fi - -# ── clone and branch ────────────────────────────────────────────────────────── -echo "Cloning upstream SBo repository..." -git clone https://github.com/Ponce/slackbuilds.git "$REPO" || { - echo "ERROR: git clone failed. Aborting." >&2 - exit 1 -} +# ── build the new tree beside the live one ──────────────────────────────────── +# A failure here leaves $REPO untouched. +rm -rf "$NEW" +echo "Cloning upstream SBo repository into $NEW..." +git clone https://github.com/Ponce/slackbuilds.git "$NEW" -cd "$REPO" +cd "$NEW" git checkout current git checkout -b danix-current -# ── add subtrees ────────────────────────────────────────────────────────────── echo "Adding personal subtrees..." git remote add my-slackbuilds https://github.com/danixland/my-slackbuilds.git git remote add my-pentesting https://github.com/danixland/Slackware-Pentesting-Suite.git git subtree add --prefix=personal my-slackbuilds main --squash git subtree add --prefix=pentesting my-pentesting main --squash +cd / + +# ── swap ────────────────────────────────────────────────────────────────────── +rm -rf "$OLD" +if [[ -d "$REPO" ]]; then + mv "$REPO" "$OLD" +fi +mv "$NEW" "$REPO" # ── shadow upstream packages + regen hintfiles (sbshadow owns both) ────────── -# sbshadow must be on PATH (deployed next to this script on the build system). -sbshadow +# --yes: as a job stdin is /dev/null, so a prompt would read "no". +# If it fails, set -e keeps $OLD for a manual rollback (mv it back). +sbshadow --yes +rm -rf "$OLD" echo echo "Done. Repository ready at $REPO" -- cgit v1.2.3