From 7ff747e5b00d419368db4c2c83317d425da84f57 Mon Sep 17 00:00:00 2001
From: Hemanth Bollamreddi <blmhemu@gmail.com>
Date: Fri, 9 Feb 2024 02:48:49 +0530
Subject: [PATCH 1/2] Fix parsing ssh keys as block string

Signed-off-by: Hemanth Bollamreddi <blmhemu@gmail.com>
---
 lima-init.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lima-init.sh b/lima-init.sh
index 87884b2..b6383b2 100755
--- a/lima-init.sh
+++ b/lima-init.sh
@@ -39,7 +39,7 @@ echo "${LIMA_CIDATA_USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/90-lima-users
 # Create authorized_keys
 LIMA_CIDATA_SSHDIR="${LIMA_CIDATA_HOMEDIR}"/.ssh
 mkdir -p -m 700 "${LIMA_CIDATA_SSHDIR}"
-awk '/ssh-authorized-keys/ {flag=1; next} /^ *$/ {flag=0} flag {sub(/^ +- /, ""); gsub("\"", ""); print $0}' \
+awk '/ssh-authorized-keys/ {flag=1; next} /^ *$/ {flag=0} flag && $0 !~ /^ +-/ {gsub(/^[ ]+/, ""); print $0}' \
 	"${LIMA_CIDATA_MNT}"/user-data >"${LIMA_CIDATA_SSHDIR}"/authorized_keys
 LIMA_CIDATA_GID=$(id -g "${LIMA_CIDATA_USER}")
 chown -R "${LIMA_CIDATA_UID}:${LIMA_CIDATA_GID}" "${LIMA_CIDATA_SSHDIR}"

From bea4c93c951cb5231e3ea41755f0e46ea2f7423a Mon Sep 17 00:00:00 2001
From: Hemanth Bollamreddi <blmhemu@gmail.com>
Date: Fri, 9 Feb 2024 23:35:18 +0530
Subject: [PATCH 2/2] Use escaped strings instead

Signed-off-by: Hemanth Bollamreddi <blmhemu@gmail.com>
---
 lima-init.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lima-init.sh b/lima-init.sh
index b6383b2..c7b6714 100755
--- a/lima-init.sh
+++ b/lima-init.sh
@@ -39,7 +39,7 @@ echo "${LIMA_CIDATA_USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/90-lima-users
 # Create authorized_keys
 LIMA_CIDATA_SSHDIR="${LIMA_CIDATA_HOMEDIR}"/.ssh
 mkdir -p -m 700 "${LIMA_CIDATA_SSHDIR}"
-awk '/ssh-authorized-keys/ {flag=1; next} /^ *$/ {flag=0} flag && $0 !~ /^ +-/ {gsub(/^[ ]+/, ""); print $0}' \
+awk '/ssh-authorized-keys/ {flag=1; next} /^ *$/ {flag=0} flag {sub(/^ +- /, ""); gsub(/^"|"$/,""); gsub("\\\\\"", "\""); print $0}' \
 	"${LIMA_CIDATA_MNT}"/user-data >"${LIMA_CIDATA_SSHDIR}"/authorized_keys
 LIMA_CIDATA_GID=$(id -g "${LIMA_CIDATA_USER}")
 chown -R "${LIMA_CIDATA_UID}:${LIMA_CIDATA_GID}" "${LIMA_CIDATA_SSHDIR}"