Files
RedBear-OS/local/scripts/archive-sources.sh
T
vasilito 5851974b20 feat: build system transition to release fork + archive hardening
Release fork infrastructure:
- REDBEAR_RELEASE=0.1.1 with offline enforcement (fetch/distclean/unfetch blocked)
- 195 BLAKE3-verified source archives in standard format
- Atomic provisioning via provision-release.sh (staging + .complete sentry)
- 5-phase improvement plan: restore format auto-detection, source tree
  validation (validate-source-trees.py), archive-map.json, REPO_BINARY fallback

Archive normalization:
- Removed 87 duplicate/unversioned archives from shared pool
- Regenerated all archives in consistent format with source/ + recipe.toml
- BLAKE3SUMS and manifest.json generated from stable tarball set

Patch management:
- verify-patches.sh: pre-sync dry-run report (OK/REVERSED/CONFLICT)
- 121 upstream-absorbed patches moved to absorbed/ directories
- 43 active patches verified clean against rebased sources
- Stress test: base updated to upstream HEAD, relibc reset and patched

Compilation fixes:
- relibc: Vec imports in redox-rt (proc.rs, lib.rs, sys.rs)
- relibc: unsafe from_raw_parts in mod.rs (2024 edition)
- fetch.rs: rev comparison handles short/full hash prefixes
- kibi recipe: corrected rev mismatch

New scripts: restore-sources.sh, provision-release.sh, verify-sources-archived.sh,
check-upstream-releases.sh, validate-source-trees.py, verify-patches.sh,
repair-archive-format.sh, generate-manifest.py

Documentation: AGENTS.md, README.md, local/AGENTS.md updated for release fork model
2026-05-02 01:41:17 +01:00

