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

Commit

Permalink
Merge pull request #233 from SvenDowideit/refactor-lost-iso-download-…
Browse files Browse the repository at this point in the history
…for-init

Bring back the Download code as before (and simplify the ssh key gen to ...
  • Loading branch information
Sven Dowideit authored and Sven Dowideit committed Aug 22, 2014
2 parents 9a5a503 + d660b11 commit a551732
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
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

0 comments on commit a551732

Please sign in to comment.