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

Commit b9082bc

Browse files
committed
Merge pull request #283 from tianon/boot2docker.iso
Update default ISO path to prefer an ISO that's next to the boot2docker CLI binary
2 parents 0a7bcf3 + 6220822 commit b9082bc

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

config.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net"
77
"os"
8+
"os/exec"
89
"path/filepath"
910
"regexp"
1011
"runtime"
@@ -61,6 +62,36 @@ func cfgFilename(dir string) string {
6162
return filename
6263
}
6364

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+
6495
// Write configuration set by the combination of profile and flags
6596
// Should result in a format that can be piped into a profile file
6697
func printConfig() string {
@@ -92,7 +123,7 @@ func config() (*flag.FlagSet, error) {
92123
//flags.StringVarP(&B2D.Dir, "dir", "d", dir, "boot2docker config directory.")
93124
B2D.Dir = dir
94125
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.")
96127

97128
// Sven disabled this, as it is broken - if I user with a fresh computer downloads
98129
// just the boot2docker-cli, and then runs `boot2docker --init ip`, we create a vm

0 commit comments

Comments
 (0)