@@ -4,7 +4,7 @@ package main
4
4
5
5
import (
6
6
"bufio"
7
- "bytes "
7
+ "errors "
8
8
"flag"
9
9
"fmt"
10
10
"html/template"
@@ -255,12 +255,12 @@ func parseRequest2BwtestItem(r *http.Request, appSel string) (*model.BwTestItem,
255
255
256
256
func parseBwTest2Cmd (d * model.BwTestItem , appSel string , pathStr string ) []string {
257
257
var command []string
258
- binname := getClientLocationBin (appSel )
258
+ installpath := getClientLocationBin (appSel )
259
259
switch appSel {
260
260
case "bwtester" , "camerapp" , "sensorapp" :
261
261
optClient := fmt .Sprintf ("-c=%s,[%s]:%d" , d .CIa , d .CAddr , d .CPort )
262
262
optServer := fmt .Sprintf ("-s=%s,[%s]:%d" , d .SIa , d .SAddr , d .SPort )
263
- command = append (command , binname , optServer , optClient )
263
+ command = append (command , installpath , optServer , optClient )
264
264
if appSel == "bwtester" {
265
265
bwCS := fmt .Sprintf ("-cs=%d,%d,%d,%dbps" , d .CSDuration / 1000 , d .CSPktSize ,
266
266
d .CSPackets , d .CSBandwidth )
@@ -360,6 +360,7 @@ func executeCommand(w http.ResponseWriter, r *http.Request) {
360
360
// execute scion go client app with client/server commands
361
361
log .Info ("Executing:" , "command" , strings .Join (command , " " ))
362
362
cmd := exec .Command (command [0 ], command [1 :]... )
363
+ cmd .Dir = getClientCwd (appSel )
363
364
364
365
log .Info ("Chosen Path:" , "pathStr" , pathStr )
365
366
@@ -373,64 +374,50 @@ func executeCommand(w http.ResponseWriter, r *http.Request) {
373
374
err = cmd .Start ()
374
375
if err != nil {
375
376
fmt .Fprintf (os .Stderr , "Failed to start err=%v" , err )
377
+ if w != nil {
378
+ w .Write ([]byte (err .Error () + "\n " ))
379
+ }
376
380
}
377
381
go writeCmdOutput (w , reader , stdin , d , appSel , pathStr , cmd )
378
382
cmd .Wait ()
379
383
}
380
384
381
385
func appsBuildCheck (app string ) {
382
- binname := getClientLocationBin (app )
383
- installpath := path .Join (lib .GOPATH , "bin" , binname )
384
- // check for install, and install only if needed
386
+ installpath := getClientLocationBin (app )
385
387
if _ , err := os .Stat (installpath ); os .IsNotExist (err ) {
386
- filepath := getClientLocationSrc (app )
387
- cmd := exec .Command ("go" , "install" )
388
- cmd .Dir = path .Dir (filepath )
389
- log .Info (fmt .Sprintf ("Installing %s..." , filepath ))
390
- var stdout , stderr bytes.Buffer
391
- cmd .Stdout = & stdout
392
- cmd .Stderr = & stderr
393
- err := cmd .Run ()
394
388
CheckError (err )
395
- outStr , errStr := string (stdout .Bytes ()), string (stderr .Bytes ())
396
- if len (outStr ) > 0 {
397
- log .Info (outStr )
398
- }
399
- if len (errStr ) > 0 {
400
- log .Error (errStr )
401
- }
389
+ CheckError (errors .New ("App missing, build all apps with 'deps.sh' and 'make'." ))
402
390
} else {
403
391
log .Info (fmt .Sprintf ("Existing install, found %s..." , app ))
404
392
}
405
393
}
406
394
407
- // Parses html selection and returns name of app binary .
408
- func getClientLocationBin (app string ) string {
409
- var binname string
395
+ // Parses html selection and returns current working directory for execution .
396
+ func getClientCwd (app string ) string {
397
+ var cwd string
410
398
switch app {
411
399
case "sensorapp" :
412
- binname = " sensorfetcher"
400
+ cwd = path . Join ( lib . GOPATH , lib . LABROOT , "sensorapp/ sensorfetcher")
413
401
case "camerapp" :
414
- binname = " imagefetcher"
402
+ cwd = path . Join ( lib . GOPATH , lib . LABROOT , "camerapp/ imagefetcher")
415
403
case "bwtester" :
416
- binname = " bwtestclient"
404
+ cwd = path . Join ( lib . GOPATH , lib . LABROOT , "bwtester/ bwtestclient")
417
405
}
418
- return binname
406
+ return cwd
419
407
}
420
408
421
- // Parses html selection and returns location of app source.
422
- func getClientLocationSrc (app string ) string {
423
- slroot := "src/github.com/netsec-ethz/scion-apps"
424
- var filepath string
409
+ // Parses html selection and returns name of app binary.
410
+ func getClientLocationBin (app string ) string {
411
+ var binname string
425
412
switch app {
426
413
case "sensorapp" :
427
- filepath = path .Join (lib .GOPATH , slroot , "sensorapp/sensorfetcher/sensorfetcher.go " )
414
+ binname = path .Join (lib .GOPATH , lib . LABROOT , "sensorapp/sensorfetcher/sensorfetcher" )
428
415
case "camerapp" :
429
- filepath = path .Join (lib .GOPATH , slroot , "camerapp/imagefetcher/imagefetcher.go " )
416
+ binname = path .Join (lib .GOPATH , lib . LABROOT , "camerapp/imagefetcher/imagefetcher" )
430
417
case "bwtester" :
431
- filepath = path .Join (lib .GOPATH , slroot , "bwtester/bwtestclient/bwtestclient.go " )
418
+ binname = path .Join (lib .GOPATH , lib . LABROOT , "bwtester/bwtestclient/bwtestclient" )
432
419
}
433
- return filepath
420
+ return binname
434
421
}
435
422
436
423
// Handles piping command line output to logs, database, and http response writer.
0 commit comments