This commit is contained in:
Bozhidar 2024-04-26 22:05:32 +03:00
parent 85354f3b63
commit 1f8cffd7f3
5 changed files with 52 additions and 5 deletions

View file

@ -2,14 +2,16 @@
namespace Modules\Docker;
class PostInstall
use App\ModulePostInstall;
class PostInstall extends ModulePostInstall
{
public function run()
{
$installDockerShellFile = base_path('Modules/Docker/shell-scripts/install-docker.sh');
shell_exec("chmod +x $installDockerShellFile");
shell_exec("bash $installDockerShellFile");
shell_exec("bash $installDockerShellFile >> $this->logFile &");
}
}

View file

@ -2,9 +2,10 @@
namespace Modules\Microweber;
use App\ModulePostInstall;
use Modules\Microweber\Filament\Clusters\Microweber\Pages\Version;
class PostInstall
class PostInstall extends ModulePostInstall
{
public function run()
{

View file

@ -2,7 +2,9 @@
namespace App\Filament\Pages;
use App\Models\Module;
use Filament\Pages\Page;
use Illuminate\Support\Str;
class Modules extends Page
{
@ -18,6 +20,8 @@ class Modules extends Page
public $installLogPulling = false;
public $installLog = '';
public $installModule = '';
public $installLogFilePath = '';
protected function getViewData(): array
{
@ -61,13 +65,41 @@ class Modules extends Page
public function getInstallLog()
{
$this->installLog = time();
$this->installLog = '';
if (file_exists($this->installLogFilePath)) {
$this->installLog = file_get_contents($this->installLogFilePath);
$this->installLog = str_replace("\n", "<br>", $this->installLog);
}
if (Str::contains($this->installLog, 'Installed')) {
$this->installLogPulling = false;
$newModule = new Module();
$newModule->name = $module;
$newModule->namespace = 'Modules\\' . $module;
$newModule->installed = 1;
$newModule->save();
}
}
public function openInstallModal($module)
{
$this->installModule = $module;
$this->installLogPulling = true;
$this->installLogFilePath = storage_path('logs/' . $module . '-install.log');
file_put_contents($this->installLogFilePath, 'Installing ' . $module . '...');
$postInstall = app()->make('Modules\\' . $module . '\\PostInstall');
if (method_exists($postInstall, 'run')) {
$postInstall->setLogFile($this->installLogFilePath);
$postInstall->run();
} else {
$newModule = new Module();
$newModule->name = $module;
$newModule->namespace = 'Modules\\' . $module;
$newModule->installed = 1;
$newModule->save();
}
$this->dispatch('open-modal', id: 'install-module-modal', props: ['module' => $module]);
}

View file

@ -8,4 +8,5 @@ use Illuminate\Database\Eloquent\Model;
class Module extends Model
{
use HasFactory;
}

View file

@ -0,0 +1,11 @@
<?php
namespace App;
abstract class ModulePostInstall
{
public function setLogFile($logFile)
{
$this->logFile = $logFile;
}
}