qemu: seed installed RS485 profiles through SEED_DIR #13
+25
-2
@@ -106,8 +106,9 @@ if [ -n "${SEED_DIR:-}" ]; then
|
||||
# on the first bad entry the same way --state fails closed above, rather
|
||||
# than copy it into the image and let it surface as a confusing read
|
||||
# later. Only a top-level plain file matches "one file per settings key"
|
||||
# (the Env note above) -- seed-fixtures.py never nests a subdirectory, and
|
||||
# neither should anything else pointed at this hook.
|
||||
# (the Env note above), with one exception, profiles/rs485/<slug>.w485p
|
||||
# (installed device profiles, checked below); seed-fixtures.py nests
|
||||
# nothing else, and neither should anything else pointed at this hook.
|
||||
#
|
||||
# Charset is seed-fixtures.py's KEY_RE, not --state's stricter
|
||||
# [A-Za-z0-9_.]+ above: seed-fixtures.py deliberately also allows '-' for
|
||||
@@ -126,6 +127,28 @@ if [ -n "${SEED_DIR:-}" ]; then
|
||||
echo "FATAL: SEED_DIR entry '$base' is a symlink (refusing to copy it into userdata verbatim)" >&2
|
||||
exit 1
|
||||
fi
|
||||
# The one directory allowed: installed RS485 device profiles, as
|
||||
# warden-modbus keeps them (/userdata/warden/profiles/rs485/<slug>.w485p),
|
||||
# so a flow can boot with a profile already installed (flare-edge#387).
|
||||
# Nothing in it but plain <slug>.w485p files directly under rs485/.
|
||||
if [ "$base" = profiles ] && [ -d "$entry" ]; then
|
||||
while IFS= read -r -d '' p; do
|
||||
rel="${p#"$entry"/}"
|
||||
if [ "$rel" = rs485 ] && [ -d "$p" ] && [ ! -L "$p" ]; then continue; fi
|
||||
case "$rel" in
|
||||
rs485/*/*) ok=0 ;;
|
||||
rs485/*.w485p) ok=1 ;;
|
||||
*) ok=0 ;;
|
||||
esac
|
||||
name="${rel#rs485/}"
|
||||
case "${name%.w485p}" in ''|*[!a-z0-9-]*) ok=0 ;; esac
|
||||
if [ "$ok" -ne 1 ] || [ -L "$p" ] || [ ! -f "$p" ]; then
|
||||
echo "FATAL: SEED_DIR entry 'profiles/$rel' is not a plain profiles/rs485/<slug>.w485p file" >&2
|
||||
exit 1
|
||||
fi
|
||||
done < <(find "$entry" -mindepth 1 -print0)
|
||||
continue
|
||||
fi
|
||||
[ -f "$entry" ] || {
|
||||
echo "FATAL: SEED_DIR entry '$base' is not a plain file (refusing to copy it into userdata verbatim)" >&2
|
||||
exit 1
|
||||
|
||||
@@ -186,5 +186,42 @@ else
|
||||
fail "SEED_DIR: mkimage.sh rejected a valid hyphenated key (see $SCRATCH/mkimage6.log)"
|
||||
fi
|
||||
|
||||
# --- scenario 7: an installed RS485 profile, profiles/rs485/<slug>.w485p,
|
||||
# seeds into userdata/warden/profiles/rs485/ (flare-edge#387) ---
|
||||
SEED7="$SCRATCH/seed7"
|
||||
mkdir -p "$SEED7/profiles/rs485"
|
||||
printf '{"w485p_version":1}\n' > "$SEED7/profiles/rs485/acme-gen-ctl.w485p"
|
||||
OUT7="$SCRATCH/out7"
|
||||
if OUT="$OUT7" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED7" \
|
||||
bash "$QEMU_DIR/mkimage.sh" > "$SCRATCH/mkimage7.log" 2>&1; then
|
||||
UIMG7="$SCRATCH/userdata7.img"
|
||||
extract_userdata "$OUT7/disk.img" "$UIMG7"
|
||||
prof="$(debugfs -R "cat /warden/profiles/rs485/acme-gen-ctl.w485p" "$UIMG7" 2>/dev/null)"
|
||||
if [ "$prof" = '{"w485p_version":1}' ]; then
|
||||
pass "SEED_DIR: an installed profile seeds into profiles/rs485/"
|
||||
else
|
||||
fail "SEED_DIR: profiles/rs485/acme-gen-ctl.w485p = '$prof'"
|
||||
fi
|
||||
else
|
||||
fail "SEED_DIR: mkimage.sh rejected a profiles/rs485/<slug>.w485p seed (see $SCRATCH/mkimage7.log)"
|
||||
fi
|
||||
|
||||
# --- scenario 8: anything else under profiles/ fails closed ---
|
||||
for bad in "rs485/x.json" "rs485/Bad.w485p" "other/x.w485p" "rs485/sub/x.w485p" "rs485/link.w485p"; do
|
||||
SEED8="$SCRATCH/seed8"
|
||||
rm -rf "$SEED8"
|
||||
mkdir -p "$SEED8/profiles/$(dirname "$bad")"
|
||||
if [ "$bad" = rs485/link.w485p ]; then ln -s /etc/passwd "$SEED8/profiles/$bad"; else printf 'x\n' > "$SEED8/profiles/$bad"; fi
|
||||
OUT8="$SCRATCH/out8"
|
||||
rm -rf "$OUT8"
|
||||
err8="$(OUT="$OUT8" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED8" bash "$QEMU_DIR/mkimage.sh" 2>&1 1>/dev/null)"
|
||||
rc8=$?
|
||||
if [ "$rc8" -ne 0 ] && printf '%s' "$err8" | grep -qF "is not a plain profiles/rs485/<slug>.w485p file"; then
|
||||
pass "SEED_DIR: profiles/$bad fails closed"
|
||||
else
|
||||
fail "SEED_DIR: profiles/$bad gave rc=$rc8, stderr='$err8'"
|
||||
fi
|
||||
done
|
||||
|
||||
[ "$FAIL" -eq 0 ] && echo "ALL SEED_DIR TESTS PASSED" || echo "SEED_DIR TESTS FAILED"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
|
||||
Reference in New Issue
Block a user