@lifeaitools/clauth 1.30.3 ā 1.30.4
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/cli/commands/agent-pool.js +22 -6
- package/cli/commands/serve.js +1070 -144
- package/cli/enrollment-script.js +62 -0
- package/cli/index.js +4 -43
- package/package.json +1 -1
- package/scripts/bin/bootstrap-linux +0 -0
- package/scripts/bin/bootstrap-macos +0 -0
- package/scripts/bin/bootstrap-win.exe +0 -0
- package/cli/commands/serve/tools/fs.js +0 -1055
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
function shellSingleQuote(value) {
|
|
6
|
+
return `'${String(value ?? "").replace(/'/g, "''")}'`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function posixShellQuote(value) {
|
|
10
|
+
return `'${String(value ?? "").replace(/'/g, "'\\\"'\\\"'")}'`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function enrollmentScriptName(label, target = "windows") {
|
|
14
|
+
const slug = String(label || "new-computer")
|
|
15
|
+
.toLowerCase()
|
|
16
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
17
|
+
.replace(/^-+|-+$/g, "")
|
|
18
|
+
.slice(0, 40) || "new-computer";
|
|
19
|
+
return `clauth-enroll-${slug}${target === "linux" ? ".sh" : ".ps1"}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function windowsScript({ supabaseUrl, anonKey, enrollmentCode }) {
|
|
23
|
+
return [
|
|
24
|
+
"$ErrorActionPreference = 'Stop'",
|
|
25
|
+
"$label = $env:COMPUTERNAME",
|
|
26
|
+
"if (-not $label) { $label = [System.Net.Dns]::GetHostName() }",
|
|
27
|
+
"npm install -g @lifeaitools/clauth@latest",
|
|
28
|
+
["clauth setup", `--supabase-url ${shellSingleQuote(supabaseUrl)}`, `--anon-key ${shellSingleQuote(anonKey)}`, `--enrollment-code ${shellSingleQuote(enrollmentCode)}`, "--label \"$label\""].join(" "),
|
|
29
|
+
"clauth serve install",
|
|
30
|
+
"$self = $PSCommandPath",
|
|
31
|
+
"Start-Process powershell.exe -WindowStyle Hidden -ArgumentList @('-NoProfile','-Command',\"Start-Sleep -Seconds 2; & ('Remove' + '-Item') -LiteralPath '$self' -Force -ErrorAction SilentlyContinue\")",
|
|
32
|
+
].join("\r\n");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function linuxScript({ supabaseUrl, anonKey, enrollmentCode }) {
|
|
36
|
+
return [
|
|
37
|
+
"#!/usr/bin/env sh",
|
|
38
|
+
"set -eu",
|
|
39
|
+
"label=$(hostname)",
|
|
40
|
+
"command -v node >/dev/null || { echo 'Node.js 18+ is required.' >&2; exit 1; }",
|
|
41
|
+
"command -v npm >/dev/null || { echo 'npm is required.' >&2; exit 1; }",
|
|
42
|
+
"npm install -g @lifeaitools/clauth@latest",
|
|
43
|
+
["clauth setup", `--supabase-url ${posixShellQuote(supabaseUrl)}`, `--anon-key ${posixShellQuote(anonKey)}`, `--enrollment-code ${posixShellQuote(enrollmentCode)}`, '--label "$label"'].join(" "),
|
|
44
|
+
"clauth serve install",
|
|
45
|
+
"echo 'For reboot persistence on a headless host, run: loginctl enable-linger \"$USER\"'",
|
|
46
|
+
"rm -f -- \"$0\"",
|
|
47
|
+
].join("\n");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function writeEnrollmentScript({ supabaseUrl, anonKey, enrollmentCode, label, target = "windows", appDir } = {}) {
|
|
51
|
+
if (!["windows", "linux"].includes(target)) throw new Error(`Unsupported enrollment target: ${target}`);
|
|
52
|
+
const outputDir = appDir || (process.platform === "win32"
|
|
53
|
+
? path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), "clauth")
|
|
54
|
+
: path.join(os.homedir(), ".config", "clauth"));
|
|
55
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
56
|
+
const scriptPath = path.join(outputDir, enrollmentScriptName(label, target));
|
|
57
|
+
const script = target === "linux"
|
|
58
|
+
? linuxScript({ supabaseUrl, anonKey, enrollmentCode })
|
|
59
|
+
: windowsScript({ supabaseUrl, anonKey, enrollmentCode });
|
|
60
|
+
fs.writeFileSync(scriptPath, `${script}\n`, { encoding: "utf8", mode: target === "linux" ? 0o700 : undefined });
|
|
61
|
+
return scriptPath;
|
|
62
|
+
}
|
package/cli/index.js
CHANGED
|
@@ -13,53 +13,11 @@ import { writeCredentialWithRecovery } from "./recovery.js";
|
|
|
13
13
|
import os from "os";
|
|
14
14
|
import fs from "fs";
|
|
15
15
|
import path from "path";
|
|
16
|
+
import { writeEnrollmentScript } from "./enrollment-script.js";
|
|
16
17
|
|
|
17
18
|
const config = new Conf(getConfOptions());
|
|
18
19
|
const VERSION = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
19
20
|
|
|
20
|
-
function shellSingleQuote(value) {
|
|
21
|
-
return `'${String(value ?? "").replace(/'/g, "''")}'`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function enrollmentScriptName(label) {
|
|
25
|
-
const slug = String(label || "new-computer")
|
|
26
|
-
.toLowerCase()
|
|
27
|
-
.replace(/[^a-z0-9]+/g, "-")
|
|
28
|
-
.replace(/^-+|-+$/g, "")
|
|
29
|
-
.slice(0, 40) || "new-computer";
|
|
30
|
-
return `clauth-enroll-${slug}.ps1`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function writeEnrollmentScript({ supabaseUrl, anonKey, enrollmentCode, label }) {
|
|
34
|
-
const appDir = process.platform === "win32"
|
|
35
|
-
? path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), "clauth")
|
|
36
|
-
: path.join(os.homedir(), ".config", "clauth");
|
|
37
|
-
fs.mkdirSync(appDir, { recursive: true });
|
|
38
|
-
const scriptPath = path.join(appDir, enrollmentScriptName(label));
|
|
39
|
-
const script = [
|
|
40
|
-
"$ErrorActionPreference = 'Stop'",
|
|
41
|
-
"$label = $env:COMPUTERNAME",
|
|
42
|
-
"if (-not $label) { $label = [System.Net.Dns]::GetHostName() }",
|
|
43
|
-
"Write-Host 'Installing clauth...'",
|
|
44
|
-
"npm install -g @lifeaitools/clauth@latest",
|
|
45
|
-
"Write-Host 'Enrolling this computer with clauth...'",
|
|
46
|
-
[
|
|
47
|
-
"clauth setup",
|
|
48
|
-
`--supabase-url ${shellSingleQuote(supabaseUrl)}`,
|
|
49
|
-
`--anon-key ${shellSingleQuote(anonKey)}`,
|
|
50
|
-
`--enrollment-code ${shellSingleQuote(enrollmentCode)}`,
|
|
51
|
-
"--label \"$label\"",
|
|
52
|
-
].join(" "),
|
|
53
|
-
"Write-Host 'Installing clauth startup service...'",
|
|
54
|
-
"clauth serve install",
|
|
55
|
-
"Write-Host 'clauth enrollment complete.'",
|
|
56
|
-
"$self = $PSCommandPath",
|
|
57
|
-
"Start-Process powershell.exe -WindowStyle Hidden -ArgumentList @('-NoProfile','-Command',\"Start-Sleep -Seconds 2; Remove-Item -LiteralPath '$self' -Force -ErrorAction SilentlyContinue\")",
|
|
58
|
-
].join("\r\n");
|
|
59
|
-
fs.writeFileSync(scriptPath, `${script}\r\n`, "utf8");
|
|
60
|
-
return scriptPath;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
21
|
// ============================================================
|
|
64
22
|
// Password prompt helper
|
|
65
23
|
// ============================================================
|
|
@@ -391,6 +349,7 @@ program
|
|
|
391
349
|
.option("--label <label>", "Suggested label for the new computer")
|
|
392
350
|
.option("--ttl-minutes <minutes>", "Enrollment lifetime, 5 to 1440 minutes", "60")
|
|
393
351
|
.option("--install-id <id>", "Override install id; default is current machine's install id")
|
|
352
|
+
.option("--target <target>", "Enrollment target: windows or linux", "windows")
|
|
394
353
|
.option("-p, --pw <password>", "Password (or will prompt)")
|
|
395
354
|
.action(async (opts) => {
|
|
396
355
|
console.log(chalk.cyan("\nš clauth enroll\n"));
|
|
@@ -414,6 +373,7 @@ program
|
|
|
414
373
|
anonKey,
|
|
415
374
|
enrollmentCode: result.enrollment_code,
|
|
416
375
|
label: opts.label,
|
|
376
|
+
target: opts.target,
|
|
417
377
|
});
|
|
418
378
|
spinner.succeed(chalk.green(`Enrollment created for install_id=${result.install_id}`));
|
|
419
379
|
console.log("");
|
|
@@ -1048,6 +1008,7 @@ program
|
|
|
1048
1008
|
.option("--staged", "Start on staging port (52438) for blue-green verification before make-live")
|
|
1049
1009
|
.option("--isolated", "Run on a non-live port without touching live PID files, browser, or boot-key credentials")
|
|
1050
1010
|
.option("--from-boot-key", "Internal: password came from boot.key auto-unlock (degrade gracefully on verify failure)")
|
|
1011
|
+
.option("--pw-env", "Internal: read the daemon password from CLAUTH_BOOT_PASSWORD")
|
|
1051
1012
|
.option("--action <action>", "Internal: action override for daemon child")
|
|
1052
1013
|
.addHelpText("after", `
|
|
1053
1014
|
Actions:
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|