From ac9f817b9f1cb87fb8990bb4622e1b8a34ae431f Mon Sep 17 00:00:00 2001 From: Marcus Pohorely Date: Mon, 30 Sep 2024 23:21:58 +0200 Subject: [PATCH] fixes #3645, incorrect adding of sudo if non-root user --- bootstrap/helpers/shared.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 350f16837..d9cf7e78b 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -1179,12 +1179,24 @@ function check_domain_usage(ServiceApplication|Application|null $resource = null function parseCommandsByLineForSudo(Collection $commands, Server $server): array { $commands = $commands->map(function ($line) { - if (! str($line)->startsWith('cd') && ! str($line)->startsWith('command') && ! str($line)->startsWith('echo') && ! str($line)->startsWith('true')) { + if (! str(trim($line))->startsWith([ + 'cd', + 'command', + 'echo', + 'true', + 'if', + 'fi', + ])) { return "sudo $line"; } + if (str(trim($line))->startsWith('if')) { + return str_replace('if', 'if sudo', $line); + } + return $line; }); + $commands = $commands->map(function ($line) use ($server) { if (Str::startsWith($line, 'sudo mkdir -p')) { return "$line && sudo chown -R $server->user:$server->user ".Str::after($line, 'sudo mkdir -p').' && sudo chmod -R o-rwx '.Str::after($line, 'sudo mkdir -p'); @@ -1192,6 +1204,7 @@ function parseCommandsByLineForSudo(Collection $commands, Server $server): array return $line; }); + $commands = $commands->map(function ($line) { $line = str($line); if (str($line)->contains('$(')) {