pinggy 0.6.5 → 0.6.7

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.
Files changed (33) hide show
  1. package/ARCHITECTURE.md +103 -39
  2. package/CLAUDE.md +21 -11
  3. package/README.md +12 -2
  4. package/dist/{TunnelManager-DXNXIH5W.js → TunnelManager-JRVEADS4.js} +4 -3
  5. package/dist/{TunnelTui-K7KESRTQ.js → TunnelTui-6H4NPUNF.js} +4 -3
  6. package/dist/{chunk-QZJGTQZC.js → chunk-2GIJXE4K.js} +3 -2
  7. package/dist/chunk-3KCXR33Y.js +954 -0
  8. package/dist/{chunk-EMCDDH3B.js → chunk-3WMTTJHI.js} +11 -299
  9. package/dist/{chunk-X6TZN5CT.js → chunk-CZOKR73F.js} +1 -1
  10. package/dist/{chunk-K5QHR5KU.js → chunk-FWTQF6AB.js} +519 -556
  11. package/dist/{chunk-3PTLHLFL.js → chunk-H527WMTF.js} +33 -240
  12. package/dist/chunk-HTIWY3O5.js +293 -0
  13. package/dist/{chunk-IRKMUV37.js → chunk-LWCVB42S.js} +2 -2
  14. package/dist/{chunk-N5WE4DYD.js → chunk-MAK5R4WQ.js} +12 -0
  15. package/dist/{chunk-7EQKHVQX.js → chunk-MHQ3CVEB.js} +4 -51
  16. package/dist/chunk-MKGD2QAI.js +51 -0
  17. package/dist/chunk-PMZJ6HFH.js +882 -0
  18. package/dist/{configStore-DXC6WMYO.js → configStore-JJUWT2YO.js} +3 -3
  19. package/dist/{daemonChild-HZ27YJKQ.js → daemonChild-24Y3AKII.js} +14 -10
  20. package/dist/{daemonConfig-MCAKZHY2.js → daemonConfig-VWK4TXVS.js} +2 -2
  21. package/dist/index.cjs +3621 -1814
  22. package/dist/index.d.cts +142 -129
  23. package/dist/index.d.ts +142 -129
  24. package/dist/index.js +18 -13
  25. package/dist/{ipcClient-XGF2KCQO.js → ipcClient-IZ5R6TPN.js} +2 -1
  26. package/dist/{main-TDQB5ZB4.js → main-HSIFQAGU.js} +19 -14
  27. package/dist/updateChild-JNGDWIAK.js +237 -0
  28. package/dist/workers/file_serve_worker.js +1 -1
  29. package/package.json +4 -3
  30. package/scripts/build_node_pty_linux.sh +27 -0
  31. package/scripts/check_linux_addons.js +168 -0
  32. package/scripts/install/install.ps1 +16 -16
  33. package/scripts/install/install.sh +57 -20
