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

Commit a551732

Browse files
Sven DowideitSven Dowideit
authored andcommitted
Merge pull request #233 from SvenDowideit/refactor-lost-iso-download-for-init
Bring back the Download code as before (and simplify the ssh key gen to ...
2 parents 9a5a503 + d660b11 commit a551732

3 files changed

Lines changed: 33 additions & 9 deletions

File tree

cmds.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,45 @@ import (
1717

1818
// Initialize the boot2docker VM from scratch.
1919
func cmdInit() error {
20+
B2D.Init = false
21+
_, err := driver.GetMachine(&B2D)
22+
if err == nil {
23+
fmt.Printf("Virtual machine %s already exists\n", B2D.VM)
24+
return nil
25+
}
26+
27+
if _, err := os.Stat(B2D.ISO); err != nil {
28+
if !os.IsNotExist(err) {
29+
return fmt.Errorf("Failed to open ISO image %q: %s", B2D.ISO, err)
30+
}
31+
32+
if err := cmdDownload(); err != nil {
33+
return err
34+
}
35+
}
2036

2137
if _, err := os.Stat(B2D.SSHKey); err != nil {
2238
if !os.IsNotExist(err) {
2339
return fmt.Errorf("Something wrong with SSH Key file %q: %s", B2D.SSHKey, err)
2440
}
2541

2642
cmd := exec.Command(B2D.SSHGen, "-t", "rsa", "-N", "", "-f", B2D.SSHKey)
43+
cmd.Stdin = os.Stdin
44+
cmd.Stdout = os.Stdout
45+
cmd.Stderr = os.Stderr
2746
if B2D.Verbose {
2847
cmd.Stderr = os.Stderr
29-
fmt.Printf("executing: %v %v", cmd.Path, strings.Join(cmd.Args, " "))
48+
fmt.Printf("executing: %v %v\n", cmd.Path, strings.Join(cmd.Args, " "))
3049
}
31-
b, err := cmd.Output()
32-
if err != nil {
50+
51+
if err := cmd.Run(); err != nil {
3352
return fmt.Errorf("Error generating new SSH Key into %s: %s", B2D.SSHKey, err)
3453
}
35-
out := string(b)
36-
if B2D.Verbose {
37-
fmt.Printf("%s returned: %s\nEND\n", B2D.SSHKey, out)
38-
}
3954
}
4055
//TODO: print a ~/.ssh/config entry for our b2d connection that the user can c&p
4156

4257
B2D.Init = true
43-
_, err := driver.GetMachine(&B2D)
58+
_, err = driver.GetMachine(&B2D)
4459
if err != nil {
4560
return fmt.Errorf("Failed to initialize machine %q: %s", B2D.VM, err)
4661
}

config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ func config() (*flag.FlagSet, error) {
121121
B2D.Dir = dir
122122
flags.StringVar(&B2D.ISO, "iso", filepath.Join(dir, "boot2docker.iso"), "path to boot2docker ISO image.")
123123

124-
flags.BoolVarP(&B2D.Init, "init", "i", false, "auto initialize vm instance.")
124+
// Sven disabled this, as it is broken - if I user with a fresh computer downloads
125+
// just the boot2docker-cli, and then runs `boot2docker --init ip`, we create a vm
126+
// which cannot run, because it fails to have have the boot2docker.iso and the ssh keys
127+
B2D.Init = false
128+
//flags.BoolVarP(&B2D.Init, "init", "i", false, "auto initialize vm instance.")
129+
125130
flags.StringVar(&B2D.SSH, "ssh", "ssh", "path to SSH client utility.")
126131
flags.StringVar(&B2D.SSHGen, "ssh-keygen", "ssh-keygen", "path to ssh-keygen utility.")
127132

virtualbox/machine.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ func CreateMachine(mc *driver.MachineConfig) (*Machine, error) {
503503
if err := makeDiskImage(diskImg, mc.DiskSize, buf.Bytes()); err != nil {
504504
return m, err
505505
}
506+
if verbose {
507+
fmt.Println("Initializing disk with ssh keys")
508+
fmt.Printf("WRITING: %s\n-----\n", buf)
509+
}
506510
}
507511
}
508512

0 commit comments

Comments
 (0)