@leclabs/fleet 0.0.0-stage → 0.0.0
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 +21 -0
- package/README.md +266 -2
- package/assets/dotfiles/atuin/config.toml +14 -0
- package/assets/dotfiles/ghostty/config.ghostty +13 -0
- package/assets/dotfiles/ghostty/themes/LexDark +31 -0
- package/assets/dotfiles/ghostty/themes/LexLight +29 -0
- package/assets/dotfiles/git/config +13 -0
- package/assets/dotfiles/starship.toml +82 -0
- package/assets/dotfiles/zshrc.zsh +35 -0
- package/assets/layers/base.toml +96 -0
- package/assets/layers/docker.toml +47 -0
- package/assets/layers/linux.toml +95 -0
- package/assets/layers/macos-x64.toml +36 -0
- package/assets/layers/macos.toml +163 -0
- package/assets/layers/nvidia.toml +49 -0
- package/dist/fleet.js +1343 -0
- package/install.sh +69 -0
- package/package.json +50 -3
package/dist/fleet.js
ADDED
|
@@ -0,0 +1,1343 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/context.ts
|
|
4
|
+
import {
|
|
5
|
+
constants,
|
|
6
|
+
accessSync,
|
|
7
|
+
readFileSync as readFileSync3,
|
|
8
|
+
readdirSync as readdirSync2,
|
|
9
|
+
realpathSync
|
|
10
|
+
} from "fs";
|
|
11
|
+
import { delimiter as delimiter2, join as join4 } from "path";
|
|
12
|
+
import { createInterface } from "readline/promises";
|
|
13
|
+
|
|
14
|
+
// src/exec.ts
|
|
15
|
+
import { spawn } from "child_process";
|
|
16
|
+
var nodeExec = (command, args, options = {}) => new Promise((resolve2) => {
|
|
17
|
+
const child = spawn(command, args, {
|
|
18
|
+
env: options.env ?? process.env,
|
|
19
|
+
cwd: options.cwd,
|
|
20
|
+
stdio: options.inherit ? "inherit" : ["ignore", "pipe", "pipe"]
|
|
21
|
+
});
|
|
22
|
+
let stdout = "";
|
|
23
|
+
let stderr = "";
|
|
24
|
+
child.stdout?.on("data", (chunk) => {
|
|
25
|
+
stdout += chunk;
|
|
26
|
+
});
|
|
27
|
+
child.stderr?.on("data", (chunk) => {
|
|
28
|
+
stderr += chunk;
|
|
29
|
+
});
|
|
30
|
+
child.on(
|
|
31
|
+
"error",
|
|
32
|
+
(error) => resolve2({ code: 127, stdout, stderr: `${stderr}${error.message}
|
|
33
|
+
` })
|
|
34
|
+
);
|
|
35
|
+
child.on("close", (code2) => resolve2({ code: code2 ?? 1, stdout, stderr }));
|
|
36
|
+
});
|
|
37
|
+
var FleetError = class extends Error {
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/mise.ts
|
|
41
|
+
import { existsSync as existsSync2 } from "fs";
|
|
42
|
+
import { delimiter, join as join3 } from "path";
|
|
43
|
+
|
|
44
|
+
// src/baseline.ts
|
|
45
|
+
import {
|
|
46
|
+
chownSync,
|
|
47
|
+
existsSync,
|
|
48
|
+
mkdirSync as mkdirSync2,
|
|
49
|
+
mkdtempSync,
|
|
50
|
+
readFileSync as readFileSync2,
|
|
51
|
+
readdirSync,
|
|
52
|
+
rmSync,
|
|
53
|
+
statSync,
|
|
54
|
+
symlinkSync,
|
|
55
|
+
writeFileSync as writeFileSync2
|
|
56
|
+
} from "fs";
|
|
57
|
+
import { tmpdir } from "os";
|
|
58
|
+
import { dirname as dirname2, join as join2, relative } from "path";
|
|
59
|
+
import { fileURLToPath } from "url";
|
|
60
|
+
import { stringify as stringify2 } from "smol-toml";
|
|
61
|
+
|
|
62
|
+
// src/host.ts
|
|
63
|
+
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
64
|
+
import { dirname, join } from "path";
|
|
65
|
+
import { parse, stringify } from "smol-toml";
|
|
66
|
+
import { z } from "zod";
|
|
67
|
+
var OPT_IN_LAYERS = ["nvidia", "docker"];
|
|
68
|
+
function isPromptEmoji(value) {
|
|
69
|
+
return [...value].length === 1 && new RegExp("^\\p{Emoji_Presentation}$", "u").test(value);
|
|
70
|
+
}
|
|
71
|
+
function isWallpaper(value) {
|
|
72
|
+
if (/^https?:\/\//i.test(value)) return URL.canParse(value);
|
|
73
|
+
return value.startsWith("/") || value.startsWith("~/");
|
|
74
|
+
}
|
|
75
|
+
var HostSchema = z.object({
|
|
76
|
+
icon: z.string().refine(isPromptEmoji, {
|
|
77
|
+
message: "must be one emoji that needs no variation selector (U+FE0F), such as \u{1F525}"
|
|
78
|
+
}).optional(),
|
|
79
|
+
wallpaper: z.string().refine(isWallpaper, {
|
|
80
|
+
message: "must be an http(s) URL or a path, absolute or under ~/"
|
|
81
|
+
}).optional(),
|
|
82
|
+
layers: z.array(z.enum(OPT_IN_LAYERS)).optional()
|
|
83
|
+
}).strict();
|
|
84
|
+
var HOST_KEYS = ["icon", "wallpaper", "layers"];
|
|
85
|
+
function hostPath(home) {
|
|
86
|
+
return join(home, ".config", "fleet", "host.toml");
|
|
87
|
+
}
|
|
88
|
+
function validateHost(value, source = "host.toml") {
|
|
89
|
+
const result = HostSchema.safeParse(value);
|
|
90
|
+
if (result.success) return result.data;
|
|
91
|
+
const lines = result.error.issues.map((issue) => {
|
|
92
|
+
const key = issue.path.join(".");
|
|
93
|
+
return `${source}${key ? `: ${key}` : ""}: ${issue.message}`;
|
|
94
|
+
});
|
|
95
|
+
throw new FleetError(lines.join("\n"));
|
|
96
|
+
}
|
|
97
|
+
function parseHost(text, source = "host.toml") {
|
|
98
|
+
let data;
|
|
99
|
+
try {
|
|
100
|
+
data = parse(text);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
throw new FleetError(
|
|
103
|
+
`${source}: ${error instanceof Error ? error.message : error}`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
return validateHost(data, source);
|
|
107
|
+
}
|
|
108
|
+
function stringifyHost(host) {
|
|
109
|
+
const ordered = {};
|
|
110
|
+
for (const key of HOST_KEYS) {
|
|
111
|
+
if (host[key] !== void 0) ordered[key] = host[key];
|
|
112
|
+
}
|
|
113
|
+
return stringify(ordered);
|
|
114
|
+
}
|
|
115
|
+
function loadHost(home) {
|
|
116
|
+
const path = hostPath(home);
|
|
117
|
+
let text;
|
|
118
|
+
try {
|
|
119
|
+
text = readFileSync(path, "utf8");
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (error.code === "ENOENT") return {};
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
return parseHost(text, path);
|
|
125
|
+
}
|
|
126
|
+
function saveHost(home, host) {
|
|
127
|
+
const path = hostPath(home);
|
|
128
|
+
const valid = validateHost(host);
|
|
129
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
130
|
+
writeFileSync(path, stringifyHost(valid));
|
|
131
|
+
return path;
|
|
132
|
+
}
|
|
133
|
+
function assertKey(key) {
|
|
134
|
+
if (HOST_KEYS.includes(key)) return key;
|
|
135
|
+
throw new FleetError(
|
|
136
|
+
`unknown key "${key}"; the keys are ${HOST_KEYS.join(", ")}`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
function readKey(host, key) {
|
|
140
|
+
const value = host[key];
|
|
141
|
+
return Array.isArray(value) ? value.join(",") : value;
|
|
142
|
+
}
|
|
143
|
+
function writeKey(host, key, text) {
|
|
144
|
+
const next = { ...host };
|
|
145
|
+
if (text === void 0) {
|
|
146
|
+
delete next[key];
|
|
147
|
+
} else if (key === "layers") {
|
|
148
|
+
next.layers = text.split(",").map((item) => item.trim()).filter(Boolean);
|
|
149
|
+
} else {
|
|
150
|
+
next[key] = text;
|
|
151
|
+
}
|
|
152
|
+
return validateHost(next);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/layers.ts
|
|
156
|
+
var OPT_IN_SUPPORT = {
|
|
157
|
+
nvidia: { os: "linux", arch: "x64" },
|
|
158
|
+
docker: { os: "linux" }
|
|
159
|
+
};
|
|
160
|
+
function selectLayers(machine, host) {
|
|
161
|
+
const layers = ["base", machine.os];
|
|
162
|
+
if (machine.os === "macos" && machine.arch === "x64")
|
|
163
|
+
layers.push("macos-x64");
|
|
164
|
+
const chosen = new Set(host.layers ?? []);
|
|
165
|
+
for (const name of OPT_IN_LAYERS) {
|
|
166
|
+
if (!chosen.has(name)) continue;
|
|
167
|
+
const support = OPT_IN_SUPPORT[name];
|
|
168
|
+
if (support.os !== machine.os || support.arch && support.arch !== machine.arch) {
|
|
169
|
+
const where = support.arch ? `${support.os} ${support.arch}` : support.os;
|
|
170
|
+
throw new FleetError(
|
|
171
|
+
`layer "${name}" is for ${where} hosts only, and this host is ${machine.os} ${machine.arch}`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
layers.push(name);
|
|
175
|
+
}
|
|
176
|
+
return layers;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/baseline.ts
|
|
180
|
+
var DEFAULT_ICON = "\u{1F4BB}";
|
|
181
|
+
var FRAGMENT_PREFIX = "fleet-";
|
|
182
|
+
function defaultAssetsDir() {
|
|
183
|
+
return fileURLToPath(new URL("../assets/", import.meta.url));
|
|
184
|
+
}
|
|
185
|
+
function miseConfigDir(home) {
|
|
186
|
+
return join2(home, ".config", "mise");
|
|
187
|
+
}
|
|
188
|
+
function walk(dir, root = dir) {
|
|
189
|
+
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
190
|
+
const path = join2(dir, entry.name);
|
|
191
|
+
return entry.isDirectory() ? walk(path, root) : [relative(root, path)];
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
var GENERATED_HEADER = "# Generated by fleet from ~/.config/fleet/host.toml. fleet rewrites this file\n# on every run; the host's own choices go in host.toml.\n";
|
|
195
|
+
function hostFragment(layers, platform) {
|
|
196
|
+
const { user, group } = platform.account;
|
|
197
|
+
if (!layers.includes("docker")) return GENERATED_HEADER;
|
|
198
|
+
if (!/^[A-Za-z_][A-Za-z0-9_-]{0,31}$/.test(user) || !/^[A-Za-z_][A-Za-z0-9_.-]{0,31}$/.test(group)) {
|
|
199
|
+
throw new FleetError(
|
|
200
|
+
`cannot declare account ${user}:${group} for the docker group`
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
return `${GENERATED_HEADER}
|
|
204
|
+
${stringify2({
|
|
205
|
+
bootstrap: { users: { [user]: { group, groups: ["docker"] } } }
|
|
206
|
+
})}`;
|
|
207
|
+
}
|
|
208
|
+
function buildFragments(platform, host, assetsDir = defaultAssetsDir()) {
|
|
209
|
+
const layers = selectLayers(platform, host);
|
|
210
|
+
const fragments = /* @__PURE__ */ new Map();
|
|
211
|
+
for (const layer of layers) {
|
|
212
|
+
const files = /* @__PURE__ */ new Map();
|
|
213
|
+
files.set(
|
|
214
|
+
"mise.toml",
|
|
215
|
+
readFileSync2(join2(assetsDir, "layers", `${layer}.toml`))
|
|
216
|
+
);
|
|
217
|
+
if (layer === "base") {
|
|
218
|
+
const dotfiles = join2(assetsDir, "dotfiles");
|
|
219
|
+
for (const path of walk(dotfiles)) {
|
|
220
|
+
const content = readFileSync2(join2(dotfiles, path));
|
|
221
|
+
files.set(
|
|
222
|
+
join2("dotfiles", path),
|
|
223
|
+
path === "starship.toml" ? content.toString("utf8").replaceAll("@ICON@", host.icon ?? DEFAULT_ICON) : content
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
fragments.set(`${FRAGMENT_PREFIX}${layer}`, files);
|
|
228
|
+
}
|
|
229
|
+
fragments.set(
|
|
230
|
+
`${FRAGMENT_PREFIX}host`,
|
|
231
|
+
/* @__PURE__ */ new Map([["mise.toml", hostFragment(layers, platform)]])
|
|
232
|
+
);
|
|
233
|
+
return fragments;
|
|
234
|
+
}
|
|
235
|
+
function mkdirOwned(dir, platform) {
|
|
236
|
+
const missing = [];
|
|
237
|
+
for (let path = dir; !existsSync(path); path = dirname2(path))
|
|
238
|
+
missing.unshift(path);
|
|
239
|
+
for (const path of missing) {
|
|
240
|
+
mkdirSync2(path);
|
|
241
|
+
if (platform.euid === 0)
|
|
242
|
+
chownSync(path, platform.account.uid, platform.account.gid);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function syncFragment(dir, files, platform, rendered, confD) {
|
|
246
|
+
mkdirOwned(dir, platform);
|
|
247
|
+
const wanted = new Set(files.keys());
|
|
248
|
+
for (const path of walk(dir)) {
|
|
249
|
+
if (!wanted.has(path)) {
|
|
250
|
+
rmSync(join2(dir, path));
|
|
251
|
+
rendered.removed.push(relative(confD, join2(dir, path)));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
for (const [path, content] of files) {
|
|
255
|
+
const target = join2(dir, path);
|
|
256
|
+
const bytes = typeof content === "string" ? Buffer.from(content) : content;
|
|
257
|
+
if (existsSync(target) && readFileSync2(target).equals(bytes)) continue;
|
|
258
|
+
mkdirOwned(dirname2(target), platform);
|
|
259
|
+
writeFileSync2(target, bytes);
|
|
260
|
+
if (platform.euid === 0)
|
|
261
|
+
chownSync(target, platform.account.uid, platform.account.gid);
|
|
262
|
+
rendered.written.push(relative(confD, target));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function renderBaseline(platform, host, assetsDir = defaultAssetsDir(), confD = join2(miseConfigDir(platform.account.home), "conf.d")) {
|
|
266
|
+
const fragments = buildFragments(platform, host, assetsDir);
|
|
267
|
+
mkdirOwned(confD, platform);
|
|
268
|
+
const rendered = {
|
|
269
|
+
layers: selectLayers(platform, host),
|
|
270
|
+
written: [],
|
|
271
|
+
removed: []
|
|
272
|
+
};
|
|
273
|
+
for (const entry of readdirSync(confD, { withFileTypes: true })) {
|
|
274
|
+
if (entry.name.startsWith(FRAGMENT_PREFIX) && !fragments.has(entry.name)) {
|
|
275
|
+
const path = join2(confD, entry.name);
|
|
276
|
+
if (statSync(path).isDirectory()) {
|
|
277
|
+
rmSync(path, { recursive: true });
|
|
278
|
+
rendered.removed.push(entry.name);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
for (const [name, files] of fragments) {
|
|
283
|
+
syncFragment(join2(confD, name), files, platform, rendered, confD);
|
|
284
|
+
}
|
|
285
|
+
return rendered;
|
|
286
|
+
}
|
|
287
|
+
function renderPreview(platform, host, assetsDir = defaultAssetsDir()) {
|
|
288
|
+
const real2 = miseConfigDir(platform.account.home);
|
|
289
|
+
const configDir = mkdtempSync(join2(tmpdir(), "fleet-preview-"));
|
|
290
|
+
const link = (from, to) => symlinkSync(from, to);
|
|
291
|
+
if (existsSync(real2)) {
|
|
292
|
+
for (const entry of readdirSync(real2)) {
|
|
293
|
+
if (entry !== "conf.d") link(join2(real2, entry), join2(configDir, entry));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const confD = join2(configDir, "conf.d");
|
|
297
|
+
mkdirSync2(confD);
|
|
298
|
+
const realConfD = join2(real2, "conf.d");
|
|
299
|
+
if (existsSync(realConfD)) {
|
|
300
|
+
for (const entry of readdirSync(realConfD)) {
|
|
301
|
+
if (!entry.startsWith(FRAGMENT_PREFIX)) {
|
|
302
|
+
link(join2(realConfD, entry), join2(confD, entry));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const rendered = renderBaseline(platform, host, assetsDir, confD);
|
|
307
|
+
return {
|
|
308
|
+
configDir,
|
|
309
|
+
rendered,
|
|
310
|
+
cleanup: () => rmSync(configDir, { recursive: true, force: true })
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// src/mise.ts
|
|
315
|
+
var USER_PARTS = [
|
|
316
|
+
"plugins",
|
|
317
|
+
"repos",
|
|
318
|
+
"dotfiles",
|
|
319
|
+
"mise-shell-activate",
|
|
320
|
+
"macos-defaults",
|
|
321
|
+
"macos-launchd-agents",
|
|
322
|
+
"linux-systemd-units",
|
|
323
|
+
"tools",
|
|
324
|
+
"settings",
|
|
325
|
+
"task"
|
|
326
|
+
];
|
|
327
|
+
var MACHINE_PARTS = [
|
|
328
|
+
"accounts",
|
|
329
|
+
"files",
|
|
330
|
+
"packages",
|
|
331
|
+
"services",
|
|
332
|
+
"firewall",
|
|
333
|
+
"macos-launchd-daemons",
|
|
334
|
+
"user",
|
|
335
|
+
"final-hook"
|
|
336
|
+
];
|
|
337
|
+
var MACHINE_MANAGERS = {
|
|
338
|
+
linux: ["apt", "snap"],
|
|
339
|
+
macos: ["brew", "brew-cask"]
|
|
340
|
+
};
|
|
341
|
+
function bootstrapArgs(scope, options = {}) {
|
|
342
|
+
const parts = scope === "user" ? USER_PARTS : MACHINE_PARTS;
|
|
343
|
+
const args = ["bootstrap", "--yes", "--only", parts.join(",")];
|
|
344
|
+
if (scope === "user") args.push("--force-dotfiles");
|
|
345
|
+
if (options.upgrade) args.push("--upgrade");
|
|
346
|
+
if (options.dryRun) args.push("--dry-run");
|
|
347
|
+
return args;
|
|
348
|
+
}
|
|
349
|
+
function miseEnv(scope, platform, base, configDir = miseConfigDir(platform.account.home)) {
|
|
350
|
+
const { home } = platform.account;
|
|
351
|
+
const homebrew = platform.os === "macos" ? ["/opt/homebrew/bin", "/opt/homebrew/sbin"] : [];
|
|
352
|
+
const env = {
|
|
353
|
+
...base,
|
|
354
|
+
MISE_CONFIG_DIR: configDir,
|
|
355
|
+
PATH: [join3(home, ".local", "bin"), ...homebrew, base.PATH].filter(Boolean).join(delimiter)
|
|
356
|
+
};
|
|
357
|
+
if (scope === "user") {
|
|
358
|
+
env.MISE_SYSTEM_PACKAGES_SUDO = "false";
|
|
359
|
+
} else {
|
|
360
|
+
env.MISE_SYSTEM_PACKAGES_MANAGERS = MACHINE_MANAGERS[platform.os].join(",");
|
|
361
|
+
}
|
|
362
|
+
return env;
|
|
363
|
+
}
|
|
364
|
+
function locateMise(env, home, exists2 = existsSync2) {
|
|
365
|
+
const candidates = [
|
|
366
|
+
...(env.PATH ?? "").split(delimiter).filter(Boolean).map((dir) => join3(dir, "mise")),
|
|
367
|
+
join3(home, ".local", "bin", "mise"),
|
|
368
|
+
"/opt/homebrew/bin/mise",
|
|
369
|
+
"/usr/local/bin/mise",
|
|
370
|
+
"/usr/bin/mise"
|
|
371
|
+
];
|
|
372
|
+
const found = candidates.find((path) => exists2(path));
|
|
373
|
+
if (!found) {
|
|
374
|
+
throw new FleetError(
|
|
375
|
+
"mise is not installed; install it with `curl https://mise.run | sh`"
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
return found;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// src/platform.ts
|
|
382
|
+
import { userInfo } from "os";
|
|
383
|
+
function detectOsArch(platform = process.platform, arch = process.arch) {
|
|
384
|
+
const os = platform === "darwin" ? "macos" : platform === "linux" ? "linux" : void 0;
|
|
385
|
+
if (!os) throw new FleetError(`unsupported operating system: ${platform}`);
|
|
386
|
+
if (arch !== "x64" && arch !== "arm64") {
|
|
387
|
+
throw new FleetError(`unsupported architecture: ${arch}`);
|
|
388
|
+
}
|
|
389
|
+
return { os, arch };
|
|
390
|
+
}
|
|
391
|
+
async function run(exec, command, args) {
|
|
392
|
+
const result = await exec(command, args);
|
|
393
|
+
if (result.code !== 0) {
|
|
394
|
+
throw new FleetError(
|
|
395
|
+
`${command} ${args.join(" ")} failed: ${result.stderr.trim()}`
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
return result.stdout.trim();
|
|
399
|
+
}
|
|
400
|
+
async function lookupAccount(user, os, exec) {
|
|
401
|
+
let home;
|
|
402
|
+
if (os === "linux") {
|
|
403
|
+
home = (await run(exec, "getent", ["passwd", user])).split(":")[5] ?? "";
|
|
404
|
+
} else {
|
|
405
|
+
const line = await run(exec, "dscl", [
|
|
406
|
+
".",
|
|
407
|
+
"-read",
|
|
408
|
+
`/Users/${user}`,
|
|
409
|
+
"NFSHomeDirectory"
|
|
410
|
+
]);
|
|
411
|
+
home = line.replace(/^NFSHomeDirectory:\s*/, "");
|
|
412
|
+
}
|
|
413
|
+
if (!home) throw new FleetError(`no home directory for ${user}`);
|
|
414
|
+
return {
|
|
415
|
+
user,
|
|
416
|
+
home,
|
|
417
|
+
group: await run(exec, "id", ["-gn", user]),
|
|
418
|
+
uid: Number(await run(exec, "id", ["-u", user])),
|
|
419
|
+
gid: Number(await run(exec, "id", ["-g", user]))
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
async function resolvePlatform(env, exec) {
|
|
423
|
+
const { os, arch } = detectOsArch();
|
|
424
|
+
const euid = process.geteuid?.() ?? 0;
|
|
425
|
+
const sudoUser = env.SUDO_USER;
|
|
426
|
+
if (euid === 0 && sudoUser && sudoUser !== "root") {
|
|
427
|
+
return { os, arch, euid, account: await lookupAccount(sudoUser, os, exec) };
|
|
428
|
+
}
|
|
429
|
+
const info = userInfo();
|
|
430
|
+
return {
|
|
431
|
+
os,
|
|
432
|
+
arch,
|
|
433
|
+
euid,
|
|
434
|
+
account: {
|
|
435
|
+
user: info.username,
|
|
436
|
+
group: await run(exec, "id", ["-gn"]),
|
|
437
|
+
home: env.HOME || info.homedir,
|
|
438
|
+
uid: info.uid,
|
|
439
|
+
gid: info.gid
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// src/context.ts
|
|
445
|
+
function pciHasNvidia(root = "/sys/bus/pci/devices") {
|
|
446
|
+
try {
|
|
447
|
+
return readdirSync2(root).some((device) => {
|
|
448
|
+
const read = (name) => readFileSync3(`${root}/${device}/${name}`, "utf8").trim();
|
|
449
|
+
return read("vendor") === "0x10de" && read("class").startsWith("0x03");
|
|
450
|
+
});
|
|
451
|
+
} catch {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function onPath(command, env) {
|
|
456
|
+
return (env.PATH ?? "").split(delimiter2).some((dir) => {
|
|
457
|
+
try {
|
|
458
|
+
accessSync(join4(dir, command), constants.X_OK);
|
|
459
|
+
return true;
|
|
460
|
+
} catch {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
function terminalPrompter() {
|
|
466
|
+
return {
|
|
467
|
+
async ask(question) {
|
|
468
|
+
const rl = createInterface({
|
|
469
|
+
input: process.stdin,
|
|
470
|
+
output: process.stdout
|
|
471
|
+
});
|
|
472
|
+
try {
|
|
473
|
+
return (await rl.question(question)).trim();
|
|
474
|
+
} finally {
|
|
475
|
+
rl.close();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
async function systemContext() {
|
|
481
|
+
const env = process.env;
|
|
482
|
+
const platform = await resolvePlatform(env, nodeExec);
|
|
483
|
+
return {
|
|
484
|
+
platform,
|
|
485
|
+
env,
|
|
486
|
+
exec: nodeExec,
|
|
487
|
+
fetch,
|
|
488
|
+
log: (message) => console.log(message),
|
|
489
|
+
warn: (message) => console.error(message),
|
|
490
|
+
prompter: process.stdin.isTTY ? terminalPrompter() : void 0,
|
|
491
|
+
detectNvidia: () => pciHasNvidia(),
|
|
492
|
+
hasCommand: (command) => onPath(command, miseEnv("user", platform, env)),
|
|
493
|
+
self: {
|
|
494
|
+
node: process.execPath,
|
|
495
|
+
script: realpathSync(process.argv[1] ?? "")
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// src/program.ts
|
|
501
|
+
import { Command } from "commander";
|
|
502
|
+
|
|
503
|
+
// src/takeover.ts
|
|
504
|
+
import { cpSync, lstatSync, mkdirSync as mkdirSync3, readlinkSync } from "fs";
|
|
505
|
+
import { dirname as dirname3, join as join5, relative as relative2, resolve } from "path";
|
|
506
|
+
import { parse as parse2 } from "smol-toml";
|
|
507
|
+
function isOwnedLink(entry) {
|
|
508
|
+
if (typeof entry !== "object" || entry === null) return false;
|
|
509
|
+
const e = entry;
|
|
510
|
+
return typeof e.source === "string" && e.mode === "symlink";
|
|
511
|
+
}
|
|
512
|
+
function ownedPaths(platform, host, assetsDir) {
|
|
513
|
+
const { home } = platform.account;
|
|
514
|
+
const confD = join5(miseConfigDir(home), "conf.d");
|
|
515
|
+
const owned = [];
|
|
516
|
+
for (const [name, files] of buildFragments(platform, host, assetsDir)) {
|
|
517
|
+
if (!name.startsWith(FRAGMENT_PREFIX)) continue;
|
|
518
|
+
const config = files.get("mise.toml");
|
|
519
|
+
if (config === void 0) continue;
|
|
520
|
+
const dotfiles = parse2(config.toString()).dotfiles;
|
|
521
|
+
if (typeof dotfiles !== "object" || dotfiles === null) continue;
|
|
522
|
+
for (const [key, entry] of Object.entries(dotfiles)) {
|
|
523
|
+
if (!key.startsWith("~/") || !isOwnedLink(entry)) continue;
|
|
524
|
+
owned.push({
|
|
525
|
+
target: join5(home, key.slice(2)),
|
|
526
|
+
source: join5(confD, name, entry.source)
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return owned;
|
|
531
|
+
}
|
|
532
|
+
function exists(path) {
|
|
533
|
+
try {
|
|
534
|
+
lstatSync(path);
|
|
535
|
+
return true;
|
|
536
|
+
} catch {
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
function isOurLink(owned) {
|
|
541
|
+
try {
|
|
542
|
+
if (!lstatSync(owned.target).isSymbolicLink()) return false;
|
|
543
|
+
const link = readlinkSync(owned.target);
|
|
544
|
+
return resolve(dirname3(owned.target), link) === owned.source;
|
|
545
|
+
} catch {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
function saveReplaced(platform, owned, options = {}) {
|
|
550
|
+
const { home } = platform.account;
|
|
551
|
+
const stamp = (options.now ?? /* @__PURE__ */ new Date()).toISOString().replace(/\.\d+Z$/, "Z").replaceAll(":", "-");
|
|
552
|
+
const saved = [];
|
|
553
|
+
for (const entry of owned) {
|
|
554
|
+
if (!exists(entry.target) || isOurLink(entry)) continue;
|
|
555
|
+
const backup = join5(
|
|
556
|
+
home,
|
|
557
|
+
".local",
|
|
558
|
+
"share",
|
|
559
|
+
"fleet",
|
|
560
|
+
"backups",
|
|
561
|
+
stamp,
|
|
562
|
+
relative2(home, entry.target)
|
|
563
|
+
);
|
|
564
|
+
if (!options.dryRun) {
|
|
565
|
+
mkdirSync3(dirname3(backup), { recursive: true });
|
|
566
|
+
cpSync(entry.target, backup, {
|
|
567
|
+
recursive: true,
|
|
568
|
+
verbatimSymlinks: true,
|
|
569
|
+
errorOnExist: true,
|
|
570
|
+
force: false
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
saved.push({ target: entry.target, backup });
|
|
574
|
+
}
|
|
575
|
+
return saved;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// src/wallpaper.ts
|
|
579
|
+
import { createHash } from "crypto";
|
|
580
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync4, writeFileSync as writeFileSync3 } from "fs";
|
|
581
|
+
import { extname, join as join6 } from "path";
|
|
582
|
+
async function resolveWallpaper(ctx, wallpaper) {
|
|
583
|
+
const { home } = ctx.platform.account;
|
|
584
|
+
if (!/^https?:\/\//i.test(wallpaper)) {
|
|
585
|
+
const path2 = wallpaper.startsWith("~/") ? join6(home, wallpaper.slice(2)) : wallpaper;
|
|
586
|
+
if (!existsSync3(path2))
|
|
587
|
+
throw new FleetError(`wallpaper ${path2} does not exist`);
|
|
588
|
+
return path2;
|
|
589
|
+
}
|
|
590
|
+
const url = new URL(wallpaper);
|
|
591
|
+
const extension = extname(url.pathname) || ".img";
|
|
592
|
+
const hash = createHash("sha256").update(wallpaper).digest("hex").slice(0, 16);
|
|
593
|
+
const path = join6(
|
|
594
|
+
home,
|
|
595
|
+
".local",
|
|
596
|
+
"share",
|
|
597
|
+
"fleet",
|
|
598
|
+
"wallpaper",
|
|
599
|
+
`${hash}${extension}`
|
|
600
|
+
);
|
|
601
|
+
if (existsSync3(path)) return path;
|
|
602
|
+
const response = await ctx.fetch(wallpaper);
|
|
603
|
+
if (!response.ok)
|
|
604
|
+
throw new FleetError(`wallpaper ${wallpaper}: HTTP ${response.status}`);
|
|
605
|
+
mkdirSync4(join6(home, ".local", "share", "fleet", "wallpaper"), {
|
|
606
|
+
recursive: true
|
|
607
|
+
});
|
|
608
|
+
writeFileSync3(path, Buffer.from(await response.arrayBuffer()));
|
|
609
|
+
return path;
|
|
610
|
+
}
|
|
611
|
+
async function applyGnome(ctx, path) {
|
|
612
|
+
const uri = `file://${encodeURI(path)}`;
|
|
613
|
+
let changed = false;
|
|
614
|
+
for (const key of ["picture-uri", "picture-uri-dark"]) {
|
|
615
|
+
const current = await ctx.exec("gsettings", [
|
|
616
|
+
"get",
|
|
617
|
+
"org.gnome.desktop.background",
|
|
618
|
+
key
|
|
619
|
+
]);
|
|
620
|
+
if (current.code === 0 && current.stdout.trim() === `'${uri}'`) continue;
|
|
621
|
+
const set = await ctx.exec("gsettings", [
|
|
622
|
+
"set",
|
|
623
|
+
"org.gnome.desktop.background",
|
|
624
|
+
key,
|
|
625
|
+
uri
|
|
626
|
+
]);
|
|
627
|
+
if (set.code !== 0)
|
|
628
|
+
throw new FleetError(`gsettings set ${key}: ${set.stderr.trim()}`);
|
|
629
|
+
changed = true;
|
|
630
|
+
}
|
|
631
|
+
return changed ? "applied" : "unchanged";
|
|
632
|
+
}
|
|
633
|
+
async function applyMacos(ctx, path) {
|
|
634
|
+
if (/["\\]/.test(path))
|
|
635
|
+
throw new FleetError(`wallpaper path ${path} has a quote or backslash`);
|
|
636
|
+
const current = await ctx.exec("osascript", [
|
|
637
|
+
"-e",
|
|
638
|
+
'tell application "System Events" to get picture of current desktop'
|
|
639
|
+
]);
|
|
640
|
+
if (current.code === 0 && current.stdout.trim() === path) return "unchanged";
|
|
641
|
+
const set = await ctx.exec("osascript", [
|
|
642
|
+
"-e",
|
|
643
|
+
`tell application "System Events" to tell every desktop to set picture to POSIX file "${path}"`
|
|
644
|
+
]);
|
|
645
|
+
if (set.code !== 0) throw new FleetError(`osascript: ${set.stderr.trim()}`);
|
|
646
|
+
return "applied";
|
|
647
|
+
}
|
|
648
|
+
async function applyWallpaper(ctx, wallpaper) {
|
|
649
|
+
const { os } = ctx.platform;
|
|
650
|
+
const gnome = os === "linux" && /gnome/i.test(ctx.env.XDG_CURRENT_DESKTOP ?? "");
|
|
651
|
+
if (os === "linux" && !gnome) {
|
|
652
|
+
ctx.log("wallpaper: skipped, no GNOME session here");
|
|
653
|
+
return "skipped";
|
|
654
|
+
}
|
|
655
|
+
const path = await resolveWallpaper(ctx, wallpaper);
|
|
656
|
+
const result = await (gnome ? applyGnome(ctx, path) : applyMacos(ctx, path));
|
|
657
|
+
ctx.log(`wallpaper: ${result}`);
|
|
658
|
+
return result;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// src/apply.ts
|
|
662
|
+
function requireCommands(ctx, commands) {
|
|
663
|
+
const missing = commands.filter((command) => !ctx.hasCommand(command));
|
|
664
|
+
if (missing.length > 0) {
|
|
665
|
+
throw new FleetError(
|
|
666
|
+
`${missing.join(" and ")} not found; install ${missing.length > 1 ? "them" : "it"}, or run \`fleet apply --machine\` first, which installs git`
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
async function elevate(ctx, options) {
|
|
671
|
+
const args = [ctx.self.node, ctx.self.script, "apply", "--machine"];
|
|
672
|
+
if (options.dryRun) args.push("--dry-run");
|
|
673
|
+
if (options.upgrade) args.push("--upgrade");
|
|
674
|
+
const result = await ctx.exec("sudo", args, { env: ctx.env, inherit: true });
|
|
675
|
+
if (result.code === 127) {
|
|
676
|
+
throw new FleetError(
|
|
677
|
+
"sudo not found; run `fleet apply --machine` as root with the fleet command on its PATH"
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
return result.code;
|
|
681
|
+
}
|
|
682
|
+
async function apply(ctx, options = {}) {
|
|
683
|
+
const { platform } = ctx;
|
|
684
|
+
const scope = options.machine ? "machine" : "user";
|
|
685
|
+
if (scope === "machine" && platform.euid !== 0) return elevate(ctx, options);
|
|
686
|
+
if (scope === "user" && platform.euid === 0 && ctx.env.SUDO_USER) {
|
|
687
|
+
throw new FleetError(
|
|
688
|
+
"the user layer runs as your own user: run `fleet apply`, and `fleet apply --machine` for the machine layer"
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
const host = loadHost(platform.account.home);
|
|
692
|
+
if (scope === "user") requireCommands(ctx, ["git", "curl"]);
|
|
693
|
+
const mise = locateMise(ctx.env, platform.account.home);
|
|
694
|
+
const preview = options.dryRun ? renderPreview(platform, host) : void 0;
|
|
695
|
+
try {
|
|
696
|
+
const rendered = preview?.rendered ?? renderBaseline(platform, host);
|
|
697
|
+
ctx.log(
|
|
698
|
+
options.dryRun ? `baseline: ${rendered.layers.join(", ")} (dry run: nothing written)` : `baseline: ${rendered.layers.join(", ")} (${rendered.written.length} files written, ${rendered.removed.length} removed)`
|
|
699
|
+
);
|
|
700
|
+
if (scope === "user") {
|
|
701
|
+
const saved = saveReplaced(platform, ownedPaths(platform, host), {
|
|
702
|
+
dryRun: options.dryRun
|
|
703
|
+
});
|
|
704
|
+
for (const { target, backup } of saved) {
|
|
705
|
+
ctx.log(
|
|
706
|
+
`${options.dryRun ? "would replace" : "replaced"} ${target}; ${options.dryRun ? "would save" : "saved"} it as ${backup}`
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
const env = miseEnv(scope, platform, ctx.env, preview?.configDir);
|
|
711
|
+
const result = await ctx.exec(
|
|
712
|
+
mise,
|
|
713
|
+
bootstrapArgs(scope, {
|
|
714
|
+
dryRun: options.dryRun,
|
|
715
|
+
upgrade: options.upgrade
|
|
716
|
+
}),
|
|
717
|
+
{ env, inherit: true }
|
|
718
|
+
);
|
|
719
|
+
if (result.code !== 0) return result.code;
|
|
720
|
+
} finally {
|
|
721
|
+
preview?.cleanup();
|
|
722
|
+
}
|
|
723
|
+
if (scope === "user" && host.wallpaper && !options.dryRun) {
|
|
724
|
+
await applyWallpaper(ctx, host.wallpaper);
|
|
725
|
+
}
|
|
726
|
+
return 0;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// src/config.ts
|
|
730
|
+
function configGet(ctx, key) {
|
|
731
|
+
const name = assertKey(key);
|
|
732
|
+
const host = loadHost(ctx.platform.account.home);
|
|
733
|
+
const value = readKey(host, name) ?? (name === "layers" ? "" : void 0);
|
|
734
|
+
if (value === void 0) return false;
|
|
735
|
+
ctx.log(value);
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
function configSet(ctx, key, value) {
|
|
739
|
+
const name = assertKey(key);
|
|
740
|
+
const home = ctx.platform.account.home;
|
|
741
|
+
saveHost(home, writeKey(loadHost(home), name, value));
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// src/init.ts
|
|
745
|
+
async function askValid(ctx, question, accept) {
|
|
746
|
+
for (; ; ) {
|
|
747
|
+
const answer = await ctx.prompter?.ask(question);
|
|
748
|
+
if (!answer) return void 0;
|
|
749
|
+
try {
|
|
750
|
+
accept(answer);
|
|
751
|
+
return answer;
|
|
752
|
+
} catch (error) {
|
|
753
|
+
ctx.warn(error instanceof Error ? error.message : String(error));
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
async function init(ctx, options) {
|
|
758
|
+
const { home } = ctx.platform.account;
|
|
759
|
+
let host = loadHost(home);
|
|
760
|
+
if (options.icon !== void 0) {
|
|
761
|
+
host = writeKey(host, "icon", options.icon);
|
|
762
|
+
} else if (host.icon === void 0) {
|
|
763
|
+
const answer = await askValid(
|
|
764
|
+
ctx,
|
|
765
|
+
"Prompt emoji for this host (Enter for the default \u{1F4BB}): ",
|
|
766
|
+
(value) => writeKey(host, "icon", value)
|
|
767
|
+
);
|
|
768
|
+
if (answer) host = writeKey(host, "icon", answer);
|
|
769
|
+
}
|
|
770
|
+
if (options.wallpaper !== void 0) {
|
|
771
|
+
host = writeKey(host, "wallpaper", options.wallpaper);
|
|
772
|
+
} else if (host.wallpaper === void 0) {
|
|
773
|
+
const answer = await askValid(
|
|
774
|
+
ctx,
|
|
775
|
+
"Wallpaper, a path or URL (Enter to skip): ",
|
|
776
|
+
(value) => writeKey(host, "wallpaper", value)
|
|
777
|
+
);
|
|
778
|
+
if (answer) host = writeKey(host, "wallpaper", answer);
|
|
779
|
+
}
|
|
780
|
+
if (options.layers !== void 0) {
|
|
781
|
+
host = writeKey(host, "layers", options.layers);
|
|
782
|
+
} else if (host.layers === void 0) {
|
|
783
|
+
const { os, arch } = ctx.platform;
|
|
784
|
+
const layers = [];
|
|
785
|
+
const available = (name) => {
|
|
786
|
+
try {
|
|
787
|
+
selectLayers({ os, arch }, { layers: [name] });
|
|
788
|
+
return true;
|
|
789
|
+
} catch {
|
|
790
|
+
return false;
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
if (available("nvidia") && ctx.detectNvidia()) layers.push("nvidia");
|
|
794
|
+
if (available("docker")) {
|
|
795
|
+
const answer = await ctx.prompter?.ask(
|
|
796
|
+
"Install Docker Engine on this host? [y/N] "
|
|
797
|
+
);
|
|
798
|
+
if (answer && /^y(es)?$/i.test(answer)) layers.push("docker");
|
|
799
|
+
}
|
|
800
|
+
host = writeKey(host, "layers", layers.join(","));
|
|
801
|
+
}
|
|
802
|
+
const checked = validateHost(host);
|
|
803
|
+
selectLayers(ctx.platform, checked);
|
|
804
|
+
const path = saveHost(home, checked);
|
|
805
|
+
ctx.log(`wrote ${path}`);
|
|
806
|
+
return checked;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// src/update.ts
|
|
810
|
+
var FLEET_TOOL = "npm:@leclabs/fleet";
|
|
811
|
+
async function update(ctx) {
|
|
812
|
+
const mise = locateMise(ctx.env, ctx.platform.account.home);
|
|
813
|
+
const env = miseEnv("user", ctx.platform, ctx.env);
|
|
814
|
+
const upgraded = await ctx.exec(mise, ["upgrade", FLEET_TOOL], {
|
|
815
|
+
env,
|
|
816
|
+
inherit: true
|
|
817
|
+
});
|
|
818
|
+
if (upgraded.code !== 0) return upgraded.code;
|
|
819
|
+
const selfUpdated = await ctx.exec(mise, ["self-update", "--yes"], {
|
|
820
|
+
env,
|
|
821
|
+
inherit: true
|
|
822
|
+
});
|
|
823
|
+
if (selfUpdated.code !== 0)
|
|
824
|
+
ctx.warn("mise did not update itself; continuing with the mise installed");
|
|
825
|
+
return 0;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// src/verify.ts
|
|
829
|
+
import {
|
|
830
|
+
constants as constants2,
|
|
831
|
+
accessSync as accessSync2,
|
|
832
|
+
mkdtempSync as mkdtempSync2,
|
|
833
|
+
readFileSync as readFileSync4,
|
|
834
|
+
readdirSync as readdirSync3,
|
|
835
|
+
realpathSync as realpathSync2,
|
|
836
|
+
rmSync as rmSync2,
|
|
837
|
+
statSync as statSync2
|
|
838
|
+
} from "fs";
|
|
839
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
840
|
+
import { join as join7, sep } from "path";
|
|
841
|
+
var STANDARD = [
|
|
842
|
+
"awk",
|
|
843
|
+
"cat",
|
|
844
|
+
"date",
|
|
845
|
+
"grep",
|
|
846
|
+
"ls",
|
|
847
|
+
"sed",
|
|
848
|
+
"stat",
|
|
849
|
+
"top"
|
|
850
|
+
];
|
|
851
|
+
var OS_COPIES = ["/usr/bin", "/bin"];
|
|
852
|
+
var OS_DIRS = [
|
|
853
|
+
"/usr/bin",
|
|
854
|
+
"/bin",
|
|
855
|
+
"/usr/sbin",
|
|
856
|
+
"/sbin",
|
|
857
|
+
"/usr/libexec",
|
|
858
|
+
"/System"
|
|
859
|
+
];
|
|
860
|
+
var BASE_PATH = {
|
|
861
|
+
linux: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
|
862
|
+
macos: "/usr/bin:/bin:/usr/sbin:/sbin"
|
|
863
|
+
};
|
|
864
|
+
var VENDOR_COMMANDS = ["claude", "omp"];
|
|
865
|
+
var UPSTREAM_NAMES = {
|
|
866
|
+
batcat: "bat",
|
|
867
|
+
fdfind: "fd"
|
|
868
|
+
};
|
|
869
|
+
var STARTUP_FILES = [
|
|
870
|
+
".zshenv",
|
|
871
|
+
".zprofile",
|
|
872
|
+
".zshrc",
|
|
873
|
+
".zlogin",
|
|
874
|
+
".bashrc",
|
|
875
|
+
".bash_profile",
|
|
876
|
+
".profile"
|
|
877
|
+
];
|
|
878
|
+
var SHELLS = [
|
|
879
|
+
{ mode: "interactive", flag: "-ic" },
|
|
880
|
+
{ mode: "login", flag: "-lc" },
|
|
881
|
+
{ mode: "non-interactive", flag: "-c" }
|
|
882
|
+
];
|
|
883
|
+
function real(path) {
|
|
884
|
+
try {
|
|
885
|
+
return realpathSync2(path);
|
|
886
|
+
} catch {
|
|
887
|
+
return path;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
function within(path, dir) {
|
|
891
|
+
return path === dir || path.startsWith(dir.endsWith(sep) ? dir : dir + sep);
|
|
892
|
+
}
|
|
893
|
+
function isExecutableFile(path) {
|
|
894
|
+
try {
|
|
895
|
+
accessSync2(path, constants2.X_OK);
|
|
896
|
+
return statSync2(path).isFile();
|
|
897
|
+
} catch {
|
|
898
|
+
return false;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
function executables(dir) {
|
|
902
|
+
try {
|
|
903
|
+
return readdirSync3(dir).filter((name) => isExecutableFile(join7(dir, name)));
|
|
904
|
+
} catch {
|
|
905
|
+
return [];
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
var APPLIED_STATES = /* @__PURE__ */ new Set([
|
|
909
|
+
"installed",
|
|
910
|
+
"applied",
|
|
911
|
+
"current",
|
|
912
|
+
"set",
|
|
913
|
+
"present",
|
|
914
|
+
"active",
|
|
915
|
+
"loaded",
|
|
916
|
+
"running",
|
|
917
|
+
"enabled"
|
|
918
|
+
]);
|
|
919
|
+
var NAME_KEYS = ["package", "tool", "target", "path_raw", "path", "name"];
|
|
920
|
+
var LIST_KEYS = /* @__PURE__ */ new Set([
|
|
921
|
+
"packages",
|
|
922
|
+
"files",
|
|
923
|
+
"units",
|
|
924
|
+
"edits",
|
|
925
|
+
"agents",
|
|
926
|
+
"daemons",
|
|
927
|
+
"entries"
|
|
928
|
+
]);
|
|
929
|
+
function isRecord(value) {
|
|
930
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
931
|
+
}
|
|
932
|
+
function describeEntry(section, entry) {
|
|
933
|
+
const id = isRecord(entry.id) ? entry.id.name : void 0;
|
|
934
|
+
const name = [...NAME_KEYS.map((key) => entry[key]), id].find(
|
|
935
|
+
(value) => typeof value === "string"
|
|
936
|
+
);
|
|
937
|
+
const detail = [entry.edit, entry.reason].filter((value) => typeof value === "string" && value !== "").join(", ");
|
|
938
|
+
const what = entry.state ?? `action ${entry.action}`;
|
|
939
|
+
return `${section} ${name ?? "?"} ${what}${detail ? ` (${detail})` : ""}`;
|
|
940
|
+
}
|
|
941
|
+
function drift(status, path = []) {
|
|
942
|
+
if (Array.isArray(status)) {
|
|
943
|
+
return status.flatMap((item) => drift(item, path));
|
|
944
|
+
}
|
|
945
|
+
if (!isRecord(status)) return [];
|
|
946
|
+
const section = path.filter((key, index) => index === 0 || !LIST_KEYS.has(key)).join(".");
|
|
947
|
+
const { state, action } = status;
|
|
948
|
+
if (typeof state === "string") {
|
|
949
|
+
const word = state.split(/\s/)[0] ?? "";
|
|
950
|
+
const unit = (word === "active" || word === "inactive") && typeof status.desired === "boolean";
|
|
951
|
+
if (word === "skipped") return [];
|
|
952
|
+
if (unit ? status.desired : APPLIED_STATES.has(word)) return [];
|
|
953
|
+
return [describeEntry(section, status)];
|
|
954
|
+
}
|
|
955
|
+
if (typeof action === "string") {
|
|
956
|
+
return action === "noop" || action === "skipped" ? [] : [describeEntry(section, status)];
|
|
957
|
+
}
|
|
958
|
+
return Object.entries(status).flatMap(
|
|
959
|
+
([key, value]) => drift(value, [...path, key])
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
async function checkBootstrap(ctx, mise, report) {
|
|
963
|
+
const result = await ctx.exec(mise, ["bootstrap", "status", "--json"], {
|
|
964
|
+
env: miseEnv("user", ctx.platform, ctx.env),
|
|
965
|
+
cwd: ctx.platform.account.home
|
|
966
|
+
});
|
|
967
|
+
let status;
|
|
968
|
+
try {
|
|
969
|
+
status = JSON.parse(result.stdout);
|
|
970
|
+
} catch {
|
|
971
|
+
report.failures.push({
|
|
972
|
+
check: "bootstrap",
|
|
973
|
+
message: `mise bootstrap status --json did not print JSON${result.stderr.trim() ? `:
|
|
974
|
+
${result.stderr.trim()}` : ""}`
|
|
975
|
+
});
|
|
976
|
+
return {};
|
|
977
|
+
}
|
|
978
|
+
const lines = drift(status);
|
|
979
|
+
if (lines.length > 0) {
|
|
980
|
+
report.failures.push({
|
|
981
|
+
check: "bootstrap",
|
|
982
|
+
message: `mise bootstrap status differs from the baseline:
|
|
983
|
+
${lines.map((line) => ` ${line}`).join("\n")}`
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
return status;
|
|
987
|
+
}
|
|
988
|
+
async function expectedCommands(ctx, mise, status) {
|
|
989
|
+
const { home } = ctx.platform.account;
|
|
990
|
+
const expect = /* @__PURE__ */ new Map();
|
|
991
|
+
const add = (command, prefix) => {
|
|
992
|
+
const prefixes = expect.get(command) ?? /* @__PURE__ */ new Set();
|
|
993
|
+
prefixes.add(real(prefix));
|
|
994
|
+
expect.set(command, prefixes);
|
|
995
|
+
};
|
|
996
|
+
const packages = status.packages ?? {};
|
|
997
|
+
for (const { package: name } of packages.brew?.packages ?? []) {
|
|
998
|
+
const opt = join7("/opt/homebrew/opt", name);
|
|
999
|
+
for (const command of executables(join7(opt, "bin"))) add(command, opt);
|
|
1000
|
+
}
|
|
1001
|
+
for (const { package: name } of packages.apt?.packages ?? []) {
|
|
1002
|
+
const listing = await ctx.exec("dpkg", ["-L", name]);
|
|
1003
|
+
for (const path of listing.stdout.split("\n")) {
|
|
1004
|
+
if (!/^\/(usr\/)?s?bin\/[^/]+$/.test(path) || !isExecutableFile(path))
|
|
1005
|
+
continue;
|
|
1006
|
+
const command = path.slice(path.lastIndexOf("/") + 1);
|
|
1007
|
+
add(command, path);
|
|
1008
|
+
const upstream = UPSTREAM_NAMES[command];
|
|
1009
|
+
if (upstream) add(upstream, path);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
for (const entry of status.dotfiles?.files ?? []) {
|
|
1013
|
+
const target = (entry.target ?? "").replace(/^~(?=\/)/, home);
|
|
1014
|
+
const source = entry.source.replace(/^~(?=\/)/, home);
|
|
1015
|
+
if (entry.mode === "symlink" && target.startsWith(`${home}/.local/bin/`)) {
|
|
1016
|
+
add(target.slice(target.lastIndexOf("/") + 1), source);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
const dataDir = ctx.env.MISE_DATA_DIR ?? join7(home, ".local/share/mise");
|
|
1020
|
+
const installs = join7(dataDir, "installs");
|
|
1021
|
+
const binPaths = await ctx.exec(mise, ["bin-paths"], {
|
|
1022
|
+
env: miseEnv("user", ctx.platform, ctx.env),
|
|
1023
|
+
cwd: home
|
|
1024
|
+
});
|
|
1025
|
+
for (const dir of binPaths.stdout.split(/\s+/).filter(Boolean)) {
|
|
1026
|
+
const tool = within(dir, installs) ? join7(installs, dir.slice(installs.length + 1).split(sep)[0] ?? "") : real(dir);
|
|
1027
|
+
for (const command of executables(dir)) add(command, tool);
|
|
1028
|
+
}
|
|
1029
|
+
for (const command of VENDOR_COMMANDS) add(command, join7(home, ".local"));
|
|
1030
|
+
for (const command of STANDARD) expect.set(command, new Set(OS_COPIES));
|
|
1031
|
+
return expect;
|
|
1032
|
+
}
|
|
1033
|
+
var PROBE = `
|
|
1034
|
+
for c in "$@"; do
|
|
1035
|
+
printf '@@kind\\t%s\\t%s\\n' "$c" "$(whence -w -- $c | cut -d' ' -f2)"
|
|
1036
|
+
whence -ap -- $c | while IFS= read -r p; do printf '@@path\\t%s\\t%s\\n' "$c" "$p"; done
|
|
1037
|
+
done
|
|
1038
|
+
`;
|
|
1039
|
+
function shellQuote(word) {
|
|
1040
|
+
return `'${word.replaceAll("'", "'\\''")}'`;
|
|
1041
|
+
}
|
|
1042
|
+
async function runShell(ctx, flag, argv, options) {
|
|
1043
|
+
if (flag !== "-ic") {
|
|
1044
|
+
const result = await ctx.exec("/bin/zsh", argv, options);
|
|
1045
|
+
return { result, stderr: result.stderr.trim() };
|
|
1046
|
+
}
|
|
1047
|
+
const dir = mkdtempSync2(join7(tmpdir2(), "fleet-verify-"));
|
|
1048
|
+
const stderrFile = join7(dir, "stderr");
|
|
1049
|
+
try {
|
|
1050
|
+
const line = `${["/bin/zsh", ...argv].map(shellQuote).join(" ")} 2>${shellQuote(stderrFile)}`;
|
|
1051
|
+
const args = ctx.platform.os === "macos" ? ["-q", "/dev/null", "/bin/sh", "-c", line] : ["-qec", line, "/dev/null"];
|
|
1052
|
+
const result = await ctx.exec("script", args, options);
|
|
1053
|
+
let stderr = "";
|
|
1054
|
+
try {
|
|
1055
|
+
stderr = readFileSync4(stderrFile, "utf8").trim();
|
|
1056
|
+
} catch {
|
|
1057
|
+
}
|
|
1058
|
+
return { result, stderr };
|
|
1059
|
+
} finally {
|
|
1060
|
+
rmSync2(dir, { recursive: true, force: true });
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
async function probe(ctx, flag, commands) {
|
|
1064
|
+
const { home, user } = ctx.platform.account;
|
|
1065
|
+
const env = {
|
|
1066
|
+
HOME: home,
|
|
1067
|
+
USER: user,
|
|
1068
|
+
SHELL: "/bin/zsh",
|
|
1069
|
+
TERM: "xterm-256color",
|
|
1070
|
+
PATH: BASE_PATH[ctx.platform.os],
|
|
1071
|
+
LANG: ctx.env.LANG ?? "en_US.UTF-8"
|
|
1072
|
+
};
|
|
1073
|
+
const { result, stderr } = await runShell(
|
|
1074
|
+
ctx,
|
|
1075
|
+
flag,
|
|
1076
|
+
[flag, PROBE, "probe", ...commands],
|
|
1077
|
+
{ env, cwd: home }
|
|
1078
|
+
);
|
|
1079
|
+
const found = /* @__PURE__ */ new Map();
|
|
1080
|
+
for (const line of result.stdout.replaceAll("\r", "").split("\n")) {
|
|
1081
|
+
const match = /@@(kind|path)\t([^\t]*)\t(.*)$/.exec(line);
|
|
1082
|
+
if (!match) continue;
|
|
1083
|
+
const [, tag, command = "", value = ""] = match;
|
|
1084
|
+
const entry = found.get(command) ?? { kind: "none", paths: [] };
|
|
1085
|
+
if (tag === "kind") entry.kind = value;
|
|
1086
|
+
else entry.paths.push(value);
|
|
1087
|
+
found.set(command, entry);
|
|
1088
|
+
}
|
|
1089
|
+
return { found, stderr, started: result.code !== 127 };
|
|
1090
|
+
}
|
|
1091
|
+
async function checkResolution(ctx, mise, expect, report) {
|
|
1092
|
+
const { home } = ctx.platform.account;
|
|
1093
|
+
const shims = join7(
|
|
1094
|
+
ctx.env.MISE_DATA_DIR ?? join7(home, ".local/share/mise"),
|
|
1095
|
+
"shims"
|
|
1096
|
+
);
|
|
1097
|
+
const commands = [...expect.keys()].sort();
|
|
1098
|
+
const standard = new Set(STANDARD);
|
|
1099
|
+
const whichCache = /* @__PURE__ */ new Map();
|
|
1100
|
+
const miseWhich = async (command) => {
|
|
1101
|
+
if (!whichCache.has(command)) {
|
|
1102
|
+
const which = await ctx.exec(mise, ["which", command], {
|
|
1103
|
+
env: miseEnv("user", ctx.platform, ctx.env),
|
|
1104
|
+
cwd: home
|
|
1105
|
+
});
|
|
1106
|
+
whichCache.set(
|
|
1107
|
+
command,
|
|
1108
|
+
which.code === 0 ? real(which.stdout.trim()) : void 0
|
|
1109
|
+
);
|
|
1110
|
+
}
|
|
1111
|
+
return whichCache.get(command);
|
|
1112
|
+
};
|
|
1113
|
+
for (const { mode, flag } of SHELLS) {
|
|
1114
|
+
const { found, stderr, started } = await probe(ctx, flag, commands);
|
|
1115
|
+
if (!started) {
|
|
1116
|
+
report.failures.push({
|
|
1117
|
+
check: "shell",
|
|
1118
|
+
message: `[${mode}] zsh cannot start (/bin/zsh, and script for a terminal); the baseline's shell is zsh`
|
|
1119
|
+
});
|
|
1120
|
+
continue;
|
|
1121
|
+
}
|
|
1122
|
+
if (mode === "interactive" && stderr) {
|
|
1123
|
+
report.failures.push({
|
|
1124
|
+
check: "shell",
|
|
1125
|
+
message: `interactive zsh writes to stderr at startup:
|
|
1126
|
+
${stderr.slice(0, 400)}`
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
for (const command of commands) {
|
|
1130
|
+
const { kind, paths } = found.get(command) ?? { kind: "none", paths: [] };
|
|
1131
|
+
const prefixes = expect.get(command) ?? /* @__PURE__ */ new Set();
|
|
1132
|
+
const fail = (message) => report.failures.push({ check: "resolution", message });
|
|
1133
|
+
if (mode === "interactive" && (kind === "alias" || kind === "function")) {
|
|
1134
|
+
fail(
|
|
1135
|
+
`[${mode}] ${command} is a${kind === "alias" ? "n" : ""} ${kind} hiding the declared command`
|
|
1136
|
+
);
|
|
1137
|
+
}
|
|
1138
|
+
const first = paths[0];
|
|
1139
|
+
if (!first) {
|
|
1140
|
+
fail(`[${mode}] ${command} does not resolve`);
|
|
1141
|
+
continue;
|
|
1142
|
+
}
|
|
1143
|
+
let landed = standard.has(command) ? first : real(first);
|
|
1144
|
+
if (!standard.has(command) && within(first, shims)) {
|
|
1145
|
+
landed = await miseWhich(command) ?? landed;
|
|
1146
|
+
}
|
|
1147
|
+
if (![...prefixes].some((prefix) => within(landed, prefix))) {
|
|
1148
|
+
fail(
|
|
1149
|
+
`[${mode}] ${command} resolves to ${first} -> ${landed}, expected ${[...prefixes].sort().join(", ")}`
|
|
1150
|
+
);
|
|
1151
|
+
continue;
|
|
1152
|
+
}
|
|
1153
|
+
for (const other of paths.slice(1)) {
|
|
1154
|
+
const target = real(other);
|
|
1155
|
+
if (within(other, shims) || [...prefixes].some((prefix) => within(target, prefix)) || OS_DIRS.some((dir) => within(other, dir)))
|
|
1156
|
+
continue;
|
|
1157
|
+
report.warnings.push({
|
|
1158
|
+
check: "resolution",
|
|
1159
|
+
message: `[${mode}] another ${command} behind the declared one: ${other} -> ${target}`
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
var SHELL_SETUP = /\bPATH\b|\bpath\+?=|^\s*(\.|source)\s|\beval\b/;
|
|
1166
|
+
function checkStartupFiles(ctx, report, skeletonDir) {
|
|
1167
|
+
const { home } = ctx.platform.account;
|
|
1168
|
+
for (const name of STARTUP_FILES) {
|
|
1169
|
+
let text;
|
|
1170
|
+
try {
|
|
1171
|
+
text = readFileSync4(join7(home, name), "utf8");
|
|
1172
|
+
} catch {
|
|
1173
|
+
continue;
|
|
1174
|
+
}
|
|
1175
|
+
let skeleton = /* @__PURE__ */ new Set();
|
|
1176
|
+
try {
|
|
1177
|
+
skeleton = new Set(
|
|
1178
|
+
readFileSync4(join7(skeletonDir, name), "utf8").split("\n")
|
|
1179
|
+
);
|
|
1180
|
+
} catch {
|
|
1181
|
+
}
|
|
1182
|
+
let inside = false;
|
|
1183
|
+
text.split("\n").forEach((line, index) => {
|
|
1184
|
+
const where = `~/${name}:${index + 1}`;
|
|
1185
|
+
if (/^# >>> mise:/.test(line)) inside = true;
|
|
1186
|
+
else if (/^# <<< mise:/.test(line)) inside = false;
|
|
1187
|
+
else if (inside || line.trimStart().startsWith("#") || skeleton.has(line)) {
|
|
1188
|
+
return;
|
|
1189
|
+
} else if (/\bmise\b.*\bactivate\b/.test(line)) {
|
|
1190
|
+
report.warnings.push({
|
|
1191
|
+
check: "startup",
|
|
1192
|
+
message: `${where} activates mise a second time, outside its managed block`
|
|
1193
|
+
});
|
|
1194
|
+
} else if (SHELL_SETUP.test(line)) {
|
|
1195
|
+
report.warnings.push({
|
|
1196
|
+
check: "startup",
|
|
1197
|
+
message: `${where} sets up the shell outside mise's managed blocks: ${line.trim()}`
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
async function checkGpuDriver(ctx, report, procFile) {
|
|
1204
|
+
const fail = (message) => report.failures.push({ check: "gpu", message });
|
|
1205
|
+
const recommended = (await ctx.exec("ubuntu-drivers", ["list", "--recommended"])).stdout.split(/\s+/).filter(Boolean);
|
|
1206
|
+
const driver = recommended.find((name) => name.startsWith("nvidia-driver-"));
|
|
1207
|
+
if (!driver) {
|
|
1208
|
+
fail("the nvidia layer is on, and Ubuntu recommends no NVIDIA driver here");
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
const installed = async (name) => (await ctx.exec("dpkg-query", ["-W", "-f=${db:Status-Abbrev}", name])).stdout.startsWith("ii");
|
|
1212
|
+
for (const name of recommended) {
|
|
1213
|
+
if (!await installed(name)) {
|
|
1214
|
+
fail(
|
|
1215
|
+
`Ubuntu recommends ${name} for this host's hardware, and it is not installed`
|
|
1216
|
+
);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
if (!await installed(driver)) return;
|
|
1220
|
+
const version = (await ctx.exec("dpkg-query", ["-W", "-f=${Version}", driver])).stdout.trim().split("-")[0];
|
|
1221
|
+
let loaded;
|
|
1222
|
+
try {
|
|
1223
|
+
loaded = /Kernel Module(?: for \S+)?\s+(\d[\d.]*)/.exec(
|
|
1224
|
+
readFileSync4(procFile, "utf8")
|
|
1225
|
+
)?.[1];
|
|
1226
|
+
} catch {
|
|
1227
|
+
}
|
|
1228
|
+
if (!loaded) {
|
|
1229
|
+
fail(
|
|
1230
|
+
`no NVIDIA kernel module is loaded; ${driver} ${version} is installed: reboot to load it`
|
|
1231
|
+
);
|
|
1232
|
+
} else if (loaded !== version) {
|
|
1233
|
+
fail(
|
|
1234
|
+
`the loaded NVIDIA module is ${loaded}, ${driver} is ${version}: reboot to load it`
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
async function check(ctx, options = {}) {
|
|
1239
|
+
const { home } = ctx.platform.account;
|
|
1240
|
+
const report = { commands: 0, failures: [], warnings: [] };
|
|
1241
|
+
const mise = locateMise(ctx.env, home);
|
|
1242
|
+
const status = await checkBootstrap(ctx, mise, report);
|
|
1243
|
+
const expect = await expectedCommands(ctx, mise, status);
|
|
1244
|
+
report.commands = expect.size;
|
|
1245
|
+
await checkResolution(ctx, mise, expect, report);
|
|
1246
|
+
checkStartupFiles(ctx, report, options.skeleton ?? "/etc/skel");
|
|
1247
|
+
if (ctx.platform.os === "linux" && loadHost(home).layers?.includes("nvidia")) {
|
|
1248
|
+
await checkGpuDriver(
|
|
1249
|
+
ctx,
|
|
1250
|
+
report,
|
|
1251
|
+
options.nvidiaProc ?? "/proc/driver/nvidia/version"
|
|
1252
|
+
);
|
|
1253
|
+
}
|
|
1254
|
+
return report;
|
|
1255
|
+
}
|
|
1256
|
+
async function verify(ctx, options = {}) {
|
|
1257
|
+
let report;
|
|
1258
|
+
try {
|
|
1259
|
+
report = await check(ctx, options);
|
|
1260
|
+
} catch (error) {
|
|
1261
|
+
if (!options.json) throw error;
|
|
1262
|
+
report = {
|
|
1263
|
+
commands: 0,
|
|
1264
|
+
failures: [
|
|
1265
|
+
{
|
|
1266
|
+
check: "error",
|
|
1267
|
+
message: error instanceof Error ? error.message : String(error)
|
|
1268
|
+
}
|
|
1269
|
+
],
|
|
1270
|
+
warnings: []
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
const ok = report.failures.length === 0;
|
|
1274
|
+
if (options.json) {
|
|
1275
|
+
ctx.log(JSON.stringify({ ok, ...report }, null, 2));
|
|
1276
|
+
} else {
|
|
1277
|
+
for (const { message } of report.warnings) ctx.log(` ! ${message}`);
|
|
1278
|
+
for (const { message } of report.failures) ctx.log(` \u2717 ${message}`);
|
|
1279
|
+
ctx.log(
|
|
1280
|
+
`${report.commands} commands checked, ${report.failures.length} failures, ${report.warnings.length} warnings`
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
return ok ? 0 : 1;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
// src/program.ts
|
|
1287
|
+
function buildProgram(context, exit) {
|
|
1288
|
+
const program = new Command("fleet").description(
|
|
1289
|
+
"Applies one opinionated baseline to the host it runs on, with mise bootstrap as its engine."
|
|
1290
|
+
).exitOverride().showHelpAfterError();
|
|
1291
|
+
program.command("init").description("create host.toml, asking only what cannot be detected").option("--icon <emoji>", "the prompt emoji").option(
|
|
1292
|
+
"--wallpaper <path-or-url>",
|
|
1293
|
+
"the wallpaper, applied on GNOME and macOS"
|
|
1294
|
+
).option("--layers <list>", "opt-in layers, comma-separated: nvidia, docker").action(async (options) => {
|
|
1295
|
+
await init(await context(), options);
|
|
1296
|
+
exit(0);
|
|
1297
|
+
});
|
|
1298
|
+
const config = program.command("config").description("read and write host.toml");
|
|
1299
|
+
config.command("get <key>").description("print the value of a key; exits 1 when it is not set").action(async (key) => {
|
|
1300
|
+
exit(configGet(await context(), key) ? 0 : 1);
|
|
1301
|
+
});
|
|
1302
|
+
config.command("set <key> [value]").description(
|
|
1303
|
+
"set a key; without a value, remove it (layers: a comma-separated list)"
|
|
1304
|
+
).action(async (key, value) => {
|
|
1305
|
+
configSet(await context(), key, value);
|
|
1306
|
+
exit(0);
|
|
1307
|
+
});
|
|
1308
|
+
program.command("apply").description(
|
|
1309
|
+
"apply the user layer; with --machine, the machine layer (asks sudo)"
|
|
1310
|
+
).option("--machine", "apply the parts that need root").option("--dry-run", "show what would change; writes nothing").option(
|
|
1311
|
+
"--upgrade",
|
|
1312
|
+
"also upgrade installed tools, or with --machine, packages"
|
|
1313
|
+
).action(async (options) => {
|
|
1314
|
+
exit(await apply(await context(), options));
|
|
1315
|
+
});
|
|
1316
|
+
program.command("update").description("upgrade fleet through mise, then mise itself").action(async () => {
|
|
1317
|
+
exit(await update(await context()));
|
|
1318
|
+
});
|
|
1319
|
+
program.command("verify").description(
|
|
1320
|
+
"check that the host matches the baseline; exits 1 naming each failure"
|
|
1321
|
+
).option("--json", "print the report as JSON").action(async (options) => {
|
|
1322
|
+
exit(await verify(await context(), options));
|
|
1323
|
+
});
|
|
1324
|
+
return program;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
// src/fleet.ts
|
|
1328
|
+
var code = 0;
|
|
1329
|
+
try {
|
|
1330
|
+
await buildProgram(systemContext, (value) => {
|
|
1331
|
+
code = value;
|
|
1332
|
+
}).parseAsync(process.argv);
|
|
1333
|
+
} catch (error) {
|
|
1334
|
+
if (error instanceof FleetError) {
|
|
1335
|
+
console.error(`fleet: ${error.message}`);
|
|
1336
|
+
code = 1;
|
|
1337
|
+
} else if (error && typeof error === "object" && "exitCode" in error) {
|
|
1338
|
+
code = Number(error.exitCode);
|
|
1339
|
+
} else {
|
|
1340
|
+
throw error;
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
process.exitCode = code;
|