AJ ONeal
5 years ago
5 changed files with 106 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||
#!/usr/bin/env bash |
|||
"$(dirname $(dirname $0))/bin/node" "$(dirname $(dirname $0))/bin/telebit.js" "$@" |
|||
exit $? |
@ -0,0 +1 @@ |
|||
"%~dp0\..\bin\node" "%~dp0\..\bin\telebit.js" %* |
@ -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); |
|||
}); |
@ -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