LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.
C cdebiandesktop-environmentebpffirewalllandlocklinuxlinux-distributionopen-sourceprivacyquickjsraspberry-pi-5reactsecuritywaylandwayland-compositor
lordos-fetch: the crown in the brand colors (half-block pixel art, plain ASCII without color) beside a summary of the computer from System Information's collector; user and host names only on screen, --share leaves them out; --color=auto|always|never, NO_COLOR, true color by COLORTERM; packaged as a link to lordos-sysreport
Federico Pereirabc1018fe4e40
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ae70e81..dbe7e2f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,12 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),### Added+- **`lordos-fetch`.** Type it in a terminal to see the LordOS crown beside a summary of your+ computer: system, kernel, CPU, GPU, display, memory, disk, packages and how apps are isolated.+ `lordos-fetch --share` leaves out your user and computer names, for a screenshot you'll post.+- **`lordos-sysreport report`** prints the hardware of this computer and what the system made of it,+ as Markdown or `--json`, with no serial numbers, addresses or names: the base of System+ Information.- **Files: This Computer and every disk.** The sidebar now has This Computer, to browse the wholesystem read-only as your user (the system's own permissions decide; the kernel's `/proc`, `/sys`,`/dev` and `/run` stay out), and every disk with a file system: one that isn't mounted showsdiff --git a/docs/BENCHMARK.md b/docs/BENCHMARK.mdindex 8f4d1d6..25b4e12 100644--- a/docs/BENCHMARK.md+++ b/docs/BENCHMARK.md@@ -243,7 +243,11 @@ which recommends `pci.ids` and `usb.ids`), and `tests/sysreport_test.c`: five faIntel laptop, Nvidia desktop, Raspberry Pi 5, VM) full of serials, UUIDs, MAC addresses, a host name, auser name, monitor serials and a MAC inside an interface name, none of which may reach a report(`build/sysreport-test fixture <dir> <kind>` writes one for `--root`). Checked on VM 116 against the real-machine. Not yet: the GPU's EGL, composition and scanout layers (they come from the running+machine. `lordos-fetch` (the same binary under that name; `lordos-sysreport fetch`) shows the crown in+the brand colors beside a short summary (system, computer, kernel, uptime, packages, shell, display, CPU,+GPU, memory, disk, isolation); the user and host names appear only on screen and `--share` leaves them out+for a screenshot to post; `--color=auto|always|never`, `NO_COLOR` respected, true color when `COLORTERM`+says so, plain ASCII without color. Not yet: the GPU's EGL, composition and scanout layers (they come from the running`lord-server`, with `lord.sysinfo`), `hw-memory-modules`, the app.1. `server/src/sysreport/`: collector, GPU layers, `pci.ids`/EDID readers, fake-sysfs fixturesdiff --git a/server/mk/sysreport.mk b/server/mk/sysreport.mkindex 15d60cd..280ae34 100644--- a/server/mk/sysreport.mk+++ b/server/mk/sysreport.mk@@ -1,8 +1,11 @@# System Information (0.8.5, src/sysreport, docs/BENCHMARK.md): the collector, shared by the-# `lordos-sysreport` command and (later) lord.sysinfo. Read-only, no root, libc only.-SYSREPORT_SRC := src/sysreport/sysreport.c src/sysreport/sysreport_out.c src/sysreport/ids.c src/hw/edid.c src/hw/jbuf.c src/sec/json.c+# `lordos-sysreport` and `lordos-fetch` commands (one binary; build/lordos-fetch is a link) and+# (later) lord.sysinfo. Read-only, no root, libc only.+SYSREPORT_SRC := src/sysreport/sysreport.c src/sysreport/fetch.c src/sysreport/sysreport_out.c src/sysreport/ids.c src/hw/edid.c src/hw/jbuf.c src/sec/json.cSYSREPORT_HDR := $(wildcard src/sysreport/*.h) src/hw/edid.h src/hw/jbuf.h src/sec/json.h-all: build/lordos-sysreport+all: build/lordos-sysreport build/lordos-fetch+build/lordos-fetch: build/lordos-sysreport+ ln -sf lordos-sysreport $@build/lordos-sysreport: src/sysreport/cli.c $(SYSREPORT_SRC) $(SYSREPORT_HDR) build/gen/lord_version.h@mkdir -p build$(CC) $(CPPFLAGS) -Ibuild/gen $(CFLAGS) $(WARN) -std=c11 -o $@ src/sysreport/cli.c $(SYSREPORT_SRC)diff --git a/server/src/sysreport/cli.c b/server/src/sysreport/cli.cindex d632540..f968993 100644--- a/server/src/sysreport/cli.c+++ b/server/src/sysreport/cli.c@@ -1,43 +1,66 @@-/* cli.c — `lordos-sysreport`, System Information's command (see docs/BENCHMARK.md). An ordinary- * user command: lord-server never runs it. It prints the same report as the app, so one can be made- * on a machine without a session (a headless Pi, a VM over SSH, CI).+/* cli.c — `lordos-sysreport` and `lordos-fetch`, System Information's commands (see+ * docs/BENCHMARK.md). Ordinary user commands: lord-server never runs them. The report is the same as+ * the app's, so one can be made on a machine without a session (a headless Pi, a VM over SSH, CI).** lordos-sysreport report [--json | --markdown]+ * lordos-fetch [--share] [--color=auto|always|never] (also: lordos-sysreport fetch …)*- * --root <dir> reads a fake tree instead of this machine (tests and fixtures only). */+ * lordos-fetch is a link to this binary. --root <dir> reads a fake tree instead of this machine+ * (tests and fixtures only). */#include "sysreport.h"+#include "fetch.h"#include "lord_version.h"#include <stdio.h>#include <stdlib.h>#include <string.h>+#include <unistd.h>-static int usage(void) {- fprintf(stderr, "usage: lordos-sysreport report [--json | --markdown]\n"- " Prints this computer's hardware and what the system made of it (no serial numbers,\n"- " addresses, host or user names). Markdown by default.\n");+static int usage(int fetch) {+ if (fetch)+ fprintf(stderr, "usage: lordos-fetch [--share] [--color=auto|always|never]\n"+ " Shows the crown and a summary of this computer. --share leaves out the user and\n"+ " host names, for a screenshot you will post.\n");+ else+ fprintf(stderr, "usage: lordos-sysreport report [--json | --markdown]\n"+ " lordos-sysreport fetch [--share] [--color=auto|always|never]\n"+ " report prints this computer's hardware and what the system made of it (no serial\n"+ " numbers, addresses, host or user names). Markdown by default.\n");return 2;}int main(int argc, char **argv) {- const char *root = "", *mode = "markdown";- int report = 0;+ const char *root = "", *mode = "markdown", *color = "auto";+ const char *base = strrchr(argv[0], '/');+ base = base ? base + 1 : argv[0];+ int fetch = !strcmp(base, "lordos-fetch"), report = 0, share = 0;for (int i = 1; i < argc; i++) {- if (!strcmp(argv[i], "report")) report = 1;- else if (!strcmp(argv[i], "--json")) mode = "json";- else if (!strcmp(argv[i], "--markdown")) mode = "markdown";+ if (!fetch && !report && !strcmp(argv[i], "report")) report = 1;+ else if (!fetch && !report && !strcmp(argv[i], "fetch")) fetch = 1;+ else if (report && !strcmp(argv[i], "--json")) mode = "json";+ else if (report && !strcmp(argv[i], "--markdown")) mode = "markdown";+ else if (fetch && !strcmp(argv[i], "--share")) share = 1;+ else if (fetch && !strncmp(argv[i], "--color=", 8)+ && (!strcmp(argv[i] + 8, "auto") || !strcmp(argv[i] + 8, "always") || !strcmp(argv[i] + 8, "never"))) color = argv[i] + 8;else if (!strcmp(argv[i], "--root") && i + 1 < argc) root = argv[++i];- else return usage();+ else return usage(fetch);}- if (!report) return usage();+ if (!report && !fetch) return usage(0);SysReport *r = malloc(sizeof *r);if (!r) return 1;sysreport_collect(r, root, NULL, NULL);snprintf(r->sw.lordos, sizeof r->sw.lordos, "%s%s%s", LORD_VERSION, LORD_CHANNEL[0] ? "-" : "", LORD_CHANNEL);- char *out = !strcmp(mode, "json") ? sysreport_json(r) : sysreport_markdown(r);+ char *out;+ if (fetch) {+ FetchLive l;+ fetch_live(&l, root, share);+ out = fetch_render(r, &l, fetch_color_mode(color, isatty(1)));+ } else {+ out = !strcmp(mode, "json") ? sysreport_json(r) : sysreport_markdown(r);+ }free(r);- if (!out) { fprintf(stderr, "lordos-sysreport: out of memory\n"); return 1; }+ if (!out) { fprintf(stderr, "%s: out of memory\n", base); return 1; }fputs(out, stdout);free(out);return ferror(stdout) ? 1 : 0;diff --git a/server/src/sysreport/fetch.c b/server/src/sysreport/fetch.cnew file mode 100644index 0000000..8db1f09--- /dev/null+++ b/server/src/sysreport/fetch.c@@ -0,0 +1,290 @@+/* fetch.c — `lordos-fetch` (see fetch.h). The crown is pixel art drawn two pixels per character+ * cell with half blocks (▀ ▄), in the brand colors (docs/LORDOS-BRAND.md); without color it is plain+ * ASCII. */+#ifndef _GNU_SOURCE+#define _GNU_SOURCE+#endif+#include "fetch.h"+#include "../hw/jbuf.h"++#include <fcntl.h>+#include <pwd.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <sys/statvfs.h>+#include <unistd.h>++/* ---- the crown ---- */++/* 31 × 23 pixels: H gem highlight, Y gem, A gem shade, W white, L lavender shading, V band, B band+ * edge, '.' nothing. */+static const char *CROWN[] = {+ "...............H...............",+ "..............HHH..............",+ ".............HHYYY.............",+ "..............AAA..............",+ "...............A...............",+ "...H...........W...........H...",+ "..HHH.........WWL.........HHH..",+ ".HHYYY.......WWWLL.......HHYYY.",+ "..AAA........WWWLL........AAA..",+ "...A........WWWWLLL........A...",+ "...W.......WWWWWLLLW.......L...",+ "...WWW.....WWWWWLLLW.....LLL...",+ "...WWWW...WWWWWWLLLWW...LLLL...",+ "...WWWWW..WWWWWWLLLWW..LLLLL...",+ "...WWWWWW.WWWWWWWWWWW.WLLLLL...",+ "...WWWWWWWWWWWWWWWWWWWWLLLLL...",+ "...WWWWWWWWWWWWWWWWWWWWLLLLL...",+ "..BVVVVVVVVVVVVVVVVVVVVVVVVVB..",+ "..BVVVVVVVVVVVVVVVVVVVVVVVVVB..",+ "..WWWWWWWWWWWWWWWWWWWWWWLLLLL..",+ "..WWWWWWWWWWWWWWWWWWWWWWLLLLL..",+ "...WWWWWWWWWWWWWWWWWWWWWLLLL...",+ "...............................",+};+#define CROWN_H ((int)(sizeof CROWN / sizeof CROWN[0]))+#define CROWN_W 31++static const char *PLAIN[] = {+ " <> ",+ " <> / \\ <> ",+ " /\\ / \\ /\\ ",+ " | \\ / \\ / | ",+ " | \\ / \\ / | ",+ " | \\_/ \\_/ | ",+ " | | ",+ " |======================| ",+ " |______________________| ",+};++typedef struct { char key; unsigned char r, g, b, idx; } Pal;+static const Pal PAL[] = {+ { 'H', 0xff, 0xf1, 0xa8, 229 }, { 'Y', 0xff, 0xd6, 0x0a, 220 }, { 'A', 0xff, 0xb0, 0x00, 214 },+ { 'W', 0xff, 0xff, 0xff, 231 }, { 'L', 0xbd, 0xb1, 0xf5, 147 }, { 'V', 0x7c, 0x5c, 0xff, 99 },+ { 'B', 0x5b, 0x3f, 0xe0, 62 },+};++static const Pal *pal(char k) {+ for (size_t i = 0; i < sizeof PAL / sizeof PAL[0]; i++) if (PAL[i].key == k) return &PAL[i];+ return NULL;+}++static void fg(HBuf *b, const Pal *p, FetchColor c) {+ if (c == FETCH_TRUECOLOR) hb_printf(b, "\033[38;2;%d;%d;%dm", p->r, p->g, p->b);+ else hb_printf(b, "\033[38;5;%dm", p->idx);+}+static void bg(HBuf *b, const Pal *p, FetchColor c) {+ if (c == FETCH_TRUECOLOR) hb_printf(b, "\033[48;2;%d;%d;%dm", p->r, p->g, p->b);+ else hb_printf(b, "\033[48;5;%dm", p->idx);+}++/* One text row of the crown: pixel rows 2y and 2y+1. */+static void crown_row(HBuf *b, int y, FetchColor c) {+ if (c == FETCH_PLAIN) { hb_printf(b, "%-*s", CROWN_W, y < (int)(sizeof PLAIN / sizeof PLAIN[0]) ? PLAIN[y] : ""); return; }+ for (int x = 0; x < CROWN_W; x++) {+ const Pal *t = 2 * y < CROWN_H ? pal(CROWN[2 * y][x]) : NULL;+ const Pal *u = 2 * y + 1 < CROWN_H ? pal(CROWN[2 * y + 1][x]) : NULL;+ if (!t && !u) { hb_printf(b, " "); continue; }+ if (t && u && t == u) { fg(b, t, c); hb_printf(b, "█"); }+ else if (t && u) { fg(b, t, c); bg(b, u, c); hb_printf(b, "▀"); }+ else if (t) { fg(b, t, c); hb_printf(b, "▀"); }+ else { fg(b, u, c); hb_printf(b, "▄"); }+ hb_printf(b, "\033[0m");+ }+}++/* ---- live facts ---- */++static char *slurp(const char *path, size_t max) {+ int fd = open(path, O_RDONLY | O_CLOEXEC);+ if (fd < 0) return NULL;+ char *p = malloc(max + 1);+ size_t got = 0;+ while (p && got < max) {+ ssize_t n = read(fd, p + got, max - got);+ if (n <= 0) break;+ got += (size_t)n;+ }+ close(fd);+ if (p) p[got] = 0;+ return p;+}++static unsigned long long meminfo_kb(const char *txt, const char *key) {+ const char *p = txt ? strstr(txt, key) : NULL;+ return p ? strtoull(p + strlen(key) + 1, NULL, 10) : 0;+}++/* printable, no spaces: a user or host name for the screen */+static void clean(char *s) {+ for (; *s; s++) if (*s <= ' ' || *s >= 0x7f) *s = '?';+}++void fetch_live(FetchLive *l, const char *root, int share) {+ memset(l, 0, sizeof *l);+ char p[1024];+ if (!share) {+ struct passwd *pw = getpwuid(getuid());+ if (pw && pw->pw_name) snprintf(l->user, sizeof l->user, "%.63s", pw->pw_name);+ snprintf(p, sizeof p, "%s/proc/sys/kernel/hostname", root);+ char *h = slurp(p, 64);+ if (h) { h[strcspn(h, "\n")] = 0; snprintf(l->host, sizeof l->host, "%.63s", h); free(h); }+ clean(l->user);+ clean(l->host);+ }+ snprintf(p, sizeof p, "%s/proc/uptime", root);+ char *t = slurp(p, 128);+ l->uptime_s = t ? atol(t) : -1;+ free(t);+ snprintf(p, sizeof p, "%s/proc/meminfo", root);+ t = slurp(p, 16384);+ unsigned long long total = meminfo_kb(t, "MemTotal:"), avail = meminfo_kb(t, "MemAvailable:");+ l->mem_used_kb = total > avail ? total - avail : 0;+ free(t);+ struct statvfs vs;+ snprintf(p, sizeof p, "%s/", root);+ if (!statvfs(p, &vs)) {+ l->disk_total = (unsigned long long)vs.f_blocks * vs.f_frsize;+ l->disk_used = l->disk_total - (unsigned long long)vs.f_bfree * vs.f_frsize;+ }+ /* dpkg's status file: one "Status: install ok installed" per installed package */+ snprintf(p, sizeof p, "%s/var/lib/dpkg/status", root);+ t = slurp(p, 64u << 20);+ l->packages = t ? 0 : -1;+ for (const char *q = t; q && (q = strstr(q, "\nStatus: install ok installed")); q++) l->packages++;+ if (t && !strncmp(t, "Status: install ok installed", 28)) l->packages++;+ free(t);+ const char *sh = getenv("SHELL");+ if (sh && *sh) {+ const char *s = strrchr(sh, '/');+ snprintf(l->shell, sizeof l->shell, "%.31s", s ? s + 1 : sh);+ clean(l->shell);+ }+ snprintf(l->session, sizeof l->session, "%s", getenv("WAYLAND_DISPLAY") ? "Wayland" : getenv("DISPLAY") ? "X11" : "");+}++FetchColor fetch_color_mode(const char *opt, int is_tty) {+ const char *ct = getenv("COLORTERM");+ FetchColor full = ct && (strstr(ct, "truecolor") || strstr(ct, "24bit")) ? FETCH_TRUECOLOR : FETCH_256;+ if (opt && !strcmp(opt, "never")) return FETCH_PLAIN;+ if (opt && !strcmp(opt, "always")) return full;+ const char *term = getenv("TERM");+ if (!is_tty || getenv("NO_COLOR") || (term && !strcmp(term, "dumb"))) return FETCH_PLAIN;+ return full;+}++/* ---- the summary ---- */++#define LINES_MAX 24+typedef struct { char label[16]; char value[256]; } Line;++static void bytes_text(unsigned long long v, char *out, size_t n) {+ if (v >= 1000ULL * 1000 * 1000 * 1000) snprintf(out, n, "%.1f TB", v / 1e12);+ else if (v >= 10ULL * 1000 * 1000 * 1000) snprintf(out, n, "%.0f GB", v / 1e9);+ else snprintf(out, n, "%.1f GB", v / 1e9);+}++static int add(Line *ls, int n, const char *label, const char *value) {+ if (n >= LINES_MAX || !value || !value[0]) return n;+ snprintf(ls[n].label, sizeof ls[n].label, "%s", label);+ snprintf(ls[n].value, sizeof ls[n].value, "%s", value);+ return n + 1;+}++char *fetch_render(const SysReport *r, const FetchLive *l, FetchColor c) {+ Line ls[LINES_MAX];+ int n = 0;+ char v[256], a[96], b2[96];++ snprintf(v, sizeof v, "LordOS %s%s%s%s", r->sw.lordos, r->sw.os[0] ? " (" : "", r->sw.os, r->sw.os[0] ? ")" : "");+ n = add(ls, n, "OS", v);+ const SrMachine *m = &r->machine;+ snprintf(v, sizeof v, "%s%s%s", m->vendor, m->vendor[0] && m->product[0] ? " " : "", m->product);+ if (!v[0]) snprintf(v, sizeof v, "%s", m->model);+ if (m->virt[0]) { size_t o = strlen(v); snprintf(v + o, sizeof v - o, "%svirtual machine (%s)", o ? " · " : "", m->virt); }+ n = add(ls, n, "Computer", v);+ n = add(ls, n, "Kernel", r->sw.kernel);+ if (l->uptime_s >= 0) {+ long d = l->uptime_s / 86400, h = l->uptime_s % 86400 / 3600, mi = l->uptime_s % 3600 / 60;+ if (d) snprintf(v, sizeof v, "%ld d %ld h %ld min", d, h, mi);+ else if (h) snprintf(v, sizeof v, "%ld h %ld min", h, mi);+ else snprintf(v, sizeof v, "%ld min", mi);+ n = add(ls, n, "Uptime", v);+ }+ if (l->packages > 0) { snprintf(v, sizeof v, "%d (dpkg)", l->packages); n = add(ls, n, "Packages", v); }+ snprintf(v, sizeof v, "%s%s%s", l->shell, l->session[0] ? " · " : "", l->session[0] ? l->session : "");+ n = add(ls, n, "Shell", v);+ for (int i = 0; i < r->ndisplay; i++) {+ const SrDisplay *x = &r->display[i];+ if (x->pref_w) snprintf(a, sizeof a, "%d × %d", x->pref_w, x->pref_h); else snprintf(a, sizeof a, "%s", x->mode);+ snprintf(v, sizeof v, "%s%s%s", x->name[0] ? x->name : x->connector, a[0] ? ", " : "", a);+ if (x->diag_tenths) { size_t o = strlen(v); snprintf(v + o, sizeof v - o, ", %d\"", (x->diag_tenths + 5) / 10); }+ n = add(ls, n, "Display", v);+ }+ const SrCpu *cpu = &r->cpu;+ snprintf(v, sizeof v, "%s (%d)", cpu->model[0] ? cpu->model : cpu->arch, cpu->threads);+ if (cpu->max_mhz) { size_t o = strlen(v); snprintf(v + o, sizeof v - o, " @ %.2f GHz", cpu->max_mhz / 1000.0); }+ n = add(ls, n, "CPU", v);+ for (int i = 0; i < r->ngpu; i++) {+ const SrGpu *g = &r->gpu[i];+ if (!g->connectors && !g->render_node) continue;+ snprintf(a, sizeof a, "%s", g->device[0] ? g->device : g->vendor[0] ? g->vendor : g->card);+ snprintf(v, sizeof v, "%s%s%s%s", a, g->driver[0] ? " (" : "", g->driver, g->driver[0] ? ")" : "");+ n = add(ls, n, "GPU", v);+ }+ if (r->mem.total_kb) {+ bytes_text(l->mem_used_kb * 1024ULL, a, sizeof a);+ bytes_text(r->mem.total_kb * 1024ULL, b2, sizeof b2);+ snprintf(v, sizeof v, "%s / %s (%d %%)", a, b2, (int)(l->mem_used_kb * 100 / r->mem.total_kb));+ n = add(ls, n, "Memory", v);+ }+ if (l->disk_total) {+ bytes_text(l->disk_used, a, sizeof a);+ bytes_text(l->disk_total, b2, sizeof b2);+ snprintf(v, sizeof v, "%s / %s (%d %%)", a, b2, (int)(l->disk_used * 100 / l->disk_total));+ n = add(ls, n, "Disk (/)", v);+ }+ /* what keeps apps in their place (docs/PRIVACY.md, docs/FIREWALL.md) */+ v[0] = 0;+ if (r->sw.landlock_abi > 0) snprintf(v, sizeof v, "Landlock %d", r->sw.landlock_abi);+ if (r->sw.netperm == 1) { size_t o = strlen(v); snprintf(v + o, sizeof v - o, "%sapp firewall", o ? " · " : ""); }+ if (r->sw.cgroup2) { size_t o = strlen(v); snprintf(v + o, sizeof v - o, "%scgroup v2", o ? " · " : ""); }+ n = add(ls, n, "Isolation", v);++ HBuf b = { 0 };+ const Pal *violet = pal('V');+ /* the title: user@host (or the product) and a rule under it */+ char title[160];+ if (l->user[0] && l->host[0]) snprintf(title, sizeof title, "%s@%s", l->user, l->host);+ else snprintf(title, sizeof title, "LordOS");+ /* title, rule, the lines, and with color a blank line and the palette; at least the crown's height */+ int rows = n + (c == FETCH_PLAIN ? 2 : 4);+ if (rows < (CROWN_H + 1) / 2) rows = (CROWN_H + 1) / 2;+ if (rows < (int)(sizeof PLAIN / sizeof PLAIN[0])) rows = (int)(sizeof PLAIN / sizeof PLAIN[0]);+ for (int y = 0; y < rows; y++) {+ hb_printf(&b, " ");+ crown_row(&b, y, c);+ hb_printf(&b, " ");+ if (y == 0) {+ if (c != FETCH_PLAIN) { hb_printf(&b, "\033[1m"); fg(&b, violet, c); }+ hb_printf(&b, "%s", title);+ if (c != FETCH_PLAIN) hb_printf(&b, "\033[0m");+ } else if (y == 1) {+ for (size_t i = 0; i < strlen(title); i++) hb_printf(&b, "%s", c == FETCH_PLAIN ? "-" : "─");+ } else if (y - 2 < n) {+ const Line *x = &ls[y - 2];+ if (c != FETCH_PLAIN) { hb_printf(&b, "\033[1m"); fg(&b, violet, c); }+ hb_printf(&b, "%s", x->label);+ if (c != FETCH_PLAIN) hb_printf(&b, "\033[0m");+ hb_printf(&b, "%*s%s", 10 - (int)strlen(x->label), "", x->value);+ } else if (y - 2 == n + 1 && c != FETCH_PLAIN) {+ static const char keys[] = "HYAWLVB";+ for (const char *k = keys; *k; k++) { bg(&b, pal(*k), c); hb_printf(&b, " "); }+ hb_printf(&b, "\033[0m");+ }+ hb_printf(&b, "\n");+ }+ return hb_take(&b);+}diff --git a/server/src/sysreport/fetch.h b/server/src/sysreport/fetch.hnew file mode 100644index 0000000..2524a9c--- /dev/null+++ b/server/src/sysreport/fetch.h@@ -0,0 +1,33 @@+/* fetch.h — `lordos-fetch`: the crown and a short summary of this computer for a terminal, from the+ * same collector as System Information (sysreport.h), plus a few live facts (uptime, memory and disk+ * in use, packages, shell). The user and host names appear only on screen and only without --share,+ * so a screenshot made for sharing carries neither. */+#ifndef LORD_SYSREPORT_FETCH_H+#define LORD_SYSREPORT_FETCH_H++#include "sysreport.h"++typedef enum { FETCH_PLAIN, FETCH_256, FETCH_TRUECOLOR } FetchColor;++typedef struct {+ char user[64], host[64]; /* empty with --share */+ long uptime_s; /* -1 unknown */+ unsigned long long mem_used_kb; /* MemTotal − MemAvailable */+ unsigned long long disk_used, disk_total; /* the root file system, bytes */+ int packages; /* Debian packages installed, -1 unknown */+ char shell[32]; /* the login shell's name */+ char session[24]; /* "Wayland", "X11", "" */+} FetchLive;++/* The live facts from <root> (proc, dpkg status) and this process (user, shell, disk). share: no+ * user or host name. */+void fetch_live(FetchLive *l, const char *root, int share);++/* The whole output (malloc'd, NULL on out-of-memory): the crown beside the summary. */+char *fetch_render(const SysReport *r, const FetchLive *l, FetchColor color);++/* How to color stdout: --color=always|never|auto (auto: a terminal, no NO_COLOR, TERM not "dumb";+ * true color when COLORTERM says so). */+FetchColor fetch_color_mode(const char *opt, int is_tty);++#endifdiff --git a/server/tests/sysreport_test.c b/server/tests/sysreport_test.cindex 87f1912..b44187e 100644--- a/server/tests/sysreport_test.c+++ b/server/tests/sysreport_test.c@@ -5,10 +5,14 @@* and that none of those values reaches the JSON or the Markdown.** build/sysreport-test the tests (make test)+ * lordos-fetch's summary is checked on the same trees: with --share it carries none of those values+ * either, and without color it has no escape codes.+ ** build/sysreport-test fixture <dir> <kind> writes a fake tree (amd, intel, nvidia, rpi5, vm), for* `lordos-sysreport report --root <dir>` */#include "sysreport/sysreport.h"#include "sysreport/ids.h"+#include "sysreport/fetch.h"#include "sec/json.h"#include <errno.h>@@ -490,6 +494,35 @@ static void test_kind(const char *kind) {rmtree(root);}+static void test_fetch(const char *kind) {+ char root[] = "/tmp/sysreport-fetch-XXXXXX";+ if (!mkdtemp(root)) { printf("mkdtemp\n"); exit(2); }+ fixture(root, kind);+ SysReport *r = calloc(1, sizeof *r);+ sysreport_collect(r, root, NULL, NULL);+ snprintf(r->sw.lordos, sizeof r->sw.lordos, "0.8.5-beta");+ FetchLive l;+ fetch_live(&l, root, 1);+ CHECK(!l.user[0] && !l.host[0], "%s: --share has no names", kind);+ FetchColor modes[3] = { FETCH_PLAIN, FETCH_256, FETCH_TRUECOLOR };+ for (int m = 0; m < 3; m++) {+ char *out = fetch_render(r, &l, modes[m]);+ CHECK(out && contains(out, "LordOS 0.8.5-beta (Debian GNU/Linux 13 (trixie))") && contains(out, "CPU"), "%s/%d: fetch lines", kind, m);+ for (size_t i = 0; i < sizeof SECRETS / sizeof SECRETS[0]; i++)+ CHECK(!contains(out, SECRETS[i]), "%s/%d: fetch --share carries \"%s\"", kind, m, SECRETS[i]);+ CHECK(m != FETCH_PLAIN || !strchr(out, '\033'), "%s: plain fetch has escape codes", kind);+ CHECK(m != FETCH_TRUECOLOR || contains(out, "\033[38;2;255;214;10m"), "%s: true color gem", kind);+ CHECK(m != FETCH_256 || contains(out, "\033[38;5;220m"), "%s: 256-color gem", kind);+ free(out);+ }+ fetch_live(&l, root, 0);+ char *out = fetch_render(r, &l, FETCH_PLAIN);+ CHECK(contains(out, "@secret-host"), "%s: without --share the host is on screen", kind);+ free(out);+ free(r);+ rmtree(root);+}+static void test_empty(void) {char root[] = "/tmp/sysreport-empty-XXXXXX";if (!mkdtemp(root)) { printf("mkdtemp\n"); exit(2); }@@ -508,7 +541,13 @@ int main(int argc, char **argv) {}test_ids();const char *kinds[] = { "amd", "intel", "nvidia", "rpi5", "vm" };- for (size_t i = 0; i < sizeof kinds / sizeof kinds[0]; i++) test_kind(kinds[i]);+ for (size_t i = 0; i < sizeof kinds / sizeof kinds[0]; i++) { test_kind(kinds[i]); test_fetch(kinds[i]); }+ setenv("NO_COLOR", "1", 1);+ CHECK(fetch_color_mode("auto", 1) == FETCH_PLAIN && fetch_color_mode("always", 0) != FETCH_PLAIN, "NO_COLOR and --color=always");+ unsetenv("NO_COLOR");+ setenv("TERM", "xterm-256color", 1);+ setenv("COLORTERM", "truecolor", 1);+ CHECK(fetch_color_mode("auto", 1) == FETCH_TRUECOLOR && fetch_color_mode("auto", 0) == FETCH_PLAIN && fetch_color_mode("never", 1) == FETCH_PLAIN, "color modes");test_empty();printf("sysreport-test: %d ok, %d failed\n", n_ok, n_bad);return n_bad ? 1 : 0;diff --git a/tools/iso/mkdeb.sh b/tools/iso/mkdeb.shindex d5c170f..e8e2b2b 100755--- a/tools/iso/mkdeb.sh+++ b/tools/iso/mkdeb.sh@@ -9,6 +9,7 @@# /usr/lib/lordos/bin/lord-fand fan control by temperature (root, own service, enabled)# /usr/lib/lordos/bin/lord-server each session's server (looks for ../themes and ../assets)# /usr/bin/lordos-sysreport System Information's report as a command (user; docs/BENCHMARK.md)+# /usr/bin/lordos-fetch the crown and a summary of the computer (a link to lordos-sysreport)# /usr/lib/lordos/themes/<theme>/ theme.json, theme.bundle.js and their resources (greeter: the# login screen)# /usr/lib/lordos/assets/ fonts, texts (locales), icons, shell integration@@ -63,6 +64,7 @@ install -m 755 server/build/lordos-firstrun "$L/bin/lordos-firstrun"install -d "$PKG/usr/bin"install -m 755 server/build/lordos-sysreport "$PKG/usr/bin/lordos-sysreport"strip --strip-unneeded "$PKG/usr/bin/lordos-sysreport" 2>/dev/null || true+ln -s lordos-sysreport "$PKG/usr/bin/lordos-fetch"# isolated PDF and archive helper (optional: make skips it without libpoppler-glib-dev/libarchive-dev);# lord-server only launches the lord-doc in its own folder[ -x server/build/lord-doc ] && install -m 755 server/build/lord-doc "$L/bin/lord-doc"