Skip to content

Commit

Permalink
Make lima-init.sh yaml parsing more robust
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jandubois committed Mar 9, 2024
1 parent a4b10ce commit 46e5baa
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lima-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,18 @@ 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(/^ *- \[/, "")
sub(/"?\] *$/, "")
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}"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 46e5baa

Please sign in to comment.