forked from IDWMaster/ntrujs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
executable file
·44 lines (39 loc) · 1.62 KB
/
install.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
var os = require('os');
var child_process = require('child_process');
var fs = require('fs');
fs.copy = function (src, dest, callBach) {
fs.open(src, 'r', function (err, rfd) {
fs.open(dest, 'w+', function (err, wfd) {
var srcStream = fs.createReadStream(null, { fd: rfd });
var destStream = fs.createWriteStream(null, { fd: wfd });
srcStream.pipe(destStream);
srcStream.on('close', function () {
callBach();
});
});
});
};
var run_installer = function () {
child_process.exec('(node-gyp rebuild) || (exit 0)', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
if (stderr.indexOf('gyp ERR!') > -1) {
console.log('Failed to compile ntrujs for your platform. To ensure successful compilation; please make sure that your platform-specific NTRU libraries are in the lib/lib folder. If you have downloaded pre-compiled binaries and do not wish to modify them, you can safely ignore this error.');
process.exit(0);
} else {
fs.copy('build/Release/addon.node', 'lib/addon-'+os.platform()+'-'+os.arch()+'.node', function () {
process.exit(0);
});
}
});
};
var src_gyp = "binding_linux.gyp";
switch(os.platform()) {
case "win32": src_gyp = "windows.gysrc"; break;
case "darwin": src_gyp = "darwin.gysrc"; break;
default: src_gyp = "linux.gysrc"; break;
}
console.log('Source .gyp file: ' + src_gyp);
fs.copy(src_gyp, 'binding.gyp', function () {
run_installer();
});