Skip to content
Open
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
21 changes: 19 additions & 2 deletions go/install/install_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/keybase/client/go/logger"
"github.com/keybase/client/go/mounter"
"github.com/keybase/client/go/protocol/keybase1"

"golang.org/x/sys/unix"
)

// defaultLaunchdWait is how long we should wait after install & start.
Expand Down Expand Up @@ -697,8 +699,23 @@ func createCommandLine(binPath string, linkPath string, log Log) error {
}
}

log.Info("Linking %s to %s", linkPath, binPath)
return os.Symlink(binPath, linkPath)
dirPath := filepath.Dir(linkPath)

if err := unix.Access(dirPath, unix.W_OK); err != nil {
log.Info("Directory %s is not writable, using sudo to create symlink", dirPath)
cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("sudo ln -s %s %s", binPath, linkPath))
output, err := cmd.CombinedOutput()
if err != nil {
log.Error("Failed to create symlink with sudo: %s", string(output))
return err
}
log.Info("Symlink created with sudo")

return nil
} else {
log.Info("Linking %s to %s", linkPath, binPath)
return os.Symlink(binPath, linkPath)
}
}

func installCommandLineForBinPath(binPath string, linkPath string, force bool, log Log) error {
Expand Down