akanjs 3.3.0 → 3.4.0-rc.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/common/PipelinePlanSchema.ts +31 -7
- package/common/index.ts +6 -0
- package/common/pipelinePlan.ts +31 -5
- package/index.ts +7 -5
- package/package.json +1 -1
- package/pipelineConfig.ts +25 -2
- package/service/agentLoop/agentLoop.ts +19 -12
- package/service/predefinedAdaptor/anthropicTools.ts +8 -2
- package/types/common/index.d.ts +1 -1
- package/types/common/pipelinePlan.d.ts +35 -6
- package/types/index.d.ts +7 -5
- package/types/pipelineConfig.d.ts +20 -3
- package/types/server/logging/rotatingLogWriter.d.ts +1 -1
- package/types/service/predefinedAdaptor/anthropicTools.d.ts +1 -0
- package/types/vendor/@akanjs/native/packages/cli/src/api-updates.d.ts +149 -0
- package/types/vendor/@akanjs/native/packages/cli/src/api.d.ts +16 -162
- package/types/vendor/@akanjs/native/packages/cli/src/config.d.ts +3 -2
- package/types/vendor/@akanjs/native/packages/cli/src/lib/api-task.d.ts +79 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/prepare.d.ts +1 -1
- package/types/vendor/@akanjs/native/packages/cli/src/lib/publish.d.ts +17 -5
- package/types/vendor/@akanjs/native/packages/cli/src/lib/updates.d.ts +29 -2
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/desktop-update.d.ts +36 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/linux-install.d.ts +15 -0
- package/types/vendor/@akanjs/native/packages/core/src/kernel.d.ts +16 -5
- package/types/vendor/@akanjs/native/packages/desktop/src/commands.d.ts +81 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/deeplinks.d.ts +5 -1
- package/types/vendor/@akanjs/native/packages/desktop/src/dispatcher.d.ts +3 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/lifecycle.d.ts +8 -1
- package/types/vendor/@akanjs/native/packages/desktop/src/plugin.d.ts +21 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/server.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/updates/src/desktop.d.ts +4 -4
- package/types/vendor/@akanjs/native/plugins/updates/src/reports.d.ts +49 -0
- package/types/vendor/@akanjs/native/plugins/updates/src/signer.d.ts +21 -0
- package/types/vendor/@akanjs/native/plugins/window/src/index.d.ts +55 -3
- package/vendor/@akanjs/native/native/desktop/src/lib.rs +209 -54
- package/vendor/@akanjs/native/packages/cli/src/api-updates.ts +332 -0
- package/vendor/@akanjs/native/packages/cli/src/api.ts +67 -419
- package/vendor/@akanjs/native/packages/cli/src/commands/build.ts +4 -1
- package/vendor/@akanjs/native/packages/cli/src/config.ts +3 -2
- package/vendor/@akanjs/native/packages/cli/src/lib/api-task.ts +223 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/prepare.ts +2 -7
- package/vendor/@akanjs/native/packages/cli/src/lib/publish.ts +164 -19
- package/vendor/@akanjs/native/packages/cli/src/lib/updates.ts +90 -3
- package/vendor/@akanjs/native/packages/cli/src/platforms/desktop-update.ts +195 -43
- package/vendor/@akanjs/native/packages/cli/src/platforms/linux-appimage.ts +1 -1
- package/vendor/@akanjs/native/packages/cli/src/platforms/linux-install.ts +206 -0
- package/vendor/@akanjs/native/packages/cli/src/platforms/linux.ts +5 -1
- package/vendor/@akanjs/native/packages/core/src/kernel.ts +21 -6
- package/vendor/@akanjs/native/packages/core/vectors/updates.json +2 -1
- package/vendor/@akanjs/native/packages/desktop/src/commands.ts +380 -0
- package/vendor/@akanjs/native/packages/desktop/src/deeplinks.ts +20 -3
- package/vendor/@akanjs/native/packages/desktop/src/dispatcher.ts +28 -13
- package/vendor/@akanjs/native/packages/desktop/src/host.ts +6 -18
- package/vendor/@akanjs/native/packages/desktop/src/lifecycle.ts +8 -1
- package/vendor/@akanjs/native/packages/desktop/src/plugin.ts +21 -0
- package/vendor/@akanjs/native/packages/desktop/src/server.ts +1 -1
- package/vendor/@akanjs/native/plugins/updates/src/desktop.ts +90 -164
- package/vendor/@akanjs/native/plugins/updates/src/reports.ts +255 -0
- package/vendor/@akanjs/native/plugins/updates/src/signer.ts +133 -0
- package/vendor/@akanjs/native/plugins/window/native-plugin.json +6 -1
- package/vendor/@akanjs/native/plugins/window/src/desktop.ts +20 -4
- package/vendor/@akanjs/native/plugins/window/src/index.ts +55 -3
|
@@ -4,12 +4,23 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync
|
|
|
4
4
|
import { basename, dirname, join } from "node:path";
|
|
5
5
|
import { createDelta } from "../../../desktop/src/delta.ts";
|
|
6
6
|
import { runtimeVersion } from "../lib/boot.ts";
|
|
7
|
-
import { execOrThrow } from "../lib/exec.ts";
|
|
7
|
+
import { currentSignal, exec, execOrThrow } from "../lib/exec.ts";
|
|
8
8
|
import { CliError, dim, log } from "../lib/log.ts";
|
|
9
9
|
import type { BuildContext } from "../lib/prepare.ts";
|
|
10
10
|
import { hostArch, sha256, type UpdateEnvelope, type UpdateManifest } from "../lib/updates.ts";
|
|
11
11
|
import { type DesktopOs, resourcesOf } from "./desktop.ts";
|
|
12
12
|
|
|
13
|
+
type Patch = NonNullable<UpdateManifest["patches"]>[number];
|
|
14
|
+
|
|
15
|
+
/** A release's tar, named by its sha256: what a delta to the next release starts from. */
|
|
16
|
+
export interface AppArchive {
|
|
17
|
+
sha256: string;
|
|
18
|
+
tar: Uint8Array;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A pack's manifest, beside its `app/` or `files/`, with what the signer decides left empty. */
|
|
22
|
+
export const PACK_TEMPLATE = "manifest.template.json";
|
|
23
|
+
|
|
13
24
|
const TAR: Record<DesktopOs, string[]> = {
|
|
14
25
|
macos: ["/usr/bin/tar", "--no-mac-metadata"],
|
|
15
26
|
windows: ["tar.exe"],
|
|
@@ -52,65 +63,206 @@ function previousTar(out: string, previous: Partial<UpdateManifest>): Uint8Array
|
|
|
52
63
|
return sha256(tar) === archive.sha256 ? tar : null;
|
|
53
64
|
}
|
|
54
65
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
os: DesktopOs,
|
|
58
|
-
app: string,
|
|
59
|
-
out: string,
|
|
60
|
-
channel: string,
|
|
61
|
-
sequence: number,
|
|
62
|
-
): Promise<{ manifest: UpdateManifest; leftovers: string[] }> {
|
|
63
|
-
const { config } = ctx.project;
|
|
64
|
-
const server = existsSync(join(resourcesOf(os, app), "server.json"));
|
|
65
|
-
assertSameServer(out, channel, server);
|
|
66
|
-
const previous = publishedApp(out, channel);
|
|
67
|
-
const dir = join(out, "app");
|
|
66
|
+
/** The app as a tar, and its gzip written as `<dir>/<tar sha256>.tar.gz`. */
|
|
67
|
+
async function archiveApp(os: DesktopOs, app: string, dir: string, tag: string | number) {
|
|
68
68
|
mkdirSync(dir, { recursive: true });
|
|
69
|
-
const tmp = join(dir, `.build-${
|
|
69
|
+
const tmp = join(dir, `.build-${tag}.tar`);
|
|
70
70
|
await execOrThrow([...TAR[os], "-cf", tmp, "-C", dirname(app), basename(app)], { echo: false });
|
|
71
71
|
const tar = readFileSync(tmp);
|
|
72
72
|
rmSync(tmp);
|
|
73
73
|
const tarSha = sha256(tar);
|
|
74
74
|
const gz = Bun.gzipSync(tar, { level: 9 });
|
|
75
75
|
writeFileSync(join(dir, `${tarSha}.tar.gz`), gz);
|
|
76
|
+
return { tar, tarSha, gz };
|
|
77
|
+
}
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
79
|
+
/** The gzip delta from `base` to `tar`, written into `dir` as publish names it, and its entry in `patches`. */
|
|
80
|
+
function writeDelta(
|
|
81
|
+
dir: string,
|
|
82
|
+
base: AppArchive,
|
|
83
|
+
tarSha: string,
|
|
84
|
+
tar: Uint8Array,
|
|
85
|
+
full: number,
|
|
86
|
+
label: string,
|
|
87
|
+
): Patch {
|
|
88
|
+
const started = performance.now();
|
|
89
|
+
const delta = Bun.gzipSync(createDelta(base.tar, tar), { level: 9 });
|
|
90
|
+
const name = `${base.sha256}-${tarSha}.delta.gz`;
|
|
91
|
+
writeFileSync(join(dir, name), delta);
|
|
92
|
+
log.info(
|
|
93
|
+
dim(
|
|
94
|
+
`delta from ${label}: ${(delta.length / 1024).toFixed(0)} KiB instead of ${(full / 1024 / 1024).toFixed(1)} MiB (${Math.round(performance.now() - started)} ms)`,
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
return { from: base.sha256, url: `app/${name}`, sha256: sha256(delta), size: delta.length };
|
|
98
|
+
}
|
|
95
99
|
|
|
96
|
-
|
|
100
|
+
function appManifest(
|
|
101
|
+
ctx: BuildContext,
|
|
102
|
+
os: DesktopOs,
|
|
103
|
+
app: string,
|
|
104
|
+
release: { channel: string; sequence: number; bundle: string; patches: Patch[] },
|
|
105
|
+
{ tar, tarSha, gz }: Awaited<ReturnType<typeof archiveApp>>,
|
|
106
|
+
): UpdateManifest {
|
|
107
|
+
const { config } = ctx.project;
|
|
108
|
+
const resources = resourcesOf(os, app);
|
|
109
|
+
return {
|
|
97
110
|
schema: 1,
|
|
98
111
|
kind: "app",
|
|
99
112
|
app: config.app.id,
|
|
100
113
|
platform: os,
|
|
101
|
-
channel,
|
|
102
|
-
sequence,
|
|
103
|
-
bundle:
|
|
114
|
+
channel: release.channel,
|
|
115
|
+
sequence: release.sequence,
|
|
116
|
+
bundle: release.bundle,
|
|
104
117
|
runtimeVersion: runtimeVersion(),
|
|
105
118
|
version: config.app.version,
|
|
106
|
-
build: (
|
|
107
|
-
|
|
108
|
-
).embeddedSequence,
|
|
119
|
+
build: (JSON.parse(readFileSync(join(resources, "updates.json"), "utf8")) as { embeddedSequence: number })
|
|
120
|
+
.embeddedSequence,
|
|
109
121
|
arch: ctx.arch ?? hostArch(),
|
|
110
122
|
files: [{ path: basename(app), sha256: tarSha, size: tar.length }],
|
|
111
123
|
archive: { sha256: tarSha, url: `app/${tarSha}.tar.gz`, size: gz.length, gzSha256: sha256(gz) },
|
|
112
|
-
patches,
|
|
113
|
-
server,
|
|
124
|
+
patches: release.patches,
|
|
125
|
+
server: existsSync(join(resources, "server.json")),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function publishAppUpdate(
|
|
130
|
+
ctx: BuildContext,
|
|
131
|
+
os: DesktopOs,
|
|
132
|
+
app: string,
|
|
133
|
+
out: string,
|
|
134
|
+
channel: string,
|
|
135
|
+
sequence: number,
|
|
136
|
+
): Promise<{ manifest: UpdateManifest; leftovers: string[] }> {
|
|
137
|
+
assertSameServer(out, channel, existsSync(join(resourcesOf(os, app), "server.json")));
|
|
138
|
+
const previous = publishedApp(out, channel);
|
|
139
|
+
const dir = join(out, "app");
|
|
140
|
+
const archive = await archiveApp(os, app, dir, sequence);
|
|
141
|
+
|
|
142
|
+
const from = previous?.archive?.sha256;
|
|
143
|
+
const base = previous && from && from !== archive.tarSha ? previousTar(out, previous) : null;
|
|
144
|
+
const patches =
|
|
145
|
+
from && base
|
|
146
|
+
? [
|
|
147
|
+
writeDelta(
|
|
148
|
+
dir,
|
|
149
|
+
{ sha256: from, tar: base },
|
|
150
|
+
archive.tarSha,
|
|
151
|
+
archive.tar,
|
|
152
|
+
archive.gz.length,
|
|
153
|
+
`${previous?.bundle}`,
|
|
154
|
+
),
|
|
155
|
+
]
|
|
156
|
+
: [];
|
|
157
|
+
const leftovers = readdirSync(dir)
|
|
158
|
+
.filter((name) => /^[0-9a-f]{64}\.tar$/.test(name))
|
|
159
|
+
.map((name) => join(dir, name));
|
|
160
|
+
const bundle = `${ctx.project.config.app.version}-${sequence}`;
|
|
161
|
+
return { manifest: appManifest(ctx, os, app, { channel, sequence, bundle, patches }, archive), leftovers };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The archive a delta starts from, as a publish or a pack named it (`<tar sha256>.tar.gz`): a file, or a URL of the
|
|
166
|
+
* feed. Refused unless it unpacks to the tar its name says, since a delta from other bytes patches no installed app.
|
|
167
|
+
*/
|
|
168
|
+
export async function readAppArchive(source: string): Promise<AppArchive> {
|
|
169
|
+
const remote = /^https?:\/\//i.test(source);
|
|
170
|
+
const name = basename(remote ? new URL(source).pathname : source);
|
|
171
|
+
const named = /^([0-9a-f]{64})\.tar\.gz$/.exec(name)?.[1];
|
|
172
|
+
if (!named) throw new CliError(`${source} is not named as a release archive is: <tar sha256>.tar.gz`);
|
|
173
|
+
let gz: Uint8Array<ArrayBuffer>;
|
|
174
|
+
if (remote) {
|
|
175
|
+
const response = await fetch(source, { signal: currentSignal(), redirect: "follow" });
|
|
176
|
+
if (!response.ok) throw new CliError(`${source} answered ${response.status}`);
|
|
177
|
+
gz = await response.bytes();
|
|
178
|
+
} else {
|
|
179
|
+
if (!existsSync(source)) throw new CliError(`${source} does not exist`);
|
|
180
|
+
gz = readFileSync(source);
|
|
181
|
+
}
|
|
182
|
+
let tar: Uint8Array;
|
|
183
|
+
try {
|
|
184
|
+
tar = Bun.gunzipSync(gz);
|
|
185
|
+
} catch {
|
|
186
|
+
throw new CliError(`${source} is not a gzip archive`);
|
|
187
|
+
}
|
|
188
|
+
if (sha256(tar) !== named) throw new CliError(`${source} does not unpack to the tar its name says`);
|
|
189
|
+
return { sha256: named, tar };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Who signed an app's files: the one an installed copy's updater holds a release to (plugins/updates signer.ts). */
|
|
193
|
+
export interface AppSigner {
|
|
194
|
+
/** macOS: the certificate's team. */
|
|
195
|
+
teamId?: string;
|
|
196
|
+
/** Windows: the certificate's SHA-1, as updates.windowsSigners lists it, and its subject when that is plain ASCII. */
|
|
197
|
+
thumbprint?: string;
|
|
198
|
+
subject?: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const SIGNER = `$ErrorActionPreference = 'Stop'
|
|
202
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
203
|
+
$signature = Get-AuthenticodeSignature -LiteralPath $env:AKAN_NATIVE_SIGNED_EXE
|
|
204
|
+
if ("$($signature.Status)" -ceq 'Valid') {
|
|
205
|
+
"akan-signer-thumbprint: $($signature.SignerCertificate.Thumbprint)"
|
|
206
|
+
"akan-signer-subject: $($signature.SignerCertificate.Subject)"
|
|
207
|
+
}`;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The signer of a built app, read from the app as its updater reads it; null for an app signed ad hoc or not at all,
|
|
211
|
+
* which takes any release. Never the pack's failure: a tool that does not answer leaves no signer named.
|
|
212
|
+
*/
|
|
213
|
+
export async function appSigner(os: DesktopOs, app: string, fileName: string): Promise<AppSigner | null> {
|
|
214
|
+
try {
|
|
215
|
+
if (os === "macos") {
|
|
216
|
+
const shown = await exec(["/usr/bin/codesign", "--display", "--verbose=2", app], { echo: false });
|
|
217
|
+
const teamId = /^TeamIdentifier=([A-Z0-9]{10})$/m.exec(`${shown.stdout}${shown.stderr}`)?.[1];
|
|
218
|
+
return shown.code === 0 && teamId ? { teamId } : null;
|
|
219
|
+
}
|
|
220
|
+
if (os !== "windows") return null;
|
|
221
|
+
const powershell = join(
|
|
222
|
+
process.env.SystemRoot ?? "C:\\Windows",
|
|
223
|
+
"System32",
|
|
224
|
+
"WindowsPowerShell",
|
|
225
|
+
"v1.0",
|
|
226
|
+
"powershell.exe",
|
|
227
|
+
);
|
|
228
|
+
const encoded = Buffer.from(SIGNER, "utf16le").toString("base64");
|
|
229
|
+
const { code, stdout } = await exec([powershell, "-NoProfile", "-NonInteractive", "-EncodedCommand", encoded], {
|
|
230
|
+
echo: false,
|
|
231
|
+
env: { ...process.env, AKAN_NATIVE_SIGNED_EXE: join(app, `${fileName}.exe`) },
|
|
232
|
+
});
|
|
233
|
+
const thumbprint = code === 0 ? /^akan-signer-thumbprint: ([0-9A-F]{40})\r?$/m.exec(stdout)?.[1] : undefined;
|
|
234
|
+
if (!thumbprint) return null;
|
|
235
|
+
const subject = /^akan-signer-subject: ([\x20-\x7e]+?)\r?$/m.exec(stdout)?.[1];
|
|
236
|
+
return { thumbprint, ...(subject ? { subject } : {}) };
|
|
237
|
+
} catch {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* An unsigned release under `out`: the archive, a delta from `previous` when one is given, and the manifest with
|
|
244
|
+
* `channel`, `sequence` and `bundle` left empty in `manifest.template.json`. It names updates.target, as an installed
|
|
245
|
+
* app refuses a release that does not; what a release revokes and when it expires are the signer's to add.
|
|
246
|
+
*/
|
|
247
|
+
export async function packAppUpdate(
|
|
248
|
+
ctx: BuildContext,
|
|
249
|
+
os: DesktopOs,
|
|
250
|
+
app: string,
|
|
251
|
+
out: string,
|
|
252
|
+
previous?: AppArchive,
|
|
253
|
+
): Promise<{ manifest: UpdateManifest; patch: Patch | null }> {
|
|
254
|
+
const dir = join(out, "app");
|
|
255
|
+
const archive = await archiveApp(os, app, dir, process.pid);
|
|
256
|
+
const patch =
|
|
257
|
+
previous && previous.sha256 !== archive.tarSha
|
|
258
|
+
? writeDelta(dir, previous, archive.tarSha, archive.tar, archive.gz.length, previous.sha256.slice(0, 12))
|
|
259
|
+
: null;
|
|
260
|
+
const target = ctx.project.config.updates?.target;
|
|
261
|
+
const manifest: UpdateManifest = {
|
|
262
|
+
...appManifest(ctx, os, app, { channel: "", sequence: 0, bundle: "", patches: patch ? [patch] : [] }, archive),
|
|
263
|
+
schema: 2,
|
|
264
|
+
...(target ? { target } : {}),
|
|
114
265
|
};
|
|
115
|
-
|
|
266
|
+
writeFileSync(join(out, PACK_TEMPLATE), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
267
|
+
return { manifest, patch };
|
|
116
268
|
}
|
|
@@ -55,7 +55,7 @@ export async function buildAppImage(ctx: BuildContext, folder: string): Promise<
|
|
|
55
55
|
);
|
|
56
56
|
if (config.updates)
|
|
57
57
|
log.warn(
|
|
58
|
-
|
|
58
|
+
`an AppImage runs from a read-only image, so the updates plugin cannot replace it: publish a new AppImage for each release. ${config.app.fileName}-${config.app.version}-${arch}.tar.gz beside it installs the app folder, which does update itself.`,
|
|
59
59
|
);
|
|
60
60
|
|
|
61
61
|
const appDir = join(ctx.outDir, "gen", "AppDir");
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { chmodSync, cpSync, mkdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { INSTALLED_MARKER } from "../../../desktop/src/deeplinks.ts";
|
|
6
|
+
import { execOrThrow } from "../lib/exec.ts";
|
|
7
|
+
import { CliError, log } from "../lib/log.ts";
|
|
8
|
+
import type { BuildContext } from "../lib/prepare.ts";
|
|
9
|
+
import { targetArch } from "./desktop.ts";
|
|
10
|
+
|
|
11
|
+
export interface LinuxInstallInput {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
fileName: string;
|
|
15
|
+
version: string;
|
|
16
|
+
/** deepLinks.schemes: the launcher entry's x-scheme-handler MIME types. */
|
|
17
|
+
schemes: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A POSIX sh single-quoted word: nothing in it expands, and a quote ends the word, is escaped, and starts it again. */
|
|
21
|
+
export const shellQuote = (value: string) => `'${value.replace(/'/g, "'\\''")}'`;
|
|
22
|
+
|
|
23
|
+
/** A Desktop Entry string value: one line, with the backslash the format escapes with doubled. */
|
|
24
|
+
const entryValue = (value: string) => value.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
|
|
25
|
+
|
|
26
|
+
const COMMON = `
|
|
27
|
+
fail() {
|
|
28
|
+
printf '%s\\n' "$*" >&2
|
|
29
|
+
exit 1
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
warn() {
|
|
33
|
+
printf '%s\\n' "warning: $*" >&2
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# An XDG base directory must be absolute; anything else is ignored (XDG Base Directory spec).
|
|
37
|
+
xdg() {
|
|
38
|
+
case "$1" in
|
|
39
|
+
esac
|
|
40
|
+
elif [ ! -e "$BIN" ]; then
|
|
41
|
+
OURS=1
|
|
42
|
+
fi
|
|
43
|
+
if [ "$OURS" = 1 ]; then
|
|
44
|
+
mkdir -p "\${BIN%/*}" && rm -f "$BIN" && ln -s "$APP/$FILE_NAME" "$BIN" || warn "$BIN could not be linked to the app"
|
|
45
|
+
else
|
|
46
|
+
warn "$BIN is not a link install.sh made, so it stays as it is: start $APP_NAME from the launcher, or as $APP/$FILE_NAME"
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
refresh_caches
|
|
50
|
+
RESTART=
|
|
51
|
+
[ "$UPGRADE" = 0 ] || RESTART=" A copy that is running keeps the old version until it is restarted."
|
|
52
|
+
printf '%s\\n' "$APP_NAME $VERSION is installed in $APP.$RESTART Uninstall it with $PARENT/uninstall.sh"
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
const UNINSTALL = `
|
|
56
|
+
usage() {
|
|
57
|
+
printf '%s\\n' "usage: $0 [--dir <folder>] [--purge]" \\
|
|
58
|
+
"Removes $APP_NAME from <folder> (default: the folder of an installed uninstall.sh, else $HOME/.local/opt/$APP_ID)." \\
|
|
59
|
+
"--purge removes the app's data too."
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
PARENT=
|
|
63
|
+
PURGE=0
|
|
64
|
+
while [ "$#" -gt 0 ]; do
|
|
65
|
+
case "$1" in
|
|
66
|
+
--dir)
|
|
67
|
+
[ "$#" -ge 2 ] || fail "--dir takes a folder"
|
|
68
|
+
PARENT=$2
|
|
69
|
+
shift 2
|
|
70
|
+
;;
|
|
71
|
+
--dir=*)
|
|
72
|
+
PARENT=\${1#--dir=}
|
|
73
|
+
shift
|
|
74
|
+
;;
|
|
75
|
+
--purge)
|
|
76
|
+
PURGE=1
|
|
77
|
+
shift
|
|
78
|
+
;;
|
|
79
|
+
-h | --help)
|
|
80
|
+
usage
|
|
81
|
+
exit 0
|
|
82
|
+
;;
|
|
83
|
+
*)
|
|
84
|
+
usage >&2
|
|
85
|
+
exit 2
|
|
86
|
+
;;
|
|
87
|
+
esac
|
|
88
|
+
done
|
|
89
|
+
|
|
90
|
+
CONFIG_HOME=$(xdg "\${XDG_CONFIG_HOME:-}" "$HOME/.config")
|
|
91
|
+
CACHE_HOME=$(xdg "\${XDG_CACHE_HOME:-}" "$HOME/.cache")
|
|
92
|
+
DATA="$DATA_HOME/$APP_ID"
|
|
93
|
+
CACHE="$CACHE_HOME/$APP_ID"
|
|
94
|
+
AUTOSTART="$CONFIG_HOME/autostart/$APP_ID.desktop"
|
|
95
|
+
LIST="$CONFIG_HOME/mimeapps.list"
|
|
96
|
+
|
|
97
|
+
# install.sh lies beside the archive's copy of this script; the installed copy lies in the install's own parent.
|
|
98
|
+
if [ -z "$PARENT" ]; then
|
|
99
|
+
if [ -f "$HERE/install.sh" ]; then PARENT="$HOME/.local/opt/$APP_ID"; else PARENT=$HERE; fi
|
|
100
|
+
fi
|
|
101
|
+
if [ -d "$PARENT" ]; then PARENT=$(CDPATH= cd -- "$PARENT" && pwd -P); fi
|
|
102
|
+
[ ! -f "$PARENT/install.sh" ] || fail "$PARENT is the unpacked archive, not an install"
|
|
103
|
+
APP="$PARENT/$FILE_NAME"
|
|
104
|
+
FOUND=1
|
|
105
|
+
if [ -e "$APP" ]; then
|
|
106
|
+
[ -f "$APP/$FILE_NAME" ] || fail "$APP holds something other than $APP_NAME: nothing is removed"
|
|
107
|
+
elif [ ! -f "$PARENT/uninstall.sh" ]; then
|
|
108
|
+
[ "$PURGE" = 1 ] || fail "$APP_NAME is not installed in $PARENT (an install elsewhere: --dir <folder>)"
|
|
109
|
+
FOUND=0
|
|
110
|
+
fi
|
|
111
|
+
|
|
112
|
+
starts_install() {
|
|
113
|
+
[ -f "$1" ] && grep '^Exec=' "$1" | grep -q -F "$APP/"
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if [ "$FOUND" = 1 ]; then
|
|
117
|
+
rm -rf "$APP" "$APP.previous" "$APP".update-* "$APP".failed-* "$APP".replaced-* "$APP".new-* ||
|
|
118
|
+
fail "$APP could not be removed"
|
|
119
|
+
# The updater's downloads and its record of this install (a trial, its strikes), as the Windows uninstaller removes
|
|
120
|
+
# them: an install made later is not this one.
|
|
121
|
+
rm -rf "$DATA/akan-native-updates" "$DATA/akan-native-updates-debug" || :
|
|
122
|
+
|
|
123
|
+
if [ -f "$ENTRY" ] && { grep -q -x -F '${INSTALLED_MARKER}' "$ENTRY" || starts_install "$ENTRY"; }; then
|
|
124
|
+
rm -f "$ENTRY"
|
|
125
|
+
fi
|
|
126
|
+
# An entry that stays is another copy's (an AppImage of the app), and so are its icon and the defaults naming it.
|
|
127
|
+
if [ ! -e "$ENTRY" ]; then
|
|
128
|
+
rm -f "$ICON"
|
|
129
|
+
if [ -f "$LIST" ] && grep -q -F "$APP_ID.desktop" "$LIST"; then
|
|
130
|
+
DESKTOP_FILE="$APP_ID.desktop" awk '{
|
|
131
|
+
at = index($0, "=")
|
|
132
|
+
if (at == 0) { print; next }
|
|
133
|
+
n = split(substr($0, at + 1), items, ";")
|
|
134
|
+
kept = ""
|
|
135
|
+
dropped = 0
|
|
136
|
+
for (i = 1; i <= n; i++) {
|
|
137
|
+
if (items[i] == ENVIRON["DESKTOP_FILE"]) dropped = 1
|
|
138
|
+
else if (items[i] != "") kept = kept items[i] ";"
|
|
139
|
+
}
|
|
140
|
+
if (!dropped) print
|
|
141
|
+
else if (kept != "") print substr($0, 1, at) kept
|
|
142
|
+
}' "$LIST" > "$LIST.tmp-$$" && cat "$LIST.tmp-$$" > "$LIST" || warn "$LIST still names $APP_ID.desktop"
|
|
143
|
+
rm -f "$LIST.tmp-$$"
|
|
144
|
+
fi
|
|
145
|
+
fi
|
|
146
|
+
if starts_install "$AUTOSTART"; then rm -f "$AUTOSTART"; fi
|
|
147
|
+
if [ -L "$BIN" ]; then
|
|
148
|
+
case "$(readlink "$BIN")" in
|
|
149
|
+
"$APP"/*) rm -f "$BIN" ;;
|
|
150
|
+
esac
|
|
151
|
+
fi
|
|
152
|
+
refresh_caches
|
|
153
|
+
rm -f "$PARENT/uninstall.sh"
|
|
154
|
+
rmdir "$PARENT" 2> /dev/null || :
|
|
155
|
+
fi
|
|
156
|
+
|
|
157
|
+
if [ "$PURGE" = 1 ]; then
|
|
158
|
+
rm -rf "$DATA" "$CACHE" || warn "the data in $DATA and $CACHE could not all be removed"
|
|
159
|
+
DATA_NOTE=" Its data is removed too."
|
|
160
|
+
elif [ -d "$DATA" ] || [ -d "$CACHE" ]; then
|
|
161
|
+
DATA_NOTE=" Its data stays in $DATA and $CACHE (--purge removes it too)."
|
|
162
|
+
else
|
|
163
|
+
DATA_NOTE=
|
|
164
|
+
fi
|
|
165
|
+
if [ "$FOUND" = 1 ]; then
|
|
166
|
+
printf '%s\\n' "$APP_NAME is uninstalled from $PARENT.$DATA_NOTE"
|
|
167
|
+
else
|
|
168
|
+
printf '%s\\n' "$APP_NAME is not installed in $PARENT.$DATA_NOTE"
|
|
169
|
+
fi
|
|
170
|
+
`;
|
|
171
|
+
|
|
172
|
+
export const installScript = (input: LinuxInstallInput): string => `${head(input)}${INSTALL}`;
|
|
173
|
+
|
|
174
|
+
export const uninstallScript = (input: LinuxInstallInput): string => `${head(input)}${UNINSTALL}`;
|
|
175
|
+
|
|
176
|
+
/** Writes the tar.gz beside the app folder and answers its path. */
|
|
177
|
+
export async function buildLinuxInstaller(ctx: BuildContext, folder: string): Promise<string> {
|
|
178
|
+
const { app, deepLinks } = ctx.project.config;
|
|
179
|
+
const input = {
|
|
180
|
+
id: app.id,
|
|
181
|
+
name: app.name,
|
|
182
|
+
fileName: app.fileName,
|
|
183
|
+
version: app.version,
|
|
184
|
+
schemes: deepLinks.schemes,
|
|
185
|
+
};
|
|
186
|
+
const top = `${app.fileName}-${app.version}-${targetArch(ctx)}`;
|
|
187
|
+
const gen = join(ctx.outDir, "gen");
|
|
188
|
+
const stage = join(gen, top);
|
|
189
|
+
rmSync(stage, { recursive: true, force: true });
|
|
190
|
+
mkdirSync(stage, { recursive: true });
|
|
191
|
+
cpSync(folder, join(stage, app.fileName), { recursive: true, verbatimSymlinks: true });
|
|
192
|
+
for (const [name, text] of [
|
|
193
|
+
["install.sh", installScript(input)],
|
|
194
|
+
["uninstall.sh", uninstallScript(input)],
|
|
195
|
+
] as const) {
|
|
196
|
+
writeFileSync(join(stage, name), text);
|
|
197
|
+
chmodSync(join(stage, name), 0o755);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
log.step("installer: tar.gz");
|
|
201
|
+
const outFile = join(ctx.outDir, `${top}.tar.gz`);
|
|
202
|
+
await execOrThrow(["tar", "-czf", outFile, "-C", gen, top], { echo: false });
|
|
203
|
+
rmSync(stage, { recursive: true, force: true });
|
|
204
|
+
log.info(`installer ${outFile} (${Math.round(statSync(outFile).size / 1024 / 1024)} MB)`);
|
|
205
|
+
return outFile;
|
|
206
|
+
}
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
writeDesktopResources,
|
|
23
23
|
} from "./desktop.ts";
|
|
24
24
|
import { buildAppImage } from "./linux-appimage.ts";
|
|
25
|
+
import { buildLinuxInstaller } from "./linux-install.ts";
|
|
25
26
|
|
|
26
27
|
const exePath = (ctx: BuildContext, dir: string) => join(dir, ctx.project.config.app.fileName);
|
|
27
28
|
|
|
@@ -45,7 +46,10 @@ export async function buildLinux(ctx: BuildContext): Promise<string> {
|
|
|
45
46
|
writeFileSync(join(resources, "icon.rgba"), windowIcon(art.master));
|
|
46
47
|
writeFileSync(join(resources, "icon.png"), encodePng(resize(art.master, 256, 256)));
|
|
47
48
|
}
|
|
48
|
-
if (ctx.linux?.appImage)
|
|
49
|
+
if (ctx.linux?.appImage) {
|
|
50
|
+
ctx.artifacts.push({ kind: "installer", path: await buildAppImage(ctx, dir) });
|
|
51
|
+
ctx.artifacts.push({ kind: "installer", path: await buildLinuxInstaller(ctx, dir) });
|
|
52
|
+
}
|
|
49
53
|
const size = await folderSize(dir);
|
|
50
54
|
if (size) log.info(dim(`size ${size}`));
|
|
51
55
|
return dir;
|
|
@@ -460,7 +460,7 @@ export const RESERVED_CHANNELS: readonly string[] = ["bundle", "manifest.templat
|
|
|
460
460
|
/** A channel the publisher can make: a file name in the release folder and a string an app's config compares. */
|
|
461
461
|
export const isChannelName = (s: string) => /^[a-z0-9][a-z0-9._-]{0,40}$/.test(s) && !RESERVED_CHANNELS.includes(s);
|
|
462
462
|
|
|
463
|
-
/** What became of a release on a phone, posted to updates.report.url (vectors/updates.json `reports`). */
|
|
463
|
+
/** What became of a release on a phone or a desktop app, posted to updates.report.url (vectors/updates.json `reports`). */
|
|
464
464
|
export const UPDATE_REPORT_EVENTS = ["downloaded", "applied", "confirmed", "rolledBack", "failed"] as const;
|
|
465
465
|
export type UpdateReportEvent = (typeof UPDATE_REPORT_EVENTS)[number];
|
|
466
466
|
|
|
@@ -477,15 +477,25 @@ export const UPDATE_REPORT_REASONS = [
|
|
|
477
477
|
] as const;
|
|
478
478
|
export type UpdateReportReason = (typeof UPDATE_REPORT_REASONS)[number];
|
|
479
479
|
|
|
480
|
+
/**
|
|
481
|
+
* The reasons only a desktop app gives, beside the phones': `signer` fails a release the installed app's team or
|
|
482
|
+
* Authenticode signer did not sign; `server` fails one that adds or drops the carried server, and rolls back one whose
|
|
483
|
+
* server did not come up.
|
|
484
|
+
*/
|
|
485
|
+
export const UPDATE_REPORT_DESKTOP_REASONS = ["signer", "server"] as const;
|
|
486
|
+
export type UpdateReportDesktopReason = (typeof UPDATE_REPORT_DESKTOP_REASONS)[number];
|
|
487
|
+
|
|
480
488
|
export interface UpdateReportEntry {
|
|
481
489
|
/** Counts up for as long as the install lasts, so a receiver can drop a batch it already took. */
|
|
482
490
|
id: number;
|
|
483
491
|
event: UpdateReportEvent;
|
|
484
492
|
bundle: string;
|
|
485
493
|
sequence: number | null;
|
|
486
|
-
reason: UpdateReportReason | null;
|
|
494
|
+
reason: UpdateReportReason | UpdateReportDesktopReason | null;
|
|
487
495
|
/** updateReportTime: UTC, always three fraction digits. */
|
|
488
496
|
at: string;
|
|
497
|
+
/** A desktop app: the key that signed the release, or that a refused envelope names; left out when it knows none. */
|
|
498
|
+
keyId?: string;
|
|
489
499
|
}
|
|
490
500
|
|
|
491
501
|
/** One request to updates.report.url, with no credentials. */
|
|
@@ -497,20 +507,25 @@ export interface UpdateReportBody {
|
|
|
497
507
|
installId: string;
|
|
498
508
|
nativeApi: string;
|
|
499
509
|
appVersion: string;
|
|
500
|
-
/** "iOS 18.1", "Android 15". */
|
|
510
|
+
/** "iOS 18.1", "Android 15", "macOS 15.5", "Windows 10.0.26200", "Linux Ubuntu 24.04.1 LTS". */
|
|
501
511
|
os: string;
|
|
512
|
+
/** A desktop app's CPU, "arm64" or "x64": its releases are per OS and CPU. A phone sends none. */
|
|
513
|
+
arch?: string;
|
|
502
514
|
events: UpdateReportEntry[];
|
|
503
515
|
}
|
|
504
516
|
|
|
505
|
-
/** The events
|
|
517
|
+
/** The events an app keeps waiting, the oldest dropped first. */
|
|
506
518
|
export const UPDATE_REPORT_LIMIT = 100;
|
|
507
519
|
|
|
508
520
|
/** The events one request carries. */
|
|
509
521
|
export const UPDATE_REPORT_BATCH = 20;
|
|
510
522
|
|
|
511
523
|
/** An event is kept once per release and reason: a check that fails at every launch is one failure. */
|
|
512
|
-
export const updateReportKey = (
|
|
513
|
-
|
|
524
|
+
export const updateReportKey = (
|
|
525
|
+
event: UpdateReportEvent,
|
|
526
|
+
bundle: string,
|
|
527
|
+
reason: UpdateReportReason | UpdateReportDesktopReason | null,
|
|
528
|
+
) => `${event}|${bundle}|${reason ?? ""}`;
|
|
514
529
|
|
|
515
530
|
export type UpdateReportOutcome = "sent" | "dropped" | "kept";
|
|
516
531
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"about": "Web bundle updates, protocol v2 (architecture.md \"업데이트\"). keyIds: [raw Ed25519 public key in base64, its keyId: the first 8 bytes of its sha256 in hex]. decisions: [the binary's keyIds in updates.publicKeys order, keyIds state.json has revoked, the envelope's keyId, the manifest's revokeKeys, its resetSequence, its sequence, the binary's embeddedSequence, the running bundle as [sequence, keyId] or null for the app's own, the answer, why] for a manifest whose signature verified; the answer is untrusted | revoked | self-revoke | revoke-later, or take|stale:<the sequence it had to beat>:<keyIds it newly revokes, comma-separated>, revocations applying even to a stale manifest. urls: [updates.url, platform, channel, nativeApi, the envelope's URL]. appUrls: [updates.url, desktop OS, CPU, channel, a desktop app's envelope URL (protocol v2: the whole app, one envelope per OS and CPU)]. publicKeys: [an updates.publicKeys entry, whether a release may be signed for it, why]: strict base64 of 32 bytes, the canonical encoding of an Ed25519 point (RFC 8032 §5.1.3) that is not of small order. envelopeKeys: the binary's updates.publicKeys for the envelopes, the public keys of RFC 8032 §7.1 TEST 1 and 2 (TEST 3 signs as a stranger), so the rows can be signed again. envelopes: [the manifest field, or [a base64 group, how many times it repeats, the base64 after them] for a large one, keyId, signature, keyIds state.json has revoked, the verdict, why] for an envelope's three fields; the verdict is open | untrusted | revoked | encoding | too-large | signature, checked in that order. limits: kernel.ts MAX_REVOKE_KEYS, MAX_UPDATE_MANIFEST, UPDATE_REPORT_LIMIT and UPDATE_REPORT_BATCH. reports (what a phone posts to updates.report.url): events and
|
|
2
|
+
"about": "Web bundle updates, protocol v2 (architecture.md \"업데이트\"). keyIds: [raw Ed25519 public key in base64, its keyId: the first 8 bytes of its sha256 in hex]. decisions: [the binary's keyIds in updates.publicKeys order, keyIds state.json has revoked, the envelope's keyId, the manifest's revokeKeys, its resetSequence, its sequence, the binary's embeddedSequence, the running bundle as [sequence, keyId] or null for the app's own, the answer, why] for a manifest whose signature verified; the answer is untrusted | revoked | self-revoke | revoke-later, or take|stale:<the sequence it had to beat>:<keyIds it newly revokes, comma-separated>, revocations applying even to a stale manifest. urls: [updates.url, platform, channel, nativeApi, the envelope's URL]. appUrls: [updates.url, desktop OS, CPU, channel, a desktop app's envelope URL (protocol v2: the whole app, one envelope per OS and CPU)]. publicKeys: [an updates.publicKeys entry, whether a release may be signed for it, why]: strict base64 of 32 bytes, the canonical encoding of an Ed25519 point (RFC 8032 §5.1.3) that is not of small order. envelopeKeys: the binary's updates.publicKeys for the envelopes, the public keys of RFC 8032 §7.1 TEST 1 and 2 (TEST 3 signs as a stranger), so the rows can be signed again. envelopes: [the manifest field, or [a base64 group, how many times it repeats, the base64 after them] for a large one, keyId, signature, keyIds state.json has revoked, the verdict, why] for an envelope's three fields; the verdict is open | untrusted | revoked | encoding | too-large | signature, checked in that order. limits: kernel.ts MAX_REVOKE_KEYS, MAX_UPDATE_MANIFEST, UPDATE_REPORT_LIMIT and UPDATE_REPORT_BATCH. reports (what a phone posts to updates.report.url, and a desktop app with desktopReasons beside the phones' reasons): events, reasons and desktopReasons, the vocabulary in order; outcomes: [HTTP status, 0 for no answer, what it does to the batch: sent | dropped | kept]; retryAfter: [the header or null, now in seconds, when the batch may go again or null, why]; waits: [retryAt or null, now, whether a send waits]; keys: [event, bundle, reason or null, the key an event is kept once by]; times: [milliseconds since the epoch, the event's at].",
|
|
3
3
|
"keyIds": [
|
|
4
4
|
["BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc=", "4bb06f8e4e3a7715"],
|
|
5
5
|
["11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=", "21fe31dfa154a261"],
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"reports": {
|
|
81
81
|
"events": ["downloaded", "applied", "confirmed", "rolledBack", "failed"],
|
|
82
82
|
"reasons": ["timeout", "relaunch", "hang", "verify", "download", "disk", "signature", "manifest"],
|
|
83
|
+
"desktopReasons": ["signer", "server"],
|
|
83
84
|
"outcomes": [
|
|
84
85
|
[200, "sent"],
|
|
85
86
|
[201, "sent"],
|