Skip to content
This repository has been archived by the owner on Feb 27, 2018. It is now read-only.

Bring back the Download code as before (and simplify the ssh key gen to ... #233

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
31 changes: 23 additions & 8 deletions cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,45 @@ 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) {
return fmt.Errorf("Something wrong with SSH Key file %q: %s", B2D.SSHKey, err)
}

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)
}
Expand Down
7 changes: 6 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down
4 changes: 4 additions & 0 deletions virtualbox/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down