Files
Scheduler/app/Bots/BashScript.php
Oskar-Mikael aa27851bd7
All checks were successful
Deploy App / deploy (push) Successful in 10s
Add basecontract
2025-09-04 17:57:15 +02:00

46 lines
1.1 KiB
PHP

<?php
namespace App\Bots;
use App\Interfaces\ScriptContract;
use Illuminate\Support\Facades\Log;
class BashScript implements ScriptContract
{
protected array $config;
public function __construct(array $config = [])
{
$this->config = $config;
}
public function run(): string
{
// Execute the bash script
$script = $this->config['script'];
$output = [];
$returnVar = null;
exec($script, $output, $returnVar);
if ($returnVar !== 0) {
Log::error("Bash script execution failed", ['script' => $script, 'output' => $output, 'returnVar' => $returnVar]);
throw new \RuntimeException("Bash script execution failed with return code {$returnVar}");
}
return implode("\n", $output);
}
public static function configSchema(): array
{
return [
'script' => [
'type' => 'textarea',
'label' => 'Bash Script',
'rules' => [
'required',
]
],
];
}
}