|
5 | 5 | "fmt" |
6 | 6 | "net" |
7 | 7 | "os" |
| 8 | + "os/exec" |
8 | 9 | "path/filepath" |
9 | 10 | "regexp" |
10 | 11 | "runtime" |
@@ -61,6 +62,36 @@ func cfgFilename(dir string) string { |
61 | 62 | return filename |
62 | 63 | } |
63 | 64 |
|
| 65 | +func defaultIsoPath(dir string) string { |
| 66 | + var err error |
| 67 | + |
| 68 | + iso := filepath.Join(dir, "boot2docker.iso") |
| 69 | + |
| 70 | + exe := os.Args[0] |
| 71 | + if filepath.Base(exe) == exe { |
| 72 | + // this logic borrowed from reexec/reexec.go in Docker itself :) |
| 73 | + if lp, err := exec.LookPath(exe); err == nil { |
| 74 | + exe = lp |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + if exe, err = filepath.Abs(exe); err != nil { |
| 79 | + return iso |
| 80 | + } |
| 81 | + |
| 82 | + if exe, err = filepath.EvalSymlinks(exe); err != nil { |
| 83 | + return iso |
| 84 | + } |
| 85 | + |
| 86 | + // if there's a "boot2docker.iso" next to our boot2docker-cli executable, let's prefer that one by default |
| 87 | + exeIso := filepath.Join(filepath.Dir(exe), "boot2docker.iso") |
| 88 | + if _, err = os.Stat(exeIso); err == nil { |
| 89 | + return exeIso |
| 90 | + } |
| 91 | + |
| 92 | + return iso |
| 93 | +} |
| 94 | + |
64 | 95 | // Write configuration set by the combination of profile and flags |
65 | 96 | // Should result in a format that can be piped into a profile file |
66 | 97 | func printConfig() string { |
@@ -92,7 +123,7 @@ func config() (*flag.FlagSet, error) { |
92 | 123 | //flags.StringVarP(&B2D.Dir, "dir", "d", dir, "boot2docker config directory.") |
93 | 124 | B2D.Dir = dir |
94 | 125 | flags.StringVar(&B2D.ISOURL, "iso-url", "https://api.github.com/repos/boot2docker/boot2docker/releases", "source URL to provision the boot2docker ISO image.") |
95 | | - flags.StringVar(&B2D.ISO, "iso", filepath.Join(dir, "boot2docker.iso"), "path to boot2docker ISO image.") |
| 126 | + flags.StringVar(&B2D.ISO, "iso", defaultIsoPath(dir), "path to boot2docker ISO image.") |
96 | 127 |
|
97 | 128 | // Sven disabled this, as it is broken - if I user with a fresh computer downloads |
98 | 129 | // just the boot2docker-cli, and then runs `boot2docker --init ip`, we create a vm |
|
0 commit comments