Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pkgutil --forget to the darwin uninstall command #1416

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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