@nervur.org/installer-node 0.0.0-stage → 0.37.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +105 -0
- package/README.md +159 -2
- package/SECURITY.md +8 -0
- package/bin/nervur.js +5 -0
- package/cargo/emscripten-module.wasm +0 -0
- package/cargo/manifest.json +1 -0
- package/cargo/sqlite3.wasm +0 -0
- package/cargo/table-i-i.wasm +0 -0
- package/cargo/table-i-ii.wasm +0 -0
- package/cargo/table-i-iii.wasm +0 -0
- package/cargo/table-i-iiii.wasm +0 -0
- package/cargo/table-i-iiiii.wasm +0 -0
- package/cargo/table-i-iiij.wasm +0 -0
- package/cargo/table-i-ij.wasm +0 -0
- package/cargo/table-v-ii.wasm +0 -0
- package/cargo/table-v-iii.wasm +0 -0
- package/cargo/worker.js +30808 -0
- package/organs/console/node/guard.d.ts +10 -0
- package/organs/console/node/guard.js +52 -0
- package/organs/console/node/index.d.ts +4 -0
- package/organs/console/node/index.js +5 -0
- package/organs/console/node/line.d.ts +16 -0
- package/organs/console/node/line.js +150 -0
- package/organs/console/node/main.js +51 -0
- package/organs/console/node/program.d.ts +1 -0
- package/organs/console/node/program.js +5 -0
- package/organs/console/node/proof.d.ts +15 -0
- package/organs/console/node/proof.js +84 -0
- package/organs/console/node/socket.d.ts +15 -0
- package/organs/console/node/socket.js +99 -0
- package/organs/disk/index.d.ts +1 -0
- package/organs/disk/index.js +2 -0
- package/organs/disk/node/files.js +162 -0
- package/organs/disk/node/main.js +20 -0
- package/organs/disk/node/program.d.ts +1 -0
- package/organs/disk/node/program.js +5 -0
- package/organs/disk/organ.d.ts +5 -0
- package/organs/disk/organ.js +69 -0
- package/organs/network/node/fill.d.ts +21 -0
- package/organs/network/node/fill.js +195 -0
- package/organs/network/node/flows.js +66 -0
- package/organs/network/node/half.js +260 -0
- package/organs/network/node/lines.d.ts +29 -0
- package/organs/network/node/lines.js +236 -0
- package/organs/network/node/link.d.ts +24 -0
- package/organs/network/node/link.js +215 -0
- package/organs/network/node/main.js +41 -0
- package/organs/network/node/moved.d.ts +2 -0
- package/organs/network/node/moved.js +20 -0
- package/organs/network/node/near.d.ts +63 -0
- package/organs/network/node/near.js +263 -0
- package/organs/network/node/program.d.ts +1 -0
- package/organs/network/node/program.js +5 -0
- package/organs/network/node/schemes.d.ts +1 -0
- package/organs/network/node/schemes.js +2 -0
- package/organs/network/node/sent.d.ts +13 -0
- package/organs/network/node/sent.js +101 -0
- package/organs/network/node/served.d.ts +19 -0
- package/organs/network/node/served.js +237 -0
- package/organs/screen/node/client.js +3 -0
- package/organs/screen/node/follow.js +266 -0
- package/organs/screen/node/frames.js +26 -0
- package/organs/screen/node/held.js +27 -0
- package/organs/screen/node/http.js +179 -0
- package/organs/screen/node/lay.js +116 -0
- package/organs/screen/node/leave.js +27 -0
- package/organs/screen/node/linked.js +69 -0
- package/organs/screen/node/listen.js +61 -0
- package/organs/screen/node/look.js +121 -0
- package/organs/screen/node/loop.js +154 -0
- package/organs/screen/node/main.js +74 -0
- package/organs/screen/node/mirror.js +112 -0
- package/organs/screen/node/notice.js +44 -0
- package/organs/screen/node/presser.js +11 -0
- package/organs/screen/node/presses.js +108 -0
- package/organs/screen/node/program.d.ts +1 -0
- package/organs/screen/node/program.js +5 -0
- package/organs/screen/node/shown.js +205 -0
- package/organs/screen/node/standing.js +29 -0
- package/organs/screen/node/state.js +80 -0
- package/organs/screen/node/tell.js +47 -0
- package/organs/screen/node/uid.js +65 -0
- package/organs/screen/node/worn.js +23 -0
- package/organs/shell/index.d.ts +1 -0
- package/organs/shell/index.js +2 -0
- package/organs/shell/node/main.js +26 -0
- package/organs/shell/node/output.js +70 -0
- package/organs/shell/node/pressure.js +14 -0
- package/organs/shell/node/program.d.ts +1 -0
- package/organs/shell/node/program.js +5 -0
- package/organs/shell/node/runs.js +220 -0
- package/organs/shell/node/told.js +70 -0
- package/organs/shell/organ.d.ts +5 -0
- package/organs/shell/organ.js +59 -0
- package/package.json +43 -4
- package/src/command/act.d.ts +31 -0
- package/src/command/act.js +261 -0
- package/src/command/answers.d.ts +3 -0
- package/src/command/answers.js +232 -0
- package/src/command/args.d.ts +14 -0
- package/src/command/args.js +220 -0
- package/src/command/arrive.d.ts +2 -0
- package/src/command/arrive.js +21 -0
- package/src/command/asked.d.ts +18 -0
- package/src/command/asked.js +49 -0
- package/src/command/backup.d.ts +18 -0
- package/src/command/backup.js +261 -0
- package/src/command/before.d.ts +40 -0
- package/src/command/before.js +249 -0
- package/src/command/born.d.ts +27 -0
- package/src/command/born.js +103 -0
- package/src/command/bridge.d.ts +19 -0
- package/src/command/bridge.js +152 -0
- package/src/command/chain.d.ts +9 -0
- package/src/command/chain.js +48 -0
- package/src/command/channel.d.ts +29 -0
- package/src/command/channel.js +263 -0
- package/src/command/choices.d.ts +35 -0
- package/src/command/choices.js +173 -0
- package/src/command/claim.d.ts +12 -0
- package/src/command/claim.js +46 -0
- package/src/command/commands.d.ts +16 -0
- package/src/command/commands.js +257 -0
- package/src/command/ends.d.ts +16 -0
- package/src/command/ends.js +78 -0
- package/src/command/follow.d.ts +12 -0
- package/src/command/follow.js +66 -0
- package/src/command/given.d.ts +39 -0
- package/src/command/given.js +53 -0
- package/src/command/held.d.ts +15 -0
- package/src/command/held.js +56 -0
- package/src/command/index.d.ts +1 -0
- package/src/command/index.js +203 -0
- package/src/command/jailer.d.ts +28 -0
- package/src/command/jailer.js +135 -0
- package/src/command/laid.d.ts +6 -0
- package/src/command/laid.js +31 -0
- package/src/command/left.d.ts +9 -0
- package/src/command/left.js +34 -0
- package/src/command/line.d.ts +7 -0
- package/src/command/line.js +39 -0
- package/src/command/link.d.ts +30 -0
- package/src/command/link.js +123 -0
- package/src/command/lobes.d.ts +1 -0
- package/src/command/lobes.js +10 -0
- package/src/command/locks.d.ts +17 -0
- package/src/command/locks.js +76 -0
- package/src/command/mcp/calls.d.ts +27 -0
- package/src/command/mcp/calls.js +155 -0
- package/src/command/mcp/notices.d.ts +22 -0
- package/src/command/mcp/notices.js +203 -0
- package/src/command/mcp/resources.d.ts +31 -0
- package/src/command/mcp/resources.js +108 -0
- package/src/command/mcp/server.d.ts +19 -0
- package/src/command/mcp/server.js +149 -0
- package/src/command/mcp/tools.d.ts +39 -0
- package/src/command/mcp/tools.js +131 -0
- package/src/command/mcp.d.ts +8 -0
- package/src/command/mcp.js +39 -0
- package/src/command/noticed.d.ts +11 -0
- package/src/command/noticed.js +55 -0
- package/src/command/older.d.ts +11 -0
- package/src/command/older.js +45 -0
- package/src/command/open.d.ts +24 -0
- package/src/command/open.js +107 -0
- package/src/command/passphrase.d.ts +6 -0
- package/src/command/passphrase.js +82 -0
- package/src/command/reclaim.d.ts +7 -0
- package/src/command/reclaim.js +47 -0
- package/src/command/refused.d.ts +4 -0
- package/src/command/refused.js +27 -0
- package/src/command/release.d.ts +27 -0
- package/src/command/release.js +153 -0
- package/src/command/repo.d.ts +31 -0
- package/src/command/repo.js +133 -0
- package/src/command/rewrap.d.ts +16 -0
- package/src/command/rewrap.js +175 -0
- package/src/command/runtime.d.ts +25 -0
- package/src/command/runtime.js +175 -0
- package/src/command/salvage.d.ts +4 -0
- package/src/command/salvage.js +42 -0
- package/src/command/screen.d.ts +14 -0
- package/src/command/screen.js +62 -0
- package/src/command/spawn.d.ts +23 -0
- package/src/command/spawn.js +213 -0
- package/src/command/start.d.ts +34 -0
- package/src/command/start.js +246 -0
- package/src/command/state.d.ts +5 -0
- package/src/command/state.js +39 -0
- package/src/command/token.d.ts +1 -0
- package/src/command/token.js +9 -0
- package/src/command/trial.d.ts +18 -0
- package/src/command/trial.js +108 -0
- package/src/command/undone.d.ts +3 -0
- package/src/command/undone.js +21 -0
- package/src/command/vouch.d.ts +1 -0
- package/src/command/vouch.js +15 -0
- package/src/command/windows-processes.d.ts +2 -0
- package/src/command/windows-processes.js +22 -0
- package/src/command/wipe.d.ts +9 -0
- package/src/command/wipe.js +105 -0
- package/src/command/words.d.ts +5 -0
- package/src/command/words.js +53 -0
- package/src/door/claim.d.ts +5 -0
- package/src/door/claim.js +21 -0
- package/src/door/claimed.d.ts +7 -0
- package/src/door/claimed.js +110 -0
- package/src/door/configuration.d.ts +40 -0
- package/src/door/configuration.js +206 -0
- package/src/door/design.d.ts +13 -0
- package/src/door/design.js +71 -0
- package/src/door/digests.d.ts +7 -0
- package/src/door/digests.js +36 -0
- package/src/door/distribution.d.ts +25 -0
- package/src/door/distribution.js +88 -0
- package/src/door/door.d.ts +41 -0
- package/src/door/door.js +219 -0
- package/src/door/dressed.d.ts +34 -0
- package/src/door/dressed.js +182 -0
- package/src/door/faculties.d.ts +29 -0
- package/src/door/faculties.js +88 -0
- package/src/door/longest.d.ts +6 -0
- package/src/door/longest.js +25 -0
- package/src/fills/account-only.d.ts +3 -0
- package/src/fills/account-only.js +24 -0
- package/src/fills/boot-key.d.ts +21 -0
- package/src/fills/boot-key.js +70 -0
- package/src/fills/boot-move.d.ts +25 -0
- package/src/fills/boot-move.js +86 -0
- package/src/fills/bridge.d.ts +13 -0
- package/src/fills/bridge.js +86 -0
- package/src/fills/chance.d.ts +2 -0
- package/src/fills/chance.js +7 -0
- package/src/fills/crypto.d.ts +2 -0
- package/src/fills/crypto.js +94 -0
- package/src/fills/flushed.d.ts +9 -0
- package/src/fills/flushed.js +80 -0
- package/src/fills/hardware.d.ts +18 -0
- package/src/fills/hardware.js +70 -0
- package/src/fills/held.d.ts +31 -0
- package/src/fills/held.js +171 -0
- package/src/fills/keepers.d.ts +23 -0
- package/src/fills/keepers.js +151 -0
- package/src/fills/keyring.d.ts +19 -0
- package/src/fills/keyring.js +131 -0
- package/src/fills/pages.d.ts +3 -0
- package/src/fills/pages.js +260 -0
- package/src/fills/reserve.d.ts +11 -0
- package/src/fills/reserve.js +72 -0
- package/src/fills/time.d.ts +2 -0
- package/src/fills/time.js +29 -0
- package/src/fills/unlocker.d.ts +6 -0
- package/src/fills/unlocker.js +26 -0
- package/src/fills/vitals.d.ts +8 -0
- package/src/fills/vitals.js +100 -0
- package/src/fills/windows-start.d.ts +2 -0
- package/src/fills/windows-start.js +21 -0
- package/src/halves/build.d.ts +10 -0
- package/src/halves/build.js +219 -0
- package/src/halves/end.d.ts +17 -0
- package/src/halves/end.js +157 -0
- package/src/halves/genome.d.ts +3 -0
- package/src/halves/genome.js +21 -0
- package/src/halves/handler.d.ts +8 -0
- package/src/halves/handler.js +40 -0
- package/src/halves/index.d.ts +5 -0
- package/src/halves/index.js +6 -0
- package/src/halves/laid.d.ts +12 -0
- package/src/halves/laid.js +103 -0
- package/src/halves/lent.d.ts +6 -0
- package/src/halves/lent.js +147 -0
- package/src/halves/native.d.ts +12 -0
- package/src/halves/native.js +53 -0
- package/src/halves/statements.d.ts +23 -0
- package/src/halves/statements.js +165 -0
- package/src/halves/tokens.d.ts +22 -0
- package/src/halves/tokens.js +135 -0
- package/src/link/link.d.ts +4 -0
- package/src/link/link.js +4 -0
- package/src/link/placeholder.d.ts +1 -0
- package/src/link/placeholder.js +21 -0
- package/src/link/steps.d.ts +52 -0
- package/src/link/steps.js +118 -0
- package/src/lobes/calls.d.ts +76 -0
- package/src/lobes/calls.js +61 -0
- package/src/lobes/channel.d.ts +76 -0
- package/src/lobes/channel.js +202 -0
- package/src/lobes/index.d.ts +1 -0
- package/src/lobes/index.js +2 -0
- package/src/lobes/lobes.d.ts +15 -0
- package/src/lobes/lobes.js +244 -0
- package/src/lobes/main.js +107 -0
- package/src/lobes/thread.d.ts +22 -0
- package/src/lobes/thread.js +270 -0
- package/src/organism/act.d.ts +8 -0
- package/src/organism/act.js +63 -0
- package/src/organism/beat.d.ts +5 -0
- package/src/organism/beat.js +45 -0
- package/src/organism/compiled.d.ts +2 -0
- package/src/organism/compiled.js +24 -0
- package/src/organism/folder.d.ts +88 -0
- package/src/organism/folder.js +259 -0
- package/src/organism/main.d.ts +1 -0
- package/src/organism/main.js +11 -0
- package/src/organism/organism.d.ts +1 -0
- package/src/organism/organism.js +220 -0
- package/src/organism/said.d.ts +12 -0
- package/src/organism/said.js +30 -0
- package/src/organism/told.d.ts +5 -0
- package/src/organism/told.js +110 -0
- package/src/organism/unlock.d.ts +8 -0
- package/src/organism/unlock.js +95 -0
- package/src/organism/upgrade.d.ts +24 -0
- package/src/organism/upgrade.js +145 -0
- package/src/organism/via.d.ts +7 -0
- package/src/organism/via.js +20 -0
- package/src/service/body.d.ts +8 -0
- package/src/service/body.js +34 -0
- package/src/service/handler.d.ts +20 -0
- package/src/service/handler.js +128 -0
- package/src/service/index.d.ts +4 -0
- package/src/service/index.js +16 -0
- package/src/service/manager.d.ts +18 -0
- package/src/service/manager.js +185 -0
- package/src/service/service.d.ts +24 -0
- package/src/service/service.js +200 -0
- package/src/service/swap.d.ts +12 -0
- package/src/service/swap.js +74 -0
- package/src/service/watchdog.d.ts +6 -0
- package/src/service/watchdog.js +31 -0
- package/src/tcp/crowd.d.ts +18 -0
- package/src/tcp/crowd.js +85 -0
- package/src/tcp/dial.d.ts +23 -0
- package/src/tcp/dial.js +102 -0
- package/src/tcp/frame.d.ts +23 -0
- package/src/tcp/frame.js +159 -0
- package/src/tcp/listen.d.ts +50 -0
- package/src/tcp/listen.js +207 -0
- package/src/tcp/source.d.ts +2 -0
- package/src/tcp/source.js +26 -0
- package/src/version/index.d.ts +1 -0
- package/src/version/index.js +2 -0
- package/src/version/version.d.ts +1 -0
- package/src/version/version.js +2 -0
- package/src/work/first.d.ts +11 -0
- package/src/work/first.js +91 -0
- package/src/work/index.d.ts +2 -0
- package/src/work/index.js +15 -0
- package/src/work/work.d.ts +20 -0
- package/src/work/work.js +136 -0
- package/src/ws/dial.d.ts +7 -0
- package/src/ws/dial.js +252 -0
- package/src/ws/dialing.d.ts +50 -0
- package/src/ws/dialing.js +72 -0
- package/src/ws/frame.d.ts +32 -0
- package/src/ws/frame.js +124 -0
- package/src/ws/handshake.d.ts +4 -0
- package/src/ws/handshake.js +27 -0
- package/src/ws/line.d.ts +45 -0
- package/src/ws/line.js +250 -0
- package/src/ws/listen.d.ts +42 -0
- package/src/ws/listen.js +272 -0
- package/src/ws/rfc6455.d.ts +18 -0
- package/src/ws/rfc6455.js +187 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Program } from '../fills/bridge.js';
|
|
2
|
+
import type { Service } from './service.js';
|
|
3
|
+
export type Body = {
|
|
4
|
+
readonly slice: string;
|
|
5
|
+
readonly service: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const inBody: (body: Body, program: Program) => Program;
|
|
8
|
+
export declare const bodyOf: (service: Service | null, runs?: (program: Program) => boolean) => Body | null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export const inBody = (body , program ) => ({
|
|
9
|
+
command: 'systemd-run',
|
|
10
|
+
args: [
|
|
11
|
+
'--user',
|
|
12
|
+
'--scope',
|
|
13
|
+
`--slice=${body.slice}`,
|
|
14
|
+
'--quiet',
|
|
15
|
+
'--collect',
|
|
16
|
+
'--property=OOMPolicy=continue',
|
|
17
|
+
`--property=BindsTo=${body.service}`,
|
|
18
|
+
`--property=After=${body.service}`,
|
|
19
|
+
'--',
|
|
20
|
+
program.command,
|
|
21
|
+
...program.args,
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const PROBE = 'test -f "/sys/fs/cgroup$(sed -n "s/^0:://p" /proc/self/cgroup)/../memory.max"';
|
|
26
|
+
|
|
27
|
+
const ranWell = (program ) =>
|
|
28
|
+
spawnSync(program.command, [...program.args], { stdio: 'ignore', timeout: 10_000 }).status === 0;
|
|
29
|
+
|
|
30
|
+
export const bodyOf = (service , runs = ranWell) => {
|
|
31
|
+
if (service?.body === undefined) return null;
|
|
32
|
+
const body = { slice: `${service.body.name}.slice`, service: `${service.name}.service` };
|
|
33
|
+
return runs(inBody(body, { command: 'sh', args: ['-c', PROBE] })) ? body : null;
|
|
34
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Account } from './service.js';
|
|
2
|
+
export type Handler = {
|
|
3
|
+
readonly files: readonly {
|
|
4
|
+
readonly file: string;
|
|
5
|
+
readonly text: string;
|
|
6
|
+
}[];
|
|
7
|
+
readonly steps: readonly (readonly string[])[];
|
|
8
|
+
readonly needs: string | null;
|
|
9
|
+
};
|
|
10
|
+
export declare const handlerOf: (account: Account, bin: string, home: string | null) => Handler | {
|
|
11
|
+
readonly why: string;
|
|
12
|
+
};
|
|
13
|
+
export type Reaches = {
|
|
14
|
+
readonly found: (program: string) => boolean;
|
|
15
|
+
readonly write: (file: string, text: string) => void;
|
|
16
|
+
readonly run: (step: readonly string[]) => string | null;
|
|
17
|
+
};
|
|
18
|
+
export declare const layHandler: (handler: Handler, reaches: Reaches) => {
|
|
19
|
+
readonly why: string;
|
|
20
|
+
} | null;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const SCHEME = 'web+quo';
|
|
12
|
+
|
|
13
|
+
const wordsOf = (account , bin , home ) => [
|
|
14
|
+
account.node,
|
|
15
|
+
bin,
|
|
16
|
+
...(home === null ? [] : ['--home', home]),
|
|
17
|
+
'open',
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const double = (word ) => `"${word.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`;
|
|
21
|
+
const plain = (word ) => `"${word}"`;
|
|
22
|
+
const single = (word ) => `'${word.replaceAll("'", "'\\''")}'`;
|
|
23
|
+
|
|
24
|
+
const linux = (account , bin , home ) => {
|
|
25
|
+
const name = 'nervur-link.desktop';
|
|
26
|
+
const exec = [...wordsOf(account, bin, home).map(double), '%u'].join(' ');
|
|
27
|
+
return {
|
|
28
|
+
files: [
|
|
29
|
+
{
|
|
30
|
+
file: join(account.home, '.local', 'share', 'applications', name),
|
|
31
|
+
text: [
|
|
32
|
+
'[Desktop Entry]',
|
|
33
|
+
'Type=Application',
|
|
34
|
+
'Name=Nervur link',
|
|
35
|
+
`Exec=${exec}`,
|
|
36
|
+
'NoDisplay=true',
|
|
37
|
+
'Terminal=false',
|
|
38
|
+
`MimeType=x-scheme-handler/${SCHEME};`,
|
|
39
|
+
'',
|
|
40
|
+
].join('\n'),
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
steps: [['xdg-mime', 'default', name, `x-scheme-handler/${SCHEME}`]],
|
|
44
|
+
needs: 'xdg-mime',
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const darwin = (account , bin , home ) => {
|
|
49
|
+
const app = join(account.home, 'Applications', 'Nervur link.app');
|
|
50
|
+
const source = join(account.home, 'Library', 'Application Support', 'Nervur', 'link.applescript');
|
|
51
|
+
const command = `${wordsOf(account, bin, home).map(single).join(' ')} `;
|
|
52
|
+
const plist = (name ) => join(app, 'Contents', name);
|
|
53
|
+
return {
|
|
54
|
+
files: [
|
|
55
|
+
{
|
|
56
|
+
file: source,
|
|
57
|
+
text: [
|
|
58
|
+
'on open location theURL',
|
|
59
|
+
` do shell script ${double(command)} & quoted form of theURL & " >/dev/null 2>&1"`,
|
|
60
|
+
'end open location',
|
|
61
|
+
'',
|
|
62
|
+
].join('\n'),
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
steps: [
|
|
66
|
+
['osacompile', '-o', app, source],
|
|
67
|
+
[
|
|
68
|
+
'plutil',
|
|
69
|
+
'-replace',
|
|
70
|
+
'CFBundleURLTypes',
|
|
71
|
+
'-json',
|
|
72
|
+
`[{"CFBundleURLName":"Nervur link","CFBundleURLSchemes":["${SCHEME}"]}]`,
|
|
73
|
+
plist('Info.plist'),
|
|
74
|
+
],
|
|
75
|
+
['plutil', '-replace', 'LSUIElement', '-bool', 'true', plist('Info.plist')],
|
|
76
|
+
[
|
|
77
|
+
'/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister',
|
|
78
|
+
'-f',
|
|
79
|
+
app,
|
|
80
|
+
],
|
|
81
|
+
],
|
|
82
|
+
needs: 'osacompile',
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const win32 = (account , bin , home ) => {
|
|
87
|
+
const key = `HKCU\\Software\\Classes\\${SCHEME}`;
|
|
88
|
+
return {
|
|
89
|
+
files: [],
|
|
90
|
+
steps: [
|
|
91
|
+
['reg', 'add', key, '/ve', '/d', 'URL:Nervur link', '/f'],
|
|
92
|
+
['reg', 'add', key, '/v', 'URL Protocol', '/d', '', '/f'],
|
|
93
|
+
[
|
|
94
|
+
'reg',
|
|
95
|
+
'add',
|
|
96
|
+
`${key}\\shell\\open\\command`,
|
|
97
|
+
'/ve',
|
|
98
|
+
'/d',
|
|
99
|
+
[...wordsOf(account, bin, home).map(plain), '"%1"'].join(' '),
|
|
100
|
+
'/f',
|
|
101
|
+
],
|
|
102
|
+
],
|
|
103
|
+
needs: 'reg',
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const handlerOf = (account , bin , home ) => {
|
|
108
|
+
if (account.platform === 'linux') return linux(account, bin, home);
|
|
109
|
+
if (account.platform === 'darwin') return darwin(account, bin, home);
|
|
110
|
+
if (account.platform === 'win32') return win32(account, bin, home);
|
|
111
|
+
return { why: `Node's installer hands ${SCHEME}: to no program on ${account.platform} yet` };
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
export const layHandler = (handler , reaches ) => {
|
|
121
|
+
if (handler.needs !== null && !reaches.found(handler.needs)) return null;
|
|
122
|
+
for (const { file, text } of handler.files) reaches.write(file, text);
|
|
123
|
+
for (const step of handler.steps) {
|
|
124
|
+
const failed = reaches.run(step);
|
|
125
|
+
if (failed !== null) return { why: `${step.join(' ')} failed: ${failed}` };
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { laidAlike, layLinkHandler, layService, laidService, removeService, unitsOf, serviceFor, startService, stopService, thisAccount, } from './manager.js';
|
|
2
|
+
export { serviceOf, type Account, type Service } from './service.js';
|
|
3
|
+
export { bodyOf, inBody, type Body } from './body.js';
|
|
4
|
+
export { swapSaid } from './swap.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
export {
|
|
3
|
+
laidAlike,
|
|
4
|
+
layLinkHandler,
|
|
5
|
+
layService,
|
|
6
|
+
laidService,
|
|
7
|
+
removeService,
|
|
8
|
+
unitsOf,
|
|
9
|
+
serviceFor,
|
|
10
|
+
startService,
|
|
11
|
+
stopService,
|
|
12
|
+
thisAccount,
|
|
13
|
+
} from './manager.js';
|
|
14
|
+
export { serviceOf, } from './service.js';
|
|
15
|
+
export { bodyOf, inBody, } from './body.js';
|
|
16
|
+
export { swapSaid } from './swap.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Account, type Service, type Unit } from './service.js';
|
|
2
|
+
type Why = {
|
|
3
|
+
readonly why: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const thisAccount: () => Account;
|
|
6
|
+
export declare const laidService: (folder: string) => Service | null;
|
|
7
|
+
export declare const unitsOf: (service: Service) => readonly Unit[];
|
|
8
|
+
export declare const laidAlike: (service: Service) => boolean;
|
|
9
|
+
export declare const serviceFor: (folder: string) => Service | Why;
|
|
10
|
+
export declare const unitsFolderClosed: (manager: Service['manager'], file: string) => void;
|
|
11
|
+
export declare const layService: (service: Service, home?: string | null) => Promise<{
|
|
12
|
+
readonly warning: string | null;
|
|
13
|
+
} | Why>;
|
|
14
|
+
export declare const startService: (service: Service) => null | Why;
|
|
15
|
+
export declare const stopService: (service: Service, home?: string | null) => Promise<null | Why>;
|
|
16
|
+
export declare const removeService: (service: Service) => Promise<null | Why>;
|
|
17
|
+
export declare const layLinkHandler: (home: string | null) => Why | null;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { execFileSync, spawnSync } from 'node:child_process';
|
|
3
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { foldersLaid, laidWhole, treeFlushed } from '../fills/flushed.js';
|
|
5
|
+
import { homedir, totalmem, userInfo } from 'node:os';
|
|
6
|
+
import { delimiter, dirname, join } from 'node:path';
|
|
7
|
+
import { LONGEST_WAIT } from '../door/longest.js';
|
|
8
|
+
import { heardOf } from '../organism/beat.js';
|
|
9
|
+
import { layHandler, handlerOf } from './handler.js';
|
|
10
|
+
import { serviceOf, userBusOf, windowsCommandOf, } from './service.js';
|
|
11
|
+
|
|
12
|
+
const [, COMMAND = ''] = process.argv;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export const thisAccount = () => ({
|
|
17
|
+
platform: process.platform,
|
|
18
|
+
user: userInfo().username,
|
|
19
|
+
home: homedir(),
|
|
20
|
+
node: process.execPath,
|
|
21
|
+
command: process.platform === 'win32' ? windowsCommandOf(COMMAND) : COMMAND,
|
|
22
|
+
path: process.env['PATH'] ?? '/usr/bin:/bin',
|
|
23
|
+
memory: totalmem(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const ran = (command , args ) => {
|
|
27
|
+
try {
|
|
28
|
+
execFileSync(command, [...args], {
|
|
29
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
30
|
+
env: userBusOf(process.env, process.getuid?.() ?? 0),
|
|
31
|
+
});
|
|
32
|
+
return null;
|
|
33
|
+
} catch (thrown) {
|
|
34
|
+
const said =
|
|
35
|
+
thrown instanceof Error && 'stderr' in thrown && thrown.stderr instanceof Buffer
|
|
36
|
+
? thrown.stderr.toString('utf8').trim()
|
|
37
|
+
: String(thrown);
|
|
38
|
+
return { why: `${[command, ...args].join(' ')} failed: ${said}` };
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const domainOf = () => `gui/${process.getuid?.() ?? 0}`;
|
|
43
|
+
|
|
44
|
+
export const laidService = (folder ) => {
|
|
45
|
+
const service = serviceOf(folder, thisAccount());
|
|
46
|
+
return 'why' in service || !existsSync(service.file) ? null : service;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const unitsOf = (service ) =>
|
|
50
|
+
[service, service.body, service.script].filter((unit) => unit !== undefined);
|
|
51
|
+
|
|
52
|
+
export const laidAlike = (service ) =>
|
|
53
|
+
unitsOf(service).every((unit) => existsSync(unit.file) && readFileSync(unit.file, 'utf8') === unit.text);
|
|
54
|
+
|
|
55
|
+
export const serviceFor = (folder ) => {
|
|
56
|
+
const service = serviceOf(folder, thisAccount());
|
|
57
|
+
return 'why' in service || service.manager !== 'systemd' || !noSystemctl() ? service : NO_SYSTEMCTL;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const noSystemctl = () => spawnSync('systemctl', ['--version'], { stdio: 'ignore' }).error !== undefined;
|
|
61
|
+
const NO_SYSTEMCTL = {
|
|
62
|
+
why: 'this machine has no systemctl, so nothing could start the organism at boot: name a folder with --home to lay it with no service',
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const lingering = () => {
|
|
66
|
+
const account = userInfo().username;
|
|
67
|
+
if (existsSync(join('/var/lib/systemd/linger', account))) return null;
|
|
68
|
+
const refused = ran('loginctl', ['enable-linger', account]);
|
|
69
|
+
return refused === null
|
|
70
|
+
? null
|
|
71
|
+
: `The organism starts as ${account} logs in, and at boot once the account lingers, which this host refused it: an administrator runs loginctl enable-linger ${account}.`;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const AGAIN = 100;
|
|
75
|
+
|
|
76
|
+
const holds = (service ) => ran('launchctl', ['print', `${domainOf()}/${service.name}`]) === null;
|
|
77
|
+
|
|
78
|
+
const bootedOut = async (service , home ) => {
|
|
79
|
+
if (!holds(service)) return null;
|
|
80
|
+
ran('launchctl', ['bootout', `${domainOf()}/${service.name}`]);
|
|
81
|
+
const beat = home === null ? null : heardOf(home);
|
|
82
|
+
const quiet = beat?.quiet ?? LONGEST_WAIT;
|
|
83
|
+
let heard = beat?.of() ?? null;
|
|
84
|
+
for (let silent = 0; silent < quiet; silent += AGAIN) {
|
|
85
|
+
if (!holds(service)) return null;
|
|
86
|
+
await new Promise((done) => setTimeout(done, AGAIN));
|
|
87
|
+
const now = beat?.of() ?? null;
|
|
88
|
+
if (now !== heard) {
|
|
89
|
+
heard = now;
|
|
90
|
+
silent = 0;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
why: `launchd still holds ${service.name}, and the organism told nothing for ${quiet / 1000} s after it was booted out`,
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const unitsFolderClosed = (manager , file ) => {
|
|
99
|
+
if (manager !== 'systemd') return;
|
|
100
|
+
try {
|
|
101
|
+
chmodSync(dirname(file), 0o700);
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const layService = async (
|
|
107
|
+
service ,
|
|
108
|
+
home = null,
|
|
109
|
+
) => {
|
|
110
|
+
for (const unit of unitsOf(service)) {
|
|
111
|
+
foldersLaid(dirname(unit.file), 0o700);
|
|
112
|
+
laidWhole(unit.file, unit.text, 0o600);
|
|
113
|
+
unitsFolderClosed(service.manager, unit.file);
|
|
114
|
+
}
|
|
115
|
+
if (service.manager === 'schtasks') {
|
|
116
|
+
return ran('schtasks', ['/Create', '/TN', service.name, '/XML', service.file, '/F']) ?? { warning: null };
|
|
117
|
+
}
|
|
118
|
+
if (service.manager === 'systemd') {
|
|
119
|
+
const enabled =
|
|
120
|
+
ran('systemctl', ['--user', 'daemon-reload']) ??
|
|
121
|
+
ran('systemctl', ['--user', 'enable', `${service.name}.service`]);
|
|
122
|
+
if (enabled !== null) return enabled;
|
|
123
|
+
treeFlushed(join(dirname(service.file), 'default.target.wants'));
|
|
124
|
+
return { warning: lingering() };
|
|
125
|
+
}
|
|
126
|
+
const out = await bootedOut(service, home);
|
|
127
|
+
return out ?? { warning: null };
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const startService = (service ) => {
|
|
131
|
+
if (service.manager === 'schtasks') {
|
|
132
|
+
return (
|
|
133
|
+
ran('schtasks', ['/Change', '/TN', service.name, '/ENABLE']) ?? ran('schtasks', ['/Run', '/TN', service.name])
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
if (service.manager === 'systemd') return ran('systemctl', ['--user', 'start', `${service.name}.service`]);
|
|
137
|
+
return holds(service)
|
|
138
|
+
? ran('launchctl', ['kickstart', `${domainOf()}/${service.name}`])
|
|
139
|
+
: ran('launchctl', ['bootstrap', domainOf(), service.file]);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const stopService = async (service , home = null) => {
|
|
143
|
+
if (service.manager === 'schtasks') return ran('schtasks', ['/Change', '/TN', service.name, '/DISABLE']);
|
|
144
|
+
return service.manager === 'systemd'
|
|
145
|
+
? ran('systemctl', ['--user', 'stop', `${service.name}.service`])
|
|
146
|
+
: bootedOut(service, home);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const removeService = async (service ) => {
|
|
150
|
+
if (service.manager === 'schtasks') {
|
|
151
|
+
const deleted = ran('schtasks', ['/Delete', '/TN', service.name, '/F']);
|
|
152
|
+
if (deleted !== null) return deleted;
|
|
153
|
+
for (const unit of unitsOf(service)) rmSync(unit.file, { force: true });
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
if (service.manager === 'systemd') {
|
|
157
|
+
const disabled = ran('systemctl', ['--user', 'disable', '--now', `${service.name}.service`]);
|
|
158
|
+
if (disabled !== null) return disabled;
|
|
159
|
+
for (const unit of unitsOf(service)) rmSync(unit.file, { force: true });
|
|
160
|
+
return ran('systemctl', ['--user', 'daemon-reload']);
|
|
161
|
+
}
|
|
162
|
+
const out = await bootedOut(service, null);
|
|
163
|
+
rmSync(service.file, { force: true });
|
|
164
|
+
return out;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const found = (program ) =>
|
|
168
|
+
(process.env['PATH'] ?? '').split(delimiter).some((folder) => existsSync(join(folder, program)));
|
|
169
|
+
|
|
170
|
+
export const layLinkHandler = (home ) => {
|
|
171
|
+
const account = thisAccount();
|
|
172
|
+
const handler = handlerOf(account, account.command, home);
|
|
173
|
+
if ('why' in handler) return null;
|
|
174
|
+
return layHandler(handler, {
|
|
175
|
+
found: account.platform === 'win32' ? () => true : found,
|
|
176
|
+
write: (file, text) => {
|
|
177
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
178
|
+
writeFileSync(file, text, { mode: 0o644 });
|
|
179
|
+
},
|
|
180
|
+
run: (step) => {
|
|
181
|
+
const [command, ...args] = step;
|
|
182
|
+
return command === undefined ? null : (ran(command, args)?.why ?? null);
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type Account = {
|
|
2
|
+
readonly platform: NodeJS.Platform;
|
|
3
|
+
readonly user: string;
|
|
4
|
+
readonly home: string;
|
|
5
|
+
readonly node: string;
|
|
6
|
+
readonly command: string;
|
|
7
|
+
readonly path: string;
|
|
8
|
+
readonly memory: number;
|
|
9
|
+
};
|
|
10
|
+
export type Unit = {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly file: string;
|
|
13
|
+
readonly text: string;
|
|
14
|
+
};
|
|
15
|
+
export type Service = Unit & {
|
|
16
|
+
readonly manager: 'systemd' | 'launchd' | 'schtasks';
|
|
17
|
+
readonly body?: Unit;
|
|
18
|
+
readonly script?: Unit;
|
|
19
|
+
};
|
|
20
|
+
export declare const windowsCommandOf: (script: string) => string;
|
|
21
|
+
export declare const serviceOf: (folder: string, account: Account) => Service | {
|
|
22
|
+
readonly why: string;
|
|
23
|
+
};
|
|
24
|
+
export declare const userBusOf: (env: NodeJS.ProcessEnv, uid: number) => NodeJS.ProcessEnv;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { join, win32 } from 'node:path';
|
|
4
|
+
import { logOf, stoppedOf } from '../organism/folder.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const tagOf = (folder ) => createHash('sha256').update(folder).digest('hex').slice(0, 12);
|
|
25
|
+
|
|
26
|
+
const wordsOf = (folder , account ) => [
|
|
27
|
+
account.node,
|
|
28
|
+
account.command,
|
|
29
|
+
'organism',
|
|
30
|
+
folder,
|
|
31
|
+
'boot',
|
|
32
|
+
'--at-boot',
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
const unitWord = (word ) => word.replaceAll('%', '%%').replaceAll('$', '$$$$');
|
|
36
|
+
const quoted = (word ) => `"${unitWord(word).replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`;
|
|
37
|
+
|
|
38
|
+
const AGAIN_AFTER = 3;
|
|
39
|
+
|
|
40
|
+
const MIB = 1024 ** 2;
|
|
41
|
+
const GIB = 1024 * MIB;
|
|
42
|
+
|
|
43
|
+
const bodyMemoryOf = (memory ) => memory - Math.min(Math.max(GIB, memory / 4), memory / 2);
|
|
44
|
+
|
|
45
|
+
const bodySliceOf = (folder , name , account ) => ({
|
|
46
|
+
name: `${name}-body`,
|
|
47
|
+
file: join(account.home, '.config', 'systemd', 'user', `${name}-body.slice`),
|
|
48
|
+
text: [
|
|
49
|
+
'[Unit]',
|
|
50
|
+
`Description=The body of the Nervur organism at ${unitWord(folder)}`,
|
|
51
|
+
'',
|
|
52
|
+
'[Slice]',
|
|
53
|
+
`MemoryMax=${Math.floor(bodyMemoryOf(account.memory) / MIB)}M`,
|
|
54
|
+
'',
|
|
55
|
+
].join('\n'),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const systemd = (folder , account ) => {
|
|
59
|
+
const name = `nervur-${tagOf(folder)}`;
|
|
60
|
+
const text = [
|
|
61
|
+
'[Unit]',
|
|
62
|
+
`Description=The Nervur organism at ${unitWord(folder)}`,
|
|
63
|
+
'StartLimitIntervalSec=0',
|
|
64
|
+
`ConditionPathExists=!${unitWord(stoppedOf(folder))}`,
|
|
65
|
+
'',
|
|
66
|
+
'[Service]',
|
|
67
|
+
'Type=simple',
|
|
68
|
+
`ExecStart=${wordsOf(folder, account).map(quoted).join(' ')}`,
|
|
69
|
+
`Environment=${quoted(`PATH=${account.path}`)}`,
|
|
70
|
+
'Restart=always',
|
|
71
|
+
`RestartSec=${AGAIN_AFTER}`,
|
|
72
|
+
'WatchdogSec=60',
|
|
73
|
+
'WatchdogSignal=SIGKILL',
|
|
74
|
+
'NotifyAccess=all',
|
|
75
|
+
'LimitCORE=0',
|
|
76
|
+
'OOMPolicy=continue',
|
|
77
|
+
'UMask=0077',
|
|
78
|
+
'StandardOutput=null',
|
|
79
|
+
`StandardError=append:${unitWord(logOf(folder))}`,
|
|
80
|
+
'',
|
|
81
|
+
'[Install]',
|
|
82
|
+
'WantedBy=default.target',
|
|
83
|
+
'',
|
|
84
|
+
].join('\n');
|
|
85
|
+
return {
|
|
86
|
+
manager: 'systemd',
|
|
87
|
+
name,
|
|
88
|
+
file: join(account.home, '.config', 'systemd', 'user', `${name}.service`),
|
|
89
|
+
text,
|
|
90
|
+
body: bodySliceOf(folder, name, account),
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const escaped = (word ) =>
|
|
95
|
+
word.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
|
|
96
|
+
const string = (word ) => `<string>${escaped(word)}</string>`;
|
|
97
|
+
|
|
98
|
+
const UMASK = 0o077;
|
|
99
|
+
|
|
100
|
+
const launchd = (folder , account ) => {
|
|
101
|
+
const name = `org.nervur.organism.${tagOf(folder)}`;
|
|
102
|
+
const text = [
|
|
103
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
104
|
+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
105
|
+
'<plist version="1.0">',
|
|
106
|
+
'<dict>',
|
|
107
|
+
` <key>Label</key>${string(name)}`,
|
|
108
|
+
' <key>ProgramArguments</key>',
|
|
109
|
+
' <array>',
|
|
110
|
+
...wordsOf(folder, account).map((word) => ` ${string(word)}`),
|
|
111
|
+
' </array>',
|
|
112
|
+
' <key>EnvironmentVariables</key>',
|
|
113
|
+
` <dict><key>PATH</key>${string(account.path)}</dict>`,
|
|
114
|
+
' <key>RunAtLoad</key><true/>',
|
|
115
|
+
` <key>KeepAlive</key><dict><key>PathState</key><dict><key>${escaped(stoppedOf(folder))}</key><false/></dict></dict>`,
|
|
116
|
+
` <key>ThrottleInterval</key><integer>${AGAIN_AFTER}</integer>`,
|
|
117
|
+
` <key>Umask</key><integer>${UMASK}</integer>`,
|
|
118
|
+
' <key>SoftResourceLimits</key><dict><key>Core</key><integer>0</integer></dict>',
|
|
119
|
+
' <key>HardResourceLimits</key><dict><key>Core</key><integer>0</integer></dict>',
|
|
120
|
+
` <key>StandardOutPath</key>${string('/dev/null')}`,
|
|
121
|
+
` <key>StandardErrorPath</key>${string(logOf(folder))}`,
|
|
122
|
+
'</dict>',
|
|
123
|
+
'</plist>',
|
|
124
|
+
'',
|
|
125
|
+
].join('\n');
|
|
126
|
+
return {
|
|
127
|
+
manager: 'launchd',
|
|
128
|
+
name,
|
|
129
|
+
file: join(account.home, 'Library', 'LaunchAgents', `${name}.plist`),
|
|
130
|
+
text,
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const batch = (word ) => word.replaceAll('%', '%%');
|
|
135
|
+
|
|
136
|
+
const startOf = (account ) =>
|
|
137
|
+
account.command.endsWith('.cmd')
|
|
138
|
+
? `call "${batch(account.command)}"`
|
|
139
|
+
: `"${batch(account.node)}" "${batch(account.command)}"`;
|
|
140
|
+
|
|
141
|
+
const taskScriptOf = (folder , name , at , account ) => ({
|
|
142
|
+
name: `${name}-script`,
|
|
143
|
+
file: win32.join(at, `${name}.cmd`),
|
|
144
|
+
text: [
|
|
145
|
+
'@echo off',
|
|
146
|
+
`set "PATH=${batch(account.path)}"`,
|
|
147
|
+
`if exist "${batch(stoppedOf(folder))}" exit /b 0`,
|
|
148
|
+
`${startOf(account)} organism "${batch(folder)}" boot --at-boot 1>nul 2>>"${batch(logOf(folder))}"`,
|
|
149
|
+
'',
|
|
150
|
+
].join('\r\n'),
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const schtasks = (folder , account ) => {
|
|
154
|
+
const name = `nervur-${tagOf(folder)}`;
|
|
155
|
+
const at = win32.join(account.home, 'AppData', 'Local', 'Nervur');
|
|
156
|
+
const script = taskScriptOf(folder, name, at, account);
|
|
157
|
+
const text = [
|
|
158
|
+
'<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">',
|
|
159
|
+
' <Triggers><BootTrigger><Enabled>true</Enabled></BootTrigger>',
|
|
160
|
+
' <TimeTrigger><Enabled>true</Enabled><StartBoundary>2000-01-01T00:00:00</StartBoundary>',
|
|
161
|
+
' <Repetition><Interval>PT1M</Interval><StopAtDurationEnd>false</StopAtDurationEnd></Repetition>',
|
|
162
|
+
' </TimeTrigger></Triggers>',
|
|
163
|
+
` <Principals><Principal id="Author"><UserId>${escaped(account.user)}</UserId><LogonType>S4U</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals>`,
|
|
164
|
+
' <Settings>',
|
|
165
|
+
' <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>',
|
|
166
|
+
' <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>',
|
|
167
|
+
' <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>',
|
|
168
|
+
' <StartWhenAvailable>true</StartWhenAvailable>',
|
|
169
|
+
' <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>',
|
|
170
|
+
' <Priority>5</Priority>',
|
|
171
|
+
' </Settings>',
|
|
172
|
+
` <Actions Context="Author"><Exec><Command>cmd.exe</Command><Arguments>/d /c "${escaped(script.file)}"</Arguments></Exec></Actions>`,
|
|
173
|
+
'</Task>',
|
|
174
|
+
'',
|
|
175
|
+
]
|
|
176
|
+
.join('\r\n')
|
|
177
|
+
.replace(/[^\p{ASCII}]/gu, (one) => `&#${one.codePointAt(0) ?? 0};`);
|
|
178
|
+
return { manager: 'schtasks', name, file: win32.join(at, `${name}.xml`), text, script };
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export const windowsCommandOf = (script ) => {
|
|
182
|
+
const at = script.indexOf('\\node_modules\\nervur\\');
|
|
183
|
+
return at < 0 ? script : win32.join(script.slice(0, at), 'nervur.cmd');
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export const serviceOf = (folder , account ) => {
|
|
187
|
+
if (account.platform === 'linux') return systemd(folder, account);
|
|
188
|
+
if (account.platform === 'darwin') return launchd(folder, account);
|
|
189
|
+
if (account.platform === 'win32') return schtasks(folder, account);
|
|
190
|
+
return { why: `Node's installer starts no organism at boot on ${account.platform} yet` };
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export const userBusOf = (env , uid ) => {
|
|
194
|
+
const runtime = env['XDG_RUNTIME_DIR'] ?? `/run/user/${uid}`;
|
|
195
|
+
return {
|
|
196
|
+
...env,
|
|
197
|
+
XDG_RUNTIME_DIR: runtime,
|
|
198
|
+
DBUS_SESSION_BUS_ADDRESS: env['DBUS_SESSION_BUS_ADDRESS'] ?? `unix:path=${runtime}/bus`,
|
|
199
|
+
};
|
|
200
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type Host = {
|
|
2
|
+
readonly platform: NodeJS.Platform;
|
|
3
|
+
readonly file: (path: string) => string | null;
|
|
4
|
+
readonly entries: (path: string) => readonly string[];
|
|
5
|
+
readonly device: (path: string) => {
|
|
6
|
+
readonly dev: number;
|
|
7
|
+
readonly rdev: number;
|
|
8
|
+
} | null;
|
|
9
|
+
readonly ran: (program: string, args: readonly string[]) => string | null;
|
|
10
|
+
};
|
|
11
|
+
export declare const thisHost: Host;
|
|
12
|
+
export declare const swapSaid: (host?: Host) => string;
|