@@ -1,33 +1,38 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  runDaemonChild
4
- } from "./chunk-K5QHR5KU.js";
4
+ } from "./chunk-FWTQF6AB.js";
5
5
  import {
6
6
  RemoteManagementUnauthorizedError,
7
7
  TunnelOperations,
8
8
  closeRemoteManagement,
9
+ getRemoteManagementState,
10
+ initiateRemoteManagement
11
+ } from "./chunk-H527WMTF.js";
12
+ import "./chunk-CZOKR73F.js";
13
+ import "./chunk-MHQ3CVEB.js";
14
+ import "./chunk-2GIJXE4K.js";
15
+ import "./chunk-XZ64ZAGO.js";
16
+ import {
17
+ TunnelManager
18
+ } from "./chunk-3WMTTJHI.js";
19
+ import "./chunk-UB26QJ4T.js";
20
+ import "./chunk-PMZJ6HFH.js";
21
+ import {
9
22
  ensureDaemonRunning,
10
23
  getActiveTunnelSummaries,
11
24
  getDaemonInfo,
12
25
  getInProcessDaemonHandle,
13
- getRemoteManagementState,
14
- initiateRemoteManagement,
15
26
  isDaemonRunning
16
- } from "./chunk-3PTLHLFL.js";
17
- import "./chunk-X6TZN5CT.js";
27
+ } from "./chunk-3KCXR33Y.js";
18
28
  import {
19
29
  DaemonHost
20
- } from "./chunk-7EQKHVQX.js";
21
- import "./chunk-QZJGTQZC.js";
22
- import "./chunk-XZ64ZAGO.js";
23
- import {
24
- TunnelManager
25
- } from "./chunk-EMCDDH3B.js";
26
- import "./chunk-UB26QJ4T.js";
30
+ } from "./chunk-MKGD2QAI.js";
31
+ import "./chunk-HTIWY3O5.js";
27
32
  import {
28
33
  enablePackageLogging
29
- } from "./chunk-IRKMUV37.js";
30
- import "./chunk-N5WE4DYD.js";
34
+ } from "./chunk-LWCVB42S.js";
35
+ import "./chunk-MAK5R4WQ.js";
31
36
  export {
32
37
  DaemonHost,
33
38
  RemoteManagementUnauthorizedError,
@@ -0,0 +1,237 @@
1
+ import {
2
+ UpdateError,
3
+ acquireUpdateLock,
4
+ assetNameFor,
5
+ createUpdateTarget,
6
+ downloadRelease,
7
+ isNewerVersion,
8
+ isReleaseComplete,
9
+ isUpdateLockOurs,
10
+ readBinaryIpcVersion,
11
+ releaseUpdateLock,
12
+ removeQuietly,
13
+ removeStaleUnixFiles,
14
+ removeStaleUpdateFiles,
15
+ resolveLatestNpmVersion,
16
+ resolveLatestTag,
17
+ runPinggyBinary,
18
+ versionFromTag
19
+ } from "./chunk-PMZJ6HFH.js";
20
+ import {
21
+ InstallKind,
22
+ backgroundInstallKind,
23
+ canReplaceItself,
24
+ createInstallProbe,
25
+ daemonIpcVersion,
26
+ detectInstallKind,
27
+ getDaemonInfo,
28
+ nowEpochSeconds,
29
+ readUpdateState,
30
+ recordLatestVersion,
31
+ unixLayoutPaths,
32
+ writeUpdateState
33
+ } from "./chunk-3KCXR33Y.js";
34
+ import "./chunk-MKGD2QAI.js";
35
+ import {
36
+ errorMessage,
37
+ getVersion
38
+ } from "./chunk-HTIWY3O5.js";
39
+ import "./chunk-LWCVB42S.js";
40
+ import {
41
+ ensurePinggyLogDir,
42
+ getUpdateLogPath
43
+ } from "./chunk-MAK5R4WQ.js";
44
+
45
+ // src/update/updateChild.ts
46
+ import fs from "fs";
47
+ import os from "os";
48
+ var TIME_LIMIT_MILLIS = 30 * 60 * 1e3;
49
+ var CHECK_TIMEOUT_MILLIS = 15e3;
50
+ var CHECK_INTERVAL_SECONDS = 24 * 60 * 60;
51
+ var MAX_FAILED_ATTEMPTS = 3;
52
+ function checkedRecently(state, now) {
53
+ const last = state.lastCheckEpochSeconds;
54
+ return last !== void 0 && last <= now && now - last < CHECK_INTERVAL_SECONDS;
55
+ }
56
+ function saveCheckTime(environment) {
57
+ environment.writeState({ lastCheckEpochSeconds: environment.nowEpochSeconds() });
58
+ }
59
+ async function latestVersionAndTag(environment) {
60
+ try {
61
+ if (environment.kind === InstallKind.Npm) {
62
+ const latest = await environment.resolveNpmVersion();
63
+ return { tag: `v${latest}`, latest };
64
+ }
65
+ const tag = await environment.resolveTag();
66
+ return { tag, latest: versionFromTag(tag) };
67
+ } catch (error) {
68
+ environment.log(`Could not find the latest version: ${errorMessage(error)}`);
69
+ return null;
70
+ }
71
+ }
72
+ async function releaseIsReady(tag, environment) {
73
+ if (environment.kind === InstallKind.Npm) return true;
74
+ try {
75
+ if (await environment.isReleaseComplete(tag)) return true;
76
+ environment.log(`Release ${tag} has no SHA256SUMS yet`);
77
+ } catch (error) {
78
+ environment.log(`Could not check release ${tag}: ${errorMessage(error)}`);
79
+ }
80
+ return false;
81
+ }
82
+ function daemonStillDiffers(state, environment) {
83
+ const daemon = environment.liveDaemon();
84
+ return daemon !== null && daemonIpcVersion(daemon) !== state.deferredIpcVersion;
85
+ }
86
+ function skipReason(latest, state, environment) {
87
+ if (!canReplaceItself(environment.kind) || environment.target === null) return "this install cannot update itself";
88
+ if (latest === state.rolledBackFromVersion) return "the user rolled back from this version";
89
+ if (latest === state.failedVersion && (state.failedAttempts ?? 0) >= MAX_FAILED_ATTEMPTS) return "this version failed too many times";
90
+ if (latest === state.deferredVersion && daemonStillDiffers(state, environment)) return "a live daemon still needs a restart first";
91
+ return null;
92
+ }
93
+ function countFailure(latest, environment) {
94
+ const state = environment.readState();
95
+ const attempts = state.failedVersion === latest ? (state.failedAttempts ?? 0) + 1 : 1;
96
+ environment.writeState({ failedVersion: latest, failedAttempts: attempts });
97
+ }
98
+ async function holdForLiveDaemon(latest, target, environment) {
99
+ const newIpcVersion = await environment.readIpcVersion(target.downloadPath);
100
+ const daemon = environment.liveDaemon();
101
+ if (daemon === null || daemonIpcVersion(daemon) === newIpcVersion) return false;
102
+ environment.writeState({ deferredVersion: latest, deferredIpcVersion: newIpcVersion });
103
+ environment.log(`Held ${latest}: the running daemon speaks IPC v${daemonIpcVersion(daemon)}, this release v${newIpcVersion}`);
104
+ return true;
105
+ }
106
+ function lostTheRight(latest, environment) {
107
+ return !environment.isLockOurs() || environment.readState().rolledBackFromVersion === latest;
108
+ }
109
+ var Outcome = {
110
+ Finished: "finished",
111
+ TryAgainSoon: "try-again-soon"
112
+ };
113
+ async function installRelease(release, installed, target, environment) {
114
+ const { tag, latest } = release;
115
+ try {
116
+ await environment.download(target, tag);
117
+ if (await holdForLiveDaemon(latest, target, environment)) return Outcome.Finished;
118
+ if (lostTheRight(latest, environment)) {
119
+ environment.log("Stopped before the swap: the lock was lost, or the user rolled back");
120
+ return Outcome.TryAgainSoon;
121
+ }
122
+ await target.install({ newVersion: latest, runningVersion: environment.runningVersion });
123
+ environment.writeState({
124
+ updatedFromVersion: installed,
125
+ updatedToVersion: latest,
126
+ failedVersion: void 0,
127
+ failedAttempts: void 0,
128
+ deferredVersion: void 0,
129
+ deferredIpcVersion: void 0
130
+ });
131
+ environment.log(`Updated ${installed} to ${latest}`);
132
+ } catch (error) {
133
+ if (error instanceof UpdateError && error.countsAsBadRelease) countFailure(latest, environment);
134
+ environment.log(`Update to ${latest} failed: ${errorMessage(error)}`);
135
+ } finally {
136
+ environment.removeFile(target.downloadPath);
137
+ }
138
+ return Outcome.Finished;
139
+ }
140
+ async function runLocked(environment) {
141
+ environment.startLog();
142
+ if (checkedRecently(environment.readState(), environment.nowEpochSeconds())) {
143
+ environment.log("Another update checked within the last 24 hours");
144
+ return;
145
+ }
146
+ const release = await latestVersionAndTag(environment);
147
+ if (!release) return;
148
+ const installed = environment.target?.installedVersion(environment.runningVersion) ?? environment.runningVersion;
149
+ if (!isNewerVersion(release.latest, installed)) {
150
+ environment.recordLatestVersion(release.latest);
151
+ saveCheckTime(environment);
152
+ environment.log(`${installed} is up to date`);
153
+ return;
154
+ }
155
+ if (!await releaseIsReady(release.tag, environment)) return;
156
+ environment.recordLatestVersion(release.latest);
157
+ const reason = skipReason(release.latest, environment.readState(), environment);
158
+ if (reason || environment.target === null) {
159
+ saveCheckTime(environment);
160
+ environment.log(`No download: ${reason}`);
161
+ return;
162
+ }
163
+ if (await installRelease(release, installed, environment.target, environment) === Outcome.Finished) saveCheckTime(environment);
164
+ }
165
+ async function runUpdateChild(environment = createUpdateChildEnvironment()) {
166
+ const cancelTimeLimit = environment.startTimeLimit(() => {
167
+ if (environment.target) environment.removeFile(environment.target.downloadPath);
168
+ environment.exitProcess();
169
+ });
170
+ try {
171
+ environment.removeStaleFiles();
172
+ if (!await environment.acquireLock()) return;
173
+ try {
174
+ await runLocked(environment);
175
+ } finally {
176
+ environment.releaseLock();
177
+ }
178
+ } catch (error) {
179
+ environment.log(`Failed: ${errorMessage(error)}`);
180
+ } finally {
181
+ cancelTimeLimit();
182
+ }
183
+ }
184
+ function removeStaleFilesFor(platform, homeRealPath) {
185
+ if (platform === "win32") removeStaleUpdateFiles();
186
+ else removeStaleUnixFiles(unixLayoutPaths(homeRealPath));
187
+ }
188
+ function writeLogLine(logPath, line) {
189
+ try {
190
+ fs.appendFileSync(logPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}${os.EOL}`);
191
+ } catch {
192
+ }
193
+ }
194
+ function startLogFile(logPath) {
195
+ try {
196
+ ensurePinggyLogDir();
197
+ fs.writeFileSync(logPath, "");
198
+ } catch {
199
+ }
200
+ }
201
+ function createUpdateChildEnvironment() {
202
+ const probe = createInstallProbe();
203
+ const kind = backgroundInstallKind(detectInstallKind(probe), probe.execPath, probe.homeRealPath);
204
+ const runningVersion = getVersion();
205
+ const timeout = { timeoutMillis: CHECK_TIMEOUT_MILLIS };
206
+ const logPath = getUpdateLogPath();
207
+ return {
208
+ kind,
209
+ target: createUpdateTarget(kind, probe),
210
+ runningVersion,
211
+ nowEpochSeconds,
212
+ acquireLock: acquireUpdateLock,
213
+ releaseLock: releaseUpdateLock,
214
+ isLockOurs: isUpdateLockOurs,
215
+ readState: readUpdateState,
216
+ writeState: writeUpdateState,
217
+ recordLatestVersion,
218
+ resolveTag: () => resolveLatestTag(timeout),
219
+ resolveNpmVersion: () => resolveLatestNpmVersion(timeout),
220
+ isReleaseComplete: (tag) => isReleaseComplete(tag, timeout),
221
+ download: (target, tag) => downloadRelease(target, tag, assetNameFor(probe.platform, process.arch), runningVersion),
222
+ readIpcVersion: (binaryPath) => readBinaryIpcVersion(binaryPath, runPinggyBinary),
223
+ liveDaemon: getDaemonInfo,
224
+ removeStaleFiles: () => removeStaleFilesFor(probe.platform, probe.homeRealPath),
225
+ removeFile: removeQuietly,
226
+ startLog: () => startLogFile(logPath),
227
+ log: (line) => writeLogLine(logPath, line),
228
+ startTimeLimit: (onLimit) => {
229
+ const timer = setTimeout(onLimit, TIME_LIMIT_MILLIS);
230
+ return () => clearTimeout(timer);
231
+ },
232
+ exitProcess: () => process.exit(0)
233
+ };
234
+ }
235
+ export {
236
+ runUpdateChild
237
+ };
@@ -3,7 +3,7 @@ import {
3
3
  } from "../chunk-UB26QJ4T.js";
4
4
  import {
5
5
  logger
6
- } from "../chunk-IRKMUV37.js";
6
+ } from "../chunk-LWCVB42S.js";
7
7
 
8
8
  // src/workers/file_serve_worker.ts
9
9
  import { parentPort, workerData } from "worker_threads";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinggy",
3
- "version": "0.6.5",
3
+ "version": "0.6.7",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "Create secure, shareable tunnels to your localhost and manage them from the command line. ",
@@ -22,8 +22,8 @@
22
22
  "dev": "npm link @pinggy/pinggy && npm run build && npm link ",
23
23
  "pre-pkg": "node scripts/pre_pkg_processing.js remove",
24
24
  "post-pkg": "node scripts/pre_pkg_processing.js restore",
25
- "pack:linux-x64": "npm run pre-pkg && pkg . --targets node20-linux-x64 --output out/pinggy-linux-x64 && npm run post-pkg",
26
- "pack:linux-arm64": "npm run pre-pkg && pkg . --targets node20-linux-arm64 --output out/pinggy-linux-arm64 && npm run post-pkg",
25
+ "pack:linux-x64": "node scripts/check_linux_addons.js x64 && npm run pre-pkg && pkg . --targets node20-linux-x64 --output out/pinggy-linux-x64 && npm run post-pkg",
26
+ "pack:linux-arm64": "node scripts/check_linux_addons.js arm64 && npm run pre-pkg && pkg . --targets node20-linux-arm64 --output out/pinggy-linux-arm64 && npm run post-pkg",
27
27
  "pack:linux": "npm run pack:linux-x64 && npm run pack:linux-arm64",
28
28
  "pack:win-x64": "npm run pre-pkg && pkg . --targets node20-win-x64 --output out/pinggy-win-x64.exe && npm run post-pkg",
29
29
  "pack:win-arm64": "npm run pre-pkg && pkg . --targets node20-win-arm64 --output out/pinggy-win-arm64.exe && npm run post-pkg",
@@ -48,6 +48,7 @@
48
48
  "node_modules/@pinggy/pinggy/**/*",
49
49
  "node_modules/blessed/lib/**/*",
50
50
  "node_modules/blessed/usr/**/*",
51
+ "node_modules/node-pty/build/Release/pty.node",
51
52
  "dist/workers/**/*"
52
53
  ],
53
54
  "ignore": [
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env bash
2
+ # Compiles node-pty's Linux addon on Debian 12, so the packaged binary's terminal loads on glibc 2.34
3
+ # and newer. npm ci compiles it with the machine's own compiler, and on Ubuntu 26.04 (ubuntu-latest)
4
+ # that pty.node needs GLIBC_2.42. Run it after npm ci, on the architecture the binary targets.
5
+ # Needs Docker. scripts/check_linux_addons.js explains the limits, and checks the SDK's files too.
6
+ set -euo pipefail
7
+
8
+ IMAGE="node:24-bookworm"
9
+
10
+ if [ "$(uname -s)" != "Linux" ]; then
11
+ echo "build_node_pty_linux.sh: runs on Linux only. It compiles pty.node for this machine's architecture." >&2
12
+ exit 1
13
+ fi
14
+
15
+ cd "$(dirname "$0")/.."
16
+
17
+ # The runner's user owns the result. npm and node-gyp write their caches, and the Node headers
18
+ # node-gyp downloads, under /tmp in the container.
19
+ docker run --rm \
20
+ --user "$(id -u):$(id -g)" \
21
+ --env HOME=/tmp \
22
+ --volume "$PWD:/work" \
23
+ --workdir /work \
24
+ "$IMAGE" \
25
+ npm rebuild node-pty
26
+
27
+ node scripts/check_linux_addons.js "$(node -p process.arch)"
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Refuses a Linux native file that the packaged binary cannot load on the distros it supports.
5
+ *
6
+ * Usage: node scripts/check_linux_addons.js <x64|arm64>
7
+ *
8
+ * It checks node-pty's pty.node and the SDK's addon.node and libpinggy.so. libpinggy.so needs the
9
+ * system's OpenSSL 3, so the oldest distro the CLI runs on is RHEL 9: glibc 2.34, and GCC 11's
10
+ * libgcc_s and libstdc++. A native file needs the symbol versions of the machine that compiled it.
11
+ * pty.node compiled on Ubuntu 26.04 needs GLIBC_2.42, and the terminal then stays off on Ubuntu 24.04.
12
+ * scripts/build_node_pty_linux.sh compiles it on Debian 12. The SDK's files come prebuilt, unless the
13
+ * download fails and node-pre-gyp compiles them on this machine.
14
+ */
15
+
16
+ import { existsSync, readFileSync } from 'fs';
17
+ import { dirname, join } from 'path';
18
+ import { fileURLToPath } from 'url';
19
+
20
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
21
+
22
+ const NODE_PTY_REMEDY = 'Run npm ci on Linux, then scripts/build_node_pty_linux.sh, on the architecture the binary targets.';
23
+ const SDK_REMEDY = 'Run npm ci again on Linux, on the architecture the binary targets, so it downloads the SDK\'s prebuilt files.';
24
+
25
+ const NATIVE_FILES = [
26
+ { file: 'node_modules/node-pty/build/Release/pty.node', remedy: NODE_PTY_REMEDY },
27
+ { file: 'node_modules/@pinggy/pinggy/lib/addon.node', remedy: SDK_REMEDY },
28
+ { file: 'node_modules/@pinggy/pinggy/lib/libpinggy.so', remedy: SDK_REMEDY },
29
+ ];
30
+
31
+ /**
32
+ * The newest version of each family a file may need, from RHEL 9's libraries. On x64 its libgcc_s
33
+ * defines up to GCC_7.0.0, and on arm64 up to GCC_11.0.
34
+ */
35
+ const LIMITS = { GLIBC: '2.34', GLIBCXX: '3.4.29', CXXABI: '1.3.13', GCC: '7.0.0' };
36
+
37
+ // GLIBCXX before GLIBC, so the alternation takes the longer name.
38
+ const FAMILY_VERSION = /^(GLIBCXX|CXXABI|GLIBC|GCC)_(.+)$/;
39
+ const NUMBERED = /^[0-9]+(\.[0-9]+)*$/;
40
+
41
+ /** ELF `e_machine` values. */
42
+ const MACHINES = { x64: 62, arm64: 183 };
43
+ const ELF_MAGIC = '\x7fELF';
44
+
45
+ // Byte offsets in an ELF64 file: the file header, a section header, and the Verneed and Vernaux
46
+ // entries of the .gnu.version_r section.
47
+ const HEADER = { machine: 18, sectionsAt: 0x28, sectionSize: 0x3a, sectionCount: 0x3c };
48
+ const SECTION = { type: 4, offset: 24, link: 40, info: 44 };
49
+ const VERNEED = { auxCount: 2, auxAt: 8, next: 12 };
50
+ const VERNAUX = { name: 8, next: 12 };
51
+ const SHT_GNU_VERNEED = 0x6ffffffe;
52
+
53
+ function fail(message, hint) {
54
+ console.error(`check_linux_addons: ${message}`);
55
+ if (hint) console.error(hint);
56
+ process.exit(1);
57
+ }
58
+
59
+ function compareVersions(a, b) {
60
+ const left = a.split('.').map(Number);
61
+ const right = b.split('.').map(Number);
62
+ for (let i = 0; i < Math.max(left.length, right.length); i++) {
63
+ const difference = (left[i] ?? 0) - (right[i] ?? 0);
64
+ if (difference !== 0) return difference;
65
+ }
66
+ return 0;
67
+ }
68
+
69
+ function machineName(code) {
70
+ const name = Object.keys(MACHINES).find((arch) => MACHINES[arch] === code);
71
+ return name ?? `ELF machine ${code}`;
72
+ }
73
+
74
+ function checkArchitecture(elf, { file, remedy }, arch) {
75
+ if (elf.toString('latin1', 0, 4) !== ELF_MAGIC) fail(`${file} is not an ELF file.`, remedy);
76
+ const machine = elf.readUInt16LE(HEADER.machine);
77
+ if (machine !== MACHINES[arch]) fail(`${file} is built for ${machineName(machine)}, and the binary targets ${arch}.`, remedy);
78
+ }
79
+
80
+ function sectionHeaders(elf) {
81
+ const start = Number(elf.readBigUInt64LE(HEADER.sectionsAt));
82
+ const size = elf.readUInt16LE(HEADER.sectionSize);
83
+ return Array.from({ length: elf.readUInt16LE(HEADER.sectionCount) }, (_, index) => {
84
+ const header = start + index * size;
85
+ return {
86
+ type: elf.readUInt32LE(header + SECTION.type),
87
+ offset: Number(elf.readBigUInt64LE(header + SECTION.offset)),
88
+ link: elf.readUInt32LE(header + SECTION.link),
89
+ info: elf.readUInt32LE(header + SECTION.info),
90
+ };
91
+ });
92
+ }
93
+
94
+ function readString(elf, offset) {
95
+ return elf.toString('latin1', offset, elf.indexOf(0, offset));
96
+ }
97
+
98
+ /** The version names 1 Verneed entry asks of its library. */
99
+ function entryVersionNames(elf, entry, strings) {
100
+ const names = [];
101
+ let aux = entry + elf.readUInt32LE(entry + VERNEED.auxAt);
102
+ for (let i = 0; i < elf.readUInt16LE(entry + VERNEED.auxCount); i++) {
103
+ names.push(readString(elf, strings + elf.readUInt32LE(aux + VERNAUX.name)));
104
+ aux += elf.readUInt32LE(aux + VERNAUX.next);
105
+ }
106
+ return names;
107
+ }
108
+
109
+ /** Every symbol version the file needs, from its .gnu.version_r section. */
110
+ function neededVersions(elf, { file, remedy }) {
111
+ const sections = sectionHeaders(elf);
112
+ if (sections.length === 0) fail(`${file} has no section headers, so its symbol versions cannot be read.`, remedy);
113
+ const verneed = sections.find((section) => section.type === SHT_GNU_VERNEED);
114
+ if (!verneed) return [];
115
+ const strings = sections[verneed.link].offset;
116
+ const names = [];
117
+ let entry = verneed.offset;
118
+ for (let i = 0; i < verneed.info; i++) {
119
+ names.push(...entryVersionNames(elf, entry, strings));
120
+ entry += elf.readUInt32LE(entry + VERNEED.next);
121
+ }
122
+ return names;
123
+ }
124
+
125
+ /**
126
+ * The newest numbered version per family, and the family's names that carry no number, such as
127
+ * GLIBC_ABI_DT_RELR (glibc 2.36). Names of other libraries, such as libssl.so.3's OPENSSL_3.0.0, are
128
+ * not this check's to judge.
129
+ */
130
+ function sortVersions(names) {
131
+ const newest = {};
132
+ const unnumbered = [];
133
+ for (const name of names) {
134
+ const match = FAMILY_VERSION.exec(name);
135
+ if (!match) continue;
136
+ const [, family, version] = match;
137
+ if (!NUMBERED.test(version)) unnumbered.push(name);
138
+ else if (!newest[family] || compareVersions(version, newest[family]) > 0) newest[family] = version;
139
+ }
140
+ return { newest, unnumbered };
141
+ }
142
+
143
+ function checkVersions({ newest, unnumbered }, { file, remedy }) {
144
+ const tooNew = Object.entries(newest)
145
+ .filter(([family, version]) => compareVersions(version, LIMITS[family]) > 0)
146
+ .map(([family, version]) => `${family}_${version} (limit ${family}_${LIMITS[family]})`);
147
+ const refused = [...tooNew, ...unnumbered.map((name) => `${name} (not a numbered version)`)];
148
+ if (refused.length > 0) fail(`${file} needs ${refused.join(', ')}. It would not load on RHEL 9.`, remedy);
149
+ }
150
+
151
+ function checkFile(nativeFile, arch) {
152
+ const path = join(ROOT, nativeFile.file);
153
+ if (!existsSync(path)) fail(`${nativeFile.file} is missing.`, nativeFile.remedy);
154
+ const elf = readFileSync(path);
155
+ checkArchitecture(elf, nativeFile, arch);
156
+ const versions = sortVersions(neededVersions(elf, nativeFile));
157
+ checkVersions(versions, nativeFile);
158
+ const needs = Object.entries(versions.newest).map(([family, version]) => `${family}_${version}`).join(', ');
159
+ console.log(`check_linux_addons: ${nativeFile.file} is ${arch} and needs ${needs}.`);
160
+ }
161
+
162
+ function main() {
163
+ const arch = process.argv[2];
164
+ if (!MACHINES[arch]) fail(`usage: node scripts/check_linux_addons.js <${Object.keys(MACHINES).join('|')}>`);
165
+ for (const nativeFile of NATIVE_FILES) checkFile(nativeFile, arch);
166
+ }
167
+
168
+ main();
@@ -12,12 +12,11 @@
12
12
  # command line. The script removes the variable from this window when it ends
13
13
  #
14
14
  # Overrides, for dev and tests:
15
- # $env:PINGGY_VERSION a release tag, such as v0.6.1. Default: the latest release
15
+ # $env:PINGGY_VERSION a release tag, such as v0.6.1. Default: the version pinggy.io publishes
16
16
  # $env:PINGGY_BINARY_URL a full binary URL, file:// included. Replaces the installed binary without a version check
17
17
  # $env:PINGGY_MANAGE a non-production dashboard host, passed to `pinggy device login` or `connect` as --manage
18
18
  #
19
19
  # The source lives in Pinggy-io/cli-js, scripts/install/. A release copies it to pinggy.io.
20
- # Design: docs/pinggy-devices/install-script-plan.md in the pinggy_backend repo.
21
20
  #
22
21
  # iex runs this inside the user's own session. So it never calls exit, which would close their window, and every
23
22
  # helper and preference is local to Install-Pinggy. Nothing runs until the last line.
@@ -32,9 +31,11 @@ function Install-Pinggy {
32
31
  $ProgressPreference = 'SilentlyContinue'
33
32
 
34
33
  $releasesUrl = 'https://github.com/Pinggy-io/cli-js/releases'
34
+ $versionUrl = 'https://pinggy.io/cli/version.json'
35
35
  $installDir = Join-Path $env:LOCALAPPDATA 'Pinggy\bin'
36
36
  $installPath = Join-Path $installDir 'pinggy.exe'
37
37
  $versionPattern = 'Pinggy CLI version:\s*(\S+)'
38
+ $autoUpdatePinLine = 'Auto-update replaces this version. Set PINGGY_AUTO_UPDATE=false to keep it.'
38
39
  # The task `pinggy daemon service-install` registers. Its name lives in src/daemon/lifecycle/serviceInstaller.ts.
39
40
  $loginTaskName = 'PinggyDaemon'
40
41
  $cpuArchitectureX64 = 9
@@ -59,27 +60,24 @@ function Install-Pinggy {
59
60
  throw "pinggy install: unsupported CPU: $processArchitecture. The pinggy binaries are built for x64 and arm64."
60
61
  }
61
62
 
62
- # GitHub redirects /releases/latest to /releases/tag/<tag>. Reading the redirect costs no API call, so the
63
- # API's 60 requests an hour per IP do not apply.
63
+ # pinggy.io publishes the latest version in the deploy that publishes this script, so the script and the binary
64
+ # come from 1 release. GitHub's /releases/latest can name a newer release, or one whose binaries still upload.
64
65
  function Get-TargetTag {
65
66
  if ($env:PINGGY_VERSION) {
66
67
  if ($env:PINGGY_VERSION.StartsWith('v')) { return $env:PINGGY_VERSION }
67
68
  return "v$($env:PINGGY_VERSION)"
68
69
  }
69
- $response = Invoke-WebRequest -Uri "$releasesUrl/latest" -Method Head -UseBasicParsing
70
- $baseResponse = $response.BaseResponse
71
- if ($baseResponse.PSObject.Properties['ResponseUri']) {
72
- # Windows PowerShell 5.1: HttpWebResponse
73
- $finalUrl = $baseResponse.ResponseUri.AbsoluteUri
74
- } else {
75
- # PowerShell 7: HttpResponseMessage
76
- $finalUrl = $baseResponse.RequestMessage.RequestUri.AbsoluteUri
70
+ $retryHint = 'Try again later, or set $env:PINGGY_VERSION to a release tag, such as v0.6.1.'
71
+ try {
72
+ $latest = Invoke-RestMethod -Uri $versionUrl -UseBasicParsing
73
+ } catch {
74
+ throw "pinggy install: could not reach $versionUrl. $retryHint"
77
75
  }
78
- $tag = ($finalUrl -split '/')[-1]
79
- if ($tag -notmatch '^v\d') {
80
- throw "pinggy install: could not read the latest release tag from $releasesUrl/latest"
76
+ $version = [string] $latest.version
77
+ if ($version -notmatch '^\d+\.\d+\.\d+$') {
78
+ throw "pinggy install: could not read the latest version from $versionUrl. $retryHint"
81
79
  }
82
- return $tag
80
+ return "v$version"
83
81
  }
84
82
 
85
83
  # The version a binary reports, or '' when it does not run. 'Continue', because Windows PowerShell 5.1 turns a
@@ -184,6 +182,7 @@ function Install-Pinggy {
184
182
  Install-Binary $tag $cpu
185
183
  } else {
186
184
  Write-Host "Keeping pinggy $installedVersion."
185
+ if (-not $env:PINGGY_VERSION) { Write-Host $autoUpdatePinLine }
187
186
  }
188
187
  }
189
188
 
@@ -288,6 +287,7 @@ function Install-Pinggy {
288
287
  try {
289
288
  $cpu = Get-Cpu
290
289
  Install-OrUpdate $cpu
290
+ if ($env:PINGGY_VERSION) { Write-Host $autoUpdatePinLine }
291
291
  Add-InstallDirToPath
292
292
  if ($env:DEVICE_AGENT_TOKEN) {
293
293
  Invoke-DeviceConnect