diff --git a/cmd/launcher/uninstall_darwin.go b/cmd/launcher/uninstall_darwin.go index 0de461af3..57567931c 100644 --- a/cmd/launcher/uninstall_darwin.go +++ b/cmd/launcher/uninstall_darwin.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "strings" + "time" ) func removeLauncher(ctx context.Context, identifier string) error { @@ -21,7 +22,9 @@ func removeLauncher(ctx context.Context, identifier string) error { launchCtlPath := "/bin/launchctl" launchCtlArgs := []string{"unload", launchDaemonPList} - cmd := exec.CommandContext(ctx, launchCtlPath, launchCtlArgs...) + launchctlCtx, cancel := context.WithTimeout(ctx, 30*time.Second) + defer cancel() + cmd := exec.CommandContext(launchctlCtx, launchCtlPath, launchCtlArgs...) if out, err := cmd.Output(); err != nil { fmt.Printf("error occurred while unloading launcher daemon, launchctl output %s: err: %s\n", out, err) return err @@ -36,13 +39,29 @@ func removeLauncher(ctx context.Context, identifier string) error { fmt.Sprintf("/etc/newsyslog.d/%s.conf", identifier), } + removeErr := false + // Now remove the paths used for launcher/osquery binaries and app data for _, path := range pathsToRemove { if err := os.RemoveAll(path); err != nil { + removeErr = true fmt.Printf("error removing path %s: %s\n", path, err) } } + if removeErr { + return nil + } + + pkgutiltCtx, cancel := context.WithTimeout(ctx, 30*time.Second) + defer cancel() + pkgUtilcmd := exec.CommandContext(pkgutiltCtx, "/usr/sbin/pkgutil", "--forget", fmt.Sprintf("com.%s.launcher", identifier)) + + if out, err := pkgUtilcmd.Output(); err != nil { + fmt.Printf("error occurred while forgetting package: output %s: err: %s\n", out, err) + return nil + } + fmt.Println("Kolide launcher uninstalled successfully") return nil