From b681c8272b0bc14b61e4aa7a65588a9232c3fb26 Mon Sep 17 00:00:00 2001 From: dlorenc Date: Fri, 24 Nov 2017 09:38:19 -0800 Subject: [PATCH] Add an error message when running hyperkit without permissions. --- pkg/drivers/hyperkit/driver.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/drivers/hyperkit/driver.go b/pkg/drivers/hyperkit/driver.go index 5632fe3c7731..78729b775b28 100644 --- a/pkg/drivers/hyperkit/driver.go +++ b/pkg/drivers/hyperkit/driver.go @@ -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 { @@ -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 {