Skip to content

Commit 60a9b2b

Browse files
Revert "Bundle elastic-agent.app for MacOS, needed to be able to enable the … (#714)"
This reverts commit 64cb5a0.
1 parent c6a22d4 commit 60a9b2b

File tree

7 files changed

+114
-280
lines changed

7 files changed

+114
-280
lines changed

dev-tools/packaging/files/darwin/PkgInfo

Lines changed: 0 additions & 1 deletion
This file was deleted.

dev-tools/packaging/packages.yml

Lines changed: 100 additions & 130 deletions
Large diffs are not rendered by default.

dev-tools/packaging/templates/darwin/Info.plist.tmpl

Lines changed: 0 additions & 20 deletions
This file was deleted.

internal/pkg/agent/application/info/state.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,18 @@ import (
88
"fmt"
99
"os"
1010
"path/filepath"
11-
"runtime"
1211
"strings"
1312

1413
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
1514
"github.com/elastic/elastic-agent/internal/pkg/release"
1615
)
1716

18-
const (
19-
darwin = "darwin"
20-
)
21-
2217
// RunningInstalled returns true when executing Agent is the installed Agent.
2318
//
2419
// This verifies the running executable path based on hard-coded paths
2520
// for each platform type.
2621
func RunningInstalled() bool {
27-
expectedPaths := []string{filepath.Join(paths.InstallPath, paths.BinaryName)}
28-
if runtime.GOOS == darwin {
29-
// For the symlink on darwin the execPath is /usr/local/bin/elastic-agent
30-
expectedPaths = append(expectedPaths, paths.ShellWrapperPath)
31-
}
22+
expected := filepath.Join(paths.InstallPath, paths.BinaryName)
3223
execPath, _ := os.Executable()
3324
execPath, _ = filepath.Abs(execPath)
3425
execName := filepath.Base(execPath)
@@ -37,24 +28,13 @@ func RunningInstalled() bool {
3728
// executable path is being reported as being down inside of data path
3829
// move up to directories to perform the comparison
3930
execDir = filepath.Dir(filepath.Dir(execDir))
40-
if runtime.GOOS == darwin {
41-
execDir = filepath.Dir(filepath.Dir(filepath.Dir(execDir)))
42-
}
4331
execPath = filepath.Join(execDir, execName)
4432
}
45-
for _, expected := range expectedPaths {
46-
if paths.ArePathsEqual(expected, execPath) {
47-
return true
48-
}
49-
}
50-
return false
33+
return paths.ArePathsEqual(expected, execPath)
5134
}
5235

5336
// IsInsideData returns true when the exePath is inside of the current Agents data path.
5437
func IsInsideData(exePath string) bool {
5538
expectedPath := filepath.Join("data", fmt.Sprintf("elastic-agent-%s", release.ShortCommit()))
56-
if runtime.GOOS == darwin {
57-
expectedPath = filepath.Join(expectedPath, "elastic-agent.app", "Contents", "MacOS")
58-
}
5939
return strings.HasSuffix(exePath, expectedPath)
6040
}

internal/pkg/agent/application/info/state_test.go

Lines changed: 0 additions & 53 deletions
This file was deleted.

internal/pkg/agent/application/paths/common.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"os"
1111
"path/filepath"
12-
"runtime"
1312
"strings"
1413
"sync"
1514

@@ -22,8 +21,6 @@ const (
2221
// AgentLockFileName is the name of the overall Elastic Agent file lock.
2322
AgentLockFileName = "agent.lock"
2423
tempSubdir = "tmp"
25-
26-
darwin = "darwin"
2724
)
2825

