@durableintel/nenya 0.0.0-stage → 1.2.1
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/README.md +392 -2
- package/bin/nenya.cjs +25 -0
- package/bin/nenya.js +72 -0
- package/bin/start.cjs +9 -0
- package/lib/cli.mjs +305 -0
- package/lib/feedenv.mjs +124 -0
- package/lib/filefeed.mjs +40 -0
- package/lib/install.mjs +579 -0
- package/lib/linux.mjs +156 -0
- package/lib/message.mjs +752 -0
- package/lib/release.mjs +120 -0
- package/lib/tools.mjs +227 -0
- package/lib/verify.mjs +146 -0
- package/lib/windows.mjs +395 -0
- package/package.json +25 -4
- package/release-keys.pub +8 -0
package/lib/linux.mjs
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Linux is "one admin install" (operator O2): this command never installs there. It prints the
|
|
2
|
+
// repository set-up from scripts/release/linux-repos/INSTALL.md (the files the nenya-app package
|
|
3
|
+
// itself writes), as single lines, and the one package-manager line for the `nenya-app` package.
|
|
4
|
+
// On Arch (and ID_LIKE=arch) it prints the AUR package's lines instead (#6321): nenya-app-bin, the
|
|
5
|
+
// release's .deb repackaged (scripts/release/aur), built and installed the standard AUR way.
|
|
6
|
+
|
|
7
|
+
export const LINUX_PACKAGE = "nenya-app";
|
|
8
|
+
export const AUR_PACKAGE = "nenya-app-bin";
|
|
9
|
+
|
|
10
|
+
// "apt" for the Debian family, "dnf" for the Fedora/RHEL family, "pacman" for Arch and its family,
|
|
11
|
+
// null when os-release says none of them (then the apt and dnf lines are printed).
|
|
12
|
+
export function linuxFamily(osRelease = "") {
|
|
13
|
+
const fields = new Map();
|
|
14
|
+
for (const line of osRelease.split("\n")) {
|
|
15
|
+
const match = /^([A-Z_]+)=("?)(.*)\2$/.exec(line.trim());
|
|
16
|
+
if (match) fields.set(match[1], match[3]);
|
|
17
|
+
}
|
|
18
|
+
const ids = `${fields.get("ID") ?? ""} ${fields.get("ID_LIKE") ?? ""}`
|
|
19
|
+
.toLowerCase()
|
|
20
|
+
.split(/\s+/);
|
|
21
|
+
if (ids.some((id) => ["debian", "ubuntu"].includes(id))) return "apt";
|
|
22
|
+
if (ids.some((id) => ["fedora", "rhel", "centos"].includes(id))) {
|
|
23
|
+
return "dnf";
|
|
24
|
+
}
|
|
25
|
+
if (ids.includes("arch")) return "pacman";
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The paths and contents are the ones the nenya-app package itself writes when it adds its repository
|
|
30
|
+
// (apps/desktop/scripts/forge-linux-repo.mts, packaging/deb/postinst, packaging/rpm/post; D116): the
|
|
31
|
+
// package then finds the same file at the same path, never a second entry. The first line is the marker
|
|
32
|
+
// the package and install.sh write too: purging or erasing nenya-app removes a marked file that names
|
|
33
|
+
// only Nenya's repository, and the keyring once no source names it and it holds exactly Nenya's key.
|
|
34
|
+
// apt 3 refuses any source list naming one repository twice with different Signed-By ("Conflicting
|
|
35
|
+
// values set for option Signed-By"), so the lines first take away what the lines before alpha.21 wrote
|
|
36
|
+
// for this feed (harness.sources with /etc/apt/keyrings/harness-archive-keyring.gpg, harness.repo), by
|
|
37
|
+
// the package's rule: only a file exactly as written for this feed (any channel, whitespace aside), and
|
|
38
|
+
// its key only when nothing else names it. Any other one there (edited, disabled, pointed at a mirror,
|
|
39
|
+
// another feed's), or one rm cannot remove, stays, and then the lines stop there with one line saying
|
|
40
|
+
// how to switch (each line but the last ends in &&), so ours is not added.
|
|
41
|
+
export const MANAGED_MARKER =
|
|
42
|
+
"# Managed by Nenya (nenya-app). Removed when nenya-app is purged.";
|
|
43
|
+
export const APT_SOURCE = "/etc/apt/sources.list.d/nenya.sources";
|
|
44
|
+
export const APT_KEYRING = "/usr/share/keyrings/nenya-archive-keyring.gpg";
|
|
45
|
+
export const YUM_REPO = "/etc/yum.repos.d/nenya.repo";
|
|
46
|
+
const LEGACY_APT_SOURCE = "/etc/apt/sources.list.d/harness.sources";
|
|
47
|
+
const LEGACY_APT_KEYRING = "/etc/apt/keyrings/harness-archive-keyring.gpg";
|
|
48
|
+
const LEGACY_YUM = "/etc/yum.repos.d/harness.repo";
|
|
49
|
+
// The test key the repositories were signed with before alpha.21 (apps/desktop/build/test-signing): RPM 6
|
|
50
|
+
// deletes it by fingerprint, RPM 4 by its entry's exact name (key id and creation time).
|
|
51
|
+
const TEST_KEY = "4930b71777030e235cf7d9bb94e59bf3a70d4999";
|
|
52
|
+
const TEST_KEY_RPM4 = "gpg-pubkey-a70d4999-6ace3a01";
|
|
53
|
+
|
|
54
|
+
// One command over several lines: pasted together, they stop at the first line that fails.
|
|
55
|
+
const chain = (commands) =>
|
|
56
|
+
commands.map((command, i) =>
|
|
57
|
+
i < commands.length - 1 ? `${command} &&` : command,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// Removes the harness.sources earlier lines wrote for this feed when it is exactly as written (with its
|
|
61
|
+
// keyring, unless another source names it); fails, leaving it, when it is anything else or cannot be removed.
|
|
62
|
+
function aptMigration(baseUrl) {
|
|
63
|
+
const uri = `${baseUrl}/linux/apt`;
|
|
64
|
+
return String.raw`sudo sh -c 'f=${LEGACY_APT_SOURCE} k=${LEGACY_APT_KEYRING}; [ -e "$f" ] || [ -L "$f" ] || exit 0; t=$(sed "s/[[:space:]]\{1,\}/ /g; s/^ //; s/ \$//; /^\$/d" "$f"); for c in stable beta alpha; do [ "$t" = "$(printf "Types: deb\nURIs: %s\nSuites: %s\nComponents: main\nSigned-By: %s" "${uri}" "$c" "$k")" ] || continue; rm "$f" || exit 1; grep -qsF "$k" /etc/apt/sources.list /etc/apt/sources.list.d/* || rm -f "$k"; exit 0; done; echo "$f is not as an earlier nenya setup wrote it, so it stays and the Nenya source is not added; to switch, delete it and run these lines again" >&2; exit 1'`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// The same for harness.repo, as nenya setup ([harness-desktop]) or INSTALL.md ([harness]) wrote it, and the
|
|
68
|
+
// test key dnf imported for it unless another repository file still names the old keyring.
|
|
69
|
+
function dnfMigration(baseUrl) {
|
|
70
|
+
return String.raw`sudo sh -c 'f=${LEGACY_YUM}; [ -e "$f" ] || [ -L "$f" ] || exit 0; t=$(sed "s/[[:space:]]\{1,\}/ /g; s/^ //; s/ \$//; s/^\([a-z_]*\) *= */\1=/; /^\$/d" "$f"); for c in stable beta alpha; do for s in harness harness-desktop; do [ "$t" = "$(printf "[%s]\nname=Harness desktop (%s)\nbaseurl=%s/linux/yum/%s/\$basearch\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\nmetadata_expire=6h\ngpgkey=%s/linux/harness-archive-keyring.asc" "$s" "$c" "${baseUrl}" "$c" "${baseUrl}")" ] || continue; rm "$f" || exit 1; grep -qsF harness-archive-keyring /etc/yum.repos.d/*.repo || rpmkeys --delete ${TEST_KEY} >/dev/null 2>&1 || rpm -e ${TEST_KEY_RPM4} >/dev/null 2>&1 || true; exit 0; done; done; echo "$f is not as an earlier nenya setup wrote it, so it stays and the Nenya repository is not added; to switch, delete it and run these lines again" >&2; exit 1'`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function aptLines(baseUrl, channel, repair) {
|
|
74
|
+
const source = [
|
|
75
|
+
MANAGED_MARKER,
|
|
76
|
+
"Types: deb",
|
|
77
|
+
`URIs: ${baseUrl}/linux/apt`,
|
|
78
|
+
`Suites: ${channel}`,
|
|
79
|
+
"Components: main",
|
|
80
|
+
`Signed-By: ${APT_KEYRING}`,
|
|
81
|
+
];
|
|
82
|
+
return chain([
|
|
83
|
+
aptMigration(baseUrl),
|
|
84
|
+
`sudo curl -fsSLo ${APT_KEYRING} ${baseUrl}/linux/nenya-archive-keyring.gpg`,
|
|
85
|
+
`sudo chmod 0644 ${APT_KEYRING}`,
|
|
86
|
+
`printf '%s\\n' ${source.map((l) => `'${l}'`).join(" ")} | sudo tee ${APT_SOURCE} >/dev/null`,
|
|
87
|
+
"sudo apt-get update",
|
|
88
|
+
repair
|
|
89
|
+
? `sudo apt-get install --reinstall ${LINUX_PACKAGE}`
|
|
90
|
+
: `sudo apt-get install ${LINUX_PACKAGE}`,
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function dnfLines(baseUrl, channel, repair) {
|
|
95
|
+
const repo = [
|
|
96
|
+
MANAGED_MARKER,
|
|
97
|
+
"[nenya]",
|
|
98
|
+
`name=Nenya desktop (${channel})`,
|
|
99
|
+
`baseurl=${baseUrl}/linux/yum/${channel}/$basearch`,
|
|
100
|
+
"enabled=1",
|
|
101
|
+
"gpgcheck=1",
|
|
102
|
+
"repo_gpgcheck=1",
|
|
103
|
+
"metadata_expire=6h",
|
|
104
|
+
`gpgkey=${baseUrl}/linux/nenya-archive-keyring.asc`,
|
|
105
|
+
];
|
|
106
|
+
return chain([
|
|
107
|
+
dnfMigration(baseUrl),
|
|
108
|
+
`printf '%s\\n' ${repo.map((l) => `'${l}'`).join(" ")} | sudo tee ${YUM_REPO} >/dev/null`,
|
|
109
|
+
repair
|
|
110
|
+
? `sudo dnf reinstall ${LINUX_PACKAGE}`
|
|
111
|
+
: `sudo dnf install ${LINUX_PACKAGE}`,
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// The lines to print: what to run, then the invite code to pass on.
|
|
116
|
+
export function linuxLines({ family, baseUrl, channel, repair, invite }) {
|
|
117
|
+
const lines = [
|
|
118
|
+
repair
|
|
119
|
+
? "On Linux an administrator installs Nenya again with these package-manager lines:"
|
|
120
|
+
: "On Linux an administrator installs Nenya once with these package-manager lines:",
|
|
121
|
+
"",
|
|
122
|
+
];
|
|
123
|
+
const blocks = [];
|
|
124
|
+
// The AUR's own route (makepkg checks the .deb's pinned sha256 and pacman installs the package); an AUR
|
|
125
|
+
// helper (yay -S nenya-app-bin) does the same, and its updates bring each stable release. Repair runs where
|
|
126
|
+
// setup's checkout already is, which git clone refuses, so it updates that one (#6379).
|
|
127
|
+
const clone = `git clone https://aur.archlinux.org/${AUR_PACKAGE}.git`;
|
|
128
|
+
if (family === "pacman")
|
|
129
|
+
blocks.push([
|
|
130
|
+
"Arch Linux:",
|
|
131
|
+
chain([
|
|
132
|
+
repair
|
|
133
|
+
? `if [ -d ${AUR_PACKAGE} ]; then git -C ${AUR_PACKAGE} pull --ff-only; else ${clone}; fi`
|
|
134
|
+
: clone,
|
|
135
|
+
`cd ${AUR_PACKAGE}`,
|
|
136
|
+
"makepkg -si",
|
|
137
|
+
]),
|
|
138
|
+
]);
|
|
139
|
+
if (family !== "pacman" && family !== "dnf")
|
|
140
|
+
blocks.push(["Debian and Ubuntu:", aptLines(baseUrl, channel, repair)]);
|
|
141
|
+
if (family !== "pacman" && family !== "apt")
|
|
142
|
+
blocks.push([
|
|
143
|
+
"Fedora and other dnf systems:",
|
|
144
|
+
dnfLines(baseUrl, channel, repair),
|
|
145
|
+
]);
|
|
146
|
+
for (const [title, commands] of blocks) {
|
|
147
|
+
if (blocks.length > 1) lines.push(title);
|
|
148
|
+
lines.push(...commands.map((command) => ` ${command}`), "");
|
|
149
|
+
}
|
|
150
|
+
if (invite) {
|
|
151
|
+
lines.push(
|
|
152
|
+
`Your invite code is ${invite}: Nenya asks for it when you sign up.`,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
return lines;
|
|
156
|
+
}
|