twokey 1.0.5 → 1.0.7
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/bin/postinstall.js +53 -1
- package/bin/twokey.js +1 -1
- package/package.json +1 -1
package/bin/postinstall.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { spawn } from "node:child_process";
|
|
3
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
|
|
@@ -12,6 +12,39 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
12
12
|
const __dirname = path.dirname(__filename);
|
|
13
13
|
const cliPath = path.join(__dirname, "twokey.js");
|
|
14
14
|
|
|
15
|
+
const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
16
|
+
const sudoUser = process.env.SUDO_USER;
|
|
17
|
+
|
|
18
|
+
if (isRoot && sudoUser && sudoUser !== "root") {
|
|
19
|
+
const uid = resolveUid(sudoUser);
|
|
20
|
+
const homeDir = resolveHomeDir(sudoUser);
|
|
21
|
+
const env = { ...process.env };
|
|
22
|
+
|
|
23
|
+
if (homeDir) {
|
|
24
|
+
env.HOME = homeDir;
|
|
25
|
+
}
|
|
26
|
+
if (uid && !env.XDG_RUNTIME_DIR) {
|
|
27
|
+
env.XDG_RUNTIME_DIR = `/run/user/${uid}`;
|
|
28
|
+
}
|
|
29
|
+
if (env.XDG_RUNTIME_DIR && !env.DBUS_SESSION_BUS_ADDRESS) {
|
|
30
|
+
env.DBUS_SESSION_BUS_ADDRESS = `unix:path=${env.XDG_RUNTIME_DIR}/bus`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const delegated = spawn(
|
|
34
|
+
"sudo",
|
|
35
|
+
["-u", sudoUser, "-H", process.execPath, cliPath, "--desktop", "--enable-autostart", "--quiet"],
|
|
36
|
+
{
|
|
37
|
+
stdio: "ignore",
|
|
38
|
+
shell: false,
|
|
39
|
+
env,
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
delegated.on("error", () => process.exit(0));
|
|
44
|
+
delegated.on("close", () => process.exit(0));
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
|
|
15
48
|
const child = spawn(process.execPath, [cliPath, "--desktop", "--enable-autostart", "--quiet"], {
|
|
16
49
|
stdio: "ignore",
|
|
17
50
|
shell: false,
|
|
@@ -19,3 +52,22 @@ const child = spawn(process.execPath, [cliPath, "--desktop", "--enable-autostart
|
|
|
19
52
|
|
|
20
53
|
child.on("error", () => process.exit(0));
|
|
21
54
|
child.on("close", () => process.exit(0));
|
|
55
|
+
|
|
56
|
+
function resolveUid(username) {
|
|
57
|
+
const out = spawnSync("id", ["-u", username], { encoding: "utf8" });
|
|
58
|
+
if (out.status !== 0) {
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
return String(out.stdout || "").trim();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function resolveHomeDir(username) {
|
|
65
|
+
const out = spawnSync("getent", ["passwd", username], { encoding: "utf8" });
|
|
66
|
+
if (out.status !== 0) {
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const entry = String(out.stdout || "").trim();
|
|
71
|
+
const parts = entry.split(":");
|
|
72
|
+
return parts[5] || "";
|
|
73
|
+
}
|
package/bin/twokey.js
CHANGED
|
@@ -6,7 +6,7 @@ import os from "node:os";
|
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import readline from "node:readline";
|
|
8
8
|
|
|
9
|
-
const VERSION = process.env.npm_package_version || "1.0.
|
|
9
|
+
const VERSION = process.env.npm_package_version || "1.0.7";
|
|
10
10
|
const DEFAULT_MODEL = process.env.TWOKEY_OLLAMA_MODEL || "qwen2.5:3b";
|
|
11
11
|
const DEFAULT_OLLAMA_URL = process.env.TWOKEY_OLLAMA_URL || "http://127.0.0.1:11434";
|
|
12
12
|
const LATEST_RELEASE_API = "https://api.github.com/repos/meinzeug/twokey/releases/latest";
|