Skip to content

Commit 5a09f68

Browse files
authored
Merge pull request #126 from rancher-sandbox/mounts
Make lima-init.sh yaml parsing more robust
2 parents a4b10ce + 46e5baa commit 5a09f68

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lima-init.sh

+15-9
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,18 @@ awk -f- "${LIMA_CIDATA_MNT}"/user-data <<'EOF' >>"${MOUNT_SCRIPT}"
5353
flag = 1
5454
next
5555
}
56-
/^ *$/ {
57-
flag = 0
58-
}
59-
flag {
56+
/^- / && flag {
6057
# Use a pattern unlikely to appear in a filename. "\0" unfortunately doesn't work.
6158
FS = "<;><><;>"
6259
sub(/^ *- \[/, "")
6360
sub(/"?\] *$/, "")
6461
gsub("\"?, \"?", FS)
6562
printf "mkdir -p \"%s\"\n", $2
6663
printf "mount -t %s -o \"%s\" %s \"%s\"\n", $3, $4, $1, $2
64+
next
65+
}
66+
{
67+
flag = 0
6768
}
6869
EOF
6970
chmod +x "${MOUNT_SCRIPT}"
@@ -134,16 +135,21 @@ awk -f- "${LIMA_CIDATA_MNT}"/user-data <<'EOF' > ${LIMA_CA_CERTS}
134135
trusted = 1
135136
next
136137
}
137-
/^ *$/ {
138-
cacerts = 0
139-
trusted = 0
140-
}
141138
/^ -/ {
142139
next
143140
}
144-
trusted {
141+
/^ / && trusted {
145142
sub(/^ +/, "")
146143
print
144+
next
145+
}
146+
# As long as the line is indented we may still be in the ca_certs block, looking for "trusted"
147+
/^ / {
148+
next
149+
}
150+
{
151+
cacerts = 0
152+
trusted = 0
147153
}
148154
EOF
149155
if [ -s ${LIMA_CA_CERTS} ]; then

0 commit comments

Comments
 (0)