mecano
Version:
Common functions for system deployment.
73 lines (70 loc) • 2.15 kB
JavaScript
// Generated by CoffeeScript 1.11.1
var string;
module.exports = {
system: function(options) {
return this.execute({
cmd: 'cat /etc/system-release',
shy: true,
code_skipped: 1
}, function(err, status, stdout, stderr) {
var base, base1, base2, base3, index, line;
if (err) {
throw err;
}
line = string.lines(stdout)[0];
if (/CentOS/.test(line)) {
if ((base = options.store)['mecano:system:type'] == null) {
base['mecano:system:type'] = 'centos';
}
index = line.split(' ').indexOf('release');
if ((base1 = options.store)['mecano:system:release'] == null) {
base1['mecano:system:release'] = line.split(' ')[index + 1];
}
}
if (/Red\sHat/.test(line)) {
if ((base2 = options.store)['mecano:system:type'] == null) {
base2['mecano:system:type'] = 'redhat';
}
index = line.split(' ').indexOf('release');
if ((base3 = options.store)['mecano:system:release'] == null) {
base3['mecano:system:release'] = line.split(' ')[index + 1];
}
}
if (options.store['mecano:system:type'] == null) {
throw Error('Unsupported OS');
}
});
},
loader: function(options) {
return this.execute({
shy: true,
cmd: "if which systemctl >/dev/null; then exit 1; fi ;\nif which service >/dev/null; then exit 2; fi ;\nexit 3 ;",
code: [1, 2],
unless: options.loader != null,
shy: true
}, function(err, status, stdout, stderr, signal) {
if ((err != null ? err.code : void 0) === 3) {
throw Error("Undetected Operating System Loader");
}
if (err) {
throw err;
}
if (!status) {
return;
}
if (options.store == null) {
options.store = {};
}
options.loader = (function() {
switch (signal) {
case 1:
return 'systemctl';
case 2:
return 'service';
}
})();
return options.store['mecano:service:loader'] = options.loader;
});
}
};
string = require('../misc/string');