46 lines
1.1 KiB
PHP
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',
|
|
]
|
|
],
|
|
];
|
|
}
|
|
}
|