Skip to content

Commit 25dbf81

Browse files
facchinmmatteosuppo
authored andcommitted
allow SSH command without file upload
1 parent 8ec66f5 commit 25dbf81

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func uploadHandler(c *gin.Context) {
141141
// Upload
142142
if data.Extra.Network {
143143
send(map[string]string{uploadStatusStr: "Starting", "Cmd": "Network"})
144-
err = upload.Network(data.Port, data.Board, filePath, commandline, data.Extra.Auth, l)
144+
err = upload.Network(data.Port, data.Board, filePath, commandline, data.Extra.Auth, l, data.Extra.SSH)
145145
} else {
146146
send(map[string]string{uploadStatusStr: "Starting", "Cmd": "Serial"})
147147
err = upload.Serial(data.Port, commandline, data.Extra, l)

upload/upload.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Extra struct {
4141
Verbose bool `json:"verbose"`
4242
ParamsVerbose string `json:"params_verbose"`
4343
ParamsQuiet string `json:"params_quiet"`
44+
SSH bool `json:"ssh", omitempty`
4445
}
4546

4647
// PartiallyResolve replaces some symbols in the commandline with the appropriate values
@@ -80,7 +81,7 @@ func fixupPort(port, commandline string) string {
8081
}
8182

8283
// Network performs a network upload
83-
func Network(port, board, file, commandline string, auth Auth, l Logger) error {
84+
func Network(port, board, file, commandline string, auth Auth, l Logger, SSH bool) error {
8485
Busy = true
8586

8687
// Defaults
@@ -97,7 +98,7 @@ func Network(port, board, file, commandline string, auth Auth, l Logger) error {
9798
err := form(port, board, file, auth, l)
9899
if err != nil {
99100
// try with ssh
100-
err = ssh(port, file, commandline, auth, l)
101+
err = ssh(port, file, commandline, auth, l, SSH)
101102
}
102103

103104
Busy = false
@@ -364,7 +365,7 @@ func form(port, board, file string, auth Auth, l Logger) error {
364365
return nil
365366
}
366367

367-
func ssh(port, file, commandline string, auth Auth, l Logger) error {
368+
func ssh(port, file, commandline string, auth Auth, l Logger, SSH bool) error {
368369
// Connect via ssh
369370
client, err := simplessh.ConnectWithPassword(port+":22", auth.Username, auth.Password)
370371
debug(l, "Connect via ssh ", client, err)
@@ -373,20 +374,23 @@ func ssh(port, file, commandline string, auth Auth, l Logger) error {
373374
}
374375
defer client.Close()
375376

376-
// Copy the sketch
377-
err = scp(client, file, "/tmp/sketch"+filepath.Ext(file))
378-
debug(l, "Copy the sketch ", err)
379-
if err != nil {
380-
return errors.Wrapf(err, "Copy sketch")
381-
}
377+
if !SSH {
378+
// Copy the sketch
379+
err = client.Upload(file, "/tmp/sketch"+filepath.Ext(file))
380+
debug(l, "Copy the sketch ", err)
381+
if err != nil {
382+
return errors.Wrapf(err, "Copy sketch")
383+
}
382384

383-
// very special case for Yun (remove once AVR boards.txt is fixed)
384-
if commandline == "" {
385-
commandline = "merge-sketch-with-bootloader.lua /tmp/sketch.hex && /usr/bin/run-avrdude /tmp/sketch.hex"
385+
// very special case for Yun (remove once AVR boards.txt is fixed)
386+
if commandline == "" {
387+
commandline = "merge-sketch-with-bootloader.lua /tmp/sketch.hex && /usr/bin/run-avrdude /tmp/sketch.hex"
388+
}
386389
}
387390

388391
// Execute commandline
389392
output, err := client.Exec(commandline)
393+
info(l, output)
390394
debug(l, "Execute commandline ", commandline, output, err)
391395
if err != nil {
392396
return errors.Wrapf(err, "Execute commandline")

0 commit comments

Comments
 (0)