diff --git a/web/app/Models/GitRepository.php b/web/app/Models/GitRepository.php index 7bb62c0..2c8b3a5 100644 --- a/web/app/Models/GitRepository.php +++ b/web/app/Models/GitRepository.php @@ -207,8 +207,11 @@ class GitRepository extends Model $cloneUrl = 'git@'.$gitSSHUrl['provider'].':'.$gitSSHUrl['owner'].'/'.$gitSSHUrl['name'].'.git'; - $shellFile = '/tmp/git-clone-' . $this->id . '.sh'; - $shellLog = '/tmp/git-clone-' . $this->id . '.log'; + $shellFile = $findDomain->domain_root . '/git/tmp/git-clone-' . $this->id . '.sh'; + $shellLog = $findDomain->domain_root . '/git/tmp/git-clone-' . $this->id . '.log'; + + shell_exec('mkdir -p ' . dirname($shellFile)); + shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' -R ' . dirname(dirname($shellFile))); $shellContent = view('actions.git.clone-repo', [ 'gitProvider' => $gitSSHUrl['provider'], @@ -217,12 +220,15 @@ class GitRepository extends Model 'cloneUrl' => $cloneUrl, 'projectDir' => $projectDir, 'privateKeyFile' => $privateKeyFile, + 'selfFile' => $shellFile, ])->render(); file_put_contents($shellFile, $shellContent); shell_exec('chmod +x ' . $shellFile); - shell_exec('bash '.$shellFile.' >> ' . $shellLog . ' &'); + shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' ' . $shellFile); + + shell_exec('su -m ' . $findHostingSubscription->system_username . ' -c "bash '.$shellFile.' >> ' . $shellLog . ' &"'); } diff --git a/web/resources/views/actions/git/clone-repo.blade.php b/web/resources/views/actions/git/clone-repo.blade.php index fc0aad2..2994add 100644 --- a/web/resources/views/actions/git/clone-repo.blade.php +++ b/web/resources/views/actions/git/clone-repo.blade.php @@ -1,6 +1,5 @@ echo "Cloning started at {{ date('Y-m-d H:i:s') }}" -su -m {{$systemUsername}} -c "export HOME=/home/{{$systemUsername}}" @if($privateKeyFile) @@ -8,14 +7,12 @@ ssh-keyscan {{$gitProvider}} >> /home/{{$systemUsername}}/.ssh/known_hosts chmod 0600 /home/{{$systemUsername}}/.ssh/known_hosts chown {{$systemUsername}}:{{$systemUsername}} /home/{{$systemUsername}}/.ssh/known_hosts -su -m {{$systemUsername}} -c 'git -c core.sshCommand="ssh -i {{$privateKeyFile}}" clone {{$cloneUrl}} {{$projectDir}}' +git -c core.sshCommand="ssh -i {{$privateKeyFile}}" clone {{$cloneUrl}} {{$projectDir}} @else -su -m {{$systemUsername}} -c 'git clone {{$cloneUrl}} {{$projectDir}}' +git clone {{$cloneUrl}} {{$projectDir}} @endif -phyre-php /usr/local/phyre/web/artisan git-repository:mark-as-cloned {{$gitRepositoryId}} - -rm -rf /tmp/git-clone-{{$gitRepositoryId}}.sh +rm -rf {{$selfFile}}