#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")" # LinuxCNC source basis: manifest listers expose LinuxCNC-root relative source # entries from RS274, kinematics, remap, config, tooldata, and metadata # manifests after check-linuxcnc-inputs.sh validates their source coverage. manifest=${1:?manifest required} filter_group=${2:?filter group required} output_mode=${3:?output mode required} allowed_groups=${4:?allowed groups required} duplicate_groups=${5:?duplicate groups required} missing_source_message=${6:?missing source message required} linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc} contains_group() { local groups=$1 local group=$2 [[ ",$groups," == *",$group,"* ]] } checks_duplicate_group() { local groups=$1 local group=$2 [[ "$groups" == "all" ]] || contains_group "$groups" "$group" } LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-inputs-cached.sh "$manifest" linuxcnc_root=$(cd "$linuxcnc_root" && pwd) if [[ "$filter_group" != "all" && ! "$filter_group" =~ ^[A-Za-z0-9_-]+$ ]]; then echo "manifest source filter must be a manifest group name: $filter_group" >&2 exit 1 fi if [[ "$filter_group" != "all" ]] && ! contains_group "$allowed_groups" "$filter_group"; then echo "unknown manifest source filter: $filter_group" >&2 exit 1 fi case "$output_mode" in relative|full) ;; *) echo "unknown manifest source output mode: $output_mode" >&2 exit 1 ;; esac seen_sources=() manifest_line_number=0 while IFS= read -r manifest_line || [[ -n "$manifest_line" ]]; do manifest_line_number=$((manifest_line_number + 1)) case "$manifest_line" in ""|\#*) continue ;; esac IFS=: read -r group path note extra <<<"$manifest_line" if [[ -z "$group" || -z "$path" || -z "$note" || -n "${extra:-}" ]]; then echo "bad manifest line $manifest_line_number: $manifest_line" >&2 exit 1 fi if ! contains_group "$allowed_groups" "$group"; then echo "unknown manifest group: $group" >&2 exit 1 fi if [[ "$path" = /* || "$path" == .. || "$path" == ../* || "$path" == */.. || "$path" == */../* ]]; then echo "manifest source must be LinuxCNC-root relative: $path" >&2 exit 1 fi full_path="$linuxcnc_root/$path" if [[ ! -f "$full_path" ]]; then echo "$missing_source_message: $path" >&2 exit 1 fi if checks_duplicate_group "$duplicate_groups" "$group"; then if printf '%s\n' "${seen_sources[@]}" | grep -Fx -- "$path" >/dev/null; then echo "duplicate manifest source: $path" >&2 exit 1 fi seen_sources+=("$path") fi if [[ "$filter_group" == "all" || "$filter_group" == "$group" ]]; then if [[ "$output_mode" == "full" ]]; then printf '%s\n' "$full_path" else printf '%s\n' "$path" fi fi done < "$manifest"