-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set osquery version in packaging context (#1901)
- Loading branch information
1 parent
63230d3
commit e6d3fee
Showing
7 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,58 @@ | ||
package packaging | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/go-kit/kit/log" | ||
"github.com/go-kit/kit/log/level" | ||
"github.com/kolide/launcher/pkg/contexts/ctxlog" | ||
"github.com/kolide/launcher/pkg/packagekit" | ||
) | ||
|
||
// sanitizeHostname will replace any ":" characters in a given hostname with "-" | ||
// This is useful because ":" is not a valid character for file paths. | ||
func sanitizeHostname(hostname string) string { | ||
return strings.Replace(hostname, ":", "-", -1) | ||
} | ||
|
||
// setOsqueryVersionInCtx retrieves the osquery version (by running the binary) and | ||
// sets it in the context. | ||
func (p *PackageOptions) setOsqueryVersionInCtx(ctx context.Context) { | ||
logger := log.With(ctxlog.FromContext(ctx), "library", "setOsqueryVersionInCtx") | ||
|
||
osqueryPath := p.osqueryLocation() | ||
stdout, err := p.execOut(ctx, osqueryPath, "-version") | ||
if err != nil { | ||
level.Warn(logger).Log( | ||
"msg", "could not run osqueryd -version", | ||
"err", err, | ||
) | ||
return | ||
} | ||
|
||
osquerydVersionTrimmed := strings.TrimPrefix(strings.TrimSpace(stdout), "osqueryd version ") | ||
|
||
packagekit.SetInContext(ctx, packagekit.ContextOsqueryVersionKey, osquerydVersionTrimmed) | ||
} | ||
|
||
// osqueryLocation returns the location of the osquery binary within `binDir`. For darwin, | ||
// it may be in an app bundle -- we check to see if the binary exists there first, and then | ||
// fall back to the common location if it doesn't. | ||
func (p *PackageOptions) osqueryLocation() string { | ||
if p.target.Platform == Darwin { | ||
// We want /usr/local/osquery.app, not /usr/local/bin/Kolide.app, so we use Dir to strip out `bin` | ||
appBundleBinaryPath := filepath.Join(p.packageRoot, filepath.Dir(p.binDir), "osquery.app", "Contents", "MacOS", "launcher") | ||
if info, err := os.Stat(appBundleBinaryPath); err == nil && !info.IsDir() { | ||
return appBundleBinaryPath | ||
} | ||
} | ||
|
||
if p.target.Platform == Windows { | ||
return filepath.Join(p.packageRoot, p.binDir, string(p.target.Arch), p.target.PlatformBinaryName("osqueryd")) | ||
} | ||
|
||
return filepath.Join(p.packageRoot, p.binDir, p.target.PlatformBinaryName("osqueryd")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters