From ac78ee16a51017625bf967b773f98d07f038f8d2 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 14 Sep 2023 04:28:01 -0700 Subject: [PATCH 1/6] Only uninstall if --force is present --- internal/pkg/agent/install/install.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/internal/pkg/agent/install/install.go b/internal/pkg/agent/install/install.go index 307daa49a52..264941dcd01 100644 --- a/internal/pkg/agent/install/install.go +++ b/internal/pkg/agent/install/install.go @@ -43,6 +43,28 @@ func Install(cfgFile, topPath string, pt ProgressTrackerStep) error { errors.M("directory", filepath.Dir(topPath))) } s.Succeeded() +======= + // We only uninstall currently-installed Agent if --force + // is present. + status, _ := Status(topPath) + if status == Installed && force { + // Uninstall current installation + // + // There is no uninstall token for "install" command. + // Uninstall will fail on protected agent. + // The protected Agent will need to be uninstalled first before it can be installed. + pt.StepStart("Uninstalling current Elastic Agent") + err = Uninstall(cfgFile, topPath, "") + if err != nil { + pt.StepFailed() + return errors.New( + err, + fmt.Sprintf("failed to uninstall Agent at (%s)", filepath.Dir(topPath)), + errors.M("directory", filepath.Dir(topPath))) + } + pt.StepSucceeded() + } +>>>>>>> 369e7d8ba (Only uninstall if --force is present) // ensure parent directory exists err = os.MkdirAll(filepath.Dir(topPath), 0755) From 1980382aed1acbac370acfadce3dce16ca906e4d Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 14 Sep 2023 04:28:51 -0700 Subject: [PATCH 2/6] Improve help text --- internal/pkg/agent/cmd/install.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/agent/cmd/install.go b/internal/pkg/agent/cmd/install.go index f967d0b52aa..38ec90a0ed3 100644 --- a/internal/pkg/agent/cmd/install.go +++ b/internal/pkg/agent/cmd/install.go @@ -40,7 +40,7 @@ would like the Agent to operate. }, } - cmd.Flags().BoolP("force", "f", false, "Force overwrite the current and do not prompt for confirmation") + cmd.Flags().BoolP("force", "f", false, "Force overwrite the current installation and do not prompt for confirmation") cmd.Flags().BoolP("non-interactive", "n", false, "Install Elastic Agent in non-interactive mode which will not prompt on missing parameters but fails instead.") cmd.Flags().String(flagInstallBasePath, paths.DefaultBasePath, "The path where the Elastic Agent will be installed. It must be an absolute path.") addEnrollFlags(cmd) From 315b56762f715212983d8b3ab69ec09aa9931289 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 14 Sep 2023 04:34:37 -0700 Subject: [PATCH 3/6] Add missing newline --- internal/pkg/agent/cmd/install.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/agent/cmd/install.go b/internal/pkg/agent/cmd/install.go index 38ec90a0ed3..410c232e65b 100644 --- a/internal/pkg/agent/cmd/install.go +++ b/internal/pkg/agent/cmd/install.go @@ -83,7 +83,7 @@ func installCmd(streams *cli.IOStreams, cmd *cobra.Command) error { nonInteractive, _ := cmd.Flags().GetBool("non-interactive") if nonInteractive { - fmt.Fprintf(streams.Out, "Installing in non-interactive mode.") + fmt.Fprintln(streams.Out, "Installing in non-interactive mode.") } if status == install.PackageInstall { From 090831e333958620cb6deb3acd37aca844ddfac2 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 14 Sep 2023 04:46:47 -0700 Subject: [PATCH 4/6] Don't pass force --- internal/pkg/agent/install/install.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/pkg/agent/install/install.go b/internal/pkg/agent/install/install.go index 264941dcd01..291ddf82257 100644 --- a/internal/pkg/agent/install/install.go +++ b/internal/pkg/agent/install/install.go @@ -46,8 +46,11 @@ func Install(cfgFile, topPath string, pt ProgressTrackerStep) error { ======= // We only uninstall currently-installed Agent if --force // is present. +======= + // We only uninstall Agent if it is currently installed. +>>>>>>> df1d9888d (Don't pass force) status, _ := Status(topPath) - if status == Installed && force { + if status == Installed { // Uninstall current installation // // There is no uninstall token for "install" command. From 2da2fed5c2f27dbe7968439a75f27f577782012f Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Mon, 25 Sep 2023 08:13:01 -0700 Subject: [PATCH 5/6] Fix more conflicts --- internal/pkg/agent/install/install.go | 29 ++++----------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/internal/pkg/agent/install/install.go b/internal/pkg/agent/install/install.go index 291ddf82257..5695189687b 100644 --- a/internal/pkg/agent/install/install.go +++ b/internal/pkg/agent/install/install.go @@ -28,27 +28,7 @@ func Install(cfgFile, topPath string, pt ProgressTrackerStep) error { return errors.New(err, "failed to discover the source directory for installation", errors.TypeFilesystem) } - // Uninstall current installation - // - // There is no uninstall token for "install" command. - // Uninstall will fail on protected agent. - // The protected Agent will need to be uninstalled first before it can be installed. - s := pt.StepStart("Uninstalling current Elastic Agent") - err = Uninstall(cfgFile, topPath, "", s) - if err != nil { - s.Failed() - return errors.New( - err, - fmt.Sprintf("failed to uninstall Agent at (%s)", filepath.Dir(topPath)), - errors.M("directory", filepath.Dir(topPath))) - } - s.Succeeded() -======= - // We only uninstall currently-installed Agent if --force - // is present. -======= // We only uninstall Agent if it is currently installed. ->>>>>>> df1d9888d (Don't pass force) status, _ := Status(topPath) if status == Installed { // Uninstall current installation @@ -56,18 +36,17 @@ func Install(cfgFile, topPath string, pt ProgressTrackerStep) error { // There is no uninstall token for "install" command. // Uninstall will fail on protected agent. // The protected Agent will need to be uninstalled first before it can be installed. - pt.StepStart("Uninstalling current Elastic Agent") - err = Uninstall(cfgFile, topPath, "") + s := pt.StepStart("Uninstalling current Elastic Agent") + err = Uninstall(cfgFile, topPath, "", s) if err != nil { - pt.StepFailed() + s.Failed() return errors.New( err, fmt.Sprintf("failed to uninstall Agent at (%s)", filepath.Dir(topPath)), errors.M("directory", filepath.Dir(topPath))) } - pt.StepSucceeded() + s.Succeeded() } ->>>>>>> 369e7d8ba (Only uninstall if --force is present) // ensure parent directory exists err = os.MkdirAll(filepath.Dir(topPath), 0755) From cf5deb0bd93155579e84549389cbaca62afa335a Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Mon, 25 Sep 2023 08:17:09 -0700 Subject: [PATCH 6/6] Fixing compile error introduced while resolving conflicts --- internal/pkg/agent/install/install.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/agent/install/install.go b/internal/pkg/agent/install/install.go index 5695189687b..58539737e6a 100644 --- a/internal/pkg/agent/install/install.go +++ b/internal/pkg/agent/install/install.go @@ -58,7 +58,7 @@ func Install(cfgFile, topPath string, pt ProgressTrackerStep) error { } // copy source into install path - s = pt.StepStart("Copying files") + s := pt.StepStart("Copying files") err = copy.Copy(dir, topPath, copy.Options{ OnSymlink: func(_ string) copy.SymlinkAction { return copy.Shallow