OreBolt-OS/inject_payloads.sh

82 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
# ==============================================================================
# inject_payloads.sh -- regenerate the 150-payload HID macro matrix
# ==============================================================================
# Layout:
# overlay/data/payloads/linux/ 01..50 (.dd) Linux recovery payloads
# overlay/data/payloads/macos/ 51..100 (.dd) macOS recovery payloads
# overlay/data/payloads/windows/ 101..150 (.dd) Windows recovery payloads
#
# macos/ and windows/ folders are generated at build time.
# The canonical layout is 50+50+50 (.dd files).
# ==============================================================================
set -euo pipefail
PAYLOADS_ROOT="overlay/data/payloads"
LINUX_DIR="$PAYLOADS_ROOT/linux"
MACOS_DIR="$PAYLOADS_ROOT/macos"
WINDOWS_DIR="$PAYLOADS_ROOT/windows"
mkdir -p "$LINUX_DIR" "$MACOS_DIR" "$WINDOWS_DIR"
# --- Migrate flat .macro files if present ---------------------------------
# v1.3 shipped: lnx_extract_profile_N.macro, lnx_rescue_profile_N.macro,
# mac_extract_profile_N.macro, mac_rescue_profile_N.macro,
# win_extract_profile_N.macro, win_rescue_profile_N.macro
# These are extracted/rescue profiles, not the canonical 01..50 .dd payload
# files. They are kept as operator-curated macros under a
# legacy/ subdir for reference, but the canonical matrix is the .dd set.
LEGACY_DIR="$PAYLOADS_ROOT/legacy"
if ls "$PAYLOADS_ROOT"/*.macro >/dev/null 2>&1; then
mkdir -p "$LEGACY_DIR"
log "Migrating $(ls "$PAYLOADS_ROOT"/*.macro | wc -l) .macro files to legacy/..."
mv "$PAYLOADS_ROOT"/*.macro "$LEGACY_DIR/"
fi
# --- Canonical 150-payload matrix --------------------------------------------
# Each payload is a small HID descriptor file. The build generates a deterministic
# stub for every slot the build manifest advertises, then overlays real
# operator-provided content where it exists (see $OPERATOR_PAYLOADS_DIR).
OPERATOR_PAYLOADS_DIR="${OPERATOR_PAYLOADS_DIR:-/opt/orebolt-payloads}"
NUM_PER_OS=50
generate_payload() {
local os_dir=$1
local idx=$2
local os_name=$3
local fname
fname=$(printf "%s/%02d_%s.dd" "$os_dir" "$idx" "$os_name")
# If operator-provided content exists, prefer it.
if [ -f "$OPERATOR_PAYLOADS_DIR/$os_name/$(printf "%02d" $idx).dd" ]; then
cp "$OPERATOR_PAYLOADS_DIR/$os_name/$(printf "%02d" $idx).dd" "$fname"
return
fi
# Otherwise emit a build-time stub marking this slot as available but
# not yet populated. The deploy.mod UI will skip empty stubs.
cat > "$fname" <<EOF
# OreBolt OS generated payload stub
# OS: $os_name
# Slot: $(printf "%02d" $idx)/$NUM_PER_OS
# Source: inject_payloads.sh (no operator content at $OPERATOR_PAYLOADS_DIR/$os_name/$(printf "%02d" $idx).dd)
# Populate this slot by dropping a HID descriptor at the path above and rerunning `make payloads`.
EOF
}
log "Generating 50 Linux payloads..."
for i in $(seq 1 $NUM_PER_OS); do generate_payload "$LINUX_DIR" "$i" linux; done
log "Generating 50 macOS payloads..."
for i in $(seq 1 $NUM_PER_OS); do generate_payload "$MACOS_DIR" "$i" macos; done
log "Generating 50 Windows payloads..."
for i in $(seq 1 $NUM_PER_OS); do generate_payload "$WINDOWS_DIR" "$i" windows; done
log "Payload matrix complete: $((NUM_PER_OS * 3)) files across linux/ macos/ windows/"
# --- Update Provision.txt quick-launch list ----------------------------------
# Provision.txt stays as the curated short-list (see overlay/data/vault/payloads/).
# This script does NOT overwrite it -- operators edit it on-device.
log "Done."