#!/usr/bin/env bash # Idempotent installer for the cross-machine snapshot bundle. # Run from inside xenia-rs/migration/ on a fresh clone. # # Restores the parts of the working state that live OUTSIDE the xenia-rs # git repo: # 1. Claude auto-memory directory # 2. project-root .claude/settings.json (Stop hook + permissions) # 3. project-root ppc-manual/ # 4. project-root run-canary.sh # 5. xenia-canary clone (if missing) # # Does NOT restore the Sylpheed ISO (manual) or sylpheed.db (regenerate # via analysis tooling after first build). See migration/README.md. set -euo pipefail # Resolve paths from this script's location. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" # xenia-rs/ ROOT_DIR="$(cd "$REPO_DIR/.." && pwd)" # project root (parent of xenia-rs) echo "==> Cross-machine setup" echo " script: $SCRIPT_DIR" echo " repo: $REPO_DIR" echo " root: $ROOT_DIR" echo # ---------- 1. Auto-memory ---------- # Path is derived from Claude Code's cwd-sanitized scheme: every '/' in # the absolute working directory becomes '-'. If the project root path # differs from the original (/home/fabi/RE Project Sylpheed), the memory # directory name MUST differ to match this machine's cwd. CWD_SANITIZED="$(printf '%s' "$REPO_DIR" | tr '/' '-' | sed 's/^-//')" MEMORY_TARGET="$HOME/.claude/projects/-${CWD_SANITIZED}/memory" # But for backward-compat (memory files reference the original absolute # paths), the original directory name is also restored unconditionally. MEMORY_TARGET_ORIG="$HOME/.claude/projects/-home-fabi-RE-Project-Sylpheed/memory" for target in "$MEMORY_TARGET" "$MEMORY_TARGET_ORIG"; do if [ -d "$target" ] && [ "$(ls -A "$target" 2>/dev/null | wc -l)" -gt 0 ]; then echo "==> [skip] memory dir already populated: $target" else echo "==> Installing auto-memory: $target" mkdir -p "$target" cp -a "$SCRIPT_DIR/claude-memory/." "$target/" echo " -> $(ls "$target" | wc -l) files restored" fi done # ---------- 2. Project-root .claude/settings.json ---------- if [ -f "$ROOT_DIR/.claude/settings.json" ]; then echo "==> [skip] $ROOT_DIR/.claude/settings.json already exists" else echo "==> Installing project-root .claude/settings.json (Stop hook + permissions)" mkdir -p "$ROOT_DIR/.claude" cp "$SCRIPT_DIR/project-root/dot-claude/settings.json" "$ROOT_DIR/.claude/settings.json" fi # ---------- 3. ppc-manual ---------- if [ -d "$ROOT_DIR/ppc-manual" ]; then echo "==> [skip] $ROOT_DIR/ppc-manual already exists" else echo "==> Installing ppc-manual (PowerPC reference docs)" cp -a "$SCRIPT_DIR/project-root/ppc-manual" "$ROOT_DIR/ppc-manual" fi # ---------- 4. run-canary.sh ---------- if [ -f "$ROOT_DIR/run-canary.sh" ]; then echo "==> [skip] $ROOT_DIR/run-canary.sh already exists" else echo "==> Installing run-canary.sh helper" cp "$SCRIPT_DIR/project-root/run-canary.sh" "$ROOT_DIR/run-canary.sh" chmod +x "$ROOT_DIR/run-canary.sh" fi # ---------- 5. xenia-canary clone ---------- CANARY_DIR="$ROOT_DIR/xenia-canary" CANARY_REMOTE="https://git.mc02.dev/fabi/Xenia-Canary.git" CANARY_HEAD="6de80dffe261b368ecefee36c9b2b337335228c0" if [ -d "$CANARY_DIR/.git" ]; then echo "==> [skip] xenia-canary already cloned at $CANARY_DIR" echo " HEAD: $(git -C "$CANARY_DIR" rev-parse HEAD)" else echo "==> Cloning xenia-canary into $CANARY_DIR" if git clone "$CANARY_REMOTE" "$CANARY_DIR"; then git -C "$CANARY_DIR" checkout "$CANARY_HEAD" || \ echo " [warn] could not check out pinned HEAD $CANARY_HEAD; using whatever HEAD the clone defaulted to" else echo " [warn] xenia-canary clone failed; you can clone manually later" echo " git clone $CANARY_REMOTE $CANARY_DIR" echo " git -C $CANARY_DIR checkout $CANARY_HEAD" fi fi # ---------- Final checklist ---------- cat < Setup complete. Remaining manual steps: 1. Sylpheed ISO (cannot ship via git): Copy your local copy of "Project Sylpheed - Arc of Deception (USA, Europe) (En,Ja).iso" into $ROOT_DIR/ 2. Build xenia-rs: cd "$REPO_DIR" cargo build --release 3. Build xenia-canary Debug (only if you intend to run cross-runtime probes): cd "$CANARY_DIR" cmake --preset linux-debug # or whatever invocation your canary tree expects cmake --build build/ 4. Regenerate sylpheed.db (analyzer reads XEX from the ISO): cd "$REPO_DIR" # Check current --help for exact subcommand; the analysis crates are # under crates/xenia-analysis/ and crates/xenia-app/src/main.rs cargo run --release --bin xenia-rs -- analyze \\ "$ROOT_DIR/Project Sylpheed - Arc of Deception (USA, Europe) (En,Ja).iso" 5. Switch back to whatever branch you want to continue work on. The audit history (audit-findings.md + audit-runs/) and migration/ bundle are already on chore/portable-snapshot. Either: - keep working on chore/portable-snapshot (simplest), OR - merge it into master and continue on master. 6. Start Claude Code. Memory loads automatically when cwd matches: cd "$REPO_DIR" claude Read MEMORY.md first; the last paused audit is AUDIT-058 with AUDIT-059 recommended in its memory file. EOF