MCPcopy Create free account
hub / github.com/easingthemes/ssh-deploy / remoteCmd

Function remoteCmd

src/remoteCmd.js:14–41  ·  view source on GitHub ↗
(content, privateKeyPath, isRequired, label)

Source from the content-addressed store, hash-verified

12};
13
14const remoteCmd = async (content, privateKeyPath, isRequired, label) => new Promise((resolve, reject) => {
15 const uuid = crypto.randomUUID();
16 const filename = `local_ssh_script-${label}-${uuid}.sh`;
17 try {
18 writeToFile({ dir: githubWorkspace, filename, content });
19 const dataLimit = 10000;
20 const rsyncStdout = (process.env.RSYNC_STDOUT || '').substring(0, dataLimit);
21 console.log(`Executing remote script: ssh -i ${privateKeyPath} ${sshServer}`);
22 exec(
23 `DEBIAN_FRONTEND=noninteractive ssh -p ${(remotePort || 22)} -i ${privateKeyPath} -o StrictHostKeyChecking=no ${sshServer} 'RSYNC_STDOUT="${rsyncStdout}" bash -s' < ${filename}`,
24 (err, data = '', stderr = '') => {
25 if (err) {
26 const message = `⚠️ [CMD] Remote script failed: ${err.message}`;
27 console.warn(`${message} \n`, data, stderr);
28 handleError(message, isRequired, reject);
29 } else {
30 const limited = data.substring(0, dataLimit);
31 console.log('✅ [CMD] Remote script executed. \n', limited, stderr);
32 deleteFile({ dir: githubWorkspace, filename });
33 console.log('✅ [FILE] Script file deleted.');
34 resolve(limited);
35 }
36 }
37 );
38 } catch (err) {
39 handleError(err.message, isRequired, reject);
40 }
41});
42
43module.exports = {
44 remoteCmdBefore: async (cmd, privateKeyPath, isRequired) => remoteCmd(cmd, privateKeyPath, isRequired, 'before'),

Callers 1

remoteCmd.jsFile · 0.85

Calls 3

writeToFileFunction · 0.85
deleteFileFunction · 0.85
handleErrorFunction · 0.70

Tested by

no test coverage detected