2020-04-11 17:29:20 +03:00
|
|
|
const { sync: commandExists } = require('command-exists');
|
|
|
|
const { get: nodeCmd } = require('node-cmd');
|
|
|
|
|
|
|
|
const validateRsync = (callback = () => {}) => {
|
2020-04-11 18:42:37 +03:00
|
|
|
const rsyncCli = commandExists('rsync');
|
2020-04-11 17:29:20 +03:00
|
|
|
|
|
|
|
if (!rsyncCli) {
|
|
|
|
nodeCmd(
|
|
|
|
'sudo apt-get --no-install-recommends install rsync',
|
|
|
|
(err, data, stderr) => {
|
|
|
|
if (err) {
|
2020-04-11 17:54:21 +03:00
|
|
|
console.log('⚠️ [CLI] Rsync installation failed. Aborting ... ', err.message);
|
2020-04-11 17:29:20 +03:00
|
|
|
process.abort();
|
|
|
|
} else {
|
|
|
|
console.log('✅ [CLI] Rsync installed. \n', data, stderr);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const validateInputs = (inputs) => {
|
2020-04-11 17:54:21 +03:00
|
|
|
const inputKeys = Object.keys(inputs);
|
|
|
|
const validInputs = inputKeys.filter((inputKey) => {
|
|
|
|
const inputValue = inputs[inputKey];
|
|
|
|
|
|
|
|
if (!inputValue) {
|
|
|
|
console.error(`⚠️ [INPUTS] ${inputKey} is mandatory`);
|
2020-04-11 17:29:20 +03:00
|
|
|
}
|
|
|
|
|
2020-04-11 17:54:21 +03:00
|
|
|
return inputValue;
|
2020-04-11 17:29:20 +03:00
|
|
|
});
|
|
|
|
|
2020-04-11 17:54:21 +03:00
|
|
|
if (validInputs.length !== inputKeys.length) {
|
2020-09-19 00:26:31 +03:00
|
|
|
console.error('⚠️ [INPUTS] Inputs not valid, aborting ...');
|
2020-04-11 17:29:20 +03:00
|
|
|
process.abort();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
validateRsync,
|
|
|
|
validateInputs
|
2020-09-19 00:26:31 +03:00
|
|
|
};
|