Skip to content
This repository was archived by the owner on Feb 27, 2018. It is now read-only.
Closed
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
98 changes: 2 additions & 96 deletions cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,8 @@ func vmNotRunningError(vmName string) error {
return fmt.Errorf("VM %q is not running. (Did you run `boot2docker up`?)", vmName)
}

// 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\n", cmd.Path, strings.Join(cmd.Args, " "))
}

if err := cmd.Run(); err != nil {
return fmt.Errorf("Error generating new SSH Key into %s: %s", B2D.SSHKey, err)
}
}
//TODO: print a ~/.ssh/config entry for our b2d connection that the user can c&p

B2D.Init = true
_, err = driver.GetMachine(&B2D)
if err != nil {
return fmt.Errorf("Failed to initialize machine %q: %s", B2D.VM, err)
}
fmt.Printf("Initialization of virtual machine %q complete.\n", B2D.VM)
fmt.Printf("Use `boot2docker up` to start it.\n")
return nil
func cmdNotSupported(cmd string) error {
return fmt.Errorf("Sorry, command %q is no longer supported.", cmd)
}

// Bring up the VM from all possible states.
Expand Down Expand Up @@ -355,24 +310,6 @@ func cmdPoweroff() error {
}

// Upgrade the boot2docker ISO - preserving server state
func cmdUpgrade() error {
if err := upgradeBoot2DockerBinary(); err != nil {
return fmt.Errorf("Error upgrading boot2docker binary: %s", err)
}
m, err := driver.GetMachine(&B2D)
if err == nil {
if m.GetState() == driver.Running || m.GetState() == driver.Saved || m.GetState() == driver.Paused {
// Windows won't let us move the ISO aside while it's in use
if err = cmdStop(); err == nil {
if err = cmdDownload(); err == nil {
err = cmdUp()
}
}
return err
}
}
return cmdDownload()
}

func upgradeBoot2DockerBinary() error {
var (
Expand Down Expand Up @@ -587,34 +524,3 @@ func cmdIP() error {
}
return nil
}

// Download the boot2docker ISO image.
func cmdDownload() error {
url := B2D.ISOURL

// match github (enterprise) release urls:
// https://api.github.com/repos/../../relases or
// https://some.github.enterprise/api/v3/repos/../../relases
re := regexp.MustCompile("https://([^/]+)(/api/v3)?/repos/([^/]+)/([^/]+)/releases")
if matches := re.FindStringSubmatch(url); len(matches) == 5 {
tag, err := getLatestReleaseName(url)
if err != nil {
return fmt.Errorf("Failed to get latest release: %s", err)
}
host := matches[1]
org := matches[3]
repo := matches[4]
if host == "api.github.com" {
host = "github.com"
}
fmt.Printf("Latest release for %s/%s/%s is %s\n", host, org, repo, tag)
url = fmt.Sprintf("https://%s/%s/%s/releases/download/%s/boot2docker.iso", host, org, repo, tag)
}

fmt.Println("Downloading boot2docker ISO image...")
if err := download(B2D.ISO, url); err != nil {
return fmt.Errorf("Failed to download ISO image: %s", err)
}
fmt.Printf("Success: downloaded %s\n\tto %s\n", url, B2D.ISO)
return nil
}
17 changes: 7 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ var (

const (
hardcodedWarning = `
WARNING: The 'boot2docker' command line interface is being officially deprecated.
Users are expected to switch to Docker Machine (https://docs.docker.com/machine/) instead ASAP.
The Docker Toolbox is the recommended way to install it: https://docker.com/toolbox/
WARNING: The 'boot2docker' command line interface is officially deprecated.

Please switch to Docker Machine (https://docs.docker.com/machine/) ASAP.

Docker Toolbox (https://docker.com/toolbox) is the recommended install method.
`
warningURL = "https://raw.githubusercontent.com/boot2docker/boot2docker-cli/master/DEPRECATION_WARNING"
)
Expand Down Expand Up @@ -55,13 +56,11 @@ func run() error {
}

switch cmd := flags.Arg(0); cmd {
case "download":
return cmdDownload()
case "download", "upgrade", "init":
printDeprecationWarning()
return cmdNotSupported(cmd)
case "config", "cfg":
return cmdConfig()
case "init":
printDeprecationWarning()
return cmdInit()
case "up", "start", "boot", "resume":
printDeprecationWarning()
return cmdUp()
Expand All @@ -87,8 +86,6 @@ func run() error {
return cmdSSH()
case "ip":
return cmdIP()
case "upgrade":
return cmdUpgrade()
case "version":
// Version is now printed by the call to config()
return nil
Expand Down