Files

41 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# sage-1004/1006 Window B rehearsal, step 1: seed a scratch root at 5fa9cc8f2 and 3h on stand-in units, then adopt.
# Real 5fa9cc8f2 bus host (no --pm, PM launch emulated), healthz stand-in for the Console. Scratch paths only.
set -euo pipefail
. /home/jwoltje/darkwing-scratch/r1004/b/env.sh
[ ! -e "$RB" ] || { echo "seed.sh: $RB exists; remove it first" >&2; exit 1; }
[ ! -e "$LOGF" ] || { echo "seed.sh: $LOGF exists" >&2; exit 1; }
! (exec 3<>/dev/tcp/127.0.0.1/$PORT) 2>/dev/null || { echo "seed.sh: port $PORT is in use" >&2; exit 1; }
mkdir -p "$RB"/{home,cfg/businesses,xcfg,xdata,xstate,run,sd,bin,tmp,data/notify/mosaic-stack}
chmod 700 "$RB/run"
cat > "$RB/cfg/config.json" <<EOF
{"configVersion":1,"environment":"development","dataRoot":"$RB/data","execution":{"backend":"docker","provider":"zai","model":"glm-5.3-flash","adapter":"mock"}}
EOF
cp "$R/bfiles/B/businesses/mosaic-stack.json" "$RB/cfg/businesses/mosaic-stack.json"
printf '{"notifyVersion":1,"binding":null}' > "$RB/data/notify/mosaic-stack/notify.json"; chmod 600 "$RB/data/notify/mosaic-stack/notify.json"
step "root: $RB; business file $(sha256sum < "$RB/cfg/businesses/mosaic-stack.json" | cut -c1-64) (scratch-business-B.json: Window A's plug-ins, usage-source transcript and channel cli,webui)"
# The broker refuses to boot unless every credential file in the business file exists, mode 0600. These are
# FAKE placeholder strings, not tokens; both base URLs in the file are 127.0.0.1:9.
NS="$R/bfiles/nosecret"; [ ! -e "$NS" ] || { echo "seed.sh: $NS exists; remove it first" >&2; exit 1; }
mkdir -m 700 "$NS"
for f in $(node -e 'const b=require(process.argv[1]);const o=[];(function w(x){if(x&&typeof x==="object")for(const[k,v]of Object.entries(x)){if(k==="file"&&typeof v==="string")o.push(v);w(v)}})(b);console.log(o.join(" "))' "$RB/cfg/businesses/mosaic-stack.json"); do
case "$f" in "$NS"/*) ;; *) echo "seed.sh: credential path outside $NS: $f" >&2; exit 1;; esac
printf 'scratch-fake-placeholder-%s\n' "$(basename "$f" .token)" > "$f"; chmod 600 "$f"
done
step "fake credential files: $(ls "$NS" | wc -l) under $NS, each 'scratch-fake-placeholder-<name>', mode 0600"
step "tool: $REPO (git clone --shared of the canonical checkout) at $(git -C "$REPO" rev-parse HEAD), scripts/stack-release.sh blob $(git -C "$REPO" hash-object scripts/stack-release.sh)"
printf '#!/usr/bin/env bash\n# mosaic-cli wrapper (Q81, agents/sage/work/q81/mosaic-cli.sh)\n[ "${1:-}" = __lease-capability ] && exec "%s/mosaic-old" "$@"\nexit 1\n' "$RB/bin" > "$RB/bin/mosaic"; chmod 755 "$RB/bin/mosaic"
run() { step "run: $*"; local rc=0; (cd "$REPO" && "${E[@]}" "$@") >> "$LOGF" 2>&1 || rc=$?; step "exit $rc"; return $rc; }
run scripts/bus-service.sh install --copy $OLD --copies "$COPIES" --pm --claude "$B/claude"
run systemctl --user start [email protected]
run scripts/webui-service.sh install --copy $OLD --copies "$COPIES" --port $PORT --business mosaic-stack
run systemctl --user start mosaic-webui.service
run scripts/stack-copy.sh wrapper $OLD --copies "$COPIES" --bin "$RB/bin"
run "$COPIES/$OLD/scripts/mosaic" bus status --json
run "$COPIES/$OLD/scripts/mosaic" launches list --json
run scripts/stack-release.sh adopt mosaic-stack --copies "$COPIES" --bin "$RB/bin"
run scripts/stack-release.sh status mosaic-stack --copies "$COPIES" --bin "$RB/bin" || true
step "pointer: $(cat "$RB/data/state/stack-active.json")"
step "store schema: $(node -e 'const {DatabaseSync}=require("node:sqlite");const d=new DatabaseSync(process.argv[1],{readOnly:true});console.log(JSON.stringify(d.prepare("select * from meta").all()))' "$RB/data/bus/bus.sqlite" 2>&1 || true)"
cat "$LOGF"