Skip to content

Commit 2e10d67

Browse files
authored
Merge pull request coollabsio#3647 from derpoho/next
fixes coollabsio#3645, incorrect adding of sudo if non-root user
2 parents cec0d7d + 39d2fdc commit 2e10d67

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

bootstrap/helpers/shared.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,19 +1184,32 @@ function check_domain_usage(ServiceApplication|Application|null $resource = null
11841184
function parseCommandsByLineForSudo(Collection $commands, Server $server): array
11851185
{
11861186
$commands = $commands->map(function ($line) {
1187-
if (! str($line)->startsWith('cd') && ! str($line)->startsWith('command') && ! str($line)->startsWith('echo') && ! str($line)->startsWith('true')) {
1187+
if (! str(trim($line))->startsWith([
1188+
'cd',
1189+
'command',
1190+
'echo',
1191+
'true',
1192+
'if',
1193+
'fi',
1194+
])) {
11881195
return "sudo $line";
11891196
}
11901197

1198+
if (str(trim($line))->startsWith('if')) {
1199+
return str_replace('if', 'if sudo', $line);
1200+
}
1201+
11911202
return $line;
11921203
});
1204+
11931205
$commands = $commands->map(function ($line) use ($server) {
11941206
if (Str::startsWith($line, 'sudo mkdir -p')) {
11951207
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');
11961208
}
11971209

11981210
return $line;
11991211
});
1212+
12001213
$commands = $commands->map(function ($line) {
12011214
$line = str($line);
12021215
if (str($line)->contains('$(')) {

0 commit comments

Comments
 (0)