Skip to content

Commit 603c064

Browse files
committed
Auto-detect and set permission for Json files
1 parent 0c93fe8 commit 603c064

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Commands/ChangeOwnerConfigJson.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ChangeOwnerConfigJson extends Command
1212
* @var string
1313
*/
1414
protected $signature = 'config-json:change-owner
15-
{user : The user to change owner}
15+
{user? : The user to change owner}
1616
{group? : The group to change owner}';
1717

1818
/**
@@ -29,12 +29,23 @@ class ChangeOwnerConfigJson extends Command
2929
*/
3030
public function handle(): void
3131
{
32-
$user = $this->argument('user');
32+
if (PHP_OS_FAMILY !== 'Linux') {
33+
$this->error('This command only works on Linux');
34+
return;
35+
}
36+
37+
$user = $this->argument('user') ?? '';
3338
$group = $this->argument('group') ?? $user;
3439

40+
if (empty($user) || empty($group)) {
41+
$group = $user = exec('ps aux | egrep "(apache|httpd|nginx)" | grep -v "root" | head -n1 | cut -d\ -f1');
42+
}
43+
3544
$jsonsPath = config('telegram-git-notifier.data_file.storage_folder');
3645
if (is_string($jsonsPath) && file_exists($jsonsPath)) {
37-
exec("chown -R $user:$group $jsonsPath");
46+
shell_exec("chown -R $user:$group $jsonsPath");
47+
} else {
48+
$this->error('The path to the jsons folder is not valid');
3849
}
3950
}
4051
}

0 commit comments

Comments
 (0)