4
4
"errors"
5
5
"fmt"
6
6
"io"
7
- "io/fs"
8
7
"os"
9
8
"path/filepath"
10
9
"regexp"
@@ -19,6 +18,7 @@ import (
19
18
qemu "github.com/lima-vm/lima/pkg/qemu/const"
20
19
"github.com/lima-vm/lima/pkg/sshutil"
21
20
"github.com/lima-vm/lima/pkg/store/filenames"
21
+ "github.com/lima-vm/lima/pkg/usrlocalsharelima"
22
22
"github.com/sirupsen/logrus"
23
23
)
24
24
@@ -204,43 +204,10 @@ func GuestAgentBinary(arch string) (io.ReadCloser, error) {
204
204
if arch == "" {
205
205
return nil , errors .New ("arch must be set" )
206
206
}
207
- self , err := os . Executable ()
207
+ dir , err := usrlocalsharelima . Dir ()
208
208
if err != nil {
209
209
return nil , err
210
210
}
211
- selfSt , err := os .Stat (self )
212
- if err != nil {
213
- return nil , err
214
- }
215
- if selfSt .Mode ()& fs .ModeSymlink != 0 {
216
- self , err = os .Readlink (self )
217
- if err != nil {
218
- return nil , err
219
- }
220
- }
221
-
222
- // self: /usr/local/bin/limactl
223
- selfDir := filepath .Dir (self )
224
- selfDirDir := filepath .Dir (selfDir )
225
- candidates := []string {
226
- // candidate 0:
227
- // - self: /Applications/Lima.app/Contents/MacOS/limactl
228
- // - agent: /Applications/Lima.app/Contents/MacOS/lima-guestagent.Linux-x86_64
229
- filepath .Join (selfDir , "lima-guestagent.Linux-" + arch ),
230
- // candidate 1:
231
- // - self: /usr/local/bin/limactl
232
- // - agent: /usr/local/share/lima/lima-guestagent.Linux-x86_64
233
- filepath .Join (selfDirDir , "share/lima/lima-guestagent.Linux-" + arch ),
234
- // TODO: support custom path
235
- }
236
- for _ , candidate := range candidates {
237
- if f , err := os .Open (candidate ); err == nil {
238
- return f , nil
239
- } else if ! errors .Is (err , os .ErrNotExist ) {
240
- return nil , err
241
- }
242
- }
243
-
244
- return nil , fmt .Errorf ("failed to find \" lima-guestagent.Linux-%s\" binary for %q, attempted %v" ,
245
- arch , self , candidates )
211
+ gaPath := filepath .Join (dir , "lima-guestagent.Linux-" + arch )
212
+ return os .Open (gaPath )
246
213
}
0 commit comments