diff --git a/cmds.go b/cmds.go index 9f5b6b6..d0a4675 100644 --- a/cmds.go +++ b/cmds.go @@ -17,6 +17,22 @@ import ( // Initialize the boot2docker VM from scratch. func cmdInit() error { + B2D.Init = false + _, err := driver.GetMachine(&B2D) + if err == nil { + fmt.Printf("Virtual machine %s already exists\n", B2D.VM) + return nil + } + + if _, err := os.Stat(B2D.ISO); err != nil { + if !os.IsNotExist(err) { + return fmt.Errorf("Failed to open ISO image %q: %s", B2D.ISO, err) + } + + if err := cmdDownload(); err != nil { + return err + } + } if _, err := os.Stat(B2D.SSHKey); err != nil { if !os.IsNotExist(err) { @@ -24,23 +40,22 @@ func cmdInit() error { } cmd := exec.Command(B2D.SSHGen, "-t", "rsa", "-N", "", "-f", B2D.SSHKey) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr if B2D.Verbose { cmd.Stderr = os.Stderr - fmt.Printf("executing: %v %v", cmd.Path, strings.Join(cmd.Args, " ")) + fmt.Printf("executing: %v %v\n", cmd.Path, strings.Join(cmd.Args, " ")) } - b, err := cmd.Output() - if err != nil { + + if err := cmd.Run(); err != nil { return fmt.Errorf("Error generating new SSH Key into %s: %s", B2D.SSHKey, err) } - out := string(b) - if B2D.Verbose { - fmt.Printf("%s returned: %s\nEND\n", B2D.SSHKey, out) - } } //TODO: print a ~/.ssh/config entry for our b2d connection that the user can c&p B2D.Init = true - _, err := driver.GetMachine(&B2D) + _, err = driver.GetMachine(&B2D) if err != nil { return fmt.Errorf("Failed to initialize machine %q: %s", B2D.VM, err) } diff --git a/config.go b/config.go index e44a4a5..0a45b13 100644 --- a/config.go +++ b/config.go @@ -121,7 +121,12 @@ func config() (*flag.FlagSet, error) { B2D.Dir = dir flags.StringVar(&B2D.ISO, "iso", filepath.Join(dir, "boot2docker.iso"), "path to boot2docker ISO image.") - flags.BoolVarP(&B2D.Init, "init", "i", false, "auto initialize vm instance.") + // Sven disabled this, as it is broken - if I user with a fresh computer downloads + // just the boot2docker-cli, and then runs `boot2docker --init ip`, we create a vm + // which cannot run, because it fails to have have the boot2docker.iso and the ssh keys + B2D.Init = false + //flags.BoolVarP(&B2D.Init, "init", "i", false, "auto initialize vm instance.") + flags.StringVar(&B2D.SSH, "ssh", "ssh", "path to SSH client utility.") flags.StringVar(&B2D.SSHGen, "ssh-keygen", "ssh-keygen", "path to ssh-keygen utility.") diff --git a/virtualbox/machine.go b/virtualbox/machine.go index 7171bd0..183a37d 100644 --- a/virtualbox/machine.go +++ b/virtualbox/machine.go @@ -503,6 +503,10 @@ func CreateMachine(mc *driver.MachineConfig) (*Machine, error) { if err := makeDiskImage(diskImg, mc.DiskSize, buf.Bytes()); err != nil { return m, err } + if verbose { + fmt.Println("Initializing disk with ssh keys") + fmt.Printf("WRITING: %s\n-----\n", buf) + } } }