From 46e5baacc497a83a924894ccca70a099fcab78bd Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Fri, 8 Mar 2024 19:27:10 -0800 Subject: [PATCH] Make lima-init.sh yaml parsing more robust Parsing the `mounts` and `ca_certs` sections no longer need an empty line to signal the end of the section; they will now detect when the next line can no longer be part of the block. Signed-off-by: Jan Dubois --- lima-init.sh | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lima-init.sh b/lima-init.sh index 1489da8..515ddec 100755 --- a/lima-init.sh +++ b/lima-init.sh @@ -53,10 +53,7 @@ awk -f- "${LIMA_CIDATA_MNT}"/user-data <<'EOF' >>"${MOUNT_SCRIPT}" flag = 1 next } -/^ *$/ { - flag = 0 -} -flag { +/^- / && flag { # Use a pattern unlikely to appear in a filename. "\0" unfortunately doesn't work. FS = "<;><><;>" sub(/^ *- \[/, "") @@ -64,6 +61,10 @@ flag { gsub("\"?, \"?", FS) printf "mkdir -p \"%s\"\n", $2 printf "mount -t %s -o \"%s\" %s \"%s\"\n", $3, $4, $1, $2 + next +} +{ + flag = 0 } EOF chmod +x "${MOUNT_SCRIPT}" @@ -134,16 +135,21 @@ awk -f- "${LIMA_CIDATA_MNT}"/user-data <<'EOF' > ${LIMA_CA_CERTS} trusted = 1 next } -/^ *$/ { - cacerts = 0 - trusted = 0 -} /^ -/ { next } -trusted { +/^ / && trusted { sub(/^ +/, "") print + next +} +# As long as the line is indented we may still be in the ca_certs block, looking for "trusted" +/^ / { + next +} +{ + cacerts = 0 + trusted = 0 } EOF if [ -s ${LIMA_CA_CERTS} ]; then