From 8308fe7af8cae8f27567f4ac6c83d49e27cbd15e Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 5 Aug 2019 02:41:47 -0600 Subject: [PATCH] remove old installer stuff --- .../cloud.telebit.remote.plist.tpl | 61 --- usr/share/dist/bin/telebit.tpl | 2 - usr/share/dist/bin/telebitd.tpl | 2 - .../.config/systemd/user/telebit.service.tpl | 64 --- .../cloud.telebit.remote.plist.tpl | 70 --- .../etc/systemd/system/telebit.service.tpl | 67 --- usr/share/install-launcher.js | 448 ------------------ usr/share/telebitd.tpl.yml | 5 - usr/share/template-launcher.js | 97 ---- 9 files changed, 816 deletions(-) delete mode 100644 usr/share/dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl delete mode 100644 usr/share/dist/bin/telebit.tpl delete mode 100644 usr/share/dist/bin/telebitd.tpl delete mode 100644 usr/share/dist/etc/skel/.config/systemd/user/telebit.service.tpl delete mode 100644 usr/share/dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl delete mode 100644 usr/share/dist/etc/systemd/system/telebit.service.tpl delete mode 100644 usr/share/install-launcher.js delete mode 100644 usr/share/telebitd.tpl.yml delete mode 100644 usr/share/template-launcher.js diff --git a/usr/share/dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl b/usr/share/dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl deleted file mode 100644 index 44aae73..0000000 --- a/usr/share/dist/Library/LaunchDaemons/cloud.telebit.remote.plist.tpl +++ /dev/null @@ -1,61 +0,0 @@ - - - - - Label - Telebit Remote - ProgramArguments - - {TELEBIT_NODE} - {TELEBITD_JS} - daemon - --config - {TELEBITD_CONFIG} - - EnvironmentVariables - - TELEBIT_PATH - {TELEBIT_PATH} - NODE_PATH - {NODE_PATH} - NPM_CONFIG_PREFIX - {NPM_CONFIG_PREFIX} - - - UserName - {TELEBIT_USER} - GroupName - {TELEBIT_GROUP} - InitGroups - - - RunAtLoad - - KeepAlive - - - - SoftResourceLimits - - NumberOfFiles - 8192 - - HardResourceLimits - - - WorkingDirectory - {TELEBIT_PATH} - - StandardErrorPath - {TELEBIT_LOG_DIR}/telebit.log - StandardOutPath - {TELEBIT_LOG_DIR}/telebit.log - - diff --git a/usr/share/dist/bin/telebit.tpl b/usr/share/dist/bin/telebit.tpl deleted file mode 100644 index 13dcfc9..0000000 --- a/usr/share/dist/bin/telebit.tpl +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -{TELEBIT_NODE} {TELEBIT_JS} "$@" diff --git a/usr/share/dist/bin/telebitd.tpl b/usr/share/dist/bin/telebitd.tpl deleted file mode 100644 index ae308ec..0000000 --- a/usr/share/dist/bin/telebitd.tpl +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -{TELEBIT_NODE} {TELEBITD_JS} daemon "$@" diff --git a/usr/share/dist/etc/skel/.config/systemd/user/telebit.service.tpl b/usr/share/dist/etc/skel/.config/systemd/user/telebit.service.tpl deleted file mode 100644 index 45da0ea..0000000 --- a/usr/share/dist/etc/skel/.config/systemd/user/telebit.service.tpl +++ /dev/null @@ -1,64 +0,0 @@ -# Pre-req -# sudo adduser telebit --home {TELEBIT_PATH} -# sudo mkdir -p {TELEBIT_PATH}/ -# sudo chown -R {TELEBIT_USER}:{TELEBIT_GROUP} {TELEBIT_PATH}/ - -[Unit] -Description=Telebit Remote -Documentation=https://git.coolaj86.com/coolaj86/telebit.js/ -; After=network-online.target -; Wants=network-online.target systemd-networkd-wait-online.service - -[Service] -# Restart on crash (bad signal), and also on 'clean' failure (error exit code) -# Allow up to 3 restarts within 10 seconds -# (it's unlikely that a user or properly-running script will do this) -Restart=always -StartLimitInterval=10 -StartLimitBurst=3 - -# User and group the process will run as -;User={TELEBIT_USER} -;Group={TELEBIT_GROUP} - -WorkingDirectory={TELEBIT_PATH} -# custom directory cannot be set and will be the place where this exists, not the working directory -ExecStart={TELEBIT_NODE} {TELEBITD_JS} daemon --config {TELEBITD_CONFIG} -ExecReload=/bin/kill -USR1 $MAINPID - -# Limit the number of file descriptors and processes; see `man systemd.exec` for more limit settings. -# Unmodified, this is not expected to use more than this. -;LimitNOFILE=1048576 # no issues yet, but disabled just in case -;LimitNPROC=64 # doesn't work on some systems - -# Use private /tmp and /var/tmp, which are discarded after this stops. -PrivateTmp=true -# Use a minimal /dev -;PrivateDevices=true -# Hide /home, /root, and /run/user. Nobody will steal your SSH-keys. -ProtectHome=true -# Make /usr, /boot, /etc and possibly some more folders read-only. -ProtectSystem=full -# ... except for a few because we want a place for config, logs, etc -# This merely retains r/w access rights, it does not add any new. -# Must still be writable on the host! -ReadWriteDirectories={TELEBIT_RW_DIRS} - -# Note: in v231 and above ReadWritePaths has been renamed to ReadWriteDirectories -; ReadWritePaths={TELEBIT_RW_DIRS} - -# The following additional security directives only work with systemd v229 or later. -# They further retrict privileges that can be gained. -# Note that you may have to add capabilities required by any plugins in use. -;CapabilityBoundingSet=CAP_NET_BIND_SERVICE -;AmbientCapabilities=CAP_NET_BIND_SERVICE -NoNewPrivileges=true - -# Caveat: Some features may need additional capabilities. -# For example an "upload" may need CAP_LEASE -; CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_LEASE -; AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_LEASE -; NoNewPrivileges=true - -[Install] -WantedBy=multi-user.target 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 deleted file mode 100644 index bfbb52f..0000000 --- a/usr/share/dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl +++ /dev/null @@ -1,70 +0,0 @@ - - - - - Label - Telebit Remote - - ProgramArguments - - {TELEBIT_NODE} - {TELEBITD_JS} - daemon - --config - {TELEBITD_CONFIG} - - - EnvironmentVariables - - TELEBIT_PATH - {TELEBIT_PATH} - NODE_PATH - {NODE_PATH} - NPM_CONFIG_PREFIX - {NPM_CONFIG_PREFIX} - - - - - RunAtLoad - - KeepAlive - - - - - - WorkingDirectory - {TELEBIT_PATH} - - StandardErrorPath - {TELEBIT_LOG_DIR}/telebit.log - StandardOutPath - {TELEBIT_LOG_DIR}/telebit.log - - diff --git a/usr/share/dist/etc/systemd/system/telebit.service.tpl b/usr/share/dist/etc/systemd/system/telebit.service.tpl deleted file mode 100644 index 3f61e1e..0000000 --- a/usr/share/dist/etc/systemd/system/telebit.service.tpl +++ /dev/null @@ -1,67 +0,0 @@ -# Pre-req -# sudo adduser telebit --home {TELEBIT_PATH} -# sudo mkdir -p {TELEBIT_PATH}/ -# sudo chown -R {TELEBIT_USER}:{TELEBIT_GROUP} {TELEBIT_PATH}/ - -[Unit] -Description=Telebit Remote -Documentation=https://git.coolaj86.com/coolaj86/telebit.js/ -After=network-online.target -Wants=network-online.target systemd-networkd-wait-online.service - -[Service] -# Restart on crash (bad signal), and also on 'clean' failure (error exit code) -# Allow up to 3 restarts within 10 seconds -# (it's unlikely that a user or properly-running script will do this) -Restart=always -StartLimitInterval=10 -StartLimitBurst=3 - -# User and group the process will run as -User={TELEBIT_USER} -Group={TELEBIT_GROUP} - -WorkingDirectory={TELEBIT_PATH} -# custom directory cannot be set and will be the place where this exists, not the working directory -ExecStart={TELEBIT_NODE} {TELEBITD_JS} daemon --config {TELEBITD_CONFIG} -ExecReload=/bin/kill -USR1 $MAINPID - -# Limit the number of file descriptors and processes; see `man systemd.exec` for more limit settings. -# Unmodified, this is not expected to use more than this. -LimitNOFILE=1048576 -LimitNPROC=64 - -# Use private /tmp and /var/tmp, which are discarded after this stops. -PrivateTmp=true -# Use a minimal /dev -PrivateDevices=true -# Hide /home, /root, and /run/user. Nobody will steal your SSH-keys. -ProtectHome=true -# Make /usr, /boot, /etc and possibly some more folders read-only. -ProtectSystem=full -# ... except for a few because we want a place for config, logs, etc -# This merely retains r/w access rights, it does not add any new. -# Must still be writable on the host! -ReadWriteDirectories={TELEBIT_RW_DIRS} - -# Note: in v231 and above ReadWritePaths has been renamed to ReadWriteDirectories -; ReadWritePaths={TELEBIT_RW_DIRS} - -# The following additional security directives only work with systemd v229 or later. -# They further retrict privileges that can be gained. -# Note that you may have to add capabilities required by any plugins in use. -CapabilityBoundingSet=CAP_NET_BIND_SERVICE -AmbientCapabilities=CAP_NET_BIND_SERVICE -NoNewPrivileges=true - -# Caveat: Some features may need additional capabilities. -# For example an "upload" may need CAP_LEASE -; CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_LEASE -; AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_LEASE -; NoNewPrivileges=true - -[Install] -# For system-level service -;WantedBy=multi-user.target -# For userspace service -WantedBy=default.target diff --git a/usr/share/install-launcher.js b/usr/share/install-launcher.js deleted file mode 100644 index 8e04fad..0000000 --- a/usr/share/install-launcher.js +++ /dev/null @@ -1,448 +0,0 @@ -'use strict'; - -//var fs = require('fs'); -var os = require('os'); -var mkdirp = require('mkdirp'); -var exec = require('child_process').exec; -var path = require('path'); - -var Launcher = module.exports; -Launcher._killAll = function (fn) { - var psList = require('ps-list'); - psList().then(function (procs) { - procs.forEach(function (proc) { - if ('node' === proc.name && /\btelebitd\b/i.test(proc.cmd)) { - console.log(proc); - process.kill(proc.pid); - return true; - } - }); - // Two things: - // 1) wait to see if the process dies - // 2) wait to give time for the socket to connect - setTimeout(function () { - if (fn) { fn(null); return; } - }, 1.75 * 1000); - }); -}; -Launcher._getError = function getError(err, stderr) { - if (err) { return err; } - if (stderr) { - err = new Error(stderr); - err.code = 'ELAUNCHER'; - return err; - } -}; -Launcher._detect = function (things, fn) { - if (things.launcher) { - if ('string' === typeof things.launcher) { - fn(null, things.launcher); - return; - } - if ('function' === typeof things.launcher) { - things.launcher(things); - 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('command -v launchctl', things._execOpts, function (err, stdout, stderr) { - err = Launcher._getError(err, stderr); - fn(err, 'launchctl'); - }); - } else { - exec('command -v systemctl', things._execOpts, function (err, stdout, stderr) { - err = Launcher._getError(err, stderr); - fn(err, 'systemctl'); - }); - } - } 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', things._execOpts, function (err, stdout, stderr) { - //console.log((stdout||'').trim()); - if (stderr) { - console.error(stderr); - } - fn(err, 'reg.exe'); - }); - } -}; -Launcher.install = function (things, fn) { - if (!fn) { fn = function (err) { if (err) { console.error(err); } }; } - things = things || {}; - // in some future version we can take this file out - // and accept process.env from things - var installLauncher = require('./template-launcher'); - - // Right now this is just for npm install -g and npx - if (things.env) { - things.env.PATH = things.env.PATH || process.env.PATH; - } else { - things.env = process.env; - } - things.argv = things.argv || process.argv; - things._execOpts = { windowsHide: true, env: things.env }; - var telebitRoot = path.join(__dirname, '../..'); - var vars = { - telebitPath: telebitRoot - , telebitUser: os.userInfo().username - , telebitGroup: (/^darwin/i.test(os.platform()) ? 'staff' : os.userInfo().username) - , telebitRwDirs: [ - telebitRoot - , path.join(os.homedir(), '.config/telebit') - , path.join(os.homedir(), '.local/share/telebit') - ] - , telebitNode: (things.argv[0]||'').replace(/\.exe/i, '') // path.join(telebitRoot, 'bin/node') - , telebitBin: path.join(telebitRoot, 'bin/telebit') - , telebitdBin: path.join(telebitRoot, 'bin/telebitd') - , telebitJs: path.join(telebitRoot, 'bin/telebit.js') - , telebitdJs: path.join(telebitRoot, 'bin/telebitd.js') - , telebitConfig: path.join(os.homedir(), '.config/telebit/telebit.yml') - , telebitdConfig: path.join(os.homedir(), '.config/telebit/telebitd.yml') - , TELEBIT_LOG_DIR: path.join(os.homedir(), '.local/share/telebit/var/log') - , TELEBIT_SOCK_DIR: path.join(os.homedir(), '.local/share/telebit/var/run') - }; - vars.telebitBinTpl = path.join(telebitRoot, 'usr/share/dist/bin/telebit.tpl'); - vars.telebitNpm = path.resolve(vars.telebitNode, '../npm'); - vars.nodePath = path.resolve(vars.telebitNode, '../../lib/node_modules'); - vars.npmConfigPrefix = path.resolve(vars.telebitNode, '..', '..'); - vars.userspace = (!things.telebitUser || (things.telebitUser === os.userInfo().username)) ? true : false; - if (-1 === vars.telebitRwDirs.indexOf(vars.npmConfigPrefix)) { - vars.telebitRwDirs.push(vars.npmConfigPrefix); - } - vars.telebitRwDirs = vars.telebitRwDirs.join(' '); - var launchers = { - 'node': function () { - var fs = require('fs'); - var spawn = require('child_process').spawn; - var logpath = path.join(os.homedir(), '.local/share/telebit/var/log'); - try { - mkdirp.sync(logpath); - } catch(e) { - if (fn) { fn(e); return; } - return; - } - var stdout = fs.openSync(path.join(logpath, 'info.log'), 'a'); - var stderr = fs.openSync(path.join(logpath, 'error.log'), 'a'); - - var killed = 0; - var err; - var args = [ - path.join(telebitRoot, 'bin/telebitd.js') - , 'daemon' - , '--config' - , vars.telebitdConfig - ]; - var subprocess = spawn( - vars.telebitNode - , args - , { detached: true - , stdio: [ 'ignore', stdout, stderr ] - } - ); - //console.log('[debug]', vars.telebitNode, args.join(' ')); - subprocess.unref(); - subprocess.on('error', function (_err) { - err = _err; - killed += 1; - }); - subprocess.on('exit', function (code, signal) { - if (!err) { err = new Error('' + code + ' ' + signal + ' failure to launch'); } - killed += 1; - }); - - // Two things: - // 1) wait to see if the process dies - // 2) wait to give time for the socket to connect - setTimeout(function () { - if (fn) { fn(err); return; } - }, 1.75 * 1000); - return; - } - , 'launchctl': function () { - var launcher = path.join(os.homedir(), 'Library/LaunchAgents/cloud.telebit.remote.plist'); - try { - mkdirp.sync(path.join(os.homedir(), 'Library/LaunchAgents')); - installLauncher.sync({ - file: { - tpl: vars.telebitBinTpl - , launcher: path.join(vars.telebitPath, 'bin/telebit') - , executable: true - } - , vars: vars - }); - installLauncher({ - file: { - tpl: path.join(vars.telebitPath, 'usr/share/dist/etc/skel/Library/LaunchAgents/cloud.telebit.remote.plist.tpl') - , launcher: launcher - } - , vars: vars - }); - var launcherstr = (vars.userspace ? "" : "sudo ") + "launchctl "; - var execstr = launcherstr + "unload -w " + launcher; - exec(execstr, things._execOpts, function (/*err, stdout, stderr*/) { - // we probably only need to skip the stderr (saying that it can't stop something that isn't started) - //err = Launcher._getError(err, stderr); - //if (err) { fn(err); return; } - //console.log((stdout||'').trim()); - //console.log('unload worked?'); - execstr = launcherstr + "load -w " + launcher; - exec(execstr, things._execOpts, function (err, stdout, stderr) { - err = Launcher._getError(err, stderr); - if (err) { fn(err); return; } - //console.log((stdout||'').trim()); - //console.log('load worked?'); - setTimeout(function () { - fn(null); - }, 1.25 * 1000); - }); - }); - } catch(e) { - console.error("'" + launcher + "' error:"); - console.error(e); - if (fn) { fn(e); return; } - } - } - , 'systemctl': function () { - var launcher = path.join(os.homedir(), '.config/systemd/user/telebit.service'); - var launchername = 'telebit.service'; - try { - mkdirp.sync(path.join(os.homedir(), '.config/systemd/user')); - installLauncher({ - file: { - tpl: path.join(vars.telebitPath, 'usr/share/dist/etc/skel/.config/systemd/user/telebit.service.tpl') - , launcher: launcher - } - , vars: vars - }, function () { - // IMPORTANT - // It's a dangerous to go alone, take this: - // SYSTEMD_LOG_LEVEL=debug journalctl -xef --user-unit=telebit - // (makes debugging systemd issues not "easy" per se, but possible) - var launcherstr = (vars.userspace ? "" : "sudo ") + "systemctl " + (vars.userspace ? "--user " : ""); - var execstr = launcherstr + "daemon-reload"; - exec(execstr, things._execOpts, function (err, stdout, stderr) { - err = Launcher._getError(err, stderr); - if (err) { fn(err); return; } - //console.log((stdout||'').trim()); - var execstr = launcherstr + "enable " + launchername; - exec(execstr, things._execOpts, function (err, stdout, stderr) { - err = Launcher._getError(err, stderr && !/Created symlink/i.test(stderr) && stderr || ''); - if (err) { fn(err); return; } - //console.log((stdout||'').trim()); - var execstr = launcherstr + "restart " + launchername; - exec(execstr, things._execOpts, function (err, stdout, stderr) { - err = Launcher._getError(err, stderr); - if (err) { fn(err); return; } - //console.log((stdout||'').trim()); - setTimeout(function () { - var execstr = launcherstr + "status " + launchername; - exec(execstr, things._execOpts, function (err, stdout, stderr) { - err = Launcher._getError(err, stderr); - if (err) { fn(err); return; } - if (!/active.*running/i.test(stdout)) { - err = new Error("systemd failed to start '" + launchername + "'"); - } - if (err) { fn(err); return; } - //console.log((stdout||'').trim()); - fn(null); - }); - }, 1.25 * 1000); - }); - }); - }); - }); - } catch(e) { - console.error("'" + launcher + "' error:"); - console.error(e); - if (fn) { fn(e); return; } - } - } - , 'reg.exe': function () { - if (!vars.userspace) { - console.warn("sysetm-level, privileged services are not yet supported on windows"); - } - vars.telebitNode += '.exe'; - var cmd = 'reg.exe add "HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"' - + ' /V "Telebit" /t REG_SZ /D ' - + '"' + things.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, things._execOpts, function (err, stdout, stderr) { - err = Launcher._getError(err, stderr); - if (err) { fn(err); return; } - // need to start it for the first time ourselves - run(null, 'node'); - }); - } - }; - - function run(err, launcher) { - if (err) { - console.error("No luck with '" + launcher + "', trying a child process instead..."); - console.error(err); - launcher = 'node'; - } - - if (launchers[launcher]) { - // console.log('Launching with launcher ' + launcher); - mkdirp.sync(path.join(vars.telebitPath, 'bin')); - mkdirp.sync(vars.TELEBIT_LOG_DIR); - mkdirp.sync(vars.TELEBIT_SOCK_DIR); - launchers[launcher](); - return; - } else { - console.error("No launcher handler for '" + launcher+ "'"); - } - } - - things._vars = vars; - things._userspace = vars.userspace; - Launcher._detect(things, run); -}; -Launcher.uninstall = function (things, fn) { - if (!fn) { fn = function (err) { if (err) { console.error(err); } }; } - things = things || {}; - - // Right now this is just for npm install -g and npx - if (things.env) { - things.env.PATH = things.env.PATH || process.env.PATH; - } else { - things.env = process.env; - } - things.argv = things.argv || process.argv; - things._execOpts = { windowsHide: true, env: things.env }; - var vars = { - telebitUser: os.userInfo().username - }; - vars.userspace = (!things.telebitUser || (things.telebitUser === os.userInfo().username)) ? true : false; - var launchers = { - 'node': function () { - Launcher._killAll(fn); - } - , 'launchctl': function () { - var launcher = path.join(os.homedir(), 'Library/LaunchAgents/cloud.telebit.remote.plist'); - try { - var launcherstr = (vars.userspace ? "" : "sudo ") + "launchctl "; - var execstr = launcherstr + "unload -w " + launcher; - exec(execstr, things._execOpts, function (err, stdout, stderr) { - // we probably only need to skip the stderr (saying that it can't stop something that isn't started) - //err = Launcher._getError(err, stderr); - //if (err) { fn(err); return; } - //console.log((stdout||'').trim()); - //console.log('unload worked?'); - err = Launcher._getError(err, stderr); - if (err) { fn(err); return; } - //console.log((stdout||'').trim()); - //console.log('load worked?'); - setTimeout(function () { - fn(null); - }, 1.25 * 1000); - }); - } catch(e) { - console.error("'" + launcher + "' error (uninstall):"); - console.error(e); - if (fn) { fn(e); return; } - } - } - , 'systemctl': function () { - var launcher = path.join(os.homedir(), '.config/systemd/user/telebit.service'); - var launchername = 'telebit.service'; - try { - mkdirp.sync(path.join(os.homedir(), '.config/systemd/user')); - // IMPORTANT - // It's a dangerous to go alone, take this: - // SYSTEMD_LOG_LEVEL=debug journalctl -xef --user-unit=telebit - // (makes debugging systemd issues not "easy" per se, but possible) - var launcherstr = (vars.userspace ? "" : "sudo ") + "systemctl " + (vars.userspace ? "--user " : ""); - var execstr = launcherstr + "disable " + launchername; - exec(execstr, things._execOpts, function (err, stdout, stderr) { - err = Launcher._getError(err, stderr && !/Removed symlink/i.test(stderr) && stderr || ''); - if (err) { fn(err); return; } - //console.log((stdout||'').trim()); - var execstr = launcherstr + "stop " + launchername; - exec(execstr, things._execOpts, function (err, stdout, stderr) { - err = Launcher._getError(err, stderr); - if (err) { fn(err); return; } - //console.log((stdout||'').trim()); - setTimeout(function () { - var execstr = launcherstr + "status " + launchername; - exec(execstr, things._execOpts, function (err, stdout, stderr) { - err = Launcher._getError(err, stderr); - if (err) { fn(err); return; } - if (!/inactive.*dead/i.test(stdout)) { - err = new Error("systemd failed to stop '" + launchername + "'"); - } - if (err) { fn(err); return; } - //console.log((stdout||'').trim()); - fn(null); - }); - }, 1.25 * 1000); - }); - }); - } catch(e) { - console.error("'" + launcher + "' error:"); - console.error(e); - if (fn) { fn(e); return; } - } - } - , 'reg.exe': function () { - if (!vars.userspace) { - console.warn("sysetm-level, privileged services are not yet supported on windows"); - } - var cmd = 'reg.exe add "HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"' - + ' /V "Telebit" /F' - ; - exec(cmd, things._execOpts, function (err, stdout, stderr) { - err = Launcher._getError(err, stderr); - if (err) { fn(err); return; } - // need to start it for the first time ourselves - kill(null, 'node'); - }); - } - }; - - function kill(err, launcher) { - if (err) { - console.error("No luck with '" + launcher + "', trying a process.kill() instead..."); - console.error(err); - launcher = 'node'; - } - - if (launchers[launcher]) { - launchers[launcher](); - return; - } else { - console.error("No launcher handler (uninstall) for '" + launcher + "'"); - } - } - - things._vars = vars; - things._userspace = vars.userspace; - Launcher._detect(things, kill); -}; - -if (module === require.main) { - Launcher.install({ - argv: process.argv - , env: process.env - }, function (err) { - if (err) { console.error(err); return; } - console.log("Telebit launched, or so it seems."); - }); -} diff --git a/usr/share/telebitd.tpl.yml b/usr/share/telebitd.tpl.yml deleted file mode 100644 index ca08fd5..0000000 --- a/usr/share/telebitd.tpl.yml +++ /dev/null @@ -1,5 +0,0 @@ -#agree_tos: true # agree to the Telebit, Greenlock, and Let's Encrypt TOSes -community_member: true # receive infrequent relevant updates -telemetry: true # contribute to project telemetric data -newsletter: false # contribute to project telemetric data -ssh_auto: false # forward ssh-looking packets, from any connection, to port 22 diff --git a/usr/share/template-launcher.js b/usr/share/template-launcher.js deleted file mode 100644 index 9c0f259..0000000 --- a/usr/share/template-launcher.js +++ /dev/null @@ -1,97 +0,0 @@ -'use strict'; - -var path = require('path'); -var fs = require('fs'); -var os = require('os'); - -module.exports = function (opts, fn) { - // TODO make async version - try { - module.exports.sync(opts); - } catch(e) { - if (fn) { fn(e); } - } - - if (fn) { fn(null); } -}; -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(/{NODE_PATH}/g, vars.nodePath || '{NODE_PATH}') - .replace(/{NPM_CONFIG_PREFIX}/g, vars.npmConfigPrefix || '{NPM_CONFIG_PREFIX}') - .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}') - .replace(/{TELEBIT_LOG_DIR}/g, vars.TELEBIT_LOG_DIR || '{TELEBIT_LOG_DIR}') - .replace(/{TELEBIT_SOCK_DIR}/g, vars.TELEBIT_LOG_DIR || '{TELEBIT_SOCK_DIR}') - ; - fs.writeFileSync(f.launcher, text, 'utf8'); - if (f.executable && !/^win/i.test(os.platform())) { - // TODO not sure if chmod works on windows - fs.chmodSync(f.launcher, parseInt('755', 8)); - } -}; - -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 || process.argv[0] || path.resolve(telebitRoot, 'bin/node') - , 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') - ] - , 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') - , TELEBIT_LOG_DIR: process.env.TELEBIT_LOG_DIR || path.join(os.homedir(), '.local/share/telebit/var/log') - }; - vars.telebitNpm = process.env.TELEBIT_NPM || path.resolve(vars.telebitNode, '../npm'); - vars.nodePath = process.env.NODE_PATH || path.resolve(vars.telebitNode, '../../lib/node_modules'); - vars.npmConfigPrefix = process.env.NPM_CONFIG_PREFIX || path.resolve(vars.telebitNode, '..', '..'); - if (-1 === vars.telebitRwDirs.indexOf(vars.npmConfigPrefix)) { - vars.telebitRwDirs.push(vars.npmConfigPrefix); - } - vars.telebitRwDirs = vars.telebitRwDirs.join(' '); - module.exports({ - file: f - , vars: vars - }); - }); -} - -if (module === require.main) { - run(); -}