Skip to content
This repository was archived by the owner on Feb 27, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.11.1
v0.11.1-pre1
56 changes: 54 additions & 2 deletions cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func cmdInit() int {
logf("Something wrong with SSH Key file %q: %s", B2D.SSHKey, err)
return 1
}
if err := cmd(B2D.SSHGen, "-t", "rsa", "-N", "", "-f", B2D.SSHKey); err != nil {
if err := cmdInteractive(B2D.SSHGen, "-t", "rsa", "-N", "", "-f", B2D.SSHKey); err != nil {
logf("Error generating new SSH Key into %s: %s", B2D.SSHKey, err)
return 1
}
Expand Down Expand Up @@ -190,6 +190,15 @@ func cmdInit() int {
logf("Error making tarfile: %s", err)
return 1
}
file = &tar.Header{Name: ".ssh/authorized_keys2", Size: int64(len(pubKey)), Mode: 0644}
if err := tw.WriteHeader(file); err != nil {
logf("Error making tarfile: %s", err)
return 1
}
if _, err := tw.Write([]byte(pubKey)); err != nil {
logf("Error making tarfile: %s", err)
return 1
}
if err := tw.Close(); err != nil {
logf("Error making tarfile: %s", err)
return 1
Expand Down Expand Up @@ -397,7 +406,8 @@ func cmdSSH() int {
i++
}

if err := cmd(B2D.SSH,
if err := cmdInteractive(B2D.SSH,
//"-vvv", //TODO: add if its boot2docker -v
"-o", "StrictHostKeyChecking=no",
"-o", "UserKnownHostsFile=/dev/null",
"-p", fmt.Sprintf("%d", m.SSHPort),
Expand All @@ -411,6 +421,48 @@ func cmdSSH() int {
return 0
}

func cmdIP() int {
m, err := vbx.GetMachine(B2D.VM)
if err != nil {
logf("Failed to get machine %q: %s", B2D.VM, err)
return 2
}

if m.State != vbx.Running {
logf("VM %q is not running.", B2D.VM)
return 1
}

out, err := cmd(B2D.SSH,
//"-vvv", //TODO: add if its boot2docker -v
"-o", "StrictHostKeyChecking=no",
"-o", "UserKnownHostsFile=/dev/null",
"-p", fmt.Sprintf("%d", m.SSHPort),
"-i", B2D.SSHKey,
"docker@localhost",
"ip addr show dev eth1",
)
if err != nil {
logf("%s", err)
return 1
}
// parse to find: inet 192.168.59.103/24 brd 192.168.59.255 scope global eth1
lines := strings.Split(out, "\n")
for _, line := range lines {
vals := strings.Split(strings.TrimSpace(line), " ")
if vals[0] == "inet" {
ip := vals[1][:strings.Index(vals[1], "/")]
errf("\nThe VM's Host only interface IP address is: ")
fmt.Printf("%s", ip)
errf("\n\n")
return 0
}
}
errf("\nFailed to get VM Host only IP address.\n")
errf("\tWas the VM initilized using boot2docker?\n")
return 0
}

// Download the boot2docker ISO image.
func cmdDownload() int {
logf("Downloading boot2docker ISO image...")
Expand Down
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func config() (*flag.FlagSet, error) {
}

func usageShort() {
errf("Usage: %s [<options>] {help|init|up|ssh|save|down|poweroff|reset|restart|config|status|info|delete|download|version} [<args>]\n", os.Args[0])
errf("Usage: %s [<options>] {help|init|up|ssh|save|down|poweroff|reset|restart|config|status|info|ip|delete|download|version} [<args>]\n", os.Args[0])

}

Expand All @@ -184,6 +184,7 @@ Commands:
delete Delete boot2docker VM and its disk image.
config|cfg Show selected profile file settings.
info Display detailed information of VM.
ip Display the IP address of the VM's Host-only network.
status Display current state of VM.
download Download boot2docker ISO image.
version Display version information.
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func run() int {
return cmdStatus()
case "ssh":
return cmdSSH()
case "ip":
return cmdIP()
case "version":
outf("Client version: %s\nGit commit: %s\n", Version, GitSHA)
return 0
Expand Down
22 changes: 14 additions & 8 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,25 @@ func getLatestReleaseName(url string) (string, error) {
}

// Convenient function to exec a command.
func cmd(name string, args ...string) error {
func cmd(name string, args ...string) (string, error) {
cmd := exec.Command(name, args...)
if B2D.Verbose {
logf("executing: %v %v", name, strings.Join(args, " "))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
log.Printf("executing: %v %v", name, strings.Join(args, " "))
}
// TODO: replace this hardcoded test with something more generic
if name == B2D.SSHGen || name == B2D.SSH {
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

b, err := cmd.Output()
return string(b), err
}

func cmdInteractive(name string, args ...string) error {
cmd := exec.Command(name, args...)
if B2D.Verbose {
logf("executing: %v %v", name, strings.Join(args, " "))
}
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

Expand Down