#!/usr/bin/env bash # apply-rb-suffix.sh — Apply the +rb version build-metadata suffix to all Cat 2 forks. # # This script is now a thin wrapper around sync-versions.sh Phase 2. # It exists for backward compatibility and focused Cat-2-only operation. # # Policy (local/AGENTS.md § "Version conventions"): # # Every Cat 2 fork version MUST be `+rb` where: # = the upstream version the fork currently tracks # = the current Red Bear OS git branch (e.g. 0.2.5) # # The `+rb` suffix is Cargo build metadata. It does NOT affect # SemVer precedence and allows transitive crates.io deps requiring # `^X.Y.Z` to resolve to the local fork via [patch.crates-io]. # # Usage: # ./local/scripts/apply-rb-suffix.sh # Apply +rb to all # ./local/scripts/apply-rb-suffix.sh --check # Verify only # ./local/scripts/apply-rb-suffix.sh --rollback # Revert to stable X.Y.Z # # For full Cat 1 + Cat 2 sync, use sync-versions.sh instead. set -euo pipefail ROOT="$(cd "$(dirname "$0")/../.." && pwd)" cd "$ROOT" CHECK_ONLY=0 ROLLBACK=0 while [[ $# -gt 0 ]]; do case "$1" in --check) CHECK_ONLY=1 ;; --rollback) ROLLBACK=1 ;; *) echo "Unknown option: $1" >&2; exit 1 ;; esac shift done if [[ $CHECK_ONLY -eq 1 ]] && [[ $ROLLBACK -eq 1 ]]; then echo "ERROR: --check and --rollback are mutually exclusive" >&2 exit 1 fi # ---- Determine branch version ---- BRANCH="$(git branch --show-current 2>/dev/null || echo "")" if [[ -z "$BRANCH" ]]; then echo "ERROR: cannot determine current git branch" >&2 exit 1 fi BRANCH_VERSION="$(echo "$BRANCH" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || true)" if [[ -z "$BRANCH_VERSION" ]]; then echo "ERROR: branch '$BRANCH' does not contain a semantic version" >&2 exit 1 fi RB_SUFFIX="+rb${BRANCH_VERSION}" # ---- Rollback mode: strip all +rb suffixes ---- if [[ $ROLLBACK -eq 1 ]]; then echo "=== Rolling back Cat 2 forks to stable versions (stripping +rb*) ===" for fork_dir in local/sources/*/; do [ -d "$fork_dir" ] || continue fork_name=$(basename "$fork_dir") f="${fork_dir}Cargo.toml" [ -f "$f" ] || continue if ! grep -qE '^[[:space:]]*\[(package|workspace\.package)\]' "$f" 2>/dev/null; then continue fi current="$(grep -E '^version\s*=' "$f" | head -1 | sed 's/.*"\(.*\)".*/\1/' || true)" [[ -n "$current" ]] || continue if [[ "$current" == *"+rb"* ]]; then base="$(echo "$current" | sed -E 's/\+rb([0-9]+(\.[0-9]+\.[0-9]+)?)$//')" sed -i "s|^version = \"${current}\"|version = \"${base}\"|" "$f" echo " ROLLBACK: $fork_name $current → $base" fi done echo "Rolled back to stable versions." exit 0 fi # ---- List of Cat 2 forks ---- CAT2_FORKS=( syscall libredox relibc kernel base bootloader installer redoxfs userutils redox-scheme ) # ---- Apply or check ---- DRIFT=0 APPLIED=0 echo "=== Cat 2 fork versions (suffix: $RB_SUFFIX) ===" for fork in "${CAT2_FORKS[@]}"; do f="local/sources/${fork}/Cargo.toml" if [[ ! -f "$f" ]]; then echo " SKIP ${fork}: no Cargo.toml" continue fi if ! grep -qE '^[[:space:]]*\[(package|workspace\.package)\]' "$f" 2>/dev/null; then echo " SKIP ${fork}: workspace-only root" continue fi current="$(grep -E '^version\s*=' "$f" | head -1 | sed 's/.*"\(.*\)".*/\1/' || true)" [[ -n "$current" ]] || { echo " SKIP ${fork}: empty version"; continue; } base="$(echo "$current" | sed -E 's/(\+rb[0-9]+(\.[0-9]+\.[0-9]+)?)+$//')" target="${base}${RB_SUFFIX}" if [[ "$current" == "$target" ]]; then echo " OK ${fork}: ${target}" continue fi if [[ $CHECK_ONLY -eq 1 ]]; then echo " DRIFT ${fork}: ${current} → ${target}" DRIFT=$((DRIFT + 1)) else sed -i "s|^version = \"${current}\"|version = \"${target}\"|" "$f" echo " SET ${fork}: ${current} → ${target}" APPLIED=$((APPLIED + 1)) fi done echo "" if [[ $CHECK_ONLY -eq 1 ]]; then if [[ $DRIFT -gt 0 ]]; then echo "FAIL: $DRIFT fork(s) out of policy (expected $RB_SUFFIX)" exit 1 fi echo "PASS: all Cat 2 forks have $RB_SUFFIX suffix" exit 0 fi echo "Applied $RB_SUFFIX suffix to $APPLIED fork(s)" # ---- Verify content matches upstream ---- SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" if [ -x "$SCRIPT_DIR/verify-fork-versions.sh" ]; then if ! "$SCRIPT_DIR/verify-fork-versions.sh" 2>&1 | grep -q "^All Cat 2 forks pass"; then echo "WARNING: verify-fork-versions.sh found content mismatches." >&2 echo " The +rb suffix is applied but some forks may not match upstream." >&2 fi fi