mirror of
https://git.coolaj86.com/coolaj86/telebit.js.git
synced 2024-11-20 12:34:41 +00:00
add some preinstall/postinstall scripts
This commit is contained in:
parent
33dd835092
commit
b4b4b68bac
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,7 @@
|
||||
*.tar.gz
|
||||
*.zip
|
||||
telebit-stable-*
|
||||
|
||||
node_modules.*
|
||||
*.*.sw*
|
||||
etc/acme/
|
||||
|
3
bin-public/telebit
Executable file
3
bin-public/telebit
Executable 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
1
bin-public/telebit.cmd
Normal file
@ -0,0 +1 @@
|
||||
"%~dp0\..\bin\node" "%~dp0\..\bin\telebit.js" %*
|
49
scripts/postinstall.js
Normal file
49
scripts/postinstall.js
Normal 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
49
scripts/preinstall.js
Normal 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);
|
||||
});
|
Loading…
Reference in New Issue
Block a user