is_root() ? '' : 'sudo '; } /** * Run a shell command string with sudo if needed */ protected function shell_exec_privileged(string $command): ?string { $full_command = $this->sudo_prefix() . $command; return shell_exec($full_command); } /** * Run a Process command array with sudo if needed */ protected function run_privileged_command(array $command, bool $throw_on_error = true): string { if (!$this->is_root()) { array_unshift($command, 'sudo'); } $process = new Process($command); $process->setTimeout(60); $process->run(); if ($throw_on_error && !$process->isSuccessful()) { throw new ProcessFailedException($process); } return $process->getOutput(); } }