add some preinstall/postinstall scripts

This commit is contained in:
AJ ONeal 2019-08-10 01:42:48 -06:00
parent 33dd835092
commit b4b4b68bac
5 changed files with 106 additions and 0 deletions

4
.gitignore vendored
View File

@ -1,3 +1,7 @@
*.tar.gz
*.zip
telebit-stable-*
node_modules.*
*.*.sw*
etc/acme/

3
bin-public/telebit Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
"$(dirname $(dirname $0))/bin/node" "$(dirname $(dirname $0))/bin/telebit.js" "$@"
exit $?

1
bin-public/telebit.cmd Normal file
View File

@ -0,0 +1 @@
"%~dp0\..\bin\node" "%~dp0\..\bin\telebit.js" %*

49
scripts/postinstall.js Normal file
View File

@ -0,0 +1,49 @@
'use strict';
// use pathman and serviceman to make telebit ready
var spawn = require('child_process').spawn;
var os = require('os');
var path = require('path');
var ext = /^win/i.test(os.platform()) ? '.exe' : '';
function run(bin, args) {
return new Promise(function(resolve, reject) {
var runner = spawn(path.join(bin + ext), args, {
windowsHide: true
});
runner.stdout.on('data', function(chunk) {
console.info(chunk.toString('utf8'));
});
runner.stderr.on('data', function(chunk) {
console.error(chunk.toString('utf8'));
});
runner.on('exit', function(code) {
if (0 !== code) {
reject(
new Error("exited with non-zero status code '" + code + "'")
);
return;
}
resolve({ code: code });
});
});
}
run('serviceman', [
'add',
'--name',
'telebit',
'--title',
'Telebit',
'--rdns',
'io.telebit.remote.telebit',
path.resolve(__dirname, '..', 'bin', 'telebit.js'),
'daemon',
'--config',
path.join(os.homedir(), '.config/telebit/telebitd.yml')
])
.then(function() {})
.catch(function(e) {
console.error(e.message);
});

49
scripts/preinstall.js Normal file
View File

@ -0,0 +1,49 @@
'use strict';
// use pathman and serviceman to make telebit ready
var spawn = require('child_process').spawn;
var os = require('os');
var path = require('path');
var ext = /^win/i.test(os.platform()) ? '.exe' : '';
function run(bin, args) {
return new Promise(function(resolve, reject) {
var runner = spawn(path.join(bin + ext), args, {
windowsHide: true
});
var out = '';
runner.stdout.on('data', function(chunk) {
var txt = chunk.toString('utf8');
out += txt;
});
runner.stderr.on('data', function(chunk) {
var txt = chunk.toString('utf8');
out += txt;
});
runner.on('exit', function(code) {
if (0 !== code && !/service matching/.test(out)) {
console.error(out);
reject(
new Error("exited with non-zero status code '" + code + "'")
);
return;
}
resolve({ code: code });
});
});
}
var confpath = path.join(os.homedir(), '.config/telebit');
require('mkdirp')(confpath, function(err) {
if (err) {
console.error("Error creating config path '" + confpath + "':");
console.error(err);
}
// not having a config is fine
});
run('serviceman', ['stop', 'telebit']).catch(function(e) {
// TODO ignore
console.error(e.message);
});