@@ -51,7 +51,7 @@ func cmdInit() int {
5151 logf ("Something wrong with SSH Key file %q: %s" , B2D .SSHKey , err )
5252 return 1
5353 }
54- if err := cmd (B2D .SSHGen , "-t" , "rsa" , "-N" , "" , "-f" , B2D .SSHKey ); err != nil {
54+ if err := cmdInteractive (B2D .SSHGen , "-t" , "rsa" , "-N" , "" , "-f" , B2D .SSHKey ); err != nil {
5555 logf ("Error generating new SSH Key into %s: %s" , B2D .SSHKey , err )
5656 return 1
5757 }
@@ -190,6 +190,15 @@ func cmdInit() int {
190190 logf ("Error making tarfile: %s" , err )
191191 return 1
192192 }
193+ file = & tar.Header {Name : ".ssh/authorized_keys2" , Size : int64 (len (pubKey )), Mode : 0644 }
194+ if err := tw .WriteHeader (file ); err != nil {
195+ logf ("Error making tarfile: %s" , err )
196+ return 1
197+ }
198+ if _ , err := tw .Write ([]byte (pubKey )); err != nil {
199+ logf ("Error making tarfile: %s" , err )
200+ return 1
201+ }
193202 if err := tw .Close (); err != nil {
194203 logf ("Error making tarfile: %s" , err )
195204 return 1
@@ -397,7 +406,8 @@ func cmdSSH() int {
397406 i ++
398407 }
399408
400- if err := cmd (B2D .SSH ,
409+ if err := cmdInteractive (B2D .SSH ,
410+ //"-vvv", //TODO: add if its boot2docker -v
401411 "-o" , "StrictHostKeyChecking=no" ,
402412 "-o" , "UserKnownHostsFile=/dev/null" ,
403413 "-p" , fmt .Sprintf ("%d" , m .SSHPort ),
@@ -411,6 +421,48 @@ func cmdSSH() int {
411421 return 0
412422}
413423
424+ func cmdIP () int {
425+ m , err := vbx .GetMachine (B2D .VM )
426+ if err != nil {
427+ logf ("Failed to get machine %q: %s" , B2D .VM , err )
428+ return 2
429+ }
430+
431+ if m .State != vbx .Running {
432+ logf ("VM %q is not running." , B2D .VM )
433+ return 1
434+ }
435+
436+ out , err := cmd (B2D .SSH ,
437+ //"-vvv", //TODO: add if its boot2docker -v
438+ "-o" , "StrictHostKeyChecking=no" ,
439+ "-o" , "UserKnownHostsFile=/dev/null" ,
440+ "-p" , fmt .Sprintf ("%d" , m .SSHPort ),
441+ "-i" , B2D .SSHKey ,
442+ "docker@localhost" ,
443+ "ip addr show dev eth1" ,
444+ )
445+ if err != nil {
446+ logf ("%s" , err )
447+ return 1
448+ }
449+ // parse to find: inet 192.168.59.103/24 brd 192.168.59.255 scope global eth1
450+ lines := strings .Split (out , "\n " )
451+ for _ , line := range lines {
452+ vals := strings .Split (strings .TrimSpace (line ), " " )
453+ if vals [0 ] == "inet" {
454+ ip := vals [1 ][:strings .Index (vals [1 ], "/" )]
455+ errf ("\n The VM's Host only interface IP address is: " )
456+ fmt .Printf ("%s" , ip )
457+ errf ("\n \n " )
458+ return 0
459+ }
460+ }
461+ errf ("\n Failed to get VM Host only IP address.\n " )
462+ errf ("\t Was the VM initilized using boot2docker?\n " )
463+ return 0
464+ }
465+
414466// Download the boot2docker ISO image.
415467func cmdDownload () int {
416468 logf ("Downloading boot2docker ISO image..." )
0 commit comments