211 lines
6.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# archive-sources.sh — Export fully-patched source archives for Red Bear OS.
#
# Usage:
# ./local/scripts/archive-sources.sh [--release=<ver>] [--all] [--recipe <path>] [--target <triple>]
#
# Creates versioned, fully-patched source archives in sources/<target>/
# or sources/.staging/redbear-<release>/tarballs/:
# <category>-<pkgname>-v<version>-patched.tar.gz
#
# Each archive contains: source/ (fully patched) + recipe.toml
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
TARGET="${TARGET:-x86_64-unknown-redox}"
RELEASE=""
SOURCES_DIR=""
MANIFEST=""
GREEN='\033[1;32m'
RED='\033[1;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
status() { echo -e "${GREEN}==>${NC} $*"; }
warn() { echo -e "${YELLOW}WARN${NC}: $*"; }
err() { echo -e "${RED}ERROR${NC}: $*" >&2; }
extract_version() {
local recipe="$1"
local recipe_dir
recipe_dir=$(dirname "$recipe")
local ver=""
# Try tar URL version extraction — handles formats:
# pkg-1.2.3.tar.xz, pkg-v6.10.0.tar.gz, /archive/v6.10.0/pkg-v6.10.0.tar.gz
ver=$(grep -oP 'tar\s*=\s*".*?(?:/|-)v?(\d+\.\d+(?:\.\d+)?)\.(?:tar|tgz)' "$recipe" 2>/dev/null | grep -oP '\d+\.\d+(?:\.\d+)?' | head -1)
if [ -z "$ver" ]; then
# Fallback: KDE archive URLs like /archive/v6.10.0/pkgname-v6.10.0.tar.gz
ver=$(grep -oP '/archive/v(\d+\.\d+(?:\.\d+)?)/' "$recipe" 2>/dev/null | grep -oP '\d+\.\d+(?:\.\d+)?' | head -1)
fi
if [ -n "$ver" ]; then
echo "$ver"
return
fi
# Try explicit rev field
ver=$(grep -oP 'rev\s*=\s*"([a-f0-9]+)"' "$recipe" 2>/dev/null | grep -oP '[a-f0-9]{7,}' | head -1)
if [ -n "$ver" ]; then
echo "${ver:0:7}"
return
fi
# Try git HEAD if source directory exists with .git
local source_dir="${recipe_dir}/source"
if [ -d "${source_dir}/.git" ]; then
ver=$(git -C "$source_dir" rev-parse --short HEAD 2>/dev/null)
if [ -n "$ver" ]; then
echo "$ver"
return
fi
fi
# Fallback
echo "unknown"
}
extract_pkgname() {
local recipe_dir="$1"
basename "$recipe_dir"
}
extract_category() {
local recipe_dir="$1"
# recipe_dir is like recipes/core/base or local/recipes/system/redbear-authd
# Extract the category (parent of pkgname)
local parent
parent=$(dirname "$recipe_dir")
basename "$parent"
}
archive_recipe() {
local recipe_dir="$1"
local recipe="${recipe_dir}/recipe.toml"
if [ ! -f "$recipe" ]; then
warn "No recipe.toml at $recipe_dir — skipping"
return 1
fi
local pkgname version category archive_name
pkgname=$(extract_pkgname "$recipe_dir")
version=$(extract_version "$recipe")
category=$(extract_category "$recipe_dir")
archive_name="${category}-${pkgname}-v${version}-patched.tar.gz"
local archive_path="${SOURCES_DIR}/${archive_name}"
# Check if source directory exists
local source_dir="${recipe_dir}/source"
if [ ! -d "$source_dir" ]; then
warn "No source/ in $recipe_dir — skipping (may be a meta-package)"
return 1
fi
# Create archive with source + recipe
status "Archiving ${pkgname} v${version}..."
if tar -czf "$archive_path" -C "$(dirname "$recipe_dir")" "$(basename "$recipe_dir")/source" "$(basename "$recipe_dir")/recipe.toml" 2>/dev/null; then
local size
size=$(du -h "$archive_path" | cut -f1)
echo -e " ${GREEN}${NC} ${archive_name} (${size})"
echo "${archive_name}" >> "$MANIFEST"
return 0
else
err "Failed to archive ${pkgname}"
return 1
fi
}
archive_all() {
> "$MANIFEST"
local count=0 failed=0 skipped=0
# Find all recipe directories with recipe.toml files
while IFS= read -r -d '' recipe_file; do
local recipe_dir
recipe_dir=$(dirname "$recipe_file")
# Skip if already in sources/ (avoid double-archiving)
local pkgname
pkgname=$(basename "$recipe_dir")
if archive_recipe "$recipe_dir"; then
count=$((count + 1))
else
failed=$((failed + 1))
fi
done < <(find "${PROJECT_ROOT}/recipes" "${PROJECT_ROOT}/local/recipes" -name "recipe.toml" -print0 2>/dev/null)
echo ""
status "Archive complete: ${count} packages, ${failed} failures → ${SOURCES_DIR}"
}
# ── Main ────────────────────────────────────────────────────────────
MODE=""
RECIPE_PATH=""
while [ $# -gt 0 ]; do
case "$1" in
--release=*)
RELEASE="${1#*=}"
;;
--recipe)
if [ -z "${2:-}" ]; then
err "--recipe requires a path"
exit 1
fi
MODE="recipe"
RECIPE_PATH="$2"
shift
;;
--all)
MODE="all"
;;
*)
echo "Usage: $0 [--release=<ver>] --all | --recipe <path>"
echo ""
echo " --release=<ver> Optional release staging target (e.g. 0.2.0)"
echo " --all Archive all recipes with source directories"
echo " --recipe PATH Archive a specific recipe (e.g. recipes/core/base)"
echo ""
echo " Environment: TARGET=x86_64-unknown-redox (default)"
exit 1
;;
esac
shift
done
if [ -n "$RELEASE" ]; then
SOURCES_DIR="${PROJECT_ROOT}/sources/.staging/redbear-${RELEASE}/tarballs"
else
SOURCES_DIR="${PROJECT_ROOT}/sources/${TARGET}"
fi
MANIFEST="${SOURCES_DIR}/packages.txt"
mkdir -p "${SOURCES_DIR}"
case "$MODE" in
recipe)
status "Writing archives to ${SOURCES_DIR}"
> "$MANIFEST"
archive_recipe "${PROJECT_ROOT}/${RECIPE_PATH}"
;;
all)
status "Writing archives to ${SOURCES_DIR}"
archive_all
;;
*)
echo "Usage: $0 [--release=<ver>] --all | --recipe <path>"
echo ""
echo " --release=<ver> Optional release staging target (e.g. 0.2.0)"
echo " --all Archive all recipes with source directories"
echo " --recipe PATH Archive a specific recipe (e.g. recipes/core/base)"
echo ""
echo " Environment: TARGET=x86_64-unknown-redox (default)"
exit 1
;;
esac