-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modify runtime variable 'install.in_default' with rpm/deb
modify the `install.in_default` runtime protection variable so that when elastic-agent is installed via deb or rpm package manager it is still considered to be in the default path. This is necessary because endpoint supports being a component when elastic-agent is installed via rpm/deb.
- Loading branch information
Showing
7 changed files
with
79 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
//go:build !windows | ||
|
||
package pkgmgr | ||
|
||
import ( | ||
"os/exec" | ||
"runtime" | ||
"strings" | ||
|
||
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" | ||
) | ||
|
||
// InstalledViaExternalPkgMgr returns true if Agent was installed with | ||
// rpm or dep package managers | ||
func InstalledViaExternalPkgMgr() bool { | ||
if runtime.GOOS != "linux" { | ||
return false | ||
} | ||
|
||
binaryName := paths.BinaryName | ||
|
||
// NOTE searching for english words might not be a great idea as far as portability goes. | ||
// list all installed packages then search for paths.BinaryName? | ||
// dpkg is strange as the remove and purge processes leads to the package bing isted after a remove, but not after a purge | ||
|
||
// check debian based systems (or systems that use dpkg) | ||
// If the package has been installed, the status starts with "install" | ||
// If the package has been removed (but not pruged) status starts with "deinstall" | ||
// If purged or never installed, rc is 1 | ||
if _, err := exec.Command("which", "dpkg-query").Output(); err == nil { | ||
out, err := exec.Command("dpkg-query", "-W", "-f", "${Status}", binaryName).Output() | ||
if err != nil { | ||
return false | ||
} | ||
if strings.HasPrefix(string(out), "deinstall") { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
// check rhel and sles based systems (or systems that use rpm) | ||
// if package has been installed the query will returns the list of associated files. | ||
// otherwise if uninstalled, or has never been installled status ends with "not installed" | ||
if _, err := exec.Command("which", "rpm").Output(); err == nil { | ||
out, err := exec.Command("rpm", "-q", binaryName, "--state").Output() | ||
if err != nil { | ||
return false | ||
} | ||
if strings.HasSuffix(string(out), "not installed") { | ||
return false | ||
} | ||
return true | ||
|
||
} | ||
|
||
return false | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
//go:build windows | ||
|
||
package pkgmgr | ||
|
||
// InstalledViaPackageManager returns false under windows | ||
func InstalledViaPackageManager() bool { | ||
return false | ||
} |
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