Skip to content

Commit

Permalink
Add pkgutil --forget to the darwin uninstall command (#1416)
Browse files Browse the repository at this point in the history
Co-authored-by: James Pickett <[email protected]>
  • Loading branch information
directionless and James-Pickett authored Oct 18, 2023
1 parent 62f1e34 commit 4a1d3d1
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cmd/launcher/uninstall_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"strings"
"time"
)

func removeLauncher(ctx context.Context, identifier string) error {
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4a1d3d1

Please sign in to comment.