2014-09-23 16:02:34 +02:00
|
|
|
var child_process = require('child_process');
|
|
|
|
var Promise = require('bluebird');
|
|
|
|
var join = require('path').join;
|
|
|
|
var mkdirp = Promise.promisifyAll(require('mkdirp'));
|
|
|
|
|
2015-04-28 22:12:28 +02:00
|
|
|
var execFile = Promise.promisify(child_process.execFile);
|
2015-02-18 20:17:47 +01:00
|
|
|
|
|
|
|
var getBaseNames = function (grunt) {
|
|
|
|
var packageName = grunt.config.get('pkg.name');
|
|
|
|
var version = grunt.config.get('pkg.version');
|
|
|
|
var platforms = grunt.config.get('platforms');
|
|
|
|
return platforms.map(function (platform) {
|
|
|
|
return packageName + '-' + version + '-' + platform;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function createPackages(grunt) {
|
2014-09-23 16:02:34 +02:00
|
|
|
grunt.registerTask('create_packages', function () {
|
|
|
|
var done = this.async();
|
|
|
|
var target = grunt.config.get('target');
|
|
|
|
var distPath = join(grunt.config.get('build'), 'dist');
|
2015-04-28 23:01:48 +02:00
|
|
|
var version = grunt.config.get('pkg.version');
|
2014-09-23 16:02:34 +02:00
|
|
|
|
2015-02-18 20:17:47 +01:00
|
|
|
var createPackage = function (name) {
|
2015-01-09 19:08:14 +01:00
|
|
|
var options = { cwd: distPath };
|
|
|
|
var archiveName = join(target, name);
|
2015-04-28 23:01:48 +02:00
|
|
|
var commands = [];
|
|
|
|
var arch = /x64$/.test(name) ? 'x86_64' : 'i686';
|
2014-09-23 16:02:34 +02:00
|
|
|
|
2015-05-05 02:06:32 +02:00
|
|
|
var fpm_options = [ 'fpm', '-f', '-p', target, '-s', 'dir', '-n', 'kibana', '-v', version,
|
2015-05-05 01:55:04 +02:00
|
|
|
'--after-install', join(distPath, 'user', 'installer.sh'),
|
2015-05-05 02:06:32 +02:00
|
|
|
'--after-remove', join(distPath, 'user', 'remover.sh'),
|
|
|
|
'--config-files', '/opt/kibana/config/kibana.yml' ];
|
2015-04-28 23:01:48 +02:00
|
|
|
var fpm_files = join(distPath, name) + '/=/opt/kibana';
|
|
|
|
|
|
|
|
// kibana.tar.gz
|
|
|
|
commands.push([ 'tar', '-zcf', archiveName + '.tar.gz', name ]);
|
|
|
|
|
|
|
|
// kibana.zip
|
2015-02-18 20:17:47 +01:00
|
|
|
if (/windows/.test(name)) {
|
2015-04-28 23:01:48 +02:00
|
|
|
commands.push([ 'zip', '-rq', '-ll', archiveName + '.zip', name ]);
|
|
|
|
} else {
|
|
|
|
commands.push([ 'zip', '-rq', archiveName + '.zip', name ]);
|
|
|
|
}
|
|
|
|
|
2015-05-21 21:45:09 +02:00
|
|
|
if (grunt.option('os-packages')) {
|
|
|
|
// TODO(sissel): Add before-install scripts to create kibana user
|
|
|
|
// TODO(sissel): Check if `fpm` is available
|
|
|
|
if (/linux-x(86|64)$/.test(name)) {
|
|
|
|
// kibana.rpm and kibana.deb
|
|
|
|
var sysv_init = join(distPath, 'services', 'sysv') + '/etc/=/etc/';
|
|
|
|
commands.push(fpm_options.concat(['-t', 'rpm', '-a', arch, '--rpm-os', 'linux', fpm_files, sysv_init]));
|
|
|
|
commands.push(fpm_options.concat(['-t', 'deb', '-a', arch, fpm_files, sysv_init]));
|
|
|
|
} else if (/darwin-x(86|64)$/.test(name)) {
|
|
|
|
// kibana.pkg
|
|
|
|
var launchd = join(distPath, 'services', 'launchd') + '/=/';
|
|
|
|
commands.push(fpm_options.concat(['-t', 'osxpkg', '-a', arch, fpm_files, launchd]));
|
|
|
|
}
|
2015-01-16 19:35:46 +01:00
|
|
|
}
|
|
|
|
|
2015-01-09 19:08:14 +01:00
|
|
|
return mkdirp.mkdirpAsync(target)
|
|
|
|
.then(function (arg) {
|
2015-04-28 23:01:48 +02:00
|
|
|
return Promise.map(commands, function (cmd) {
|
|
|
|
return execFile(cmd.shift(), cmd, options);
|
|
|
|
});
|
2015-04-28 22:12:28 +02:00
|
|
|
}, function (err) { console.log('Failure on ' + name + ': ' + err); });
|
2015-01-09 19:08:14 +01:00
|
|
|
};
|
2014-09-23 16:02:34 +02:00
|
|
|
|
2015-02-18 20:17:47 +01:00
|
|
|
Promise.map(getBaseNames(grunt), createPackage).finally(done);
|
2014-09-23 16:02:34 +02:00
|
|
|
});
|
2015-02-18 20:17:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = createPackages;
|
|
|
|
createPackages.getBaseNames = getBaseNames;
|