2016-05-25 22:19:16 +02:00
|
|
|
import { resolve } from 'path';
|
|
|
|
import { indexBy } from 'lodash';
|
|
|
|
import exec from '../utils/exec';
|
2016-05-25 21:21:36 +02:00
|
|
|
|
2016-05-25 22:19:16 +02:00
|
|
|
export default (grunt) => {
|
2016-05-27 22:40:57 +02:00
|
|
|
const { config } = grunt;
|
|
|
|
const exec = require('../utils/exec');
|
|
|
|
const targetDir = config.get('target');
|
2016-05-25 22:19:16 +02:00
|
|
|
const packageScriptsDir = grunt.config.get('packageScriptsDir');
|
2016-05-27 22:40:57 +02:00
|
|
|
const servicesByName = indexBy(config.get('services'), 'name');
|
|
|
|
const packages = config.get('packages');
|
2016-05-25 22:15:09 +02:00
|
|
|
const fpm = args => exec('fpm', args);
|
2015-08-14 06:16:54 +02:00
|
|
|
|
2015-08-14 22:27:41 +02:00
|
|
|
grunt.registerTask('_build:osPackages', function () {
|
2016-06-16 16:36:06 +02:00
|
|
|
grunt.file.mkdir(targetDir);
|
2016-06-16 16:18:40 +02:00
|
|
|
|
2016-05-27 22:40:57 +02:00
|
|
|
config.get('platforms')
|
2016-05-25 22:15:09 +02:00
|
|
|
.filter(({ name }) => /linux-x(86|64)$/.test(name))
|
|
|
|
.map(({ name, buildDir }) => {
|
|
|
|
const architecture = /x64$/.test(name) ? 'x86_64' : 'i386';
|
|
|
|
return {
|
|
|
|
buildDir,
|
|
|
|
architecture
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.forEach(({ buildDir, architecture }) => {
|
|
|
|
const baseOptions = [
|
2015-08-14 22:27:41 +02:00
|
|
|
'--force',
|
|
|
|
'--package', targetDir,
|
|
|
|
'-s', 'dir', // input type
|
2016-05-25 22:15:09 +02:00
|
|
|
'--architecture', architecture,
|
2016-05-27 22:40:57 +02:00
|
|
|
'--name', packages.name,
|
|
|
|
'--description', packages.description,
|
|
|
|
'--version', packages.version,
|
|
|
|
'--url', packages.site,
|
|
|
|
'--vendor', packages.vendor,
|
|
|
|
'--maintainer', packages.maintainer,
|
|
|
|
'--license', packages.license,
|
2016-03-28 04:06:16 +02:00
|
|
|
'--after-install', resolve(packageScriptsDir, 'post_install.sh'),
|
2016-05-09 21:40:05 +02:00
|
|
|
'--before-install', resolve(packageScriptsDir, 'pre_install.sh'),
|
2016-03-28 04:06:16 +02:00
|
|
|
'--before-remove', resolve(packageScriptsDir, 'pre_remove.sh'),
|
|
|
|
'--after-remove', resolve(packageScriptsDir, 'post_remove.sh'),
|
2016-05-27 22:40:57 +02:00
|
|
|
'--config-files', packages.path.kibanaConfig,
|
|
|
|
'--template-value', `user=${packages.user}`,
|
|
|
|
'--template-value', `group=${packages.group}`,
|
|
|
|
'--template-value', `optimizeDir=${packages.path.home}/optimize`,
|
2016-05-26 00:05:28 +02:00
|
|
|
'--template-value', `configDir=${packages.path.conf}`,
|
|
|
|
'--template-value', `pluginsDir=${packages.path.plugins}`,
|
2016-05-25 21:21:36 +02:00
|
|
|
//config folder is moved to path.conf, exclude {path.home}/config
|
|
|
|
//uses relative path to --prefix, strip the leading /
|
2016-05-27 22:40:57 +02:00
|
|
|
'--exclude', `${packages.path.home.slice(1)}/config`
|
2015-08-14 06:16:54 +02:00
|
|
|
];
|
2016-05-25 22:15:09 +02:00
|
|
|
const debOptions = [
|
|
|
|
'-t', 'deb',
|
|
|
|
'--deb-priority', 'optional'
|
|
|
|
];
|
|
|
|
const rpmOptions = [
|
|
|
|
'-t', 'rpm',
|
|
|
|
'--rpm-os', 'linux'
|
|
|
|
];
|
|
|
|
const args = [
|
2016-05-27 22:40:57 +02:00
|
|
|
`${buildDir}/=${packages.path.home}/`,
|
|
|
|
`${buildDir}/config/=${packages.path.conf}/`,
|
2016-05-25 16:12:08 +02:00
|
|
|
`${servicesByName.sysv.outputDir}/etc/=/etc/`,
|
|
|
|
`${servicesByName.systemd.outputDir}/lib/=/lib/`
|
|
|
|
];
|
2015-08-14 06:16:54 +02:00
|
|
|
|
2015-12-29 22:32:06 +01:00
|
|
|
//Manually find flags, multiple args without assignment are not entirely parsed
|
2016-05-25 22:19:16 +02:00
|
|
|
const flags = grunt.option.flags().filter(flag => /deb|rpm/.test(flag)).join(',');
|
2016-05-25 22:15:09 +02:00
|
|
|
const buildDeb = flags.includes('deb') || !flags.length;
|
|
|
|
const buildRpm = flags.includes('rpm') || !flags.length;
|
|
|
|
if (buildDeb) {
|
|
|
|
fpm([...baseOptions, ...debOptions, ...args]);
|
2015-08-14 06:16:54 +02:00
|
|
|
}
|
2016-05-25 22:15:09 +02:00
|
|
|
if (buildRpm) {
|
|
|
|
fpm([...baseOptions, ...rpmOptions, ...args]);
|
2015-12-29 22:32:06 +01:00
|
|
|
}
|
|
|
|
|
2015-08-14 06:16:54 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|