2926
var (
@@ -71,10 +68,8 @@ func SetTop(path string) {
7168
func TempDir() string {
7269
tmpDir := filepath.Join(Data(), tempSubdir)
7370
tmpCreator.Do(func() {
74-
// Create tempdir as it probably don't exists.
75-
// The error was not checked here before and the linter is not happy about it.
76-
// Changing this now would lead to the wide change scope that intended at the moment, so just making the linter happy for now.
77-
_ = os.MkdirAll(tmpDir, 0750)
71+
// create tempdir as it probably don't exists
72+
os.MkdirAll(tmpDir, 0750)
7873
})
7974
return tmpDir
8075
}
@@ -177,15 +172,10 @@ func SetInstall(path string) {
177172
// initialTop returns the initial top-level path for the binary
178173
//
179174
// When nested in top-level/data/elastic-agent-${hash}/ the result is top-level/.
180-
// The agent fexecutable for MacOS is wrappend in the bundle, so the path to the binary is
181-
// top-level/data/elastic-agent-${hash}/elastic-agent.app/Contents/MacOS
182175
func initialTop() string {
183176
exePath := retrieveExecutablePath()
184177
if insideData(exePath) {
185-
exePath = filepath.Dir(filepath.Dir(exePath))
186-
if runtime.GOOS == darwin {
187-
exePath = filepath.Dir(filepath.Dir(filepath.Dir(exePath)))
188-
}
178+
return filepath.Dir(filepath.Dir(exePath))
189179
}
190180
return exePath
191181
}
@@ -206,8 +196,5 @@ func retrieveExecutablePath() string {
206196
// insideData returns true when the exePath is inside of the current Agents data path.
207197
func insideData(exePath string) bool {
208198
expectedPath := filepath.Join("data", fmt.Sprintf("elastic-agent-%s", release.ShortCommit()))
209-
if runtime.GOOS == darwin {
210-
expectedPath = filepath.Join(expectedPath, "elastic-agent.app", "Contents", "MacOS")
211-
}
212199
return strings.HasSuffix(exePath, expectedPath)
213200
}

internal/pkg/agent/install/install.go

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"io/ioutil"
1010
"os"
1111
"path/filepath"
12-
"runtime"
1312

1413
"github.com/otiai10/copy"
1514

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

21-
const (
22-
darwin = "darwin"
23-
)
24-
2520
// Install installs Elastic Agent persistently on the system including creating and starting its service.
2621
func Install(cfgFile string) error {
2722
dir, err := findDirectory()
@@ -58,36 +53,15 @@ func Install(cfgFile string) error {
5853

5954
// place shell wrapper, if present on platform
6055
if paths.ShellWrapperPath != "" {
61-
// Install symlink for darwin instead
62-
if runtime.GOOS == darwin {
63-
// Check if previous shell wrapper or symlink exists and remove it so it can be overwritten
64-
if _, err := os.Lstat(paths.ShellWrapperPath); err == nil {
65-
if err := os.Remove(paths.ShellWrapperPath); err != nil {
66-
return errors.New(
67-
err,
68-
fmt.Sprintf("failed to remove (%s)", paths.ShellWrapperPath),
69-
errors.M("destination", paths.ShellWrapperPath))
70-
}
71-
}
72-
err = os.Symlink("/Library/Elastic/Agent/elastic-agent", paths.ShellWrapperPath)
73-
if err != nil {
74-
return errors.New(
75-
err,
76-
fmt.Sprintf("failed to create elastic-agent symlink (%s)", paths.ShellWrapperPath),
77-
errors.M("destination", paths.ShellWrapperPath))
78-
}
79-
} else {
80-
err = os.MkdirAll(filepath.Dir(paths.ShellWrapperPath), 0755)
81-
if err == nil {
82-
//nolint: gosec // this is intended to be an executable shell script, not chaning the permissions for the linter
83-
err = ioutil.WriteFile(paths.ShellWrapperPath, []byte(paths.ShellWrapper), 0755)
84-
}
85-
if err != nil {
86-
return errors.New(
87-
err,
88-
fmt.Sprintf("failed to write shell wrapper (%s)", paths.ShellWrapperPath),
89-
errors.M("destination", paths.ShellWrapperPath))
90-
}
56+
err = os.MkdirAll(filepath.Dir(paths.ShellWrapperPath), 0755)
57+
if err == nil {
58+
err = ioutil.WriteFile(paths.ShellWrapperPath, []byte(paths.ShellWrapper), 0755)
59+
}
60+
if err != nil {
61+
return errors.New(
62+
err,
63+
fmt.Sprintf("failed to write shell wrapper (%s)", paths.ShellWrapperPath),
64+
errors.M("destination", paths.ShellWrapperPath))
9165
}
9266
}
9367

@@ -177,9 +151,6 @@ func findDirectory() (string, error) {
177151
// executable path is being reported as being down inside of data path
178152
// move up to directories to perform the copy
179153
sourceDir = filepath.Dir(filepath.Dir(sourceDir))
180-
if runtime.GOOS == darwin {
181-
sourceDir = filepath.Dir(filepath.Dir(filepath.Dir(sourceDir)))
182-
}
183154
}
184155
err = verifyDirectory(sourceDir)
185156
if err != nil {

0 commit comments

Comments
 (0)