|
|
@@ -1,12 +1,39 @@
|
|
|
/**
|
|
|
* Command executor for webhook events
|
|
|
*/
|
|
|
-import { exec } from 'child_process';
|
|
|
+import { exec, execSync } from 'child_process';
|
|
|
import { promisify } from 'util';
|
|
|
import logger from './logger.js';
|
|
|
|
|
|
const execAsync = promisify(exec);
|
|
|
|
|
|
+// Detect shell path at module load time
|
|
|
+function detectShellPath() {
|
|
|
+ try {
|
|
|
+ // Try to find bash using 'which' command
|
|
|
+ const bashPath = execSync('which bash', { encoding: 'utf8' }).trim();
|
|
|
+ if (bashPath) {
|
|
|
+ return bashPath;
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ // Fallback to common bash locations
|
|
|
+ const commonPaths = ['/bin/bash', '/usr/bin/bash', '/usr/local/bin/bash'];
|
|
|
+ for (const path of commonPaths) {
|
|
|
+ try {
|
|
|
+ execSync(`test -x ${path}`, { encoding: 'utf8' });
|
|
|
+ return path;
|
|
|
+ } catch {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // Ultimate fallback: use /bin/sh
|
|
|
+ return '/bin/sh';
|
|
|
+}
|
|
|
+
|
|
|
+const SHELL_PATH = detectShellPath();
|
|
|
+logger.info('Detected shell path', { shell: SHELL_PATH });
|
|
|
+
|
|
|
export class CommandExecutor {
|
|
|
/**
|
|
|
* Extract variables from webhook payload
|
|
|
@@ -173,7 +200,7 @@ export class CommandExecutor {
|
|
|
const { stdout, stderr } = await execAsync(fullCommand, {
|
|
|
timeout,
|
|
|
cwd: cwd || process.cwd(),
|
|
|
- shell: '/bin/bash',
|
|
|
+ shell: SHELL_PATH,
|
|
|
maxBuffer: 10 * 1024 * 1024 // 10MB
|
|
|
});
|
|
|
|