From 09f474afde82b6e1b043a1d68f42fc0ea0f8e862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Thu, 11 Jul 2024 10:50:45 +0200 Subject: [PATCH] Decompress the guestagent if required MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Anders F Björklund --- cmd/limactl/guest_install.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/cmd/limactl/guest_install.go b/cmd/limactl/guest_install.go index 2a20204d9f1f..128900fa7c12 100644 --- a/cmd/limactl/guest_install.go +++ b/cmd/limactl/guest_install.go @@ -2,7 +2,10 @@ package main import ( "bytes" + "compress/gzip" + "errors" "fmt" + "io" "os" "os/exec" "path/filepath" @@ -80,13 +83,41 @@ func guestInstallAction(cmd *cobra.Command, args []string) error { if err != nil { return err } + guestAgentFilename := filepath.Base(guestAgentBinary) + if _, err := os.Stat(guestAgentBinary); err != nil { + if !errors.Is(err, os.ErrNotExist) { + return err + } + compressedGuestAgent, err := os.Open(guestAgentBinary + ".gz") + if err != nil { + return err + } + defer compressedGuestAgent.Close() + tmpGuestAgent, err := os.CreateTemp("", "lima-guestagent-") + if err != nil { + return err + } + logrus.Debugf("Decompressing %s.gz", guestAgentBinary) + guestAgent, err := gzip.NewReader(compressedGuestAgent) + if err != nil { + return err + } + defer guestAgent.Close() + _, err = io.Copy(tmpGuestAgent, guestAgent) + if err != nil { + return err + } + tmpGuestAgent.Close() + guestAgentBinary = tmpGuestAgent.Name() + defer os.RemoveAll(guestAgentBinary) + } tmpname := "lima-guestagent" tmp, err := shell(sshExe, sshFlags, hostname, "mktemp", "-t", "lima-guestagent.XXXXXX") if err != nil { return err } bin := prefix + "/bin/lima-guestagent" - logrus.Infof("Copying %q to %s:%s", guestAgentBinary, inst.Name, tmpname) + logrus.Infof("Copying %q to %s:%s", guestAgentFilename, inst.Name, tmpname) scpArgs := []string{guestAgentBinary, hostname + ":" + tmp} if err := runCmd(scpExe, scpFlags, scpArgs...); err != nil { return nil