4
4
"fmt"
5
5
"os"
6
6
"runtime"
7
+ "strings"
7
8
8
9
"github.com/google/uuid"
9
10
@@ -38,7 +39,7 @@ func Install() error {
38
39
39
40
// install attempts to probe an endpoint and install the appropriate agent
40
41
// binary over the specified transport.
41
- func install (logger * logging.Logger , transport Transport , prompter string ) error {
42
+ func install (logger * logging.Logger , transport Transport , prompter string , cmdExe bool ) error {
42
43
// Detect the target platform.
43
44
goos , goarch , posix , err := probe (transport , prompter )
44
45
if err != nil {
@@ -68,14 +69,25 @@ func install(logger *logging.Logger, transport Transport, prompter string) error
68
69
if err != nil {
69
70
return fmt .Errorf ("unable to generate UUID for agent copying: %w" , err )
70
71
}
71
- destination := BaseName + randomUUID .String ()
72
+ remoteFileName := BaseName + randomUUID .String ()
72
73
if goos == "windows" {
73
- destination += ".exe"
74
+ remoteFileName += ".exe"
74
75
}
75
76
if posix {
76
- destination = "." + destination
77
+ remoteFileName = "." + remoteFileName
77
78
}
78
- if err = transport .Copy (agentExecutable , destination ); err != nil {
79
+ // HACK: On cmd.exe systems, the ~ special character is not understood to mean the home directory, so we leave it
80
+ // off, and hope that the default copy directory is the home directory.
81
+ pathSeparator := "/"
82
+ pathComponents := []string {filesystem .HomeDirectorySpecial }
83
+ if cmdExe {
84
+ pathSeparator = "\\ "
85
+ pathComponents = nil
86
+ }
87
+ pathComponents = append (pathComponents , remoteFileName )
88
+ fullRemotePath := strings .Join (pathComponents , pathSeparator )
89
+
90
+ if err = transport .Copy (agentExecutable , fullRemotePath ); err != nil {
79
91
return fmt .Errorf ("unable to copy agent binary: %w" , err )
80
92
}
81
93
@@ -89,7 +101,7 @@ func install(logger *logging.Logger, transport Transport, prompter string) error
89
101
if err := prompting .Message (prompter , "Setting agent executability..." ); err != nil {
90
102
return fmt .Errorf ("unable to message prompter: %w" , err )
91
103
}
92
- executabilityCommand := fmt .Sprintf ("chmod +x %s" , destination )
104
+ executabilityCommand := fmt .Sprintf ("chmod +x %s" , fullRemotePath )
93
105
if err := run (transport , executabilityCommand ); err != nil {
94
106
return fmt .Errorf ("unable to set agent executability: %w" , err )
95
107
}
@@ -100,10 +112,11 @@ func install(logger *logging.Logger, transport Transport, prompter string) error
100
112
return fmt .Errorf ("unable to message prompter: %w" , err )
101
113
}
102
114
var installCommand string
103
- if posix {
104
- installCommand = fmt .Sprintf ("./%s %s" , destination , CommandInstall )
115
+ if posix && cmdExe {
116
+ // TODO: is this path even possible?
117
+ installCommand = fmt .Sprintf ("./%s %s" , fullRemotePath , CommandInstall )
105
118
} else {
106
- installCommand = fmt .Sprintf ("%s %s" , destination , CommandInstall )
119
+ installCommand = fmt .Sprintf ("%s %s" , fullRemotePath , CommandInstall )
107
120
}
108
121
if err := run (transport , installCommand ); err != nil {
109
122
return fmt .Errorf ("unable to invoke agent installation: %w" , err )
0 commit comments