From 058b71631e21022d730f73d5854b4e40b919b6be Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Thu, 19 Sep 2024 18:35:26 +0300 Subject: [PATCH] update --- web/app/Models/GitRepository.php | 22 +++++++++++++++---- ...po.blade.php => clone-repo-user.blade.php} | 0 .../views/actions/git/git-executor.blade.php | 10 +++++++++ ...epo.blade.php => pull-repo-user.blade.php} | 2 ++ 4 files changed, 30 insertions(+), 4 deletions(-) rename web/resources/views/actions/git/{clone-repo.blade.php => clone-repo-user.blade.php} (100%) create mode 100644 web/resources/views/actions/git/git-executor.blade.php rename web/resources/views/actions/git/{pull-repo.blade.php => pull-repo-user.blade.php} (98%) diff --git a/web/app/Models/GitRepository.php b/web/app/Models/GitRepository.php index 8e17b14..f068203 100644 --- a/web/app/Models/GitRepository.php +++ b/web/app/Models/GitRepository.php @@ -166,10 +166,24 @@ class GitRepository extends Model file_put_contents($shellFile, $shellContent); - shell_exec('chmod +x ' . $shellFile); - shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' ' . $shellFile); - shell_exec('su -m ' . $findHostingSubscription->system_username . ' -c "bash '.$shellFile.' >> ' . $shellLog . ' &"'); + $gitExecutorTempPath = storage_path('app/git/tmp'); + shell_exec('mkdir -p ' . $gitExecutorTempPath); + + $gitExecutorShellFile = $gitExecutorTempPath . '/git-pull-' . $this->id . '.sh'; + $gitExecutorShellFileLog = $gitExecutorTempPath . '/git-pull-' . $this->id . '.log'; + + $gitExecutorContent = view('actions.git.git-executor', [ + 'shellFile' => $shellFile, + 'systemUsername' => $findHostingSubscription->system_username, + 'selfFile' => $gitExecutorShellFile, + 'afterCommand' => 'phyre-php /usr/local/phyre/web/artisan git-repository:mark-as-pulled '.$this->id, + ])->render(); + + file_put_contents($gitExecutorShellFile, $gitExecutorContent); + + shell_exec('chmod +x ' . $gitExecutorShellFile); + shell_exec('bash ' . $gitExecutorShellFile . ' >> ' . $gitExecutorShellFileLog . ' &'); } @@ -234,7 +248,7 @@ class GitRepository extends Model shell_exec('chmod +x ' . $shellFile); shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' ' . $shellFile); - shell_exec('su -m ' . $findHostingSubscription->system_username . ' -c "bash '.$shellFile.' >> ' . $shellLog . ' &"'); + shell_exec('su -m ' . $findHostingSubscription->system_username . ' -c "bash '.$shellFile.' >> ' . $shellLog . ' && phyre-php /usr/local/phyre/web/artisan git-repository:mark-as-cloned '.$this->id.' &"'); } diff --git a/web/resources/views/actions/git/clone-repo.blade.php b/web/resources/views/actions/git/clone-repo-user.blade.php similarity index 100% rename from web/resources/views/actions/git/clone-repo.blade.php rename to web/resources/views/actions/git/clone-repo-user.blade.php diff --git a/web/resources/views/actions/git/git-executor.blade.php b/web/resources/views/actions/git/git-executor.blade.php new file mode 100644 index 0000000..94ad7e0 --- /dev/null +++ b/web/resources/views/actions/git/git-executor.blade.php @@ -0,0 +1,10 @@ +chmod +x {{$shellFile}} +chown {{$systemUsername}}:{{$systemUsername}} {{$shellFile}} + +sudo -m {{$systemUsername}} -c "bash {{$shellFile}}" + +@if ($afterCommand) + +{{$afterCommand}} + +@endif diff --git a/web/resources/views/actions/git/pull-repo.blade.php b/web/resources/views/actions/git/pull-repo-user.blade.php similarity index 98% rename from web/resources/views/actions/git/pull-repo.blade.php rename to web/resources/views/actions/git/pull-repo-user.blade.php index f296106..958da07 100644 --- a/web/resources/views/actions/git/pull-repo.blade.php +++ b/web/resources/views/actions/git/pull-repo-user.blade.php @@ -17,3 +17,5 @@ git pull @endif rm -rf {{$selfFile}} + +curl