#!/bin/bash # Verify an RFS flist manifest: inspect, tree, and optional mount test (best-effort) # This script is safe to run on developer machines; mount test may require root and FUSE policy. set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=/dev/null source "${HERE}/common.sh" usage() { cat <<'EOF' Usage: scripts/rfs/verify-flist.sh -m path/to/manifest.fl [--tree] [--mount] [--mountpoint DIR] Actions: - Inspect manifest metadata (always) - Tree view of entries (--tree) - Optional mount test (--mount) to a temporary or given mountpoint Notes: - Mount test typically requires root and proper FUSE configuration. - On success, a quick directory listing is shown, then the mount is unmounted. EOF } section() { echo -e "\n==== $* ====\n"; } MANIFEST="" DO_TREE=0 DO_MOUNT=0 MOUNTPOINT="" # Parse args if [[ $# -eq 0 ]]; then usage exit 1 fi while [[ $# -gt 0 ]]; do case "$1" in -m|--manifest) MANIFEST="${2:-}"; shift 2;; --tree) DO_TREE=1; shift;; --mount) DO_MOUNT=1; shift;; --mountpoint) MOUNTPOINT="${2:-}"; shift 2;; -h|--help) usage; exit 0;; *) echo "Unknown argument: $1" >&2; usage; exit 1;; esac done if [[ -z "${MANIFEST}" || ! -f "${MANIFEST}" ]]; then log_error "Manifest not found: ${MANIFEST:-}" exit 1 fi # Ensure rfs binary is available rfs_common_locate_rfs section "Inspecting manifest" safe_execute "${RFS_BIN}" flist inspect -m "${MANIFEST}" || { log_warn "rfs flist inspect failed (old rfs?)" log_warn "Try: ${RFS_BIN} inspect ${MANIFEST}" } if [[ ${DO_TREE} -eq 1 ]]; then section "Listing manifest tree" safe_execute "${RFS_BIN}" flist tree -m "${MANIFEST}" 2>/dev/null || { log_warn "rfs flist tree failed; attempting fallback 'tree'" safe_execute "${RFS_BIN}" tree -m "${MANIFEST}" || true } fi if [[ ${DO_MOUNT} -eq 1 ]]; then section "Mount test" if [[ "$(id -u)" -ne 0 ]]; then log_warn "Mount test skipped: requires root (uid 0)" else # Decide mountpoint local_mp_created=0 if [[ -z "${MOUNTPOINT}" ]]; then MOUNTPOINT="$(mktemp -d /tmp/rfs-mnt.XXXXXX)" local_mp_created=1 else mkdir -p "${MOUNTPOINT}" fi log_info "Mounting ${MANIFEST} -> ${MOUNTPOINT}" set +e # Best-effort background mount (setsid "${RFS_BIN}" mount -m "${MANIFEST}" "${MOUNTPOINT}" >/tmp/rfs-mount.log 2>&1) & mpid=$! sleep 2 ls -la "${MOUNTPOINT}" | head -n 50 || true # Try to unmount and stop background process umount "${MOUNTPOINT}" 2>/dev/null || fusermount -u "${MOUNTPOINT}" 2>/dev/null || true kill "${mpid}" 2>/dev/null || true set -e if [[ ${local_mp_created} -eq 1 ]]; then rmdir "${MOUNTPOINT}" 2>/dev/null || true fi log_info "Mount test done (see /tmp/rfs-mount.log if issues)" fi fi section "Verify complete" log_info "Manifest: ${MANIFEST}"