omnius 1.0.935 → 1.0.938
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/dist/daemon-environment.cjs +139 -0
- package/dist/index.js +2 -2
- package/dist/postinstall-daemon.cjs +57 -11
- package/dist/update-worker-runtime.js +229 -53
- package/npm-shrinkwrap.json +2 -20
- package/package.json +1 -5
- package/node_modules/image-to-ascii/bin/image-to-ascii.cjs +0 -18
- package/node_modules/image-to-ascii/index.cjs +0 -308
- package/node_modules/image-to-ascii/index.d.ts +0 -48
- package/node_modules/image-to-ascii/package.json +0 -22
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
|
|
6
|
+
function decode(value) {
|
|
7
|
+
if ((value[0] === '"' || value[0] === "'") && value[value.length - 1] === value[0]) value = value.slice(1, -1);
|
|
8
|
+
return value.replace(/\\(?:x([a-f0-9]{2})|([\\"'\s])|([snrt]))/gi, (_, hex, literal, escaped) =>
|
|
9
|
+
hex ? String.fromCharCode(parseInt(hex, 16)) : literal || ({ s: " ", n: "\n", r: "\r", t: "\t" })[escaped]);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function entry(value, optional) {
|
|
13
|
+
let file = decode(value.trim());
|
|
14
|
+
if (file[0] === "-") { optional = true; file = file.slice(1); }
|
|
15
|
+
if (!path.isAbsolute(file) || /[\x00-\x1f\x7f]/.test(file)) throw new Error("Daemon environment file paths must be absolute and contain no control characters");
|
|
16
|
+
return { path: path.resolve(file), optional: Boolean(optional) };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Parse systemctl's EnvironmentFiles value, including its ignore_errors flags. */
|
|
20
|
+
function parseEnvironmentFiles(value) {
|
|
21
|
+
if (typeof value !== "string" || value.length > 128 * 1024) throw new Error("Invalid daemon EnvironmentFiles value");
|
|
22
|
+
value = value.replace(/^EnvironmentFiles=/, "").trim();
|
|
23
|
+
if (!value) return [];
|
|
24
|
+
const result = [];
|
|
25
|
+
const marker = /\s+\(ignore_errors=(yes|no)\)/g;
|
|
26
|
+
let at = 0, match;
|
|
27
|
+
while ((match = marker.exec(value))) {
|
|
28
|
+
result.push(entry(value.slice(at, match.index), match[1] === "yes"));
|
|
29
|
+
at = marker.lastIndex;
|
|
30
|
+
}
|
|
31
|
+
const remainder = value.slice(at).trim();
|
|
32
|
+
if (remainder) {
|
|
33
|
+
const tokens = remainder.match(/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\\.|[^\s"'\\])+/g) || [];
|
|
34
|
+
if (tokens.join(" ").replace(/\s+/g, " ") !== remainder.replace(/\s+/g, " ")) throw new Error("Invalid daemon EnvironmentFiles quoting");
|
|
35
|
+
for (const token of tokens) result.push(entry(token, false));
|
|
36
|
+
}
|
|
37
|
+
if (result.length > 256) throw new Error("Too many daemon environment files");
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const inside = (root, file) => file !== root && !path.relative(root, file).startsWith(".." + path.sep) && path.relative(root, file) !== ".." && !path.isAbsolute(path.relative(root, file));
|
|
42
|
+
|
|
43
|
+
/** Missing declared files become empty private configuration, never inferred values.
|
|
44
|
+
* Linux operations stay anchored to open directories, including symlinked data roots.
|
|
45
|
+
*/
|
|
46
|
+
function ensureEnvironmentFiles(options) {
|
|
47
|
+
if (!options || !path.isAbsolute(options.homeDir || "")) throw new Error("Daemon environment migration requires an absolute owner home");
|
|
48
|
+
const home = path.resolve(options.homeDir);
|
|
49
|
+
const roots = [path.join(home, ".omnius"), path.join(home, ".config", "omnius")];
|
|
50
|
+
if (options.dataDir !== undefined) {
|
|
51
|
+
if (!path.isAbsolute(options.dataDir)) throw new Error("Daemon data directory must be absolute");
|
|
52
|
+
roots.push(path.resolve(options.dataDir));
|
|
53
|
+
}
|
|
54
|
+
const uid = options.uid === undefined ? process.getuid?.() : options.uid;
|
|
55
|
+
const gid = options.gid === undefined ? process.getgid?.() : options.gid;
|
|
56
|
+
if (uid !== undefined && (!Number.isSafeInteger(uid) || uid < 0) || gid !== undefined && (!Number.isSafeInteger(gid) || gid < 0)) throw new Error("Invalid daemon environment owner");
|
|
57
|
+
const values = typeof options.environmentFiles === "string" ? parseEnvironmentFiles(options.environmentFiles) : options.environmentFiles;
|
|
58
|
+
if (!Array.isArray(values) || values.length > 256) throw new Error("Invalid daemon environment file entries");
|
|
59
|
+
const result = { created: [], existing: [], unmanagedMissing: [] };
|
|
60
|
+
const seen = new Set();
|
|
61
|
+
const descriptors = [];
|
|
62
|
+
const anchored = process.platform === "linux";
|
|
63
|
+
const fdPath = (fd, name, fallback) => anchored ? `/proc/self/fd/${fd}/${name}` : fallback;
|
|
64
|
+
const owner = (stat, label) => {
|
|
65
|
+
if (!stat.isDirectory() || process.platform !== "win32" && uid !== undefined && stat.uid !== uid) throw new Error(`Daemon environment directory is not owned by the service user: ${label}`);
|
|
66
|
+
};
|
|
67
|
+
const openDirectory = (location, label) => {
|
|
68
|
+
const fd = fs.openSync(location, fs.constants.O_RDONLY | (fs.constants.O_DIRECTORY || 0) | (fs.constants.O_NOFOLLOW || 0));
|
|
69
|
+
try { owner(fs.fstatSync(fd), label); } catch (error) { fs.closeSync(fd); throw error; }
|
|
70
|
+
descriptors.push(fd); return fd;
|
|
71
|
+
};
|
|
72
|
+
const walk = (initialFd, initialPath, components) => {
|
|
73
|
+
let fd = initialFd, location = initialPath;
|
|
74
|
+
for (const component of components) {
|
|
75
|
+
if (!component || component === "." || component === "..") throw new Error("Invalid daemon environment directory component");
|
|
76
|
+
location = path.join(location, component);
|
|
77
|
+
const next = fdPath(fd, component, location);
|
|
78
|
+
let created = false;
|
|
79
|
+
try { fs.mkdirSync(next, { mode: 0o700 }); created = true; }
|
|
80
|
+
catch (error) { if (error.code !== "EEXIST") throw error; }
|
|
81
|
+
const nextFd = fs.openSync(next, fs.constants.O_RDONLY | (fs.constants.O_DIRECTORY || 0) | (fs.constants.O_NOFOLLOW || 0));
|
|
82
|
+
try {
|
|
83
|
+
if (created) {
|
|
84
|
+
fs.fchmodSync(nextFd, 0o700);
|
|
85
|
+
if (process.platform !== "win32" && process.getuid?.() === 0 && uid !== undefined && gid !== undefined) fs.fchownSync(nextFd, uid, gid);
|
|
86
|
+
}
|
|
87
|
+
owner(fs.fstatSync(nextFd), location);
|
|
88
|
+
} catch (error) { fs.closeSync(nextFd); throw error; }
|
|
89
|
+
descriptors.push(nextFd); fd = nextFd;
|
|
90
|
+
}
|
|
91
|
+
return fd;
|
|
92
|
+
};
|
|
93
|
+
const openRoot = root => {
|
|
94
|
+
try { return openDirectory(fs.realpathSync(root), root); }
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error.code !== "ENOENT") throw error;
|
|
97
|
+
if (inside(home, root)) {
|
|
98
|
+
const realHome = fs.realpathSync(home);
|
|
99
|
+
return walk(openDirectory(realHome, home), realHome, path.relative(home, root).split(path.sep));
|
|
100
|
+
}
|
|
101
|
+
const parent = fs.realpathSync(path.dirname(root));
|
|
102
|
+
return walk(openDirectory(parent, path.dirname(root)), parent, [path.basename(root)]);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
try {
|
|
106
|
+
for (const value of values) {
|
|
107
|
+
if (!value || typeof value.path !== "string" || typeof value.optional !== "boolean") throw new Error("Invalid daemon environment file entry");
|
|
108
|
+
const file = entry(value.path, value.optional).path;
|
|
109
|
+
if (seen.has(file)) continue;
|
|
110
|
+
seen.add(file);
|
|
111
|
+
const root = roots.find(candidate => inside(candidate, file));
|
|
112
|
+
if (!root) {
|
|
113
|
+
try { fs.lstatSync(file); result.existing.push(file); }
|
|
114
|
+
catch (error) { if (error.code !== "ENOENT") throw error; result.unmanagedMissing.push(file); }
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const rootFd = openRoot(root);
|
|
118
|
+
const relative = path.relative(root, file).split(path.sep), name = relative.pop();
|
|
119
|
+
const parentFd = walk(rootFd, root, relative);
|
|
120
|
+
const target = fdPath(parentFd, name, file);
|
|
121
|
+
let fd;
|
|
122
|
+
try { fd = fs.openSync(target, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | (fs.constants.O_NOFOLLOW || 0), 0o600); }
|
|
123
|
+
catch (error) { if (error.code === "EEXIST") { result.existing.push(file); continue; } throw error; }
|
|
124
|
+
try {
|
|
125
|
+
fs.fchmodSync(fd, 0o600);
|
|
126
|
+
if (process.platform !== "win32" && process.getuid?.() === 0 && uid !== undefined && gid !== undefined) fs.fchownSync(fd, uid, gid);
|
|
127
|
+
fs.writeFileSync(fd, "# Optional Omnius daemon runtime overrides (KEY=value).\n");
|
|
128
|
+
fs.fsyncSync(fd);
|
|
129
|
+
result.created.push(file);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
try { fs.unlinkSync(target); } catch {}
|
|
132
|
+
throw error;
|
|
133
|
+
} finally { fs.closeSync(fd); }
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
} finally { for (const fd of descriptors.reverse()) fs.closeSync(fd); }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
module.exports = { parseEnvironmentFiles, ensureEnvironmentFiles };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/dist/index.js
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 41414957 bytes
|
|
4
|
+
sha256: ad80e20f9c10f29cc052d8328e6c0ad23935254921a831418c1fb01c5a515655
|
|
@@ -423,15 +423,17 @@ function resolveOmniusBinary() {
|
|
|
423
423
|
candidates.push(path.join(prefix, "bin", "omnius"));
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
|
-
// 3. PATH fallback (last resort — can resolve to npx cache or fnm shim).
|
|
427
|
-
var found = runCapture(IS_WIN ? "where omnius" : "which omnius").split(/\r?\n/)[0];
|
|
428
|
-
if (found && !/_npx|fnm_multishells/.test(found)) candidates.push(found);
|
|
429
|
-
|
|
430
426
|
for (var i = 0; i < candidates.length; i++) {
|
|
431
427
|
try {
|
|
432
428
|
if (candidates[i] && fs.existsSync(candidates[i])) return candidates[i];
|
|
433
429
|
} catch (e) {}
|
|
434
430
|
}
|
|
431
|
+
// 3. PATH fallback (last resort — can resolve to npx cache or fnm shim).
|
|
432
|
+
// Only consulted when the package-relative paths are missing.
|
|
433
|
+
var found = runCapture(IS_WIN ? "where omnius" : "which omnius").split(/\r?\n/)[0];
|
|
434
|
+
try {
|
|
435
|
+
if (found && !/_npx|fnm_multishells/.test(found) && fs.existsSync(found)) return found;
|
|
436
|
+
} catch (e) {}
|
|
435
437
|
return null;
|
|
436
438
|
}
|
|
437
439
|
|
|
@@ -725,17 +727,51 @@ function installDesktopCompanion(nodeBin, omniusScript, user) {
|
|
|
725
727
|
}
|
|
726
728
|
}
|
|
727
729
|
|
|
730
|
+
// Older builds and operator drop-ins (e.g. cygnus-env.conf) can declare
|
|
731
|
+
// EnvironmentFile= paths that were never created; systemd then refuses to
|
|
732
|
+
// start the unit. Create only the missing ones, empty and private, under the
|
|
733
|
+
// owner's Omnius directories. Existing contents are never touched.
|
|
734
|
+
// Linger is a one-time account setting. Re-requesting it on every update can
|
|
735
|
+
// raise a polkit password prompt, so ask only when it is off and never
|
|
736
|
+
// interactively; a missing grant is reported instead of prompting.
|
|
737
|
+
function ensureLinger(user, prefix) {
|
|
738
|
+
if (runCapture((prefix || "") + "loginctl show-user " + shellQuote(user) + " --property=Linger --value") === "yes") return;
|
|
739
|
+
if (!runQuiet((prefix || "") + "loginctl --no-ask-password enable-linger " + shellQuote(user))) {
|
|
740
|
+
warn("User services stop at logout until linger is enabled once: loginctl enable-linger " + user);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function ensureDeclaredDaemonEnvironmentFiles(sysctl, userHome, user) {
|
|
745
|
+
try {
|
|
746
|
+
var shown = runCapture(sysctl + " show " + SERVICE_LABEL + ".service --property=EnvironmentFiles");
|
|
747
|
+
var lines = shown.split(/\r?\n/).filter(function (line) { return line.indexOf("EnvironmentFiles=") === 0; });
|
|
748
|
+
if (lines.length === 0) return;
|
|
749
|
+
var helper = require(path.join(__dirname, "daemon-environment.cjs"));
|
|
750
|
+
var entries = [];
|
|
751
|
+
lines.forEach(function (line) { entries = entries.concat(helper.parseEnvironmentFiles(line)); });
|
|
752
|
+
var ids = {};
|
|
753
|
+
if (user) {
|
|
754
|
+
var account = runCapture("getent passwd " + user).split(":");
|
|
755
|
+
if (account[0] === user && /^\d+$/.test(account[2] || "") && /^\d+$/.test(account[3] || "")) {
|
|
756
|
+
ids.uid = Number(account[2]); ids.gid = Number(account[3]);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
var result = helper.ensureEnvironmentFiles(Object.assign({ environmentFiles: entries, homeDir: userHome }, ids));
|
|
760
|
+
result.created.forEach(function (file) { log("Created missing daemon environment file: " + file); });
|
|
761
|
+
result.unmanagedMissing.forEach(function (file) {
|
|
762
|
+
warn("Daemon unit requires " + file + " outside the Omnius directories; create it manually.");
|
|
763
|
+
});
|
|
764
|
+
} catch (e) {
|
|
765
|
+
warn("Could not verify daemon environment files: " + (e && e.message));
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
728
769
|
function installSystemd(nodeBin, omniusScript, user) {
|
|
729
770
|
if (!IS_LINUX) return false;
|
|
730
771
|
if (!hasCmd("systemctl")) {
|
|
731
772
|
warn("systemctl not found — skipping systemd install.");
|
|
732
773
|
return false;
|
|
733
774
|
}
|
|
734
|
-
if (hasSystemDaemonUnit()) {
|
|
735
|
-
log("Native system daemon unit is installed; preserving its launcher and sole service ownership.");
|
|
736
|
-
return true;
|
|
737
|
-
}
|
|
738
|
-
|
|
739
775
|
var userHome = user === process.env.USER ? HOME : path.join("/home", user);
|
|
740
776
|
try {
|
|
741
777
|
var pwdEntry = runCapture("getent passwd " + user);
|
|
@@ -745,6 +781,12 @@ function installSystemd(nodeBin, omniusScript, user) {
|
|
|
745
781
|
}
|
|
746
782
|
} catch (e) {}
|
|
747
783
|
|
|
784
|
+
if (hasSystemDaemonUnit()) {
|
|
785
|
+
log("Native system daemon unit is installed; preserving its launcher and sole service ownership.");
|
|
786
|
+
ensureDeclaredDaemonEnvironmentFiles("systemctl", userHome, user);
|
|
787
|
+
return true;
|
|
788
|
+
}
|
|
789
|
+
|
|
748
790
|
var unitDir = path.join(userHome, ".config", "systemd", "user");
|
|
749
791
|
var unitPath = path.join(unitDir, SERVICE_LABEL + ".service");
|
|
750
792
|
var envDir = path.join(userHome, ".config", "omnius");
|
|
@@ -827,16 +869,20 @@ function installSystemd(nodeBin, omniusScript, user) {
|
|
|
827
869
|
var uid = runCapture("id -u " + user);
|
|
828
870
|
if (uid && /^\d+$/.test(uid)) {
|
|
829
871
|
// Ensure loginctl linger so user services can run without a session.
|
|
830
|
-
|
|
872
|
+
ensureLinger(user);
|
|
831
873
|
asUserPrefix = "sudo -u " + user + " XDG_RUNTIME_DIR=/run/user/" + uid + " DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/" + uid + "/bus ";
|
|
832
874
|
}
|
|
833
875
|
} else if (!IS_WIN && process.getuid && process.getuid() !== 0) {
|
|
834
876
|
// Self-install: enable-linger ourselves if we can (best-effort; needs sudo on most distros).
|
|
835
|
-
|
|
877
|
+
ensureLinger(user);
|
|
836
878
|
}
|
|
837
879
|
|
|
838
880
|
var sysctl = asUserPrefix + "systemctl --user";
|
|
839
881
|
runQuiet(sysctl + " daemon-reload");
|
|
882
|
+
ensureDeclaredDaemonEnvironmentFiles(sysctl, userHome, user);
|
|
883
|
+
// A unit that previously failed (e.g. a missing EnvironmentFile) can be
|
|
884
|
+
// rate-limited; clear that state so the restart below is actually attempted.
|
|
885
|
+
runQuiet(sysctl + " reset-failed " + SERVICE_LABEL + ".service");
|
|
840
886
|
var enabled = runQuiet(sysctl + " enable " + SERVICE_LABEL + ".service");
|
|
841
887
|
var restarted = runQuiet(sysctl + " restart " + SERVICE_LABEL + ".service");
|
|
842
888
|
|