mirror of
https://github.com/laravel/valet.git
synced 2026-02-06 08:40:09 +01:00
If you've previously run `valet trust` to allow valet to run without specifying `sudo` repeatedly or entering your password with various valet commands, recent updates to MacOS may give you a `sudo: sorry, you are not allowed to preserve the environment` response when trying to run those `valet` commands. The fix is in updating the sudoers entry that `valet trust` creates. This PR tells valet how to update the sudoers entry so that this message doesn't continue. YOU WILL NEED TO RE-RUN `valet trust` IF YOU HAD PREVIOUSLY RUN IT, after installing this update, in order for this code change to have any effect. (Technical explanation: the sudoers protections have become stricter, so we have to be more explicit that we do indeed want environment variables to flow through to the sudo user's environment when using valet via sudoers entries.)
85 lines
2.1 KiB
PHP
85 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Valet;
|
|
|
|
use Httpful\Request;
|
|
|
|
class Valet
|
|
{
|
|
var $cli, $files;
|
|
|
|
var $valetBin = '/usr/local/bin/valet';
|
|
|
|
/**
|
|
* Create a new Valet instance.
|
|
*
|
|
* @param CommandLine $cli
|
|
* @param Filesystem $files
|
|
*/
|
|
function __construct(CommandLine $cli, Filesystem $files)
|
|
{
|
|
$this->cli = $cli;
|
|
$this->files = $files;
|
|
}
|
|
|
|
/**
|
|
* Symlink the Valet Bash script into the user's local bin.
|
|
*
|
|
* @return void
|
|
*/
|
|
function symlinkToUsersBin()
|
|
{
|
|
$this->cli->quietlyAsUser('rm '.$this->valetBin);
|
|
|
|
$this->cli->runAsUser('ln -s "'.realpath(__DIR__.'/../../valet').'" '.$this->valetBin);
|
|
}
|
|
|
|
/**
|
|
* Get the paths to all of the Valet extensions.
|
|
*
|
|
* @return array
|
|
*/
|
|
function extensions()
|
|
{
|
|
if (! $this->files->isDir(VALET_HOME_PATH.'/Extensions')) {
|
|
return [];
|
|
}
|
|
|
|
return collect($this->files->scandir(VALET_HOME_PATH.'/Extensions'))
|
|
->reject(function ($file) {
|
|
return is_dir($file);
|
|
})
|
|
->map(function ($file) {
|
|
return VALET_HOME_PATH.'/Extensions/'.$file;
|
|
})
|
|
->values()->all();
|
|
}
|
|
|
|
/**
|
|
* Determine if this is the latest version of Valet.
|
|
*
|
|
* @param string $currentVersion
|
|
* @return bool
|
|
* @throws \Httpful\Exception\ConnectionErrorException
|
|
*/
|
|
function onLatestVersion($currentVersion)
|
|
{
|
|
$response = Request::get('https://api.github.com/repos/laravel/valet/releases/latest')->send();
|
|
|
|
return version_compare($currentVersion, trim($response->body->tag_name, 'v'), '>=');
|
|
}
|
|
|
|
/**
|
|
* Create the "sudoers.d" entry for running Valet.
|
|
*
|
|
* @return void
|
|
*/
|
|
function createSudoersEntry()
|
|
{
|
|
$this->files->ensureDirExists('/etc/sudoers.d');
|
|
|
|
$this->files->put('/etc/sudoers.d/valet', 'Cmnd_Alias VALET = /usr/local/bin/valet *
|
|
%admin ALL=(root) NOPASSWD:SETENV: VALET'.PHP_EOL);
|
|
}
|
|
}
|