This commit is contained in:
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace App\Bots;
|
||||
|
||||
use App\Interfaces\ScriptContract;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BashScript implements BotContract
|
||||
class BashScript implements ScriptContract
|
||||
{
|
||||
protected array $config;
|
||||
|
||||
@@ -13,22 +14,20 @@ class BashScript implements BotContract
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
public function run(): string
|
||||
{
|
||||
if (!empty($this->config['script'])) {
|
||||
// Execute the bash script
|
||||
$script = $this->config['script'];
|
||||
$output = [];
|
||||
$returnVar = null;
|
||||
exec($script, $output, $returnVar);
|
||||
// Execute the bash script
|
||||
$script = $this->config['script'];
|
||||
$output = [];
|
||||
$returnVar = null;
|
||||
exec($script, $output, $returnVar);
|
||||
|
||||
if ($returnVar !== 0) {
|
||||
// Log error if the script failed
|
||||
\Illuminate\Support\Facades\Log::error("Bash script execution failed: " . implode("\n", $output));
|
||||
} else {
|
||||
Log::info("Bash script executed successfully: " . implode("\n", $output));
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user