fix: cni allocation bug

This commit is contained in:
Ran
2026-02-09 08:47:18 +08:00
parent ebbabaf9d1
commit 8b0d90d7b4
2 changed files with 80 additions and 2 deletions
+45
View File
@@ -5,7 +5,52 @@ if [ "$(uname -s)" != "Darwin" ]; then
exit 0
fi
host_yaml="$HOME/.lima/default/lima.yaml"
if [ -f "$host_yaml" ]; then
if ! awk '
BEGIN {in=0; entries=0}
/^portForwards:/ {in=1; next}
in && /^[^ ]/ {in=0}
in && /^ - / {entries=1; exit}
END {if (entries) exit 0; else exit 1}
' "$host_yaml"; then
tmp="${host_yaml}.tmp"
awk '
BEGIN {found=0; inserted=0}
/^portForwards: *\[/ {
found=1
print "portForwards:"
if (!inserted) {
print " - guestSocket: \"/run/containerd/containerd.sock\""
print " hostSocket: \"{{.Dir}}/sock/containerd/containerd.sock\""
inserted=1
}
next
}
/^portForwards:/ {
found=1
print
if (!inserted) {
print " - guestSocket: \"/run/containerd/containerd.sock\""
print " hostSocket: \"{{.Dir}}/sock/containerd/containerd.sock\""
inserted=1
}
next
}
{print}
END {
if (!found) {
print "portForwards:"
print " - guestSocket: \"/run/containerd/containerd.sock\""
print " hostSocket: \"{{.Dir}}/sock/containerd/containerd.sock\""
}
}
' "$host_yaml" > "$tmp" && mv "$tmp" "$host_yaml"
fi
fi
limactl start default
limactl shell default -- sudo -n chmod 666 /run/containerd/containerd.sock
if ! limactl shell default -- sh -lc 'command -v memoh-cli >/dev/null 2>&1'; then
vm_arch=$(limactl shell default -- uname -m)