diff --git a/pkg/autoupdate/findnew.go b/pkg/autoupdate/findnew.go index 44d28bb66..54d9db71a 100644 --- a/pkg/autoupdate/findnew.go +++ b/pkg/autoupdate/findnew.go @@ -320,6 +320,28 @@ func FindBaseDir(path string) string { return "" } + // If this is an app bundle installation, we need to adjust the directory -- otherwise we end up with a library + // of updates at /usr/local//Kolide.app/Contents/MacOS/launcher-updates. + if strings.Contains(path, "Kolide.app") { + components := strings.SplitN(path, "Kolide.app", 2) + baseDir := filepath.Dir(components[0]) + + // If baseDir still contains an update directory (i.e. the original path was something like + // /usr/local//launcher-updates//Kolide.app/Contents/MacOS/launcher), + // then strip the update directory out. + if strings.Contains(baseDir, updateDirSuffix) { + baseDirComponents := strings.SplitN(baseDir, updateDirSuffix, 2) + baseDir = filepath.Dir(baseDirComponents[0]) + } + + // We moved the Kolide.app installation out of the bin directory, but we want the bin directory + // here -- so put the "bin" suffix back on if needed. + if !strings.HasSuffix(baseDir, "bin") { + baseDir = filepath.Join(baseDir, "bin") + } + return baseDir + } + components := strings.SplitN(path, updateDirSuffix, 2) return filepath.Dir(components[0]) } diff --git a/pkg/autoupdate/findnew_test.go b/pkg/autoupdate/findnew_test.go index 084adc3c8..15eabaa40 100644 --- a/pkg/autoupdate/findnew_test.go +++ b/pkg/autoupdate/findnew_test.go @@ -91,8 +91,13 @@ func TestFindBaseDir(t *testing.T) { out string }{ {in: "", out: ""}, - {in: "/a/path/launcher", out: filepath.Clean("/a/path")}, - {in: "/a/path/launcher-updates/1569339163/launcher", out: filepath.Clean("/a/path")}, + {in: "/a/path/bin/launcher", out: filepath.Clean("/a/path/bin")}, + {in: "/a/path/bin/launcher-updates/1569339163/launcher", out: filepath.Clean("/a/path/bin")}, + {in: "/a/path/bin/launcher-updates/1569339163/Kolide.app/Contents/MacOS/launcher", out: filepath.Clean("/a/path/bin")}, + {in: "/a/path/Kolide.app/Contents/MacOS/launcher", out: filepath.Clean("/a/path/bin")}, + {in: "/a/path/Kolide.app/Contents/MacOS/launcher-updates/1569339163/Kolide.app/Contents/MacOS/launcher", out: filepath.Clean("/a/path/bin")}, + {in: "/a/path/bin/Kolide.app/Contents/MacOS/launcher", out: filepath.Clean("/a/path/bin")}, + {in: "/a/path/bin/Kolide.app/Contents/MacOS/launcher-updates/1569339163/Kolide.app/Contents/MacOS/launcher", out: filepath.Clean("/a/path/bin")}, } for _, tt := range tests {