Files
salman d3184ea205 Record and verify runtime build identity
Add a versioned manifest that records actual ROOT/musrfit versions, native ELF architecture, musrfit revision, and SHA-256 fingerprints independently of the GUI version. Source builds also record checkout provenance and CMake options.

Require matching metadata during Linux packaging and WSL staging, reject mixed or incorrectly labelled runtimes, and support explicit recording of existing trees without inventing historical build settings. Add regression coverage and document the build-only metadata workflow.
2026-10-25 16:08:41 +01:00

86 lines
2.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright (C) 2026 Zaher Salman
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Check a Linux ROOT + musrfit tree before it becomes a runtime artifact. This
# also runs inside the WSL staging container, after the tree has been relocated.
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
working_dir="$PWD"
mode=check
if [ "${1:-}" = "--record-manifest" ]; then
mode=record
shift
fi
if [ "$#" -lt 1 ]; then
echo "Usage: bash validate-runtime.sh [--record-manifest] RUNTIME_DIRECTORY [--arch ARCH]" >&2
exit 2
fi
if [ ! -d "$1" ]; then
echo "ERROR: runtime directory not found: $1" >&2
exit 1
fi
runtime_dir="$(cd -- "$1" && pwd -P)"
shift
check_seconds="${RUNTIME_CHECK_TIMEOUT:-15}"
if [[ ! "$check_seconds" =~ ^[1-9][0-9]*$ ]]; then
echo "ERROR: RUNTIME_CHECK_TIMEOUT must be a positive number of seconds" >&2
exit 2
fi
tools=(musrfit musrt0 musrview msr2data dump_header root-config)
failed=0
for tool in "${tools[@]}"; do
if [ ! -f "$runtime_dir/bin/$tool" ] || [ ! -x "$runtime_dir/bin/$tool" ]; then
echo "ERROR: required runtime tool is missing or not executable: $runtime_dir/bin/$tool" >&2
failed=1
fi
done
if [ ! -d "$runtime_dir/lib" ]; then
echo "ERROR: runtime library directory is missing: $runtime_dir/lib" >&2
failed=1
fi
if [ ! -f "$runtime_dir/musrfit_startup.xml" ] || [ ! -r "$runtime_dir/musrfit_startup.xml" ] \
|| [ ! -s "$runtime_dir/musrfit_startup.xml" ]; then
echo "ERROR: runtime startup XML is missing, unreadable, or empty: $runtime_dir/musrfit_startup.xml" >&2
failed=1
fi
if [ "$failed" -ne 0 ]; then
exit 1
fi
# Do not let the developer's ROOT installation or working directory hide a
# broken bundle. Version commands need no display, run data, or writable prefix.
export ROOTSYS="$runtime_dir"
export MUSRFITPATH="$runtime_dir"
export LD_LIBRARY_PATH="$runtime_dir/lib"
export PATH="$runtime_dir/bin:/usr/bin:/bin"
unset LD_PRELOAD
if ! timeout_bin="$(command -v timeout)"; then
echo "ERROR: runtime validation requires GNU timeout (coreutils)" >&2
exit 1
fi
check_dir="$(mktemp -d "${TMPDIR:-/tmp}/musrflow-runtime-check.XXXXXX")"
trap 'rm -rf "$check_dir"' EXIT
cd "$check_dir"
echo "Checking runtime: $runtime_dir"
for tool in "${tools[@]}"; do
if output="$("$timeout_bin" --kill-after=2s "${check_seconds}s" "$runtime_dir/bin/$tool" --version 2>&1)"; then
printf ' ok %s\n%s\n' "$tool" "$output"
printf '%s\n' "$output" > "$check_dir/$tool.version"
else
status=$?
printf 'ERROR: %s --version failed (exit %s)\n%s\n' "$tool" "$status" "$output" >&2
failed=1
fi
done
if [ "$failed" -ne 0 ]; then
exit 1
fi
# Parse JSON and bind its identity to the actual tools, not the GUI release name.
cd "$working_dir"
LD_LIBRARY_PATH= python3 "$here/runtime-manifest.py" "$mode" "$runtime_dir" "$check_dir" "$@"
echo "Runtime validation passed."