-
Notifications
You must be signed in to change notification settings - Fork 16
/
makedeb.js
executable file
·106 lines (85 loc) · 2.48 KB
/
makedeb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env node
/* jshint esversion: 6 */
const fs = require('fs-extra');
const os = require('os');
const path = require('path');
const spawn = require('child_process').spawnSync;
const copy = require('recursive-copy');
const rimraf = require('rimraf');
const which = require('which');
const program = require('commander');
const pkginfo = require('./package.json');
const plugininfo = require('./src/plugin.json');
try {
which.sync('dpkg-buildpackage');
} catch (err) {
console.log('dpkg-buildpackage executable not found');
process.exit(1);
}
let version = pkginfo.version;
let release = 1;
if (version.indexOf('-SNAPSHOT')) {
version = version.replace('-SNAPSHOT', '');
release = 0;
}
program
.version(pkginfo.version)
.option('-r --release <release>', 'Specify release number of package')
.parse(process.argv);
const options = program.opts();
if (options.release === undefined) {
options.release = release;
}
pkginfo.version = version;
pkginfo.release = release;
release = options.release;
const date = new Date().toUTCString().replace(/ [^ ]+$/, ' +0000');
const changelog = `${pkginfo.name} (${version}-${release}) unstable; urgency=low
* Autogenerated package.
-- Benjamin Reed <ranger@opennms.org> ${date}
`;
const pkgid = plugininfo.id;
const workdir = path.join(process.cwd(), 'artifacts', pkgid);
const distdir = path.join(process.cwd(), 'dist');
rimraf.sync(workdir);
fs.mkdirsSync(workdir);
return copy(distdir, workdir, {
dot: true,
junk: false,
filter: [
'**/*',
'!.git',
'!.git/**',
'!**/*.changes',
'!**/*.deb',
'!**/*.dsc',
'!**/*.tar.gz',
'!test',
'!test/**',
]
}).then((results) => {
console.log(results.length + ' files copied to ' + workdir);
const debian = path.join(workdir, 'debian');
fs.mkdirsSync(debian);
return copy(path.join(process.cwd(), 'src', 'debian'), debian).then((_copyResults) => {
console.log('debian/ directory copied');
console.log('* writing changelog');
const fh = fs.openSync(path.join(debian, 'changelog'), 'w+');
fs.writeSync(fh, changelog);
fs.closeSync(fh);
console.log('* running dpkg-buildpackage');
const ret = spawn('dpkg-buildpackage', [], {
cwd: workdir,
stdio: ['inherit', 'inherit', 'inherit'],
});
if (ret.error) {
console.log('dpkg-buildpackage failed');
process.exit(1);
}
rimraf.sync(workdir);
process.exit(0);
});
}).catch((error) => {
console.log('Copy failed: ' + error);
process.exit(1);
});