From e062e53e5169c6d73f0e9939bb41ece87b126076 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Thu, 19 Sep 2024 18:59:46 +0300 Subject: [PATCH] Update GitRepository.php --- web/app/Models/GitRepository.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/web/app/Models/GitRepository.php b/web/app/Models/GitRepository.php index 5460b40..86f6a6d 100644 --- a/web/app/Models/GitRepository.php +++ b/web/app/Models/GitRepository.php @@ -84,24 +84,26 @@ class GitRepository extends Model if (!is_dir($sshPath)) { shell_exec('mkdir -p ' . $sshPath); - shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' -R ' . dirname($sshPath)); - shell_exec('chmod 0700 ' . dirname($sshPath)); } + shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' -R ' . dirname($sshPath)); + shell_exec('chmod 0700 ' . dirname($sshPath)); + if (!file_exists($privateKeyFile)) { file_put_contents($privateKeyFile, $gitSSHKey->private_key); - - shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' ' . $privateKeyFile); - shell_exec('chmod 0400 ' . $privateKeyFile); - } + shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' ' . $privateKeyFile); + shell_exec('chmod 0400 ' . $privateKeyFile); + if (!file_exists($publicKeyFile)) { file_put_contents($publicKeyFile, $gitSSHKey->public_key); - shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' ' . $publicKeyFile); - shell_exec('chmod 0400 ' . $publicKeyFile); } + shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' ' . $publicKeyFile); + shell_exec('chmod 0400 ' . $publicKeyFile); + + return [ 'privateKeyFile' => $privateKeyFile, 'publicKeyFile' => $publicKeyFile,