From f9c8e4e47a88881fca6ce21a72bb5b4e94110c8c Mon Sep 17 00:00:00 2001 From: Cesar Araujo <56365373+cesarfda@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:36:54 -0500 Subject: [PATCH] added install-info to checkup (#1899) --- ee/debug/checkups/install.go | 40 +++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/ee/debug/checkups/install.go b/ee/debug/checkups/install.go index ba9bdb7ee..a6b99b820 100644 --- a/ee/debug/checkups/install.go +++ b/ee/debug/checkups/install.go @@ -7,13 +7,15 @@ import ( "io" "os" "runtime" + + "github.com/kolide/launcher/pkg/launcher" ) type installCheckup struct { } func (i *installCheckup) Name() string { - return "Package Install Logs" + return "Package Install" } func (i *installCheckup) Run(ctx context.Context, extraWriter io.Writer) error { @@ -24,6 +26,10 @@ func (i *installCheckup) Run(ctx context.Context, extraWriter io.Writer) error { return fmt.Errorf("gathering installation logs: %w", err) } + if err := gatherInstallerInfo(extraZip); err != nil { + return fmt.Errorf("gathering installer info: %w", err) + } + return nil } @@ -66,3 +72,35 @@ func gatherInstallationLogs(z *zip.Writer) error { return nil } + +func gatherInstallerInfo(z *zip.Writer) error { + if runtime.GOOS == "windows" { + // Installer info is not available on Windows + return nil + } + + configDir := launcher.DefaultPath(launcher.EtcDirectory) + installerInfoPath := fmt.Sprintf("%s/installer-info.json", configDir) + + installerInfoFile, err := os.Open(installerInfoPath) + if err != nil { + // If the file doesn't exist, you might want to skip without error + if os.IsNotExist(err) { + return nil + } + return fmt.Errorf("opening %s: %w", installerInfoPath, err) + } + defer installerInfoFile.Close() + + installerInfoZipPath := "installer-info.json" + out, err := z.Create(installerInfoZipPath) + if err != nil { + return fmt.Errorf("creating %s in zip: %w", installerInfoZipPath, err) + } + + if _, err := io.Copy(out, installerInfoFile); err != nil { + return fmt.Errorf("writing %s contents to zip: %w", installerInfoZipPath, err) + } + + return nil +}