ssh-deploy/src/rsyncCli.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-12-30 17:23:23 +03:00
const { sync: commandExists } = require("command-exists");
const { exec, execSync } = require("child_process");
const validateRsync = (callback = () => {}) => {
2022-12-30 17:23:23 +03:00
const rsyncCli = commandExists("rsync");
2022-12-31 12:00:32 +03:00
if (rsyncCli) {
2022-12-31 12:14:04 +03:00
console.log('⚠️ [CLI] Rsync exists');
2022-12-31 12:04:57 +03:00
const rsyncVersion = execSync("rsync --version", { stdio: 'inherit' });
2022-12-31 12:00:32 +03:00
return callback();
}
2022-12-30 16:29:31 +03:00
console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');
2022-12-31 12:00:32 +03:00
try {
2022-12-31 12:06:06 +03:00
execSync("sudo apt-get update", { stdio: 'inherit' });
2022-12-31 12:00:32 +03:00
} catch (e) {
console.log( "⚠️ [CLI] Cant run . apt-get update. Skipping ...". e.message);
}
2022-12-31 12:00:32 +03:00
2022-12-31 12:06:06 +03:00
exec("sudo apt-get --no-install-recommends install rsync", { stdio: 'inherit' }, (err, data, stderr) => {
2022-12-31 12:00:32 +03:00
if (err) {
console.log("⚠️ [CLI] Rsync installation failed. Aborting ... ", err.message);
process.abort();
} else {
console.log("✅ [CLI] Rsync installed. \n", data, stderr);
callback();
}
});
};
const validateInputs = (inputs) => {
const inputKeys = Object.keys(inputs);
const validInputs = inputKeys.filter((inputKey) => {
const inputValue = inputs[inputKey];
if (!inputValue) {
console.error(`⚠️ [INPUTS] ${inputKey} is mandatory`);
}
return inputValue;
});
if (validInputs.length !== inputKeys.length) {
2022-12-30 17:23:23 +03:00
console.error("⚠️ [INPUTS] Inputs not valid, aborting ...");
process.abort();
}
};
module.exports = {
validateRsync,
2022-12-30 17:23:23 +03:00
validateInputs,
2020-09-19 00:26:31 +03:00
};