Skip to content

Commit

Permalink
Add an error message when running hyperkit without permissions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlorenc committed Nov 27, 2017
1 parent b598939 commit fdf906c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/drivers/hyperkit/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const (
isoFilename = "boot2docker.iso"
pidFileName = "hyperkit.pid"
machineFileName = "hyperkit.json"
permErr = "%s needs to run with elevated permissions. " +
"Please run the following command, then try again: " +
"sudo chown root:wheel %s && sudo chmod u+s %s"
)

type Driver struct {
Expand All @@ -61,6 +64,20 @@ func NewDriver(hostName, storePath string) *Driver {
}
}

// PreCreateCheck is called to enforce pre-creation steps
func (d *Driver) PreCreateCheck() error {
exe, err := os.Executable()
if err != nil {
return err
}

if syscall.Geteuid() != 0 {
return fmt.Errorf(permErr, filepath.Base(exe), exe, exe)
}

return nil
}

func (d *Driver) Create() error {
// TODO: handle different disk types.
if err := pkgdrivers.MakeDiskImage(d.BaseDriver, d.Boot2DockerURL, d.DiskSize); err != nil {
Expand Down

0 comments on commit fdf906c

Please sign in to comment.