clavarium 0.2.17 → 0.2.18-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deploy/clavarium-tunnel +51 -0
- package/deploy/install.sh +4 -22
- package/deploy/online.mjs +27 -0
- package/deploy/relay.sh +1 -1
- package/deploy/tunnel.mjs +73 -0
- package/deploy/updater.mjs +16 -4
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/main.mjs +1 -1
- package/server/updates.mjs +5 -0
- package/web/app.js +21 -0
- package/web/index.html +1 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# ---------------------------------------------------------------------------
|
|
3
|
+
# THE OUTGOING TUNNEL TO THE RELAY, as systemd runs it (clavarium-tunnel.service,
|
|
4
|
+
# written by install.sh and kept up to date by the updater). Root installs it at
|
|
5
|
+
# /usr/local/sbin/clavarium-tunnel; it runs as the clavarium-tunnel account.
|
|
6
|
+
#
|
|
7
|
+
# clavarium-tunnel RELAY PORT
|
|
8
|
+
#
|
|
9
|
+
# A CUT OF THE NETWORK is noticed in 20 to 30 seconds (a keepalive every 10 s,
|
|
10
|
+
# two missed), and the tunnel is tried again 5 s later by systemd, as long as it
|
|
11
|
+
# takes: a network that comes back finds it at once.
|
|
12
|
+
#
|
|
13
|
+
# A REFUSAL IS NOT A CUT: the relay refused the key, or answered with another
|
|
14
|
+
# host key than the one kept. Trying again every 5 s changes nothing, so this
|
|
15
|
+
# waits longer each time (30 s more each, 5 minutes at most) before it gives
|
|
16
|
+
# back to systemd, and says so in the journal. The first time it holds again,
|
|
17
|
+
# the count starts over.
|
|
18
|
+
# ---------------------------------------------------------------------------
|
|
19
|
+
set -u
|
|
20
|
+
[ $# -eq 2 ] || { echo "usage: clavarium-tunnel RELAY PORT" >&2; exit 64; }
|
|
21
|
+
relay="$1"; port="$2"
|
|
22
|
+
[[ "$relay" =~ ^[A-Za-z0-9.-]{1,253}$ ]] || { echo "clavarium-tunnel: not a host name: $relay" >&2; exit 64; }
|
|
23
|
+
[[ "$port" =~ ^[0-9]{1,5}$ ]] || { echo "clavarium-tunnel: not a port: $port" >&2; exit 64; }
|
|
24
|
+
home=/var/lib/clavarium-tunnel
|
|
25
|
+
# Kept across its restarts by systemd (RuntimeDirectory, RuntimeDirectoryPreserve).
|
|
26
|
+
count="${RUNTIME_DIRECTORY:-/run/clavarium-tunnel}/refused"
|
|
27
|
+
said="$(mktemp "${RUNTIME_DIRECTORY:-/tmp}/said.XXXXXX")" || said=/dev/null
|
|
28
|
+
trap 'rm -f "$said"' EXIT
|
|
29
|
+
|
|
30
|
+
started=$SECONDS
|
|
31
|
+
ssh -N -T -o BatchMode=yes -o IdentitiesOnly=yes -o "IdentityFile=$home/key" -o "UserKnownHostsFile=$home/known_hosts" \
|
|
32
|
+
-o StrictHostKeyChecking=yes -o ExitOnForwardFailure=yes -o ServerAliveInterval=10 -o ServerAliveCountMax=2 -o ConnectTimeout=15 \
|
|
33
|
+
-R '*:8443:127.0.0.1:443' -R '*:8080:127.0.0.1:80' -p "$port" "clavarium-tunnel@$relay" 2>"$said"
|
|
34
|
+
code=$?
|
|
35
|
+
# Said to the journal once it ended -- read through a second writer (tee) it could still be on its way
|
|
36
|
+
# when it was looked at (found on a CI runner): the refusal then passed for a cut.
|
|
37
|
+
cat "$said" >&2 2>/dev/null || true
|
|
38
|
+
|
|
39
|
+
if grep -qE 'Permission denied|Host key verification failed|REMOTE HOST IDENTIFICATION HAS CHANGED|No matching host key|Too many authentication failures' "$said" 2>/dev/null; then
|
|
40
|
+
n=$(( $(cat "$count" 2>/dev/null || echo 0) + 1 ))
|
|
41
|
+
echo "$n" > "$count" 2>/dev/null || true
|
|
42
|
+
step="${CLAVARIUM_TUNNEL_STEP:-30}"; [[ "$step" =~ ^[0-9]{1,3}$ ]] || step=30
|
|
43
|
+
delay=$(( n * step > 10 * step ? 10 * step : n * step ))
|
|
44
|
+
echo "clavarium-tunnel: the relay refused this machine (its key, or the relay's host key): not a cut of the network. Next try in ${delay} s. sudo clavarium doctor says more." >&2
|
|
45
|
+
sleep "$delay"
|
|
46
|
+
else
|
|
47
|
+
# A cut of the network, or a tunnel that held: tried again soon.
|
|
48
|
+
rm -f "$count" 2>/dev/null || true
|
|
49
|
+
[ $(( SECONDS - started )) -gt 60 ] && echo "clavarium-tunnel: the tunnel to $relay was lost (a cut of the network?): tried again in 5 s" >&2
|
|
50
|
+
fi
|
|
51
|
+
exit "$code"
|
package/deploy/install.sh
CHANGED
|
@@ -692,28 +692,10 @@ if [ -n "$RELAY" ]; then
|
|
|
692
692
|
printf '%s\n' "$scanned" > /var/lib/clavarium-tunnel/known_hosts
|
|
693
693
|
chown clavarium-tunnel:clavarium-tunnel /var/lib/clavarium-tunnel/known_hosts
|
|
694
694
|
fi
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
Wants=network-online.target
|
|
700
|
-
StartLimitIntervalSec=0
|
|
701
|
-
|
|
702
|
-
[Service]
|
|
703
|
-
User=clavarium-tunnel
|
|
704
|
-
Group=clavarium-tunnel
|
|
705
|
-
# Only TLS (443) and the certificate challenge (80) are carried.
|
|
706
|
-
ExecStart=/usr/bin/ssh -N -T -o BatchMode=yes -o IdentitiesOnly=yes -o IdentityFile=/var/lib/clavarium-tunnel/key -o UserKnownHostsFile=/var/lib/clavarium-tunnel/known_hosts -o StrictHostKeyChecking=yes -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o ConnectTimeout=15 -R *:8443:127.0.0.1:443 -R *:8080:127.0.0.1:80 -p $RELAY_PORT clavarium-tunnel@$RELAY
|
|
707
|
-
Restart=always
|
|
708
|
-
RestartSec=5
|
|
709
|
-
NoNewPrivileges=yes
|
|
710
|
-
ProtectSystem=strict
|
|
711
|
-
ProtectHome=yes
|
|
712
|
-
PrivateTmp=yes
|
|
713
|
-
|
|
714
|
-
[Install]
|
|
715
|
-
WantedBy=multi-user.target
|
|
716
|
-
TUNNEL
|
|
695
|
+
# The unit is the updater's (deploy/tunnel.mjs, tunnelUnit): one text, kept up to date by each update.
|
|
696
|
+
install -o root -g root -m 0755 "$APP/deploy/clavarium-tunnel" /usr/local/sbin/clavarium-tunnel
|
|
697
|
+
"$NODE_DIR/bin/node" --input-type=module -e 'const { tunnelUnit } = await import(process.argv[1]); process.stdout.write(tunnelUnit(process.argv[2], process.argv[3]));' \
|
|
698
|
+
"$APP/deploy/tunnel.mjs" "$RELAY" "$RELAY_PORT" > /etc/systemd/system/clavarium-tunnel.service
|
|
717
699
|
systemctl daemon-reload
|
|
718
700
|
systemctl enable --quiet clavarium-tunnel.service
|
|
719
701
|
systemctl restart clavarium-tunnel.service
|
package/deploy/online.mjs
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
* `sys`, so the tests can stand in for SSH, npm and DNS.
|
|
25
25
|
*/
|
|
26
26
|
import { spawn } from 'node:child_process';
|
|
27
|
+
import { relayOfUnit, TUNNEL_UNIT } from './tunnel.mjs';
|
|
27
28
|
import { createReadStream, existsSync, mkdirSync, readFileSync, writeFileSync, rmSync, mkdtempSync, renameSync, openSync, readSync, writeSync, closeSync } from 'node:fs';
|
|
28
29
|
import { promises as dns } from 'node:dns';
|
|
29
30
|
import { connect } from 'node:net';
|
|
@@ -185,6 +186,32 @@ export function relayVersion(P = PATHS) {
|
|
|
185
186
|
return /^RELAY_VERSION="([^"]+)"$/m.exec(text)?.[1];
|
|
186
187
|
}
|
|
187
188
|
|
|
189
|
+
/* THE RELAY KEPT AT THE VERSION THIS RELEASE NAMES, by the updater after an update (a relay change, such as
|
|
190
|
+
noticing a dead tunnel sooner, reaches it with no one typing "relay update-relay"). Only with the
|
|
191
|
+
maintenance key, and once per version (`done`: the file that keeps the last one brought). Resolves with
|
|
192
|
+
{ state, version?, why? }: none (no relay), no-key, current, brought, refused (the relay does not take
|
|
193
|
+
this key: set up without it), failed. */
|
|
194
|
+
export async function keepRelayCurrent(sys, P = PATHS, { done, unit = TUNNEL_UNIT } = {}) {
|
|
195
|
+
/* An older install kept no relay.conf: the relay is the one its tunnel goes to. */
|
|
196
|
+
let conf = readRelayConf(P);
|
|
197
|
+
if (!conf) { try { const at = relayOfUnit(readFileSync(unit, 'utf8')); if (at) conf = { HOST: at.relay, PORT: at.port }; } catch { /* no tunnel */ } }
|
|
198
|
+
if (!conf) return { state: 'none' };
|
|
199
|
+
if (!existsSync(keyFiles(P).keeper)) return { state: 'no-key' };
|
|
200
|
+
const version = relayVersion(P);
|
|
201
|
+
if (!version) return { state: 'none' };
|
|
202
|
+
let last = '';
|
|
203
|
+
try { last = readFileSync(done, 'utf8').trim(); } catch { /* never brought */ }
|
|
204
|
+
if (last === version) return { state: 'current', version };
|
|
205
|
+
const r = await keeper(sys, P, conf, ['update-relay', version]);
|
|
206
|
+
if (r.code !== 0) {
|
|
207
|
+
const said = `${r.stderr ?? ''}${r.stdout ?? ''}`;
|
|
208
|
+
if (/Permission denied|Host key verification failed|REMOTE HOST IDENTIFICATION/i.test(said)) return { state: 'refused', version, why: 'the relay does not take this server\'s maintenance key' };
|
|
209
|
+
return { state: 'failed', version, why: `the relay did not take ${version} (exit ${r.code})` };
|
|
210
|
+
}
|
|
211
|
+
writeFileSync(`${done}.new`, `${version}\n`); renameSync(`${done}.new`, done);
|
|
212
|
+
return { state: 'brought', version };
|
|
213
|
+
}
|
|
214
|
+
|
|
188
215
|
/* Takes the setup key out of the relay account it was put in, and checks it no longer opens it. */
|
|
189
216
|
export async function forgetSetupKey(sys, P, conf) {
|
|
190
217
|
const f = keyFiles(P);
|
package/deploy/relay.sh
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* THE TUNNEL TO THE RELAY (see deploy/clavarium-tunnel): its unit, one text for install.sh and the
|
|
2
|
+
* updater, and how the updater keeps it up to date. No side effect when imported. */
|
|
3
|
+
import { readFileSync, writeFileSync, renameSync, existsSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
/* THE TUNNEL TO THE RELAY, kept by the updater: written by install.sh with what was known then, an update
|
|
7
|
+
did not touch it. Its unit runs the program of the release (deploy/clavarium-tunnel, installed with the
|
|
8
|
+
other privileged programs): a cut of the network noticed in 20 to 30 s and tried again every 5 s, a refusal
|
|
9
|
+
tried again ever more slowly (found 22-10: a short cut kept the pages away for two minutes). The relay and
|
|
10
|
+
its port are read from the unit there, written as before or as now. Restarted only when it changed. */
|
|
11
|
+
export const TUNNEL_UNIT = '/etc/systemd/system/clavarium-tunnel.service';
|
|
12
|
+
export const TUNNEL_PROGRAM = '/usr/local/sbin/clavarium-tunnel';
|
|
13
|
+
export function tunnelUnit(relay, port, program = TUNNEL_PROGRAM) {
|
|
14
|
+
return `[Unit]
|
|
15
|
+
Description=Clavarium - the outgoing tunnel to the relay
|
|
16
|
+
After=network-online.target caddy.service
|
|
17
|
+
Wants=network-online.target
|
|
18
|
+
StartLimitIntervalSec=0
|
|
19
|
+
|
|
20
|
+
[Service]
|
|
21
|
+
User=clavarium-tunnel
|
|
22
|
+
Group=clavarium-tunnel
|
|
23
|
+
# Only TLS (443) and the certificate challenge (80) are carried: see ${program}.
|
|
24
|
+
ExecStart=${program} ${relay} ${port}
|
|
25
|
+
Restart=always
|
|
26
|
+
RestartSec=5
|
|
27
|
+
# What it counts of the relay's refusals, kept across its restarts.
|
|
28
|
+
RuntimeDirectory=clavarium-tunnel
|
|
29
|
+
RuntimeDirectoryPreserve=yes
|
|
30
|
+
NoNewPrivileges=yes
|
|
31
|
+
ProtectSystem=strict
|
|
32
|
+
ProtectHome=yes
|
|
33
|
+
PrivateTmp=yes
|
|
34
|
+
|
|
35
|
+
[Install]
|
|
36
|
+
WantedBy=multi-user.target
|
|
37
|
+
`;
|
|
38
|
+
}
|
|
39
|
+
export function relayOfUnit(text) {
|
|
40
|
+
const now = new RegExp(`^ExecStart=\\S+clavarium-tunnel ([A-Za-z0-9.-]{1,253}) (\\d{1,5})$`, 'm').exec(text);
|
|
41
|
+
if (now) return { relay: now[1], port: now[2] };
|
|
42
|
+
const before = /-p (\d{1,5}) clavarium-tunnel@([A-Za-z0-9.-]{1,253})\s*$/m.exec(text);
|
|
43
|
+
return before ? { relay: before[2], port: before[1] } : null;
|
|
44
|
+
}
|
|
45
|
+
/* `from`: the program of THIS release -- installed first when it differs (an older updater made the
|
|
46
|
+
release, and did not know it). */
|
|
47
|
+
export async function ensureTunnel({ file = TUNNEL_UNIT, program = TUNNEL_PROGRAM, from = fileURLToPath(new URL('./clavarium-tunnel', import.meta.url)), run } = {}) {
|
|
48
|
+
let text;
|
|
49
|
+
try { text = readFileSync(file, 'utf8'); } catch { return false; }
|
|
50
|
+
let installed = false;
|
|
51
|
+
if (existsSync(from) && (!existsSync(program) || !readFileSync(from).equals(readFileSync(program)))) {
|
|
52
|
+
const r = await run(['install', '-o', 'root', '-g', 'root', '-m', '0755', from, program], { timeoutMs: 30_000 });
|
|
53
|
+
if (r.code !== 0) throw new Error(`${program}: ${String(r.stderr || r.stdout || '').trim().split('\n').pop() || `exit ${r.code}`}`);
|
|
54
|
+
installed = true;
|
|
55
|
+
}
|
|
56
|
+
if (!existsSync(program)) return false;
|
|
57
|
+
const at = relayOfUnit(text);
|
|
58
|
+
if (!at) return false;
|
|
59
|
+
const wanted = tunnelUnit(at.relay, at.port, program);
|
|
60
|
+
if (text === wanted) {
|
|
61
|
+
/* The same unit, a new program: what runs now is the old one until it is started again. */
|
|
62
|
+
if (installed && process.getuid?.() === 0) await run(['systemctl', 'try-restart', 'clavarium-tunnel.service'], { timeoutMs: 60_000 });
|
|
63
|
+
return installed;
|
|
64
|
+
}
|
|
65
|
+
writeFileSync(`${file}.new`, wanted, { mode: 0o644 });
|
|
66
|
+
renameSync(`${file}.new`, file);
|
|
67
|
+
if (process.getuid?.() === 0) {
|
|
68
|
+
await run(['systemctl', 'daemon-reload'], { timeoutMs: 60_000 });
|
|
69
|
+
await run(['systemctl', 'try-restart', 'clavarium-tunnel.service'], { timeoutMs: 60_000 });
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
package/deploy/updater.mjs
CHANGED
|
@@ -53,7 +53,7 @@ import { dirname, join, basename } from 'node:path';
|
|
|
53
53
|
import { fileURLToPath } from 'node:url';
|
|
54
54
|
import { fetchParleyArchive, REGISTRY } from './parley-archive.mjs';
|
|
55
55
|
|
|
56
|
-
export const PATHS = { code: '/opt/clavarium', conf: '/etc/clavarium/update.conf', stateDir: '/var/lib/clavarium/update', data: '/home/clavarium', host: '/usr/local/sbin/clavarium-host', gitRead: '/usr/lib/clavarium/git-read' };
|
|
56
|
+
export const PATHS = { code: '/opt/clavarium', conf: '/etc/clavarium/update.conf', stateDir: '/var/lib/clavarium/update', data: '/home/clavarium', host: '/usr/local/sbin/clavarium-host', gitRead: '/usr/lib/clavarium/git-read', tunnel: '/usr/local/sbin/clavarium-tunnel' };
|
|
57
57
|
export const NAME = 'clavarium';
|
|
58
58
|
/* Where each package checked here must have been built: its provenance says so. */
|
|
59
59
|
export const REPOS = { clavarium: 'https://github.com/clavarium/clavarium', 'clavarium-parley': 'https://github.com/clavarium/clavarium-parley' };
|
|
@@ -173,10 +173,10 @@ const toHex = (integrity) => Buffer.from(String(integrity).replace(/^sha512-/, '
|
|
|
173
173
|
|
|
174
174
|
export class Updater {
|
|
175
175
|
#o; #run; #fetch;
|
|
176
|
-
constructor({ code = PATHS.code, conf = PATHS.conf, stateDir = PATHS.stateDir, data = PATHS.data, hostTarget = PATHS.host, gitReadTarget = PATHS.gitRead, registry = REGISTRY, run = runCommand, fetcher = fetch, now = () => new Date(), log = (line) => console.log(line),
|
|
176
|
+
constructor({ code = PATHS.code, conf = PATHS.conf, stateDir = PATHS.stateDir, data = PATHS.data, hostTarget = PATHS.host, gitReadTarget = PATHS.gitRead, tunnelTarget = PATHS.tunnel, registry = REGISTRY, run = runCommand, fetcher = fetch, now = () => new Date(), log = (line) => console.log(line),
|
|
177
177
|
verifySignatures, restart, health, backup, restoreData, installPrivileged, ensureNode, serviceState, answers, restarts, mainPid, pidCwd, diagnose, dropIn = DROP_IN,
|
|
178
178
|
clock = () => Date.now(), sleep = (ms) => new Promise((r) => setTimeout(r, ms)), minFreeMb = 1024, healthMs = 60_000, watchMs = 120_000, settleMs = 10_000 } = {}) {
|
|
179
|
-
this.#o = { code, conf, stateDir, data, hostTarget, gitReadTarget, registry: registry.replace(/\/$/, ''), now, log, minFreeMb, healthMs, watchMs, settleMs, clock, sleep, dropIn };
|
|
179
|
+
this.#o = { code, conf, stateDir, data, hostTarget, gitReadTarget, tunnelTarget, registry: registry.replace(/\/$/, ''), now, log, minFreeMb, healthMs, watchMs, settleMs, clock, sleep, dropIn };
|
|
180
180
|
this.#run = run; this.#fetch = fetcher;
|
|
181
181
|
this.verifySignatures = verifySignatures ?? ((dir) => this.#npm(['audit', 'signatures'], { cwd: dir, timeoutMs: 300_000 }));
|
|
182
182
|
this.restart = restart ?? (() => this.#restart());
|
|
@@ -756,7 +756,9 @@ export class Updater {
|
|
|
756
756
|
}
|
|
757
757
|
|
|
758
758
|
async #installPrivileged(app) {
|
|
759
|
-
for (const [from, to] of [[join(app, 'deploy', 'clavarium-host'), this.#o.hostTarget], [join(app, 'deploy', 'git-read'), this.#o.gitReadTarget]]) {
|
|
759
|
+
for (const [from, to] of [[join(app, 'deploy', 'clavarium-host'), this.#o.hostTarget], [join(app, 'deploy', 'git-read'), this.#o.gitReadTarget], [join(app, 'deploy', 'clavarium-tunnel'), this.#o.tunnelTarget]]) {
|
|
760
|
+
/* A release older than a program has none to give: the one there stays. */
|
|
761
|
+
if (!existsSync(from)) continue;
|
|
760
762
|
const r = await this.#run(['install', '-o', 'root', '-g', 'root', '-m', '0755', from, to], { timeoutMs: 30_000 });
|
|
761
763
|
if (r.code !== 0) throw new Error(`${to}: ${lastLine(r)}`);
|
|
762
764
|
}
|
|
@@ -808,6 +810,16 @@ async function main(argv) {
|
|
|
808
810
|
try { const [{ installWatch }, { realSys }] = await Promise.all([import('./doctor.mjs'), import('./online.mjs')]); if (await installWatch(realSys())) console.error('updater: the certificate timer set up'); } catch (error) { console.error(`updater: the certificate timer could not be set up: ${error.message}`); }
|
|
809
811
|
try { if (await u.ensureDropIn()) console.error('updater: the drop-in of the server\'s unit written'); } catch (error) { console.error(`updater: the drop-in could not be written: ${error.message}`); }
|
|
810
812
|
try { if (await ensureProxySettings()) console.error('updater: the sign-in proxy takes one CSRF cookie per sign-in'); } catch (error) { console.error(`updater: the sign-in proxy could not be set: ${error.message}`); }
|
|
813
|
+
try { if (await ensureTunnel({ run: runCommand })) console.error('updater: the tunnel to the relay notices a cut sooner'); } catch (error) { console.error(`updater: the tunnel could not be set: ${error.message}`); }
|
|
814
|
+
/* What became of the relay is kept beside the state, for Settings (server/updates.mjs: relay). */
|
|
815
|
+
try {
|
|
816
|
+
const { keepRelayCurrent, realSys } = await import('./online.mjs');
|
|
817
|
+
const outcome = await keepRelayCurrent(realSys(), undefined, { done: join(PATHS.stateDir, 'relay-version') }).catch((error) => ({ state: 'failed', why: error.message }));
|
|
818
|
+
if (outcome.state === 'brought') console.error('updater: the relay is at the version of this release');
|
|
819
|
+
if (outcome.state === 'refused' || outcome.state === 'failed') console.error(`updater: the relay could not be brought up to date: ${outcome.why}`);
|
|
820
|
+
writeFileSync(join(PATHS.stateDir, 'relay.json.new'), `${JSON.stringify({ ...outcome, at: new Date().toISOString() })}\n`, { mode: 0o644 });
|
|
821
|
+
renameSync(join(PATHS.stateDir, 'relay.json.new'), join(PATHS.stateDir, 'relay.json'));
|
|
822
|
+
} catch (error) { console.error(`updater: the relay could not be looked at: ${error.message}`); }
|
|
811
823
|
const r = await u.runOnce(); console.log(typeof r === 'string' ? r : 'done'); return; }
|
|
812
824
|
case 'set': if (rest.length !== 2) throw new Refused('set <mode|channel|window|port> <value>'); return print(u.set(rest[0], rest[1]));
|
|
813
825
|
case 'prepare': { const r = await u.prepare({ version: value('--version'), fromDir: value('--from-dir') }); console.log(r.id); return; }
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.18-next.4",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.18-next.4",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/main.mjs
CHANGED
|
@@ -378,7 +378,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
378
378
|
for (const name of all.awake()) {
|
|
379
379
|
await toolbox.installIn(name).catch(() => {});
|
|
380
380
|
if (!toolbox.stale(name)) continue;
|
|
381
|
-
try { if (talk.event(name, { kind: 'tools-updated', text: '
|
|
381
|
+
try { if (talk.event(name, { kind: 'tools-updated', text: 'Tools updated: restart it to use them all. Its work picks up where it was.', topic: 'Tools', actions: ['restart'] })) toolbox.told(name); } catch { /* its chat is off */ }
|
|
382
382
|
}
|
|
383
383
|
});
|
|
384
384
|
/* The health of each machine, and folders that came loose put back: see health.mjs. */
|
package/server/updates.mjs
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { readFileSync, existsSync } from 'node:fs';
|
|
16
16
|
import { spawnSync } from 'node:child_process';
|
|
17
|
+
import { dirname, join } from 'node:path';
|
|
17
18
|
import { Refusal } from './conversations.mjs';
|
|
18
19
|
import { compareVersions, inWindow } from '../deploy/updater.mjs';
|
|
19
20
|
|
|
@@ -56,6 +57,8 @@ function timerLastRun() {
|
|
|
56
57
|
}
|
|
57
58
|
const firstLine = (text) => String(text ?? '').trim().split('\n').filter(Boolean).pop()?.replace(/^REFUSED: /, '').slice(0, 300) ?? '';
|
|
58
59
|
|
|
60
|
+
const RELAY_STATES = ['none', 'no-key', 'current', 'brought', 'refused', 'failed'];
|
|
61
|
+
|
|
59
62
|
export class Updates {
|
|
60
63
|
#host; #state; #conf; #version; #store; #alerts; #timer; #lastLook; #lastLookCache = { at: 0, value: null };
|
|
61
64
|
|
|
@@ -94,6 +97,8 @@ export class Updates {
|
|
|
94
97
|
refused: s.refused ?? null,
|
|
95
98
|
/* What can be gone back to: the kept releases that do not run. */
|
|
96
99
|
back: releases.filter((r) => !r.current && (VERSION.test(r.id) || LOCAL.test(r.id))).map((r) => ({ id: r.id, version: r.version })),
|
|
100
|
+
/* What became of the relay at the updater's last turn (deploy/updater.mjs, relay.json beside the state). */
|
|
101
|
+
relay: (() => { try { const r = JSON.parse(readFileSync(join(dirname(this.#state), 'relay.json'), 'utf8')); return RELAY_STATES.includes(r.state) ? { state: r.state, version: typeof r.version === 'string' ? r.version : null, why: typeof r.why === 'string' ? r.why.slice(0, 300) : null, at: typeof r.at === 'string' ? r.at : null } : null; } catch { return null; } })(),
|
|
97
102
|
history: (Array.isArray(s.history) ? s.history : []).slice(0, HISTORY_SHOWN).map(({ at, action, from, to, result, why, log }) => ({ at, action, from, to, result, why: why ?? null, log: typeof log === 'string' ? log : null })),
|
|
98
103
|
};
|
|
99
104
|
}
|
package/web/app.js
CHANGED
|
@@ -609,6 +609,16 @@
|
|
|
609
609
|
};
|
|
610
610
|
}
|
|
611
611
|
|
|
612
|
+
/* THE NETWORK CAME BACK (the browser says so, found 22-10: a short cut kept the pages away): what was open
|
|
613
|
+
is opened again at once, rather than when a connection that died without a word is noticed. */
|
|
614
|
+
addEventListener('online', () => {
|
|
615
|
+
void refresh();
|
|
616
|
+
if (!current || !socket || !wanted) return;
|
|
617
|
+
const dead = socket; socket = undefined;
|
|
618
|
+
try { dead.close(); } catch { /* gone */ }
|
|
619
|
+
connect();
|
|
620
|
+
});
|
|
621
|
+
|
|
612
622
|
terminal.onData(send);
|
|
613
623
|
terminal.onResize(sendSize);
|
|
614
624
|
new ResizeObserver(() => fit.fit()).observe($('terminal'));
|
|
@@ -3591,6 +3601,17 @@
|
|
|
3591
3601
|
if (!u) { if (updatesBusy && !$('settings').hidden) updatesTimer = setTimeout(() => { void paintUpdates(); }, 3000); return; }
|
|
3592
3602
|
lastUpdates = u;
|
|
3593
3603
|
$('updates-version').textContent = `Clavarium ${u.version ?? ''}`;
|
|
3604
|
+
/* Its relay, kept at the version of each release by the updater -- or why not, and what to do once. */
|
|
3605
|
+
const relay = u.relay;
|
|
3606
|
+
const RELAY_SAID = {
|
|
3607
|
+
brought: (r) => `The relay was brought to ${r.version} with this update.`,
|
|
3608
|
+
current: (r) => `The relay is up to date (${r.version}).`,
|
|
3609
|
+
refused: () => 'The relay does not take this server\'s maintenance key, so it is not kept up to date by itself. Once: on this server, sudo clavarium key gives its two keys; on the relay, run relay.sh again with --key and --keeper-key.',
|
|
3610
|
+
'no-key': () => 'This server has no maintenance key for its relay: the relay is not kept up to date by itself (sudo clavarium online --relay HOST sets one up).',
|
|
3611
|
+
failed: (r) => `The relay could not be brought up to date: ${r.why ?? 'unknown'}. Tried again at the next turn of the updater.`,
|
|
3612
|
+
};
|
|
3613
|
+
$('updates-relay').hidden = !relay || !RELAY_SAID[relay.state];
|
|
3614
|
+
if (relay && RELAY_SAID[relay.state]) { $('updates-relay').textContent = RELAY_SAID[relay.state](relay); $('updates-relay').dataset.state = relay.state; }
|
|
3594
3615
|
paintUpdatesWhen(u);
|
|
3595
3616
|
void paintCertificate();
|
|
3596
3617
|
for (const id of ['updates-check', 'updates-settings', 'updates-back']) $(id).hidden = !u.installed;
|
package/web/index.html
CHANGED
|
@@ -711,6 +711,7 @@
|
|
|
711
711
|
<div id="updates" tabindex="-1">
|
|
712
712
|
<div class="updates-head"><b id="updates-version"></b><span id="updates-state" role="status"></span><button type="button" id="updates-check">Check now</button></div>
|
|
713
713
|
<p id="updates-news" class="updates-news" hidden></p>
|
|
714
|
+
<p id="updates-relay" class="hint" hidden></p>
|
|
714
715
|
<!-- What the front serves to a browser (server/certificate.mjs). -->
|
|
715
716
|
<p id="updates-certificate" class="hint" role="status" hidden></p>
|
|
716
717
|
<div class="row" id="updates-offer" hidden><button type="button" id="updates-apply" class="primary"></button><button type="button" id="updates-retry-yes" class="primary" hidden>Try again</button><button type="button" id="updates-retry-no" hidden>Cancel</button><span class="hint" id="updates-retry-note" hidden></span></div>
|