From eed0ad0635cc03e2f7181a0c49493b5c634533eb Mon Sep 17 00:00:00 2001 From: Oskar Kapala Date: Mon, 8 Jun 2026 15:16:06 +0200 Subject: [PATCH] =?UTF-8?q?fix(onboard):=20fix=20yaml=5Fget=20fallback=20?= =?UTF-8?q?=E2=80=94=20strip=20inline=20comments=20and=20fix=20greedy=20co?= =?UTF-8?q?lon=20match?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs in the grep+sed fallback (triggered when yq is unavailable): 1. Greedy colon match: `s/.*: *//` consumed the *last* `: ` in the line, so values containing a colon (e.g. `systemd:magicmirror.service`) were silently truncated to the portion after the last colon. Fix: `s/^[[:space:]]*[^:]*:[[:space:]]*//' — anchored at line start, key chars are `[^:]*` (no colons), so only the first `: ` separator is removed. 2. Inline YAML comment not stripped: `first_contact: pi@pimirror2.local # ...` returned the full tail including `#`, breaking callers like ssh-copy-id. Fix: add `s/[[:space:]]\+#.*$//` — requires at least one space before `#` to preserve bare `#` characters inside a value. Also add leading/trailing whitespace trim as a separate pass. Both bugs affect any node.yaml field that has an inline comment or a colon in its value; all ten fields in hosts/lustro/node.yaml now parse correctly. Co-Authored-By: Claude Sonnet 4.6 --- scripts/onboard/lib/common.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/onboard/lib/common.sh b/scripts/onboard/lib/common.sh index fa51cbb..7345698 100644 --- a/scripts/onboard/lib/common.sh +++ b/scripts/onboard/lib/common.sh @@ -65,8 +65,15 @@ yaml_get() { yq -r ".${key} // empty" "$file" 2>/dev/null else # fallback: extract last segment of key, match " key: value" + # Strip inline YAML comment (space(s)+'#'+rest) and surrounding whitespace. + # Pattern uses \+ (BRE one-or-more) so a bare '#' inside a value is preserved. local leaf="${key##*.}" - grep -E "^\s*${leaf}:" "$file" | head -1 | sed 's/.*: *//' | tr -d '"' | tr -d "'" + grep -E "^\s*${leaf}:" "$file" | head -1 \ + | sed -e 's/^[[:space:]]*[^:]*:[[:space:]]*//' \ + -e 's/[[:space:]]\+#.*$//' \ + -e 's/^[[:space:]]*//' \ + -e 's/[[:space:]]*$//' \ + | tr -d '"' | tr -d "'" fi }