diff --git a/usr/share/dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl b/usr/share/dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl
index 6d9f496..a455b8f 100644
--- a/usr/share/dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl
+++ b/usr/share/dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl
@@ -6,11 +6,11 @@
Telebit Remote
ProgramArguments
- {TELEBIT_PATH}/bin/node
- {TELEBIT_PATH}/bin/telebitd.js
+ {TELEBIT_NODE}
+ {TELEBITD_JS}
daemon
--config
- {TELEBIT_PATH}/etc/telebitd.yml
+ {TELEBITD_CONFIG}
EnvironmentVariables
@@ -51,11 +51,11 @@
WorkingDirectory
- {TELEBIT_PATH}
+ {TELEBIT_PATH}
StandardErrorPath
- {TELEBIT_PATH}/var/log/error.log
+ {TELEBIT_PATH}/var/log/error.log
StandardOutPath
- {TELEBIT_PATH}/var/log/info.log
+ {TELEBIT_PATH}/var/log/info.log
diff --git a/usr/share/dist/bin/telebit.tpl b/usr/share/dist/bin/telebit.tpl
new file mode 100644
index 0000000..13dcfc9
--- /dev/null
+++ b/usr/share/dist/bin/telebit.tpl
@@ -0,0 +1,2 @@
+#!/bin/bash
+{TELEBIT_NODE} {TELEBIT_JS} "$@"
diff --git a/usr/share/dist/bin/telebitd.tpl b/usr/share/dist/bin/telebitd.tpl
new file mode 100644
index 0000000..ae308ec
--- /dev/null
+++ b/usr/share/dist/bin/telebitd.tpl
@@ -0,0 +1,2 @@
+#!/bin/bash
+{TELEBIT_NODE} {TELEBITD_JS} daemon "$@"
diff --git a/usr/share/dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl b/usr/share/dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl
index 4a7bb9c..5438d57 100644
--- a/usr/share/dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl
+++ b/usr/share/dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl
@@ -7,11 +7,11 @@
ProgramArguments
- {TELEBIT_PATH}/bin/node
- {TELEBIT_PATH}/bin/telebitd.js
+ {TELEBIT_NODE}
+ {TELEBITD_JS}
daemon
--config
- {TELEBIT_CONFIGD}
+ {TELEBITD_CONFIG}
EnvironmentVariables
@@ -24,22 +24,22 @@
{TELEBIT_PATH}
-
+ -->
RunAtLoad
KeepAlive
WorkingDirectory
- {TELEBIT_PATH}
+ {TELEBIT_PATH}
StandardErrorPath
- {TELEBIT_PATH}/var/log/error.log
+ {TELEBIT_PATH}/var/log/error.log
StandardOutPath
- {TELEBIT_PATH}/var/log/info.log
+ {TELEBIT_PATH}/var/log/info.log
diff --git a/usr/share/install-launcher.js b/usr/share/install-launcher.js
new file mode 100644
index 0000000..2ebc920
--- /dev/null
+++ b/usr/share/install-launcher.js
@@ -0,0 +1,180 @@
+'use strict';
+
+//var fs = require('fs');
+var os = require('os');
+var mkdirp = require('mkdirp');
+var exec = require('child_process').exec;
+var path = require('path');
+
+module.exports.install = function (things) {
+ things = things || {};
+ // in some future version we can take this file out
+ // and accept process.env from things
+ var installLauncher = require('./install-launcher');
+
+ // Right now this is just for npm install -g and npx
+ if (things.env) {
+ things.env.PATH = things.env.PATH || process.env.PATH;
+ }
+ var execOpts = { windowsHide: true, env: things.env || process.env };
+ var userspace = (!things.telebitUser || (things.telebitUser === os.userInfo().username)) ? true : false;
+ var telebitRoot = path.join(__dirname, '../..');
+ var telebitBinTpl = path.join(telebitRoot, 'dist/bin/telebit.tpl');
+ var vars = {
+ telebitPath: telebitRoot
+ , telebitUser: os.userInfo().username
+ , telebitGroup: (/^darwin/i.test(os.platform()) ? 'staff' : os.userInfo().username)
+ , telebitRwDirs: [
+ path.resolve(__dirname, '../..')
+ , path.join(os.homedir(), '.config/telebit')
+ , path.join(os.homedir(), '.local/share/telebit')
+ ].join(' ')
+ , telebitNode: path.join(telebitRoot, 'bin/node')
+ , telebitNpm: path.join(telebitRoot, 'bin/npm')
+ , telebitBin: path.join(telebitRoot, 'bin/telebit')
+ , telebitdBin: path.join(telebitRoot, 'bin/telebitd')
+ , telebitBinJs: path.join(telebitRoot, 'bin/telebit.js')
+ , telebitdBinJs: path.join(telebitRoot, 'bin/telebitd.js')
+ , telebitConfig: path.join(os.homedir(), '.config/telebit/telebit.yml')
+ , telebitdConfig: path.join(os.homedir(), '.config/telebit/telebitd.yml')
+ };
+ var launchers = {
+ 'launchctl': function () {
+ var launcher = path.join(os.homedir(), 'Library/LaunchAgents/cloud.telebit.remote.plist');
+ try {
+ mkdirp.sync(path.join(os.homedir(), 'Library/LaunchAgents'));
+ mkdirp.sync(path.join(telebitRoot, 'bin'));
+ installLauncher({
+ file: {
+ tpl: telebitBinTpl
+ , launcher: path.join(telebitRoot, 'bin/telebit')
+ }
+ , vars: vars
+ }, function (err) {
+ if (err) { console.error(err); }
+ installLauncher({
+ file: {
+ tpl: path.join(__dirname, 'dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl')
+ , launcher: launcher
+ }
+ , vars: vars
+ }, function (err) {
+ if (err) { console.error(err); }
+ var launcherstr = (userspace ? "sudo " : "") + "launchctl ";
+ exec(launcherstr + "unload -w " + launcher, execOpts, function (err, stdout, stderr) {
+ console.log(stdout);
+ if (stderr) {
+ console.error(stderr);
+ }
+ exec(launcherstr + "load -w " + launcher, execOpts, function (err, stdout, stderr) {
+ console.log(stdout);
+ if (stderr) {
+ console.error(stderr);
+ }
+ });
+ });
+ });
+ });
+ } catch(e) {
+ }
+ }
+ , 'systemctl': function () {
+ var launcher = path.join(os.homedir(), '.config/systemd/user/telebit.service');
+ try {
+ mkdirp.sync(path.join(os.homedir(), '.config/systemd/user'));
+ installLauncher({
+ file: {
+ tpl: path.join(__dirname, 'dist/etc/skel/.config/systemd/user/telebit.service.tpl')
+ , launcher: launcher
+ }
+ , vars: vars
+ }, function () {
+ var launcherstr = "systemctl " + (userspace ? "--user " : "");
+ exec(launcherstr + "daemon-reload", execOpts, function (err, stdout, stderr) {
+ console.log(stdout);
+ if (stderr) { console.error(stderr); }
+ exec(launcherstr + "enable " + launcher, execOpts, function (err, stdout, stderr) {
+ console.log(stdout);
+ if (stderr) { console.error(stderr); }
+ exec(launcherstr + "restart " + launcher, execOpts, function (err, stdout, stderr) {
+ console.log(stdout);
+ if (stderr) { console.error(stderr); }
+ });
+ });
+ });
+ });
+ } catch(e) {
+ }
+ }
+ , 'reg.exe': function () {
+ vars.telebitNode += '.exe';
+ var cmd = 'reg.exe add "HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"'
+ + ' /V "Telebit" /t REG_SZ /D '
+ + '"' + process.argv[0] + ' /c ' // something like C:\\Program Files (x64)\nodejs\node.exe
+ + [ path.join(__dirname, 'bin/telebitd.js')
+ , 'daemon'
+ , '--config'
+ , path.join(os.homedir(), '.config/telebit/telebitd.yml')
+ ].join(' ')
+ + '" /F'
+ ;
+ exec(cmd, execOpts, function (err, stdout, stderr) {
+ console.log(stdout);
+ if (stderr) {
+ console.error(stderr);
+ }
+ run(err, 'launchctl');
+ });
+ }
+ };
+
+ function run(err, launcher) {
+ if (err) {
+ console.error("No luck with '" + launcher + "'");
+ return;
+ }
+
+ if (!launchers[launcher]) {
+ launchers[launcher]();
+ return;
+ }
+ }
+
+ // could have used "command-exists" but I'm trying to stay low-dependency
+ // os.platform(), os.type()
+ if (!/^win/i.test(os.platform())) {
+ if (!/^darwin/i.test(os.platform())) {
+ exec('type -p launchctl', execOpts, function (err, stdout, stderr) {
+ console.log(stdout);
+ if (stderr) {
+ console.error(stderr);
+ }
+ run(err, 'launchctl');
+ });
+ } else {
+ exec('type -p systemctlctl', execOpts, function (err, stdout, stderr) {
+ console.log(stdout);
+ if (stderr) {
+ console.error(stderr);
+ }
+ run(err, 'launchctl');
+ });
+ }
+ } else {
+ // https://stackoverflow.com/questions/17908789/how-to-add-an-item-to-registry-to-run-at-startup-without-uac
+ // wininit? regedit? SCM?
+ // REG ADD "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "My App" /t REG_SZ /F /D "C:\MyAppPath\MyApp.exe"
+ // https://www.microsoft.com/developerblog/2015/11/09/reading-and-writing-to-the-windows-registry-in-process-from-node-js/
+ // https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/reg-add
+ // https://social.msdn.microsoft.com/Forums/en-US/5b318f44-281e-4098-8dee-3ba8435fa391/add-registry-key-for-autostart-of-app-in-ice?forum=quebectools
+ // utils.elevate
+ // https://github.com/CatalystCode/windows-registry-node
+ exec('where reg.exe', execOpts, function (err, stdout, stderr) {
+ console.log(stdout);
+ if (stderr) {
+ console.error(stderr);
+ }
+ run(err, 'reg.exe');
+ });
+ }
+};
diff --git a/usr/share/install_helper.sh b/usr/share/install_helper.sh
index f9aafe9..b19a263 100644
--- a/usr/share/install_helper.sh
+++ b/usr/share/install_helper.sh
@@ -47,11 +47,9 @@ my_secret=${4:-}
cur_user="$(id -u -n)"
TELEBIT_USER="${TELEBIT_USER:-$cur_user}"
-my_user="$TELEBIT_USER"
cur_group="$(id -g -n)"
TELEBIT_GROUP="${TELEBIT_GROUP:-$cur_group}"
-my_group="$TELEBIT_GROUP"
my_app_pkg_name="cloud.telebit.remote"
my_app="telebit"
@@ -253,53 +251,61 @@ set +e
# TODO do stuff for groups too
# TODO add ending $
if type -p dscl >/dev/null 2>/dev/null; then
- if [ -n "$(dscl . list /users | grep ^$my_user)" ] && [ -n "$(dscl . list /groups | grep ^$my_group)" ]; then
+ if [ -n "$(dscl . list /users | grep ^$TELEBIT_USER)" ] && [ -n "$(dscl . list /groups | grep ^$TELEBIT_GROUP)" ]; then
my_skip="yes"
fi
-elif [ -n "$(cat $my_root/etc/passwd | grep $my_user)" ] && [ -n "$(cat $my_root/etc/group | grep $my_group)" ]; then
+elif [ -n "$(cat $my_root/etc/passwd | grep $TELEBIT_USER)" ] && [ -n "$(cat $my_root/etc/group | grep $TELEBIT_GROUP)" ]; then
my_skip="yes"
fi
if [ -z "$my_skip" ]; then
if type -p adduser >/dev/null 2>/dev/null; then
- $real_sudo_cmd adduser --home $TELEBIT_REAL_PATH --gecos '' --disabled-password $my_user >/dev/null 2>&1
- #my_user=$my_app_name
- my_group=$my_user
+ $real_sudo_cmd adduser --home $TELEBIT_REAL_PATH --gecos '' --disabled-password $TELEBIT_USER >/dev/null 2>&1
+ #TELEBIT_USER=$my_app_name
+ TELEBIT_GROUP=$TELEBIT_USER
elif [ -n "$(cat /etc/passwd | grep www-data:)" ]; then
# Linux (Ubuntu)
- my_user=www-data
- my_group=www-data
+ TELEBIT_USER=www-data
+ TELEBIT_GROUP=www-data
elif [ -n "$(cat /etc/passwd | grep _www:)" ]; then
# Mac
- my_user=_www
- my_group=_www
+ TELEBIT_USER=_www
+ TELEBIT_GROUP=_www
else
# Unsure
- my_user=$(id -u -n) # $(whoami)
- my_group=$(id -g -n)
+ TELEBIT_USER=$(id -u -n) # $(whoami)
+ TELEBIT_GROUP=$(id -g -n)
fi
fi
set -e
-export TELEBIT_USER=$my_user
-export TELEBIT_GROUP=$my_group
+export TELEBIT_USER
+export TELEBIT_GROUP
export TELEBIT_PATH
TELEBIT_CONFIG=$HOME/.config/$my_app/$my_app.yml
# TODO check both expected sock paths in client by default
if [ "yes" == "$TELEBIT_USERSPACE" ]; then
TELEBIT_TMP_CONFIGD=$HOME/.config/$my_app/$my_daemon.yml
- TELEBIT_CONFIGD=$HOME/.config/$my_app/$my_daemon.yml
+ TELEBITD_CONFIG=$HOME/.config/$my_app/$my_daemon.yml
TELEBIT_SOCK=$HOME/.local/share/$my_app/var/run/$my_app.sock
else
TELEBIT_TMP_CONFIGD=$TELEBIT_TMP/etc/$my_daemon.yml
- TELEBIT_CONFIGD=$TELEBIT_REAL_PATH/etc/$my_daemon.yml
+ TELEBITD_CONFIG=$TELEBIT_REAL_PATH/etc/$my_daemon.yml
TELEBIT_SOCK=$TELEBIT_REAL_PATH/var/run/$my_app.sock
fi
+export TELEBIT_SOCK
+export TELEBIT_NODE=$TELEBIT_REAL_PATH/bin/node
+export TELEBIT_NPM=$TELEBIT_REAL_PATH/bin/npm
+export TELEBIT_BIN=$TELEBIT_REAL_PATH/bin/telebit
+export TELEBITD_BIN=$TELEBIT_REAL_PATH/bin/telebitd
+export TELEBIT_JS=$TELEBIT_REAL_PATH/bin/telebit.js
+export TELEBITD_JS=$TELEBIT_REAL_PATH/bin/telebitd.js
+
$my_node $TELEBIT_TMP/usr/share/template-launcher.js
# TODO don't create this in TMP_PATH if it exists in TELEBIT_REAL_PATH
mkdir -p "$(dirname $TELEBIT_TMP_CONFIGD)"
-if [ ! -e "$TELEBIT_CONFIGD" ]; then
+if [ ! -e "$TELEBITD_CONFIG" ]; then
echo "sock: $TELEBIT_SOCK" >> "$TELEBIT_TMP_CONFIGD"
echo "root: $TELEBIT_REAL_PATH" >> "$TELEBIT_TMP_CONFIGD"
@@ -323,8 +329,8 @@ fi
# rewrite system service file with real variables
# This should only affect non-USERSPACE installs
-#echo "${soft_sudo_cmde}chown -R $my_user '$TELEBIT_REAL_PATH'
-$soft_sudo_cmd chown -R $my_user "$TELEBIT_REAL_PATH"
+#echo "${soft_sudo_cmde}chown -R $TELEBIT_USER '$TELEBIT_REAL_PATH'
+$soft_sudo_cmd chown -R $TELEBIT_USER "$TELEBIT_REAL_PATH"
# $HOME/.config/systemd/user/
# %h/.config/telebit/telebit.yml
@@ -427,7 +433,7 @@ else
echo "Run the service manually (we couldn't detect your system service to do that automatically):"
echo ""
- echo " $my_daemon --config $TELEBIT_CONFIGD"
+ echo " $my_daemon --config $TELEBITD_CONFIG"
echo " $my_app --config $TELEBIT_CONFIG"
fi
diff --git a/usr/share/install_launcher.sh b/usr/share/install_launcher.sh
index 3855758..65b5cc9 100644
--- a/usr/share/install_launcher.sh
+++ b/usr/share/install_launcher.sh
@@ -11,28 +11,28 @@ if [ "systemd" == "$my_system_launcher" ]; then
my_stopper="${real_sudo_cmde}systemctl stop $my_app"
echo "Edit the config and restart, if desired:"
echo ""
- echo " ${real_sudo_cmde}$my_edit $TELEBIT_CONFIGD"
+ echo " ${real_sudo_cmde}$my_edit $TELEBITD_CONFIG"
echo " ${real_sudo_cmde}systemctl restart $my_app"
echo ""
echo "Or disabled the service and start manually:"
echo ""
echo " ${real_sudo_cmde}systemctl stop $my_app"
echo " ${real_sudo_cmde}systemctl disable $my_app"
- echo " $my_daemon --config $TELEBIT_CONFIGD"
+ echo " $my_daemon --config $TELEBITD_CONFIG"
elif [ "launchd" == "$my_system_launcher" ]; then
my_stopper="${real_sudo_cmde}launchctl unload $my_app_launchd_service"
echo "Edit the config and restart, if desired:"
echo ""
- echo " ${real_sudo_cmde}$my_edit $TELEBIT_CONFIGD"
+ echo " ${real_sudo_cmde}$my_edit $TELEBITD_CONFIG"
echo " ${real_sudo_cmde}launchctl unload $my_app_launchd_service"
echo " ${real_sudo_cmde}launchctl load -w $my_app_launchd_service"
echo ""
echo "Or disabled the service and start manually:"
echo ""
echo " ${real_sudo_cmde}launchctl unload -w $my_app_launchd_service"
- echo " $my_daemon --config $TELEBIT_CONFIGD"
+ echo " $my_daemon --config $TELEBITD_CONFIG"
else
@@ -40,7 +40,7 @@ else
echo ""
echo "Run the service manually (we couldn't detect your system service to do that automatically):"
echo ""
- echo " $my_daemon --config $TELEBIT_CONFIGD"
+ echo " $my_daemon --config $TELEBITD_CONFIG"
echo " $my_app --config $TELEBIT_CONFIG"
fi
diff --git a/usr/share/template-launcher.js b/usr/share/template-launcher.js
index 5b7a7e9..adec834 100644
--- a/usr/share/template-launcher.js
+++ b/usr/share/template-launcher.js
@@ -4,40 +4,79 @@ var path = require('path');
var fs = require('fs');
var os = require('os');
-var files = [
- [ (process.env.TELEBIT_SERVICE_TPL || path.join(__dirname, 'dist/etc/systemd/system/telebit.service.tpl'))
- , (process.env.TELEBIT_SERVICE || path.join(__dirname, 'dist/etc/systemd/system/telebit.service'))
- ]
-, [ (process.env.TELEBIT_USER_SERVICE_TPL || path.join(__dirname, 'dist/etc/skel/.config/systemd/user/telebit.service.tpl'))
- , (process.env.TELEBIT_USER_SERVICE || path.join(__dirname, 'dist/etc/skel/.config/systemd/user/telebit.service'))
- ]
-, [ (process.env.TELEBIT_PLIST_TPL || path.join(__dirname, 'dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl'))
- ,(process.env.TELEBIT_PLIST || path.join(__dirname, 'dist/Library/LaunchDaemons/cloud.telebit.remote.plist'))
- ]
-, [ (process.env.TELEBIT_USER_PLIST_TPL || path.join(__dirname, 'dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl'))
- ,(process.env.TELEBIT_USER_PLIST || path.join(__dirname, 'dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist'))
- ]
-];
-var vars = {
- telebitPath: process.env.TELEBIT_PATH || path.resolve(__dirname, '../..')
-, telebitRwDirs: [
- (process.env.TELEBIT_PATH || path.resolve(__dirname, '../..'))
- , path.join(os.homedir(), '.config/telebit')
- , path.join(os.homedir(), '.local/share/telebit')
- , ].join(' ')
-, telebitUser: process.env.TELEBIT_USER || os.userInfo().username
-, telebitGroup: process.env.TELEBIT_GROUP || ('darwin' === os.platform() ? 'staff' : os.userInfo().username)
-, telebitConfig: process.env.TELEBIT_CONFIG || path.join(os.homedir(), '.config/telebit/telebit.yml')
-, telebitConfigd: process.env.TELEBIT_CONFIGD || path.join(os.homedir(), '.config/telebit/telebitd.yml')
+module.exports = function (opts, fn) {
+ // TODO make async version
+ try {
+ module.exports.sync(opts);
+ } catch(e) {
+ if (fn) { fn(e); }
+ }
+
+ if (fn) { fn(null); }
};
-files.forEach(function (f) {
- var text = fs.readFileSync(f[0], 'utf8')
- .replace(/{TELEBIT_PATH}/g, vars.telebitPath)
- .replace(/{TELEBIT_USER}/g, vars.telebitUser)
- .replace(/{TELEBIT_GROUP}/g, vars.telebitGroup)
- .replace(/{TELEBIT_RW_DIRS}/g, vars.telebitRwDirs)
- .replace(/{TELEBIT_CONFIG}/g, vars.telebitConfig)
- .replace(/{TELEBIT_CONFIGD}/g, vars.telebitConfigd)
+module.exports.sync = function (opts) {
+ var f = opts.file;
+ var vars = opts.vars;
+ var text = fs.readFileSync(f.tpl, 'utf8')
+ .replace(/{TELEBIT_PATH}/g, vars.telebitPath || '{TELEBIT_PATH}')
+ .replace(/{TELEBIT_NODE}/g, vars.telebitNode || '{TELEBIT_NODE}')
+ .replace(/{TELEBIT_NPM}/g, vars.telebitNpm || '{TELEBIT_NPM}')
+ .replace(/{TELEBIT_BIN}/g, vars.telebitBin || '{TELEBIT_BIN}')
+ .replace(/{TELEBITD_BIN}/g, vars.telebitdBin || '{TELEBITD_BIN}')
+ .replace(/{TELEBIT_JS}/g, vars.telebitJs || '{TELEBIT_JS}')
+ .replace(/{TELEBITD_JS}/g, vars.telebitdJs || '{TELEBITD_JS}')
+ .replace(/{TELEBIT_USER}/g, vars.telebitUser || '{TELEBIT_USER}')
+ .replace(/{TELEBIT_GROUP}/g, vars.telebitGroup || '{TELEBIT_GROUP}')
+ .replace(/{TELEBIT_RW_DIRS}/g, vars.telebitRwDirs || '{TELEBIT_RW_DIRS}')
+ .replace(/{TELEBIT_CONFIG}/g, vars.telebitConfig || '{TELEBIT_CONFIG}')
+ .replace(/{TELEBITD_CONFIG}/g, vars.telebitdConfig || '{TELEBITD_CONFIG}')
;
- fs.writeFileSync(f[1], text, 'utf8');
-});
+ fs.writeFileSync(f.launcher, text, 'utf8');
+};
+
+function run() {
+ var files = [
+ { tpl: (process.env.TELEBIT_SERVICE_TPL || path.join(__dirname, 'dist/etc/systemd/system/telebit.service.tpl'))
+ , launcher: (process.env.TELEBIT_SERVICE || path.join(__dirname, 'dist/etc/systemd/system/telebit.service'))
+ }
+ , { tpl: (process.env.TELEBIT_USER_SERVICE_TPL || path.join(__dirname, 'dist/etc/skel/.config/systemd/user/telebit.service.tpl'))
+ , launcher: (process.env.TELEBIT_USER_SERVICE || path.join(__dirname, 'dist/etc/skel/.config/systemd/user/telebit.service'))
+ }
+ , { tpl: (process.env.TELEBIT_PLIST_TPL || path.join(__dirname, 'dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl'))
+ , launcher: (process.env.TELEBIT_PLIST || path.join(__dirname, 'dist/Library/LaunchDaemons/cloud.telebit.remote.plist'))
+ }
+ , { tpl: (process.env.TELEBIT_USER_PLIST_TPL || path.join(__dirname, 'dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl'))
+ , launcher: (process.env.TELEBIT_USER_PLIST || path.join(__dirname, 'dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist'))
+ }
+ ];
+
+ files.forEach(function (f) {
+ var telebitRoot = path.resolve(__dirname, '../..');
+ var vars = {
+ telebitPath: process.env.TELEBIT_PATH || telebitRoot
+ , telebitNode: process.env.TELEBIT_NODE || path.resolve(telebitRoot, 'bin/node')
+ , telebitNpm: process.env.TELEBIT_NPM || path.resolve(telebitRoot, 'bin/npm')
+ , telebitBin: process.env.TELEBIT_BIN || path.resolve(telebitRoot, 'bin/telebit')
+ , telebitdBin: process.env.TELEBITD_BIN || path.resolve(telebitRoot, 'bin/telebitd')
+ , telebitJs: process.env.TELEBIT_JS || path.resolve(telebitRoot, 'bin/telebit.js')
+ , telebitdJs: process.env.TELEBITD_JS || path.resolve(telebitRoot, 'bin/telebitd.js')
+ , telebitRwDirs: [
+ (process.env.TELEBIT_PATH || path.resolve(__dirname, '../..'))
+ , path.join(os.homedir(), '.config/telebit')
+ , path.join(os.homedir(), '.local/share/telebit')
+ ].join(' ')
+ , telebitUser: process.env.TELEBIT_USER || os.userInfo().username
+ , telebitGroup: process.env.TELEBIT_GROUP || ('darwin' === os.platform() ? 'staff' : os.userInfo().username)
+ , telebitConfig: process.env.TELEBIT_CONFIG || path.join(os.homedir(), '.config/telebit/telebit.yml')
+ , telebitdConfig: process.env.TELEBITD_CONFIG || path.join(os.homedir(), '.config/telebit/telebitd.yml')
+ };
+ module.exports({
+ file: f
+ , vars: vars
+ });
+ });
+}
+
+if (module === require.main) {
+ run();
+}