mirror of
https://github.com/laravel/valet.git
synced 2026-02-06 08:40:09 +01:00
run commands as sudo
This commit is contained in:
@@ -8,10 +8,24 @@ class CommandLine
|
||||
{
|
||||
/**
|
||||
* Simple global function to run commands.
|
||||
*
|
||||
* @param string $command
|
||||
* @return void
|
||||
*/
|
||||
public function quietly($command)
|
||||
{
|
||||
(new Process($command))->run();
|
||||
$this->runCommand($command.' > /dev/null 2>&1');
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple global function to run commands.
|
||||
*
|
||||
* @param string $command
|
||||
* @return void
|
||||
*/
|
||||
public function quietlyAsUser($command)
|
||||
{
|
||||
$this->quietly('sudo -u '.user().' '.$command.' > /dev/null 2>&1');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,7 +40,7 @@ public function passthru($command)
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given command.
|
||||
* Run the given command as the non-root user.
|
||||
*
|
||||
* @param string $command
|
||||
* @param callable $onError
|
||||
@@ -34,17 +48,29 @@ public function passthru($command)
|
||||
*/
|
||||
public function run($command, callable $onError = null)
|
||||
{
|
||||
return $this->runAsRoot('sudo -u '.$_SERVER['SUDO_USER'].' '.$command, $onError);
|
||||
return $this->runCommand($command, $onError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given command as root.
|
||||
* Run the given command.
|
||||
*
|
||||
* @param string $command
|
||||
* @param callable $onError
|
||||
* @return string
|
||||
*/
|
||||
public function runAsRoot($command, callable $onError = null)
|
||||
public function runAsUser($command, callable $onError = null)
|
||||
{
|
||||
return $this->runCommand('sudo -u '.user().' '.$command, $onError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given command.
|
||||
*
|
||||
* @param string $command
|
||||
* @param callable $onError
|
||||
* @return string
|
||||
*/
|
||||
protected function runCommand($command, callable $onError = null)
|
||||
{
|
||||
$onError = $onError ?: function () {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user