Skip to content

Commit

Permalink
Revert: Bundle elastic-agent.app for MacOS… #714 (#1387)
Browse files Browse the repository at this point in the history
* Revert "Bundle elastic-agent.app for MacOS, needed to be able to enable the  … (#714)"

This reverts commit 64cb5a0.

* linter
  • Loading branch information
michalpristas authored Sep 30, 2022
1 parent b21ddcf commit e61c506
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 279 deletions.
1 change: 0 additions & 1 deletion dev-tools/packaging/files/darwin/PkgInfo

This file was deleted.

230 changes: 100 additions & 130 deletions dev-tools/packaging/packages.yml

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions dev-tools/packaging/templates/darwin/Info.plist.tmpl

This file was deleted.

24 changes: 2 additions & 22 deletions internal/pkg/agent/application/info/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,18 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/release"
)

const (
darwin = "darwin"
)

// RunningInstalled returns true when executing Agent is the installed Agent.
//
// This verifies the running executable path based on hard-coded paths
// for each platform type.
func RunningInstalled() bool {
expectedPaths := []string{filepath.Join(paths.InstallPath, paths.BinaryName)}
if runtime.GOOS == darwin {
// For the symlink on darwin the execPath is /usr/local/bin/elastic-agent
expectedPaths = append(expectedPaths, paths.ShellWrapperPath)
}
expected := filepath.Join(paths.InstallPath, paths.BinaryName)
execPath, _ := os.Executable()
execPath, _ = filepath.Abs(execPath)
execName := filepath.Base(execPath)
Expand All @@ -37,24 +28,13 @@ func RunningInstalled() bool {
// executable path is being reported as being down inside of data path
// move up to directories to perform the comparison
execDir = filepath.Dir(filepath.Dir(execDir))
if runtime.GOOS == darwin {
execDir = filepath.Dir(filepath.Dir(filepath.Dir(execDir)))
}
execPath = filepath.Join(execDir, execName)
}
for _, expected := range expectedPaths {
if paths.ArePathsEqual(expected, execPath) {
return true
}
}
return false
return paths.ArePathsEqual(expected, execPath)
}

// IsInsideData returns true when the exePath is inside of the current Agents data path.
func IsInsideData(exePath string) bool {
expectedPath := filepath.Join("data", fmt.Sprintf("elastic-agent-%s", release.ShortCommit()))
if runtime.GOOS == darwin {
expectedPath = filepath.Join(expectedPath, "elastic-agent.app", "Contents", "MacOS")
}
return strings.HasSuffix(exePath, expectedPath)
}
53 changes: 0 additions & 53 deletions internal/pkg/agent/application/info/state_test.go

This file was deleted.

17 changes: 2 additions & 15 deletions internal/pkg/agent/application/paths/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"sync"

Expand All @@ -22,8 +21,6 @@ const (
// AgentLockFileName is the name of the overall Elastic Agent file lock.
AgentLockFileName = "agent.lock"
tempSubdir = "tmp"

darwin = "darwin"
)

var (
Expand Down Expand Up @@ -71,9 +68,7 @@ func SetTop(path string) {
func TempDir() string {
tmpDir := filepath.Join(Data(), tempSubdir)
tmpCreator.Do(func() {
// Create tempdir as it probably don't exists.
// The error was not checked here before and the linter is not happy about it.
// Changing this now would lead to the wide change scope that intended at the moment, so just making the linter happy for now.
// create tempdir as it probably don't exists
_ = os.MkdirAll(tmpDir, 0750)
})
return tmpDir
Expand Down Expand Up @@ -177,15 +172,10 @@ func SetInstall(path string) {
// initialTop returns the initial top-level path for the binary
//
// When nested in top-level/data/elastic-agent-${hash}/ the result is top-level/.
// The agent fexecutable for MacOS is wrappend in the bundle, so the path to the binary is
// top-level/data/elastic-agent-${hash}/elastic-agent.app/Contents/MacOS
func initialTop() string {
exePath := retrieveExecutablePath()
if insideData(exePath) {
exePath = filepath.Dir(filepath.Dir(exePath))
if runtime.GOOS == darwin {
exePath = filepath.Dir(filepath.Dir(filepath.Dir(exePath)))
}
return filepath.Dir(filepath.Dir(exePath))
}
return exePath
}
Expand All @@ -206,8 +196,5 @@ func retrieveExecutablePath() string {
// insideData returns true when the exePath is inside of the current Agents data path.
func insideData(exePath string) bool {
expectedPath := filepath.Join("data", fmt.Sprintf("elastic-agent-%s", release.ShortCommit()))
if runtime.GOOS == darwin {
expectedPath = filepath.Join(expectedPath, "elastic-agent.app", "Contents", "MacOS")
}
return strings.HasSuffix(exePath, expectedPath)
}
47 changes: 9 additions & 38 deletions internal/pkg/agent/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"

"github.com/otiai10/copy"

Expand All @@ -18,10 +17,6 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
)

const (
darwin = "darwin"
)

// Install installs Elastic Agent persistently on the system including creating and starting its service.
func Install(cfgFile string) error {
dir, err := findDirectory()
Expand Down Expand Up @@ -58,36 +53,15 @@ func Install(cfgFile string) error {

// place shell wrapper, if present on platform
if paths.ShellWrapperPath != "" {
// Install symlink for darwin instead
if runtime.GOOS == darwin {
// Check if previous shell wrapper or symlink exists and remove it so it can be overwritten
if _, err := os.Lstat(paths.ShellWrapperPath); err == nil {
if err := os.Remove(paths.ShellWrapperPath); err != nil {
return errors.New(
err,
fmt.Sprintf("failed to remove (%s)", paths.ShellWrapperPath),
errors.M("destination", paths.ShellWrapperPath))
}
}
err = os.Symlink("/Library/Elastic/Agent/elastic-agent", paths.ShellWrapperPath)
if err != nil {
return errors.New(
err,
fmt.Sprintf("failed to create elastic-agent symlink (%s)", paths.ShellWrapperPath),
errors.M("destination", paths.ShellWrapperPath))
}
} else {
err = os.MkdirAll(filepath.Dir(paths.ShellWrapperPath), 0755)
if err == nil {
//nolint: gosec // this is intended to be an executable shell script, not chaning the permissions for the linter
err = ioutil.WriteFile(paths.ShellWrapperPath, []byte(paths.ShellWrapper), 0755)
}
if err != nil {
return errors.New(
err,
fmt.Sprintf("failed to write shell wrapper (%s)", paths.ShellWrapperPath),
errors.M("destination", paths.ShellWrapperPath))
}
err = os.MkdirAll(filepath.Dir(paths.ShellWrapperPath), 0755)
if err == nil {
err = ioutil.WriteFile(paths.ShellWrapperPath, []byte(paths.ShellWrapper), 0755) // nolint:gosec,G306 // this is fine.
}
if err != nil {
return errors.New(
err,
fmt.Sprintf("failed to write shell wrapper (%s)", paths.ShellWrapperPath),
errors.M("destination", paths.ShellWrapperPath))
}
}

Expand Down Expand Up @@ -177,9 +151,6 @@ func findDirectory() (string, error) {
// executable path is being reported as being down inside of data path
// move up to directories to perform the copy
sourceDir = filepath.Dir(filepath.Dir(sourceDir))
if runtime.GOOS == darwin {
sourceDir = filepath.Dir(filepath.Dir(filepath.Dir(sourceDir)))
}
}
err = verifyDirectory(sourceDir)
if err != nil {
Expand Down

0 comments on commit e61c506

Please sign in to comment.