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.
- package/ARCHITECTURE.md +103 -39
- package/CLAUDE.md +21 -11
- package/README.md +12 -2
- package/dist/{TunnelManager-DXNXIH5W.js → TunnelManager-JRVEADS4.js} +4 -3
- package/dist/{TunnelTui-K7KESRTQ.js → TunnelTui-6H4NPUNF.js} +4 -3
- package/dist/{chunk-QZJGTQZC.js → chunk-2GIJXE4K.js} +3 -2
- package/dist/chunk-3KCXR33Y.js +954 -0
- package/dist/{chunk-EMCDDH3B.js → chunk-3WMTTJHI.js} +11 -299
- package/dist/{chunk-X6TZN5CT.js → chunk-CZOKR73F.js} +1 -1
- package/dist/{chunk-K5QHR5KU.js → chunk-FWTQF6AB.js} +519 -556
- package/dist/{chunk-3PTLHLFL.js → chunk-H527WMTF.js} +33 -240
- package/dist/chunk-HTIWY3O5.js +293 -0
- package/dist/{chunk-IRKMUV37.js → chunk-LWCVB42S.js} +2 -2
- package/dist/{chunk-N5WE4DYD.js → chunk-MAK5R4WQ.js} +12 -0
- package/dist/{chunk-7EQKHVQX.js → chunk-MHQ3CVEB.js} +4 -51
- package/dist/chunk-MKGD2QAI.js +51 -0
- package/dist/chunk-PMZJ6HFH.js +882 -0
- package/dist/{configStore-DXC6WMYO.js → configStore-JJUWT2YO.js} +3 -3
- package/dist/{daemonChild-HZ27YJKQ.js → daemonChild-24Y3AKII.js} +14 -10
- package/dist/{daemonConfig-MCAKZHY2.js → daemonConfig-VWK4TXVS.js} +2 -2
- package/dist/index.cjs +3621 -1814
- package/dist/index.d.cts +142 -129
- package/dist/index.d.ts +142 -129
- package/dist/index.js +18 -13
- package/dist/{ipcClient-XGF2KCQO.js → ipcClient-IZ5R6TPN.js} +2 -1
- package/dist/{main-TDQB5ZB4.js → main-HSIFQAGU.js} +19 -14
- package/dist/updateChild-JNGDWIAK.js +237 -0
- package/dist/workers/file_serve_worker.js +1 -1
- package/package.json +4 -3
- package/scripts/build_node_pty_linux.sh +27 -0
- package/scripts/check_linux_addons.js +168 -0
- package/scripts/install/install.ps1 +16 -16
- package/scripts/install/install.sh +57 -20
|
@@ -3,37 +3,21 @@ import {
|
|
|
3
3
|
TunnelConfigV1Schema,
|
|
4
4
|
TunnelOperations,
|
|
5
5
|
buildRemoteManagementWsUrl,
|
|
6
|
-
daemonIpcVersion,
|
|
7
|
-
ensureDaemonRunning,
|
|
8
|
-
getDaemonInfo,
|
|
9
6
|
initiateRemoteManagement,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
isIpcCompatible,
|
|
13
|
-
isProcessAlive,
|
|
14
|
-
startDaemon,
|
|
15
|
-
startRemoteManagement,
|
|
16
|
-
startedBeforeBoot,
|
|
17
|
-
stopDaemon
|
|
18
|
-
} from "./chunk-3PTLHLFL.js";
|
|
7
|
+
startRemoteManagement
|
|
8
|
+
} from "./chunk-H527WMTF.js";
|
|
19
9
|
import {
|
|
20
10
|
configuredLogLevel,
|
|
21
11
|
forgetDeviceAgent,
|
|
22
12
|
saveDeviceAgent,
|
|
23
13
|
savedDeviceAgent,
|
|
24
14
|
writeDaemonConfig
|
|
25
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-CZOKR73F.js";
|
|
26
16
|
import {
|
|
27
|
-
DaemonHost,
|
|
28
|
-
DeviceAgentState,
|
|
29
17
|
HTTP_NOT_FOUND,
|
|
30
18
|
IPCClient,
|
|
31
|
-
IPCHttpError
|
|
32
|
-
|
|
33
|
-
Route,
|
|
34
|
-
SessionMode,
|
|
35
|
-
ShutdownStatus
|
|
36
|
-
} from "./chunk-7EQKHVQX.js";
|
|
19
|
+
IPCHttpError
|
|
20
|
+
} from "./chunk-MHQ3CVEB.js";
|
|
37
21
|
import {
|
|
38
22
|
ConfigVerb,
|
|
39
23
|
SUBCOMMANDS,
|
|
@@ -52,33 +36,94 @@ import {
|
|
|
52
36
|
upsertConfig,
|
|
53
37
|
validateName,
|
|
54
38
|
validateNameStrict
|
|
55
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-2GIJXE4K.js";
|
|
56
40
|
import {
|
|
57
41
|
createQrCodes
|
|
58
42
|
} from "./chunk-XZ64ZAGO.js";
|
|
59
43
|
import {
|
|
60
|
-
ErrorCode,
|
|
61
44
|
TunnelManager,
|
|
62
|
-
TunnelStateType,
|
|
63
45
|
detachAllTunnelLoggers,
|
|
46
|
+
isTunnelLoggingEnabled,
|
|
47
|
+
setTunnelLoggingEnabled
|
|
48
|
+
} from "./chunk-3WMTTJHI.js";
|
|
49
|
+
import {
|
|
50
|
+
UpdateError,
|
|
51
|
+
acquireUpdateLock,
|
|
52
|
+
assetNameFor,
|
|
53
|
+
createUpdateTarget,
|
|
54
|
+
downloadRelease,
|
|
55
|
+
environmentWithoutDeviceToken,
|
|
56
|
+
isNewerVersion,
|
|
57
|
+
isReleaseComplete,
|
|
58
|
+
isUpdateLockHeld,
|
|
59
|
+
parseVersion,
|
|
60
|
+
readBinaryIpcVersion,
|
|
61
|
+
releaseUpdateLock,
|
|
62
|
+
removeQuietly,
|
|
63
|
+
removeStaleUpdateFiles,
|
|
64
|
+
resolveLatestTag,
|
|
65
|
+
runPinggyBinary,
|
|
66
|
+
versionFromTag,
|
|
67
|
+
windowsInstallPaths
|
|
68
|
+
} from "./chunk-PMZJ6HFH.js";
|
|
69
|
+
import {
|
|
70
|
+
InstallKind,
|
|
71
|
+
NPM_INSTALL_COMMAND,
|
|
72
|
+
backgroundInstallKind,
|
|
73
|
+
canReplaceItself,
|
|
74
|
+
createInstallProbe,
|
|
75
|
+
daemonIpcVersion,
|
|
76
|
+
detectInstallKind,
|
|
77
|
+
ensureDaemonRunning,
|
|
78
|
+
getDaemonInfo,
|
|
79
|
+
hasExecutableSpawnHelper,
|
|
80
|
+
hasPathSegment,
|
|
81
|
+
installCommandFor,
|
|
82
|
+
installService,
|
|
83
|
+
ipcMismatchMessage,
|
|
84
|
+
isDaemonRunning,
|
|
85
|
+
isIpcCompatible,
|
|
86
|
+
isPackagedBinary,
|
|
87
|
+
isProcessAlive,
|
|
88
|
+
makeSpawnHelperExecutable,
|
|
89
|
+
nowEpochSeconds,
|
|
90
|
+
readUpdateState,
|
|
91
|
+
recordLatestVersion,
|
|
92
|
+
requireNodePty,
|
|
93
|
+
resolveNodePtyRoot,
|
|
94
|
+
startDaemon,
|
|
95
|
+
startedBeforeBoot,
|
|
96
|
+
stopDaemon,
|
|
97
|
+
uninstallService,
|
|
98
|
+
writeUpdateState
|
|
99
|
+
} from "./chunk-3KCXR33Y.js";
|
|
100
|
+
import {
|
|
101
|
+
DaemonHost,
|
|
102
|
+
DeviceAgentState,
|
|
103
|
+
IPC_VERSION,
|
|
104
|
+
Route,
|
|
105
|
+
SessionMode,
|
|
106
|
+
ShutdownStatus
|
|
107
|
+
} from "./chunk-MKGD2QAI.js";
|
|
108
|
+
import {
|
|
109
|
+
ErrorCode,
|
|
110
|
+
TunnelStateType,
|
|
64
111
|
errorMessage,
|
|
65
112
|
getLocalAddress,
|
|
66
113
|
getRandomId,
|
|
67
114
|
getVersion,
|
|
68
115
|
isErrorResponse,
|
|
69
|
-
isTunnelLoggingEnabled,
|
|
70
116
|
isValidPort,
|
|
71
117
|
newErrorResponse,
|
|
72
|
-
printer_default
|
|
73
|
-
|
|
74
|
-
} from "./chunk-EMCDDH3B.js";
|
|
118
|
+
printer_default
|
|
119
|
+
} from "./chunk-HTIWY3O5.js";
|
|
75
120
|
import {
|
|
76
121
|
configureLogger,
|
|
77
122
|
enablePackageLogging,
|
|
78
123
|
getLogLevel,
|
|
79
124
|
logger,
|
|
80
125
|
setLogLevel
|
|
81
|
-
} from "./chunk-
|
|
126
|
+
} from "./chunk-LWCVB42S.js";
|
|
82
127
|
import {
|
|
83
128
|
ensurePinggyConfigDir,
|
|
84
129
|
ensurePinggyLogDir,
|
|
@@ -90,7 +135,7 @@ import {
|
|
|
90
135
|
getPinggyConfigDir,
|
|
91
136
|
getTunnelLogDir,
|
|
92
137
|
getTunnelLogPath
|
|
93
|
-
} from "./chunk-
|
|
138
|
+
} from "./chunk-MAK5R4WQ.js";
|
|
94
139
|
|
|
95
140
|
// src/cli/options.ts
|
|
96
141
|
var cliOptions = {
|
|
@@ -139,8 +184,15 @@ var cliOptions = {
|
|
|
139
184
|
all: { type: "boolean", description: "Start all auto-start tunnels" },
|
|
140
185
|
// `pinggy device login` and `connect` only. Their agent runs in the daemon unless this is set.
|
|
141
186
|
foreground: { type: "boolean", description: "Run the device agent in this terminal", hidden: true },
|
|
187
|
+
// `pinggy update` only.
|
|
188
|
+
check: { type: "boolean", description: "Print the latest version and change nothing", hidden: true },
|
|
189
|
+
rollback: { type: "boolean", description: "Go back to the previous version", hidden: true },
|
|
142
190
|
// Internal daemon child marker
|
|
143
191
|
"_daemon-child": { type: "boolean", description: "Internal: daemon child process marker", hidden: true },
|
|
192
|
+
// Internal: the detached process that checks for a release and installs it.
|
|
193
|
+
"_update-child": { type: "boolean", description: "Internal: background updater marker", hidden: true },
|
|
194
|
+
// Internal: prints IPC_VERSION, so an updater can compare a downloaded binary with a running daemon.
|
|
195
|
+
"_ipc-version": { type: "boolean", description: "Internal: print the IPC protocol version", hidden: true },
|
|
144
196
|
// Misc
|
|
145
197
|
version: { type: "boolean", description: "Print version" },
|
|
146
198
|
// Help
|
|
@@ -214,6 +266,11 @@ function printHelpMessage() {
|
|
|
214
266
|
console.log(" pinggy device login --foreground # Same, with the agent in this terminal");
|
|
215
267
|
console.log(" pinggy device status # Show this device and its agent");
|
|
216
268
|
console.log(" pinggy device stop # Stop the background agent");
|
|
269
|
+
console.log("\nUpdates:");
|
|
270
|
+
console.log(" pinggy update --check # Print the latest version");
|
|
271
|
+
console.log(" pinggy update # Update to the latest version now");
|
|
272
|
+
console.log(" pinggy update --rollback # Go back to the previous version");
|
|
273
|
+
console.log(" PINGGY_AUTO_UPDATE=false # Turn off automatic updates");
|
|
217
274
|
console.log("\nDaemon Lifecycle (also: pinggy d <command>):");
|
|
218
275
|
console.log(" pinggy daemon start # Start the background daemon");
|
|
219
276
|
console.log(" pinggy daemon stop # Stop the daemon (stops all tunnels)");
|
|
@@ -283,9 +340,153 @@ function parseCliArgs(options, overrideArgs) {
|
|
|
283
340
|
};
|
|
284
341
|
}
|
|
285
342
|
|
|
343
|
+
// src/update/backgroundUpdate.ts
|
|
344
|
+
import { spawn } from "child_process";
|
|
345
|
+
import fs from "fs";
|
|
346
|
+
import os2 from "os";
|
|
347
|
+
|
|
348
|
+
// src/update/updateMessages.ts
|
|
349
|
+
function daemonRestartLine(version, host) {
|
|
350
|
+
const firstSentence = `pinggy ${version} needs a daemon restart.`;
|
|
351
|
+
if (host === DaemonHost.APP) return `${firstSentence} Update the Pinggy app, then run "pinggy update".`;
|
|
352
|
+
return `${firstSentence} Run "pinggy daemon stop", then "pinggy update". This stops all running tunnels.`;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/update/backgroundUpdate.ts
|
|
356
|
+
var AUTO_UPDATE_ENV = "PINGGY_AUTO_UPDATE";
|
|
357
|
+
var OFF_VALUES = /* @__PURE__ */ new Set(["false", "0"]);
|
|
358
|
+
var ON_VALUES = /* @__PURE__ */ new Set(["true", "1"]);
|
|
359
|
+
var SUDO_UID_ENV = "SUDO_UID";
|
|
360
|
+
var CONTAINER_MARKER_FILES = ["/.dockerenv", "/run/.containerenv"];
|
|
361
|
+
var NPX_SEGMENT = "_npx";
|
|
362
|
+
var UPDATE_SUBCOMMAND = "update";
|
|
363
|
+
var UPDATE_CHILD_FLAG = "--_update-child";
|
|
364
|
+
var SECONDS_PER_DAY = 24 * 60 * 60;
|
|
365
|
+
var CHECK_INTERVAL_SECONDS = SECONDS_PER_DAY;
|
|
366
|
+
var ATTEMPT_INTERVAL_SECONDS = 60 * 60;
|
|
367
|
+
var COULD_NOT_UPDATE_AFTER_SECONDS = 7 * SECONDS_PER_DAY;
|
|
368
|
+
var COULD_NOT_CHECK_AFTER_SECONDS = 30 * SECONDS_PER_DAY;
|
|
369
|
+
function isDue(lastEpochSeconds, intervalSeconds, now) {
|
|
370
|
+
return lastEpochSeconds === void 0 || lastEpochSeconds > now || now - lastEpochSeconds > intervalSeconds;
|
|
371
|
+
}
|
|
372
|
+
function isAutoUpdateOff(variables) {
|
|
373
|
+
const value = variables[AUTO_UPDATE_ENV]?.toLowerCase();
|
|
374
|
+
if (value === void 0) return false;
|
|
375
|
+
if (!OFF_VALUES.has(value) && !ON_VALUES.has(value)) {
|
|
376
|
+
logger.debug(`Unknown ${AUTO_UPDATE_ENV} value leaves auto-update on`, { value });
|
|
377
|
+
}
|
|
378
|
+
return OFF_VALUES.has(value);
|
|
379
|
+
}
|
|
380
|
+
function isExplicitOrPrintOnly({ rawArgs, values, hasAnyArgs }) {
|
|
381
|
+
return rawArgs[0] === UPDATE_SUBCOMMAND || !hasAnyArgs || Boolean(values.help) || Boolean(values.version);
|
|
382
|
+
}
|
|
383
|
+
function isExcludedProcess(environment) {
|
|
384
|
+
return Boolean(environment.variables[SUDO_UID_ENV]) || CONTAINER_MARKER_FILES.some(environment.fileExists) || parseVersion(environment.runningVersion) === null || hasPathSegment(environment.scriptRealPath, NPX_SEGMENT);
|
|
385
|
+
}
|
|
386
|
+
function updatedNotice(state, running) {
|
|
387
|
+
if (state.updatedToVersion !== running || !state.updatedFromVersion) return null;
|
|
388
|
+
return {
|
|
389
|
+
line: `Updated pinggy ${state.updatedFromVersion} to ${running}.`,
|
|
390
|
+
patch: { updatedFromVersion: void 0, updatedToVersion: void 0 }
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function deferredNotice(state, environment) {
|
|
394
|
+
const version = state.deferredVersion;
|
|
395
|
+
if (!version || state.lastNoticeVersion === version) return null;
|
|
396
|
+
const daemon = environment.liveDaemon();
|
|
397
|
+
if (!daemon) return null;
|
|
398
|
+
return { line: daemonRestartLine(version, daemon.host), patch: { lastNoticeVersion: version } };
|
|
399
|
+
}
|
|
400
|
+
function availableLine(kind, latest, platform3) {
|
|
401
|
+
if (kind === InstallKind.Npm) return `pinggy ${latest} is available. Run: ${NPM_INSTALL_COMMAND}`;
|
|
402
|
+
if (kind === InstallKind.WindowsReadOnly || kind === InstallKind.UnixLoose) {
|
|
403
|
+
return `pinggy ${latest} is available. Run: ${installCommandFor(platform3)}`;
|
|
404
|
+
}
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
function newVersionNotice(state, kind, environment) {
|
|
408
|
+
const latest = state.latestVersion;
|
|
409
|
+
if (!latest || !isNewerVersion(latest, environment.runningVersion) || state.lastNoticeVersion === latest) return null;
|
|
410
|
+
const patch = { lastNoticeVersion: latest };
|
|
411
|
+
const available = availableLine(kind(), latest, environment.platform);
|
|
412
|
+
if (available) return { line: available, patch };
|
|
413
|
+
const seenLongAgo = state.latestSeenEpochSeconds !== void 0 && environment.nowEpochSeconds() - state.latestSeenEpochSeconds > COULD_NOT_UPDATE_AFTER_SECONDS;
|
|
414
|
+
if (canReplaceItself(kind()) && seenLongAgo && latest !== state.rolledBackFromVersion) {
|
|
415
|
+
return { line: `pinggy could not update itself to ${latest}. Run: pinggy update`, patch };
|
|
416
|
+
}
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
function couldNotCheckNotice(state, kind, environment) {
|
|
420
|
+
const now = environment.nowEpochSeconds();
|
|
421
|
+
const lastCheck = state.lastCheckEpochSeconds;
|
|
422
|
+
if (lastCheck === void 0 || now - lastCheck <= COULD_NOT_CHECK_AFTER_SECONDS) return null;
|
|
423
|
+
if (!isDue(state.lastCheckFailureNoticeEpochSeconds, COULD_NOT_CHECK_AFTER_SECONDS, now)) return null;
|
|
424
|
+
if (kind() === InstallKind.DevCheckout) return null;
|
|
425
|
+
return { line: "pinggy could not check for updates. Run: pinggy update", patch: { lastCheckFailureNoticeEpochSeconds: now } };
|
|
426
|
+
}
|
|
427
|
+
function pendingNotice(state, kind, environment) {
|
|
428
|
+
return updatedNotice(state, environment.runningVersion) ?? deferredNotice(state, environment) ?? newVersionNotice(state, kind, environment) ?? couldNotCheckNotice(state, kind, environment);
|
|
429
|
+
}
|
|
430
|
+
function printPendingNotice(state, kind, environment) {
|
|
431
|
+
const notice = pendingNotice(state, kind, environment);
|
|
432
|
+
if (notice && environment.writeState(notice.patch)) environment.print(notice.line);
|
|
433
|
+
}
|
|
434
|
+
function runGates(command, environment) {
|
|
435
|
+
if (isExplicitOrPrintOnly(command) || !environment.stdoutIsTerminal) return;
|
|
436
|
+
if (isAutoUpdateOff(environment.variables) || isExcludedProcess(environment)) return;
|
|
437
|
+
let detectedKind;
|
|
438
|
+
const kind = () => detectedKind ?? (detectedKind = environment.detectKind());
|
|
439
|
+
const state = environment.readState();
|
|
440
|
+
printPendingNotice(state, kind, environment);
|
|
441
|
+
const now = environment.nowEpochSeconds();
|
|
442
|
+
if (!isDue(state.lastCheckEpochSeconds, CHECK_INTERVAL_SECONDS, now)) return;
|
|
443
|
+
if (!isDue(state.lastAttemptEpochSeconds, ATTEMPT_INTERVAL_SECONDS, now)) return;
|
|
444
|
+
if (kind() === InstallKind.DevCheckout || environment.isLockHeld()) return;
|
|
445
|
+
if (environment.writeState({ lastAttemptEpochSeconds: now })) environment.spawnUpdater();
|
|
446
|
+
}
|
|
447
|
+
function spawnUpdater(spawnProcess = spawn) {
|
|
448
|
+
const child = spawnProcess(process.execPath, [process.argv[1], UPDATE_CHILD_FLAG], {
|
|
449
|
+
detached: true,
|
|
450
|
+
stdio: "ignore",
|
|
451
|
+
// On Windows a process holds its working directory open, so inheriting it would block deleting that folder.
|
|
452
|
+
cwd: os2.homedir(),
|
|
453
|
+
env: environmentWithoutDeviceToken(),
|
|
454
|
+
...os2.platform() === "win32" ? { windowsHide: true } : {}
|
|
455
|
+
});
|
|
456
|
+
child.on("error", (error) => logger.debug("Could not start the updater", { error: errorMessage(error) }));
|
|
457
|
+
child.unref();
|
|
458
|
+
}
|
|
459
|
+
function realEnvironment() {
|
|
460
|
+
const probe = createInstallProbe();
|
|
461
|
+
return {
|
|
462
|
+
variables: process.env,
|
|
463
|
+
stdoutIsTerminal: process.stdout.isTTY === true,
|
|
464
|
+
runningVersion: getVersion(),
|
|
465
|
+
platform: probe.platform,
|
|
466
|
+
scriptRealPath: probe.scriptRealPath,
|
|
467
|
+
nowEpochSeconds,
|
|
468
|
+
fileExists: (filePath) => fs.existsSync(filePath),
|
|
469
|
+
detectKind: () => backgroundInstallKind(detectInstallKind(probe), probe.execPath, probe.homeRealPath),
|
|
470
|
+
readState: readUpdateState,
|
|
471
|
+
writeState: writeUpdateState,
|
|
472
|
+
isLockHeld: isUpdateLockHeld,
|
|
473
|
+
liveDaemon: getDaemonInfo,
|
|
474
|
+
print: (line) => printer_default.print(line),
|
|
475
|
+
spawnUpdater: () => spawnUpdater()
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function startBackgroundUpdate(command, createEnvironment = realEnvironment) {
|
|
479
|
+
try {
|
|
480
|
+
runGates(command, createEnvironment());
|
|
481
|
+
} catch (error) {
|
|
482
|
+
logger.debug("Background update gate failed", { error: errorMessage(error) });
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
286
486
|
// src/main.ts
|
|
287
487
|
import { fileURLToPath } from "url";
|
|
288
488
|
import { argv } from "process";
|
|
489
|
+
import { platform as platform2 } from "os";
|
|
289
490
|
import { realpathSync } from "fs";
|
|
290
491
|
|
|
291
492
|
// src/cli/defaults.ts
|
|
@@ -458,7 +659,7 @@ function isValidIpV6Cidr(input) {
|
|
|
458
659
|
|
|
459
660
|
// src/cli/buildConfig.ts
|
|
460
661
|
import { TunnelType } from "@pinggy/pinggy";
|
|
461
|
-
import
|
|
662
|
+
import fs2 from "fs";
|
|
462
663
|
import path from "path";
|
|
463
664
|
import { isIP as isIP2 } from "net";
|
|
464
665
|
var domainRegex = /^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
|
|
@@ -829,10 +1030,10 @@ function parseArgs2(finalConfig, remainingPositionals) {
|
|
|
829
1030
|
}
|
|
830
1031
|
function storeJson(config, saveconf) {
|
|
831
1032
|
if (saveconf) {
|
|
832
|
-
const
|
|
1033
|
+
const path5 = saveconf;
|
|
833
1034
|
try {
|
|
834
|
-
|
|
835
|
-
logger.info(`Configuration saved to ${
|
|
1035
|
+
fs2.writeFileSync(path5, JSON.stringify(config, null, 2), { encoding: "utf-8", flag: "w" });
|
|
1036
|
+
logger.info(`Configuration saved to ${path5}`);
|
|
836
1037
|
} catch (err) {
|
|
837
1038
|
const msg = err instanceof Error ? err.message : String(err);
|
|
838
1039
|
logger.error("Error loading configuration:", msg);
|
|
@@ -844,7 +1045,7 @@ function loadJsonConfig(config) {
|
|
|
844
1045
|
if (typeof configpath === "string" && configpath.trim().length > 0) {
|
|
845
1046
|
const filepath = path.resolve(configpath);
|
|
846
1047
|
try {
|
|
847
|
-
const data =
|
|
1048
|
+
const data = fs2.readFileSync(filepath, { encoding: "utf-8" });
|
|
848
1049
|
const json = JSON.parse(data);
|
|
849
1050
|
return json;
|
|
850
1051
|
} catch (err) {
|
|
@@ -1039,13 +1240,14 @@ async function initTunnelClient() {
|
|
|
1039
1240
|
const client = new TunnelClient();
|
|
1040
1241
|
printer_default.startSpinner("Initializing...");
|
|
1041
1242
|
try {
|
|
1042
|
-
await client.ensureDaemon();
|
|
1243
|
+
await client.ensureDaemon({ holdVersionNotice: true });
|
|
1043
1244
|
} catch (err) {
|
|
1044
1245
|
const msg = err instanceof Error ? err.message : String(err);
|
|
1045
1246
|
printer_default.stopSpinnerFail(`Failed to start daemon: ${msg}`);
|
|
1046
1247
|
process.exit(1);
|
|
1047
1248
|
}
|
|
1048
1249
|
printer_default.stopSpinnerSuccess("Initialized");
|
|
1250
|
+
client.printHeldVersionNotice();
|
|
1049
1251
|
return client;
|
|
1050
1252
|
}
|
|
1051
1253
|
function printRemoteUrls(urls) {
|
|
@@ -1157,7 +1359,7 @@ async function connectTui(opts) {
|
|
|
1157
1359
|
const exitMessage = opts.exitMessage || "Stopping tunnel...";
|
|
1158
1360
|
if (!noTui && process.stdin.isTTY) {
|
|
1159
1361
|
try {
|
|
1160
|
-
const { TunnelTui } = await import("./TunnelTui-
|
|
1362
|
+
const { TunnelTui } = await import("./TunnelTui-6H4NPUNF.js");
|
|
1161
1363
|
const tui = new TunnelTui({
|
|
1162
1364
|
urls,
|
|
1163
1365
|
greet,
|
|
@@ -1380,7 +1582,7 @@ async function startBackgroundTunnels(configs, values, positionals) {
|
|
|
1380
1582
|
client.close();
|
|
1381
1583
|
}
|
|
1382
1584
|
async function startAutoStartTunnels() {
|
|
1383
|
-
const { getAutoStartConfigs: getAutoStartConfigs2 } = await import("./configStore-
|
|
1585
|
+
const { getAutoStartConfigs: getAutoStartConfigs2 } = await import("./configStore-JJUWT2YO.js");
|
|
1384
1586
|
const configs = getAutoStartConfigs2();
|
|
1385
1587
|
if (configs.length === 0) {
|
|
1386
1588
|
printer_default.warn("No configs marked for auto-start. Use: pinggy config auto <name>");
|
|
@@ -1503,335 +1705,6 @@ async function initRemoteManagement(values, blocking) {
|
|
|
1503
1705
|
// src/cli/subcommand/handlers/daemonCommandsHandler.ts
|
|
1504
1706
|
import pico6 from "picocolors";
|
|
1505
1707
|
|
|
1506
|
-
// src/daemon/lifecycle/serviceInstaller.ts
|
|
1507
|
-
import os2 from "os";
|
|
1508
|
-
import fs2 from "fs";
|
|
1509
|
-
import path2 from "path";
|
|
1510
|
-
import { execSync, execFileSync } from "child_process";
|
|
1511
|
-
var SERVICE_LABEL = "io.pinggy.agent";
|
|
1512
|
-
var SYSTEMD_SERVICE_NAME = "pinggy";
|
|
1513
|
-
var SERVICE_ANY_LOCATION_ENV = "PINGGY_SERVICE_ANY_LOCATION";
|
|
1514
|
-
function installerBinaryPath(platform2, home, env) {
|
|
1515
|
-
if (platform2 === "win32") {
|
|
1516
|
-
const localAppData = env.LOCALAPPDATA || path2.win32.join(home, "AppData", "Local");
|
|
1517
|
-
return path2.win32.join(localAppData, "Pinggy", "bin", "pinggy.exe");
|
|
1518
|
-
}
|
|
1519
|
-
return path2.posix.join(home, ".pinggy", "bin", "pinggy");
|
|
1520
|
-
}
|
|
1521
|
-
function realPath(p) {
|
|
1522
|
-
try {
|
|
1523
|
-
return fs2.realpathSync(p);
|
|
1524
|
-
} catch {
|
|
1525
|
-
return p;
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
function isInstallerBinary(ctx) {
|
|
1529
|
-
const actual = realPath(ctx.execPath);
|
|
1530
|
-
const expected = realPath(installerBinaryPath(ctx.platform, ctx.home, ctx.env));
|
|
1531
|
-
if (ctx.platform === "win32") return actual.toLowerCase() === expected.toLowerCase();
|
|
1532
|
-
return actual === expected;
|
|
1533
|
-
}
|
|
1534
|
-
function installerFix(platform2) {
|
|
1535
|
-
const installCommand = platform2 === "win32" ? "irm https://pinggy.io/install.ps1 | iex" : "curl -fsSL https://pinggy.io/install.sh | sh";
|
|
1536
|
-
return [
|
|
1537
|
-
"pinggy can only run as a service when it is installed with the Pinggy installer.",
|
|
1538
|
-
"Install it, then run this command again:",
|
|
1539
|
-
` ${installCommand}`,
|
|
1540
|
-
" pinggy daemon service-install"
|
|
1541
|
-
].join("\n");
|
|
1542
|
-
}
|
|
1543
|
-
function serviceInstallRefusal(ctx) {
|
|
1544
|
-
if (!ctx.isPkg) return `The npm version of pinggy cannot run as a service.
|
|
1545
|
-
${installerFix(ctx.platform)}`;
|
|
1546
|
-
if (ctx.env[SERVICE_ANY_LOCATION_ENV] === "1" || isInstallerBinary(ctx)) return null;
|
|
1547
|
-
return installerFix(ctx.platform);
|
|
1548
|
-
}
|
|
1549
|
-
function printInstalled() {
|
|
1550
|
-
printer_default.success("pinggy now starts automatically when this computer starts.");
|
|
1551
|
-
}
|
|
1552
|
-
function printUninstalled() {
|
|
1553
|
-
printer_default.success("pinggy no longer starts automatically when this computer starts.");
|
|
1554
|
-
}
|
|
1555
|
-
function printNotInstalled() {
|
|
1556
|
-
printer_default.print("pinggy is not set to start automatically.");
|
|
1557
|
-
}
|
|
1558
|
-
var QUIET = { stdio: ["ignore", "ignore", "pipe"] };
|
|
1559
|
-
function toolError(err) {
|
|
1560
|
-
const stderr = err.stderr?.toString().trim();
|
|
1561
|
-
return stderr ? stderr.replace(/^ERROR:\s*/i, "") : errorMessage(err);
|
|
1562
|
-
}
|
|
1563
|
-
function getSystemdServicePath() {
|
|
1564
|
-
const dir = path2.join(os2.homedir(), ".config", "systemd", "user");
|
|
1565
|
-
return path2.join(dir, `${SYSTEMD_SERVICE_NAME}.service`);
|
|
1566
|
-
}
|
|
1567
|
-
function generateSystemdUnit(program) {
|
|
1568
|
-
const execStart = `${program} --_daemon-child`;
|
|
1569
|
-
return `[Unit]
|
|
1570
|
-
Description=Pinggy Tunnel Daemon
|
|
1571
|
-
After=network-online.target
|
|
1572
|
-
Wants=network-online.target
|
|
1573
|
-
|
|
1574
|
-
[Service]
|
|
1575
|
-
Type=simple
|
|
1576
|
-
ExecStart=${execStart}
|
|
1577
|
-
Restart=on-failure
|
|
1578
|
-
RestartSec=5
|
|
1579
|
-
|
|
1580
|
-
[Install]
|
|
1581
|
-
WantedBy=default.target
|
|
1582
|
-
`;
|
|
1583
|
-
}
|
|
1584
|
-
function installSystemd(program) {
|
|
1585
|
-
const servicePath = getSystemdServicePath();
|
|
1586
|
-
const dir = path2.dirname(servicePath);
|
|
1587
|
-
fs2.mkdirSync(dir, { recursive: true });
|
|
1588
|
-
fs2.writeFileSync(servicePath, generateSystemdUnit(program), "utf-8");
|
|
1589
|
-
execSync("systemctl --user daemon-reload", QUIET);
|
|
1590
|
-
execSync(`systemctl --user enable ${SYSTEMD_SERVICE_NAME}`, QUIET);
|
|
1591
|
-
execSync(`systemctl --user start ${SYSTEMD_SERVICE_NAME}`, QUIET);
|
|
1592
|
-
logger.info("systemd user service installed", { servicePath });
|
|
1593
|
-
printInstalled();
|
|
1594
|
-
printer_default.print(`To start it before anyone signs in, run: loginctl enable-linger ${os2.userInfo().username}`);
|
|
1595
|
-
}
|
|
1596
|
-
function uninstallSystemd() {
|
|
1597
|
-
const servicePath = getSystemdServicePath();
|
|
1598
|
-
try {
|
|
1599
|
-
execSync(`systemctl --user stop ${SYSTEMD_SERVICE_NAME} 2>/dev/null || true`);
|
|
1600
|
-
execSync(`systemctl --user disable ${SYSTEMD_SERVICE_NAME} 2>/dev/null || true`);
|
|
1601
|
-
} catch {
|
|
1602
|
-
}
|
|
1603
|
-
if (fs2.existsSync(servicePath)) {
|
|
1604
|
-
fs2.unlinkSync(servicePath);
|
|
1605
|
-
execSync("systemctl --user daemon-reload", QUIET);
|
|
1606
|
-
logger.info("systemd user service removed", { servicePath });
|
|
1607
|
-
printUninstalled();
|
|
1608
|
-
} else {
|
|
1609
|
-
printNotInstalled();
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
function getLaunchdPlistPath() {
|
|
1613
|
-
return path2.join(os2.homedir(), "Library", "LaunchAgents", `${SERVICE_LABEL}.plist`);
|
|
1614
|
-
}
|
|
1615
|
-
function generateLaunchdPlist(program) {
|
|
1616
|
-
const allArgs = [program, "--_daemon-child"];
|
|
1617
|
-
const programArgs = allArgs.map((p) => ` <string>${p}</string>`).join("\n");
|
|
1618
|
-
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
1619
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
|
|
1620
|
-
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
1621
|
-
<plist version="1.0">
|
|
1622
|
-
<dict>
|
|
1623
|
-
<key>Label</key>
|
|
1624
|
-
<string>${SERVICE_LABEL}</string>
|
|
1625
|
-
<key>ProgramArguments</key>
|
|
1626
|
-
<array>
|
|
1627
|
-
${programArgs}
|
|
1628
|
-
</array>
|
|
1629
|
-
<key>RunAtLoad</key>
|
|
1630
|
-
<true/>
|
|
1631
|
-
<key>KeepAlive</key>
|
|
1632
|
-
<false/>
|
|
1633
|
-
</dict>
|
|
1634
|
-
</plist>
|
|
1635
|
-
`;
|
|
1636
|
-
}
|
|
1637
|
-
function installLaunchd(program) {
|
|
1638
|
-
const plistPath = getLaunchdPlistPath();
|
|
1639
|
-
const dir = path2.dirname(plistPath);
|
|
1640
|
-
fs2.mkdirSync(dir, { recursive: true });
|
|
1641
|
-
fs2.writeFileSync(plistPath, generateLaunchdPlist(program), "utf-8");
|
|
1642
|
-
const uid = process.getuid?.() ?? 501;
|
|
1643
|
-
try {
|
|
1644
|
-
execSync(`launchctl bootout gui/${uid}/${SERVICE_LABEL} 2>/dev/null || true`);
|
|
1645
|
-
} catch {
|
|
1646
|
-
}
|
|
1647
|
-
loadLaunchdPlist(uid, plistPath);
|
|
1648
|
-
logger.info("launchd agent installed", { plistPath });
|
|
1649
|
-
printInstalled();
|
|
1650
|
-
}
|
|
1651
|
-
function loadLaunchdPlist(uid, plistPath) {
|
|
1652
|
-
try {
|
|
1653
|
-
execSync(`launchctl bootstrap gui/${uid} ${plistPath}`);
|
|
1654
|
-
} catch {
|
|
1655
|
-
try {
|
|
1656
|
-
execSync(`launchctl load -w ${plistPath}`);
|
|
1657
|
-
} catch {
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
function uninstallLaunchd() {
|
|
1662
|
-
const plistPath = getLaunchdPlistPath();
|
|
1663
|
-
const uid = process.getuid?.() ?? 501;
|
|
1664
|
-
try {
|
|
1665
|
-
execSync(`launchctl bootout gui/${uid}/${SERVICE_LABEL} 2>/dev/null || true`);
|
|
1666
|
-
} catch {
|
|
1667
|
-
try {
|
|
1668
|
-
execSync(`launchctl unload ${plistPath} 2>/dev/null || true`);
|
|
1669
|
-
} catch {
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
if (fs2.existsSync(plistPath)) {
|
|
1673
|
-
fs2.unlinkSync(plistPath);
|
|
1674
|
-
logger.info("launchd agent removed", { plistPath });
|
|
1675
|
-
printUninstalled();
|
|
1676
|
-
} else {
|
|
1677
|
-
printNotInstalled();
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
var WINDOWS_TASK_NAME = "PinggyDaemon";
|
|
1681
|
-
function escapeXml(value) {
|
|
1682
|
-
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1683
|
-
}
|
|
1684
|
-
function getWindowsUserId() {
|
|
1685
|
-
const user = process.env.USERNAME || os2.userInfo().username;
|
|
1686
|
-
const domain = process.env.USERDOMAIN;
|
|
1687
|
-
return domain ? `${domain}\\${user}` : user;
|
|
1688
|
-
}
|
|
1689
|
-
function generateTaskXml(program, userId) {
|
|
1690
|
-
const user = escapeXml(userId);
|
|
1691
|
-
return `<?xml version="1.0" encoding="UTF-16"?>
|
|
1692
|
-
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
1693
|
-
<Triggers>
|
|
1694
|
-
<LogonTrigger>
|
|
1695
|
-
<Enabled>true</Enabled>
|
|
1696
|
-
<UserId>${user}</UserId>
|
|
1697
|
-
</LogonTrigger>
|
|
1698
|
-
</Triggers>
|
|
1699
|
-
<Principals>
|
|
1700
|
-
<Principal id="Author">
|
|
1701
|
-
<UserId>${user}</UserId>
|
|
1702
|
-
<LogonType>InteractiveToken</LogonType>
|
|
1703
|
-
<RunLevel>LeastPrivilege</RunLevel>
|
|
1704
|
-
</Principal>
|
|
1705
|
-
</Principals>
|
|
1706
|
-
<Settings>
|
|
1707
|
-
<Hidden>true</Hidden>
|
|
1708
|
-
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
|
|
1709
|
-
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
|
|
1710
|
-
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
|
|
1711
|
-
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
|
|
1712
|
-
<RestartOnFailure>
|
|
1713
|
-
<Interval>PT1M</Interval>
|
|
1714
|
-
<Count>3</Count>
|
|
1715
|
-
</RestartOnFailure>
|
|
1716
|
-
</Settings>
|
|
1717
|
-
<Actions>
|
|
1718
|
-
<Exec>
|
|
1719
|
-
<Command>${escapeXml(program)}</Command>
|
|
1720
|
-
<Arguments>daemon start</Arguments>
|
|
1721
|
-
</Exec>
|
|
1722
|
-
</Actions>
|
|
1723
|
-
</Task>`;
|
|
1724
|
-
}
|
|
1725
|
-
function createWindowsTask(program) {
|
|
1726
|
-
const xml = generateTaskXml(program, getWindowsUserId());
|
|
1727
|
-
const tmpPath = path2.join(os2.tmpdir(), `${WINDOWS_TASK_NAME}.xml`);
|
|
1728
|
-
fs2.writeFileSync(tmpPath, "\uFEFF" + xml, "utf16le");
|
|
1729
|
-
try {
|
|
1730
|
-
execFileSync("schtasks", ["/Create", "/TN", WINDOWS_TASK_NAME, "/XML", tmpPath, "/F"], QUIET);
|
|
1731
|
-
} finally {
|
|
1732
|
-
try {
|
|
1733
|
-
fs2.unlinkSync(tmpPath);
|
|
1734
|
-
} catch {
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
function windowsTaskExists() {
|
|
1739
|
-
try {
|
|
1740
|
-
execFileSync("schtasks", ["/Query", "/TN", WINDOWS_TASK_NAME], QUIET);
|
|
1741
|
-
return true;
|
|
1742
|
-
} catch {
|
|
1743
|
-
return false;
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
function isElevated() {
|
|
1747
|
-
try {
|
|
1748
|
-
return /S-1-16-(12288|16384)\b/.test(execFileSync("whoami", ["/groups"], { encoding: "utf-8" }));
|
|
1749
|
-
} catch {
|
|
1750
|
-
return false;
|
|
1751
|
-
}
|
|
1752
|
-
}
|
|
1753
|
-
function windowsTaskError(action, undo, err) {
|
|
1754
|
-
if (windowsTaskExists() && !isElevated()) {
|
|
1755
|
-
return `Could not ${action}. It was set up from an Administrator terminal. Run this command from an Administrator terminal to ${undo}.`;
|
|
1756
|
-
}
|
|
1757
|
-
return `Could not ${action}: ${toolError(err)}`;
|
|
1758
|
-
}
|
|
1759
|
-
function installWindows(program) {
|
|
1760
|
-
try {
|
|
1761
|
-
createWindowsTask(program);
|
|
1762
|
-
execFileSync("schtasks", ["/Run", "/TN", WINDOWS_TASK_NAME], QUIET);
|
|
1763
|
-
} catch (err) {
|
|
1764
|
-
printer_default.error(windowsTaskError("set pinggy to start automatically", "change it", err));
|
|
1765
|
-
process.exit(1);
|
|
1766
|
-
}
|
|
1767
|
-
logger.info("Scheduled task installed", { task: WINDOWS_TASK_NAME });
|
|
1768
|
-
printInstalled();
|
|
1769
|
-
}
|
|
1770
|
-
async function uninstallWindows() {
|
|
1771
|
-
if (!windowsTaskExists()) {
|
|
1772
|
-
printNotInstalled();
|
|
1773
|
-
return;
|
|
1774
|
-
}
|
|
1775
|
-
try {
|
|
1776
|
-
execFileSync("schtasks", ["/Delete", "/TN", WINDOWS_TASK_NAME, "/F"], QUIET);
|
|
1777
|
-
} catch (err) {
|
|
1778
|
-
printer_default.error(windowsTaskError("stop pinggy from starting automatically", "turn it off", err));
|
|
1779
|
-
process.exit(1);
|
|
1780
|
-
}
|
|
1781
|
-
logger.info("Scheduled task removed", { task: WINDOWS_TASK_NAME });
|
|
1782
|
-
if (isDaemonRunning()) {
|
|
1783
|
-
const result = await stopDaemon();
|
|
1784
|
-
if (!result.ok) console.log(`Could not stop the daemon: ${result.error}`);
|
|
1785
|
-
}
|
|
1786
|
-
printUninstalled();
|
|
1787
|
-
}
|
|
1788
|
-
function installService() {
|
|
1789
|
-
const platform2 = os2.platform();
|
|
1790
|
-
const program = process.execPath;
|
|
1791
|
-
const refusal = serviceInstallRefusal({
|
|
1792
|
-
platform: platform2,
|
|
1793
|
-
isPkg: "pkg" in process,
|
|
1794
|
-
execPath: program,
|
|
1795
|
-
home: os2.homedir(),
|
|
1796
|
-
env: process.env
|
|
1797
|
-
});
|
|
1798
|
-
if (refusal) {
|
|
1799
|
-
console.error(refusal);
|
|
1800
|
-
process.exit(1);
|
|
1801
|
-
}
|
|
1802
|
-
switch (platform2) {
|
|
1803
|
-
case "linux":
|
|
1804
|
-
installSystemd(program);
|
|
1805
|
-
break;
|
|
1806
|
-
case "darwin":
|
|
1807
|
-
installLaunchd(program);
|
|
1808
|
-
break;
|
|
1809
|
-
case "win32":
|
|
1810
|
-
installWindows(program);
|
|
1811
|
-
break;
|
|
1812
|
-
default:
|
|
1813
|
-
console.error(`Unsupported platform: ${platform2}`);
|
|
1814
|
-
process.exit(1);
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
async function uninstallService() {
|
|
1818
|
-
const platform2 = os2.platform();
|
|
1819
|
-
switch (platform2) {
|
|
1820
|
-
case "linux":
|
|
1821
|
-
uninstallSystemd();
|
|
1822
|
-
break;
|
|
1823
|
-
case "darwin":
|
|
1824
|
-
uninstallLaunchd();
|
|
1825
|
-
break;
|
|
1826
|
-
case "win32":
|
|
1827
|
-
await uninstallWindows();
|
|
1828
|
-
break;
|
|
1829
|
-
default:
|
|
1830
|
-
console.error(`Unsupported platform: ${platform2}`);
|
|
1831
|
-
process.exit(1);
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1835
1708
|
// src/utils/helpMessages.ts
|
|
1836
1709
|
function printDaemonHelp() {
|
|
1837
1710
|
console.log("\nUsage: pinggy daemon <command>");
|
|
@@ -1884,7 +1757,7 @@ function printDeviceHelp() {
|
|
|
1884
1757
|
console.log(" background. Without --token: start the enrolled device's agent again");
|
|
1885
1758
|
console.log(" stop Stop the agent running in the background, until the daemon");
|
|
1886
1759
|
console.log(" starts again");
|
|
1887
|
-
console.log(" status Show the
|
|
1760
|
+
console.log(" status Show whether the agent runs, the enrolment, and the background agent");
|
|
1888
1761
|
console.log(" remove Stop the agent and forget the local credential, after asking.");
|
|
1889
1762
|
console.log(" The device stays in the dashboard\n");
|
|
1890
1763
|
console.log("By default the agent runs in the daemon, and stays connected after this terminal closes.");
|
|
@@ -1900,6 +1773,13 @@ function printDeviceHelp() {
|
|
|
1900
1773
|
console.log(" DEVICE_AGENT_TOKEN connect only: the device token, when --token is not given. With no");
|
|
1901
1774
|
console.log(" --manage, it dials dashboard.pinggy.io. Removed once read\n");
|
|
1902
1775
|
}
|
|
1776
|
+
function printUpdateHelp() {
|
|
1777
|
+
console.log("\nUsage: pinggy update [--check | --rollback]\n");
|
|
1778
|
+
console.log("Commands:");
|
|
1779
|
+
console.log(" pinggy update Update to the latest version now");
|
|
1780
|
+
console.log(" pinggy update --check Print the latest version and change nothing");
|
|
1781
|
+
console.log(" pinggy update --rollback Go back to the previous version\n");
|
|
1782
|
+
}
|
|
1903
1783
|
|
|
1904
1784
|
// src/devices/backgroundAgent.ts
|
|
1905
1785
|
import pico5 from "picocolors";
|
|
@@ -2001,7 +1881,7 @@ var WelcomeSchema = z.object({
|
|
|
2001
1881
|
// No default either. Without it the agent runs no expiry timer, and the dashboard's sweep
|
|
2002
1882
|
// still ends an idle shell, only later. A shell has no cap on its running time.
|
|
2003
1883
|
terminal_idle_timeout_seconds: z.number().optional(),
|
|
2004
|
-
// Optional: without it the agent keeps
|
|
1884
|
+
// Optional: without it the agent keeps the window brake and never skips output.
|
|
2005
1885
|
terminal_resync: z.boolean().optional(),
|
|
2006
1886
|
// Optional: a dashboard older than these sends neither, and the agent prints only the device id.
|
|
2007
1887
|
email: z.string().optional(),
|
|
@@ -2747,9 +2627,9 @@ var MAX_CWD_CHARACTERS = 1024;
|
|
|
2747
2627
|
var MAX_COMMAND_CHARACTERS = 64;
|
|
2748
2628
|
var PROCESS_READ_TIMEOUT_MILLIS = 2e3;
|
|
2749
2629
|
var HOME_PREFIX = "~";
|
|
2750
|
-
function processTableReader(
|
|
2751
|
-
if (
|
|
2752
|
-
if (
|
|
2630
|
+
function processTableReader(platform3 = process.platform) {
|
|
2631
|
+
if (platform3 === "linux") return readFromProc;
|
|
2632
|
+
if (platform3 === "darwin") return readFromPsAndLsof;
|
|
2753
2633
|
return null;
|
|
2754
2634
|
}
|
|
2755
2635
|
function programName(rawName) {
|
|
@@ -2953,7 +2833,7 @@ var ScreenMirror = class _ScreenMirror {
|
|
|
2953
2833
|
}
|
|
2954
2834
|
/**
|
|
2955
2835
|
* Fed and not yet parsed. xterm queues writes without limit, so a shell that skips its output
|
|
2956
|
-
*
|
|
2836
|
+
* pauses on this, and on nothing else.
|
|
2957
2837
|
*/
|
|
2958
2838
|
get backlogBytes() {
|
|
2959
2839
|
return this.unparsedBytes;
|
|
@@ -3029,9 +2909,9 @@ var TerminalHandler = class _TerminalHandler {
|
|
|
3029
2909
|
this.dependencies = dependencies;
|
|
3030
2910
|
this.enabled = true;
|
|
3031
2911
|
this.suspended = false;
|
|
3032
|
-
/** `terminal_resync` in `welcome
|
|
2912
|
+
/** `terminal_resync` in `welcome`. Off, every shell keeps the window brake. */
|
|
3033
2913
|
this.resyncEnabled = false;
|
|
3034
|
-
/** Paused by `suspend`
|
|
2914
|
+
/** Paused by `suspend` without skip mode, so `resumeAll` resumes them if `welcome` turned skip mode on. */
|
|
3035
2915
|
this.pausedBySuspend = /* @__PURE__ */ new Set();
|
|
3036
2916
|
this.expiryTimer = null;
|
|
3037
2917
|
this.contextTimer = null;
|
|
@@ -3126,9 +3006,9 @@ var TerminalHandler = class _TerminalHandler {
|
|
|
3126
3006
|
this.dependencies.registry.killAll();
|
|
3127
3007
|
}
|
|
3128
3008
|
/**
|
|
3129
|
-
* The socket dropped and the agent will redial.
|
|
3009
|
+
* The socket dropped and the agent will redial. Without skip mode every shell stops being read and
|
|
3130
3010
|
* keeps running: whatever it prints waits in the kernel, and the shell blocks once that buffer is
|
|
3131
|
-
* full. In skip mode
|
|
3011
|
+
* full. In skip mode a shell is read on, and its output is skipped.
|
|
3132
3012
|
*/
|
|
3133
3013
|
suspend() {
|
|
3134
3014
|
if (this.suspended) return;
|
|
@@ -3148,7 +3028,7 @@ var TerminalHandler = class _TerminalHandler {
|
|
|
3148
3028
|
/**
|
|
3149
3029
|
* `welcome` arrived. Every shell the dashboard did not close is read again, except one whose
|
|
3150
3030
|
* window is still full. That one resumes on the `ack` that reopens it. A shell in skip mode was
|
|
3151
|
-
* never paused, and resyncs instead
|
|
3031
|
+
* never paused, and resyncs instead.
|
|
3152
3032
|
*/
|
|
3153
3033
|
resumeAll() {
|
|
3154
3034
|
if (!this.suspended) return;
|
|
@@ -3309,7 +3189,7 @@ var TerminalHandler = class _TerminalHandler {
|
|
|
3309
3189
|
}
|
|
3310
3190
|
/**
|
|
3311
3191
|
* The shell exited on its own. A shell that skipped its last output sends its last screen first, at
|
|
3312
|
-
* once, so the tabs see how it ended
|
|
3192
|
+
* once, so the tabs see how it ended. Then `exit` and `close`. With nothing to resync this
|
|
3313
3193
|
* runs to the end without yielding, as before.
|
|
3314
3194
|
*/
|
|
3315
3195
|
async finishExit(terminalId, stream, exitCode, signal) {
|
|
@@ -3341,7 +3221,7 @@ var TerminalHandler = class _TerminalHandler {
|
|
|
3341
3221
|
* exactly the bundles up to its `after_seq`. Fed when the pty is read, a bundle still being cut
|
|
3342
3222
|
* would be in the screen and drawn a second time when it is sent.
|
|
3343
3223
|
*
|
|
3344
|
-
* In skip mode
|
|
3224
|
+
* In skip mode `sendOrSkip` decides instead, and never pauses the pty.
|
|
3345
3225
|
*/
|
|
3346
3226
|
sendData(terminalId, chunk) {
|
|
3347
3227
|
const stream = this.streams.get(terminalId);
|
|
@@ -3370,7 +3250,7 @@ var TerminalHandler = class _TerminalHandler {
|
|
|
3370
3250
|
return this.resyncEnabled && stream.mirror !== null;
|
|
3371
3251
|
}
|
|
3372
3252
|
/**
|
|
3373
|
-
* Skip mode
|
|
3253
|
+
* Skip mode. A resync being serialised holds the bundle. A skipping stream, a socket that is
|
|
3374
3254
|
* down, or a closed window skips it. Otherwise it goes out as `data`.
|
|
3375
3255
|
*/
|
|
3376
3256
|
sendOrSkip(terminalId, stream, chunk) {
|
|
@@ -3416,7 +3296,7 @@ var TerminalHandler = class _TerminalHandler {
|
|
|
3416
3296
|
this.brakeIfMirrorBehind(terminalId, stream);
|
|
3417
3297
|
this.reportActivityWhileSkipping(terminalId, stream);
|
|
3418
3298
|
}
|
|
3419
|
-
/** As
|
|
3299
|
+
/** As the send without skip mode, minus the pause: with the window closed, the next bundle is skipped instead. */
|
|
3420
3300
|
transmit(terminalId, stream, chunk) {
|
|
3421
3301
|
stream.sentSeq += 1;
|
|
3422
3302
|
stream.mirror?.feed(chunk, () => this.mirrorParsed(terminalId, stream));
|
|
@@ -3504,7 +3384,7 @@ var TerminalHandler = class _TerminalHandler {
|
|
|
3504
3384
|
return stream.resyncInFlight;
|
|
3505
3385
|
}
|
|
3506
3386
|
/**
|
|
3507
|
-
* The latest screen to every tab
|
|
3387
|
+
* The latest screen to every tab. `after_seq` and `after_bytes` are read before the mirror
|
|
3508
3388
|
* is asked, as for a snapshot, and skipped bytes took neither: the screen holds the output up to
|
|
3509
3389
|
* `after_seq` plus everything skipped. Serialised under the window size, so a resync never puts more in
|
|
3510
3390
|
* flight than the window allows. Bundles held meanwhile go out after the parts, from `after_seq + 1`.
|
|
@@ -3664,7 +3544,7 @@ var TerminalHandler = class _TerminalHandler {
|
|
|
3664
3544
|
this.dependencies.send(event(CHANNEL_TERMINAL, OP_CLOSE, { terminal_id: terminalId, reason }));
|
|
3665
3545
|
}
|
|
3666
3546
|
/**
|
|
3667
|
-
* A tab attached and asked for the screen it missed
|
|
3547
|
+
* A tab attached and asked for the screen it missed. Answered in parts, each 1 frame,
|
|
3668
3548
|
* which the dashboard routes to that tab alone.
|
|
3669
3549
|
*
|
|
3670
3550
|
* `after_seq` and `after_bytes` are read in the same tick as the request, before the mirror is
|
|
@@ -3816,123 +3696,8 @@ var TerminalRegistry = class {
|
|
|
3816
3696
|
|
|
3817
3697
|
// src/devices/terminal/ptySession.ts
|
|
3818
3698
|
import { execFile as execFile2 } from "child_process";
|
|
3819
|
-
import fs6 from "fs";
|
|
3820
|
-
import os7 from "os";
|
|
3821
|
-
|
|
3822
|
-
// src/devices/terminal/nodePtyRuntime.ts
|
|
3823
3699
|
import fs5 from "fs";
|
|
3824
|
-
import
|
|
3825
|
-
import { createRequire as createRequire2 } from "module";
|
|
3826
|
-
var require3 = createRequire2(import.meta.url);
|
|
3827
|
-
var PACKAGE_NAME = "node-pty";
|
|
3828
|
-
var NATIVE_FILE = "pty.node";
|
|
3829
|
-
var SPAWN_HELPER_FILE = "spawn-helper";
|
|
3830
|
-
var EXECUTABLE_MODE = 493;
|
|
3831
|
-
var EXECUTE_BITS = 73;
|
|
3832
|
-
var RUNTIME_DIR_NAME = "runtime";
|
|
3833
|
-
var ASAR_ARCHIVE_SUFFIX = ".asar";
|
|
3834
|
-
var NATIVE_DIRECTORIES = [
|
|
3835
|
-
path3.join("build", "Release"),
|
|
3836
|
-
path3.join("prebuilds", `${process.platform}-${process.arch}`)
|
|
3837
|
-
];
|
|
3838
|
-
function isPackagedBinary() {
|
|
3839
|
-
return Boolean(process.pkg);
|
|
3840
|
-
}
|
|
3841
|
-
function isInsideAsarArchive(packageRoot) {
|
|
3842
|
-
if (!process.versions.electron) return false;
|
|
3843
|
-
return packageRoot.split(path3.sep).some((segment) => segment.endsWith(ASAR_ARCHIVE_SUFFIX));
|
|
3844
|
-
}
|
|
3845
|
-
function resolveNodePtyRoot() {
|
|
3846
|
-
const resolvedRoot = path3.dirname(require3.resolve(`${PACKAGE_NAME}/package.json`));
|
|
3847
|
-
if (!isPackagedBinary() && !isInsideAsarArchive(resolvedRoot)) return resolvedRoot;
|
|
3848
|
-
return unpackNodePty(resolvedRoot);
|
|
3849
|
-
}
|
|
3850
|
-
function requireNodePty(packageRoot) {
|
|
3851
|
-
return require3(packageRoot);
|
|
3852
|
-
}
|
|
3853
|
-
function spawnHelperPaths(packageRoot) {
|
|
3854
|
-
if (process.platform === "win32") return [];
|
|
3855
|
-
return NATIVE_DIRECTORIES.map((directory) => path3.join(packageRoot, directory, SPAWN_HELPER_FILE));
|
|
3856
|
-
}
|
|
3857
|
-
function hasExecutableSpawnHelper(packageRoot) {
|
|
3858
|
-
const helpers = spawnHelperPaths(packageRoot);
|
|
3859
|
-
if (helpers.length === 0) return true;
|
|
3860
|
-
return helpers.some((helper) => {
|
|
3861
|
-
try {
|
|
3862
|
-
const stat = fs5.statSync(helper);
|
|
3863
|
-
return stat.isFile() && (stat.mode & EXECUTE_BITS) !== 0;
|
|
3864
|
-
} catch {
|
|
3865
|
-
return false;
|
|
3866
|
-
}
|
|
3867
|
-
});
|
|
3868
|
-
}
|
|
3869
|
-
function makeSpawnHelperExecutable(packageRoot) {
|
|
3870
|
-
for (const helper of spawnHelperPaths(packageRoot)) {
|
|
3871
|
-
try {
|
|
3872
|
-
const stat = fs5.statSync(helper);
|
|
3873
|
-
if ((stat.mode & EXECUTE_BITS) === 0) {
|
|
3874
|
-
fs5.chmodSync(helper, EXECUTABLE_MODE);
|
|
3875
|
-
}
|
|
3876
|
-
} catch {
|
|
3877
|
-
}
|
|
3878
|
-
}
|
|
3879
|
-
}
|
|
3880
|
-
function unpackNodePty(snapshotRoot) {
|
|
3881
|
-
const unpackedRoot = unpackedRootPath(snapshotRoot);
|
|
3882
|
-
if (isLoadable(unpackedRoot)) return unpackedRoot;
|
|
3883
|
-
const stagingRoot = `${unpackedRoot}.${process.pid}`;
|
|
3884
|
-
fs5.rmSync(stagingRoot, { recursive: true, force: true });
|
|
3885
|
-
try {
|
|
3886
|
-
copyRuntimeFiles(snapshotRoot, stagingRoot);
|
|
3887
|
-
makeSpawnHelperExecutable(stagingRoot);
|
|
3888
|
-
fs5.renameSync(stagingRoot, unpackedRoot);
|
|
3889
|
-
} catch (error) {
|
|
3890
|
-
fs5.rmSync(stagingRoot, { recursive: true, force: true });
|
|
3891
|
-
if (!isLoadable(unpackedRoot)) throw error;
|
|
3892
|
-
}
|
|
3893
|
-
return unpackedRoot;
|
|
3894
|
-
}
|
|
3895
|
-
function unpackedRootPath(snapshotRoot) {
|
|
3896
|
-
const version = readPackageVersion(snapshotRoot);
|
|
3897
|
-
const directoryName = `${PACKAGE_NAME}-${version}-${process.platform}-${process.arch}`;
|
|
3898
|
-
return path3.join(getPinggyConfigDir(), RUNTIME_DIR_NAME, directoryName);
|
|
3899
|
-
}
|
|
3900
|
-
function readPackageVersion(packageRoot) {
|
|
3901
|
-
const manifest = JSON.parse(fs5.readFileSync(path3.join(packageRoot, "package.json"), "utf8"));
|
|
3902
|
-
return String(manifest.version);
|
|
3903
|
-
}
|
|
3904
|
-
function isLoadable(packageRoot) {
|
|
3905
|
-
if (!fs5.existsSync(path3.join(packageRoot, "package.json"))) return false;
|
|
3906
|
-
return NATIVE_DIRECTORIES.some((directory) => fs5.existsSync(path3.join(packageRoot, directory, NATIVE_FILE)));
|
|
3907
|
-
}
|
|
3908
|
-
function copyRuntimeFiles(sourceRoot, targetRoot) {
|
|
3909
|
-
fs5.mkdirSync(targetRoot, { recursive: true });
|
|
3910
|
-
copyFile(path3.join(sourceRoot, "package.json"), path3.join(targetRoot, "package.json"));
|
|
3911
|
-
copyDirectory(path3.join(sourceRoot, "lib"), path3.join(targetRoot, "lib"));
|
|
3912
|
-
for (const directory of NATIVE_DIRECTORIES) {
|
|
3913
|
-
const source = path3.join(sourceRoot, directory);
|
|
3914
|
-
if (fs5.existsSync(source)) {
|
|
3915
|
-
copyDirectory(source, path3.join(targetRoot, directory));
|
|
3916
|
-
}
|
|
3917
|
-
}
|
|
3918
|
-
}
|
|
3919
|
-
function copyDirectory(sourceDirectory, targetDirectory) {
|
|
3920
|
-
fs5.mkdirSync(targetDirectory, { recursive: true });
|
|
3921
|
-
for (const entry of fs5.readdirSync(sourceDirectory, { withFileTypes: true })) {
|
|
3922
|
-
const source = path3.join(sourceDirectory, entry.name);
|
|
3923
|
-
const target = path3.join(targetDirectory, entry.name);
|
|
3924
|
-
if (entry.isDirectory()) {
|
|
3925
|
-
copyDirectory(source, target);
|
|
3926
|
-
continue;
|
|
3927
|
-
}
|
|
3928
|
-
copyFile(source, target);
|
|
3929
|
-
}
|
|
3930
|
-
}
|
|
3931
|
-
function copyFile(source, target) {
|
|
3932
|
-
fs5.writeFileSync(target, fs5.readFileSync(source));
|
|
3933
|
-
}
|
|
3934
|
-
|
|
3935
|
-
// src/devices/terminal/ptySession.ts
|
|
3700
|
+
import os7 from "os";
|
|
3936
3701
|
var loadedPty;
|
|
3937
3702
|
var TERM_NAME = "xterm-256color";
|
|
3938
3703
|
function foregroundProcessGroup(shellPid) {
|
|
@@ -3980,7 +3745,7 @@ function ensureSpawnHelperExecutable(packageRoot) {
|
|
|
3980
3745
|
function resolveCwd(requested) {
|
|
3981
3746
|
if (requested) {
|
|
3982
3747
|
try {
|
|
3983
|
-
if (
|
|
3748
|
+
if (fs5.statSync(requested).isDirectory()) return requested;
|
|
3984
3749
|
} catch {
|
|
3985
3750
|
}
|
|
3986
3751
|
}
|
|
@@ -4030,14 +3795,14 @@ function spawnPty(request2) {
|
|
|
4030
3795
|
}
|
|
4031
3796
|
|
|
4032
3797
|
// src/devices/terminal/shellAllowlist.ts
|
|
4033
|
-
import
|
|
3798
|
+
import fs6 from "fs";
|
|
4034
3799
|
var FALLBACK_UNIX_SHELLS = ["/bin/bash", "/bin/zsh", "/bin/sh", "/usr/bin/bash", "/usr/bin/zsh"];
|
|
4035
3800
|
var WINDOWS_SHELLS = ["powershell.exe", "cmd.exe"];
|
|
4036
3801
|
var ETC_SHELLS_PATH = "/etc/shells";
|
|
4037
3802
|
function readShellEnvironment() {
|
|
4038
3803
|
let etcShells = null;
|
|
4039
3804
|
try {
|
|
4040
|
-
etcShells =
|
|
3805
|
+
etcShells = fs6.readFileSync(ETC_SHELLS_PATH, "utf8");
|
|
4041
3806
|
} catch {
|
|
4042
3807
|
etcShells = null;
|
|
4043
3808
|
}
|
|
@@ -4045,9 +3810,9 @@ function readShellEnvironment() {
|
|
|
4045
3810
|
platform: process.platform,
|
|
4046
3811
|
loginShell: process.env.SHELL,
|
|
4047
3812
|
etcShells,
|
|
4048
|
-
exists: (
|
|
3813
|
+
exists: (path5) => {
|
|
4049
3814
|
try {
|
|
4050
|
-
return
|
|
3815
|
+
return fs6.statSync(path5).isFile();
|
|
4051
3816
|
} catch {
|
|
4052
3817
|
return false;
|
|
4053
3818
|
}
|
|
@@ -4080,13 +3845,13 @@ function resolveShell(requested, environment) {
|
|
|
4080
3845
|
}
|
|
4081
3846
|
|
|
4082
3847
|
// src/devices/foregroundAgent.ts
|
|
4083
|
-
import
|
|
3848
|
+
import fs7 from "fs";
|
|
4084
3849
|
var RECORD_CHECK_INTERVAL_MILLIS = 1e3;
|
|
4085
3850
|
var STOP_WAIT_MILLIS = 1e4;
|
|
4086
3851
|
var STOP_POLL_INTERVAL_MILLIS = 200;
|
|
4087
3852
|
function readRecordFile(filePath) {
|
|
4088
3853
|
try {
|
|
4089
|
-
const record = JSON.parse(
|
|
3854
|
+
const record = JSON.parse(fs7.readFileSync(filePath, "utf-8"));
|
|
4090
3855
|
return Number.isInteger(record.pid) && record.pid > 0 ? record : null;
|
|
4091
3856
|
} catch {
|
|
4092
3857
|
return null;
|
|
@@ -4094,7 +3859,7 @@ function readRecordFile(filePath) {
|
|
|
4094
3859
|
}
|
|
4095
3860
|
function deleteRecordFile(filePath) {
|
|
4096
3861
|
try {
|
|
4097
|
-
|
|
3862
|
+
fs7.unlinkSync(filePath);
|
|
4098
3863
|
} catch (err) {
|
|
4099
3864
|
logger.debug("No foreground agent record to delete", { error: errorMessage(err) });
|
|
4100
3865
|
}
|
|
@@ -4120,7 +3885,7 @@ function recordForegroundAgent(onRecordDeleted) {
|
|
|
4120
3885
|
const record = { pid: process.pid, started_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
4121
3886
|
try {
|
|
4122
3887
|
ensurePinggyConfigDir();
|
|
4123
|
-
|
|
3888
|
+
fs7.writeFileSync(filePath, JSON.stringify(record, null, 2), "utf-8");
|
|
4124
3889
|
} catch (err) {
|
|
4125
3890
|
logger.warn(
|
|
4126
3891
|
"Could not write device-agent.json. pinggy device remove cannot stop this agent.",
|
|
@@ -4129,7 +3894,7 @@ function recordForegroundAgent(onRecordDeleted) {
|
|
|
4129
3894
|
return () => void 0;
|
|
4130
3895
|
}
|
|
4131
3896
|
const timer = setInterval(() => {
|
|
4132
|
-
if (!
|
|
3897
|
+
if (!fs7.existsSync(filePath)) {
|
|
4133
3898
|
clearInterval(timer);
|
|
4134
3899
|
onRecordDeleted();
|
|
4135
3900
|
}
|
|
@@ -4628,8 +4393,8 @@ var DeviceLoginApiError = class extends Error {
|
|
|
4628
4393
|
var UNREADABLE_ANSWER = "invalid_answer";
|
|
4629
4394
|
function createDeviceLoginApi(manage, fetchImpl = fetch) {
|
|
4630
4395
|
const baseUrl = buildDashboardHttpUrl(manage);
|
|
4631
|
-
async function post(
|
|
4632
|
-
const response2 = await fetchImpl(`${baseUrl}/${
|
|
4396
|
+
async function post(path5, body, schema) {
|
|
4397
|
+
const response2 = await fetchImpl(`${baseUrl}/${path5}`, {
|
|
4633
4398
|
method: "POST",
|
|
4634
4399
|
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
4635
4400
|
body: JSON.stringify(body)
|
|
@@ -5092,8 +4857,7 @@ async function foregroundRefusal(dependencies) {
|
|
|
5092
4857
|
const device = reading.status.deviceAgentId ? `device ${reading.status.deviceAgentId}` : "a device";
|
|
5093
4858
|
return `This machine already runs as ${device} in the background. Stop it first: pinggy device stop`;
|
|
5094
4859
|
}
|
|
5095
|
-
|
|
5096
|
-
const reading = await readBackgroundAgent(dependencies);
|
|
4860
|
+
function printBackgroundStatus(reading, dependencies) {
|
|
5097
4861
|
if (!reading) {
|
|
5098
4862
|
return;
|
|
5099
4863
|
}
|
|
@@ -5102,6 +4866,20 @@ async function printBackgroundStatus(dependencies) {
|
|
|
5102
4866
|
dependencies.print(` Last error ${reading.status.lastError.message}`);
|
|
5103
4867
|
}
|
|
5104
4868
|
}
|
|
4869
|
+
function describeDeviceState(reading, daemonFound, foreground) {
|
|
4870
|
+
if (reading && isAgentRunning(reading.status)) {
|
|
4871
|
+
const connection = reading.status.state;
|
|
4872
|
+
const color = connection === DeviceAgentState.Connected ? pico5.green : pico5.yellow;
|
|
4873
|
+
return color(`running, ${connection}`);
|
|
4874
|
+
}
|
|
4875
|
+
if (foreground) {
|
|
4876
|
+
return pico5.green("running, with --foreground in another terminal");
|
|
4877
|
+
}
|
|
4878
|
+
if (reading || !daemonFound) {
|
|
4879
|
+
return `${pico5.red("stopped")}. To start it, run: pinggy device connect`;
|
|
4880
|
+
}
|
|
4881
|
+
return pico5.gray("unknown, could not read the daemon");
|
|
4882
|
+
}
|
|
5105
4883
|
function describeAgentForDaemonStatus(status) {
|
|
5106
4884
|
switch (status.state) {
|
|
5107
4885
|
case DeviceAgentState.Connected:
|
|
@@ -5473,11 +5251,11 @@ async function handleAttach(args) {
|
|
|
5473
5251
|
}
|
|
5474
5252
|
|
|
5475
5253
|
// src/cli/subcommand/handlers/logsCommand.ts
|
|
5476
|
-
import
|
|
5254
|
+
import fs9 from "fs";
|
|
5477
5255
|
|
|
5478
5256
|
// src/daemon/logPaths.ts
|
|
5479
|
-
import
|
|
5480
|
-
import
|
|
5257
|
+
import fs8 from "fs";
|
|
5258
|
+
import path2 from "path";
|
|
5481
5259
|
var TUNNEL_ORIGINS = ["app", "cli", "remote", "device"];
|
|
5482
5260
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
5483
5261
|
function parseTunnelLogFilename(filename) {
|
|
@@ -5497,8 +5275,8 @@ function parseTunnelLogFilename(filename) {
|
|
|
5497
5275
|
}
|
|
5498
5276
|
function listTunnelLogFiles() {
|
|
5499
5277
|
const logDir = getTunnelLogDir();
|
|
5500
|
-
if (!
|
|
5501
|
-
return
|
|
5278
|
+
if (!fs8.existsSync(logDir)) return [];
|
|
5279
|
+
return fs8.readdirSync(logDir).filter((f) => f.endsWith(".log") && !/\.log\.\d+$/.test(f));
|
|
5502
5280
|
}
|
|
5503
5281
|
function newestLogFile(q) {
|
|
5504
5282
|
const logDir = getTunnelLogDir();
|
|
@@ -5509,8 +5287,8 @@ function newestLogFile(q) {
|
|
|
5509
5287
|
const nameMatch = parsed.name !== void 0 && parsed.name === q;
|
|
5510
5288
|
const idMatch = parsed.tunnelId !== void 0 && (parsed.tunnelId === q || parsed.tunnelId.startsWith(q));
|
|
5511
5289
|
if (nameMatch || idMatch) {
|
|
5512
|
-
const filePath =
|
|
5513
|
-
matches.push({ ...parsed, path: filePath, mtime:
|
|
5290
|
+
const filePath = path2.join(logDir, file);
|
|
5291
|
+
matches.push({ ...parsed, path: filePath, mtime: fs8.statSync(filePath).mtimeMs });
|
|
5514
5292
|
}
|
|
5515
5293
|
}
|
|
5516
5294
|
if (matches.length === 0) return null;
|
|
@@ -5586,7 +5364,7 @@ async function handleLogs(args, follow) {
|
|
|
5586
5364
|
return;
|
|
5587
5365
|
}
|
|
5588
5366
|
client.close();
|
|
5589
|
-
if (!filePath || !
|
|
5367
|
+
if (!filePath || !fs9.existsSync(filePath)) {
|
|
5590
5368
|
printer_default.error(`Log file not found: ${filePath}`);
|
|
5591
5369
|
process.exit(1);
|
|
5592
5370
|
}
|
|
@@ -5597,18 +5375,18 @@ async function handleLogs(args, follow) {
|
|
|
5597
5375
|
}
|
|
5598
5376
|
}
|
|
5599
5377
|
function printTail(filePath, lines) {
|
|
5600
|
-
const content =
|
|
5378
|
+
const content = fs9.readFileSync(filePath, "utf-8");
|
|
5601
5379
|
const allLines = content.split("\n");
|
|
5602
5380
|
const tail = allLines.slice(-lines).join("\n");
|
|
5603
5381
|
process.stdout.write(tail);
|
|
5604
5382
|
if (!tail.endsWith("\n")) process.stdout.write("\n");
|
|
5605
5383
|
}
|
|
5606
5384
|
async function followFile(filePath) {
|
|
5607
|
-
if (
|
|
5608
|
-
let fileSize =
|
|
5385
|
+
if (fs9.existsSync(filePath)) printTail(filePath, 20);
|
|
5386
|
+
let fileSize = fs9.existsSync(filePath) ? fs9.statSync(filePath).size : 0;
|
|
5609
5387
|
let watcher = null;
|
|
5610
5388
|
const openStream = () => {
|
|
5611
|
-
const stream =
|
|
5389
|
+
const stream = fs9.createReadStream(filePath, { start: fileSize, encoding: "utf-8" });
|
|
5612
5390
|
stream.on("data", (chunk) => {
|
|
5613
5391
|
process.stdout.write(chunk);
|
|
5614
5392
|
fileSize += Buffer.byteLength(chunk, "utf-8");
|
|
@@ -5616,9 +5394,9 @@ async function followFile(filePath) {
|
|
|
5616
5394
|
stream.on("error", () => {
|
|
5617
5395
|
});
|
|
5618
5396
|
};
|
|
5619
|
-
watcher =
|
|
5397
|
+
watcher = fs9.watch(filePath, { persistent: true }, (event2) => {
|
|
5620
5398
|
if (event2 === "change") {
|
|
5621
|
-
const stat =
|
|
5399
|
+
const stat = fs9.existsSync(filePath) ? fs9.statSync(filePath) : null;
|
|
5622
5400
|
if (!stat || stat.size < fileSize) {
|
|
5623
5401
|
fileSize = 0;
|
|
5624
5402
|
}
|
|
@@ -5994,16 +5772,186 @@ async function handleDeviceStatus(background) {
|
|
|
5994
5772
|
printer_default.print(pico10.yellow("This machine is not enrolled. Run: pinggy device login"));
|
|
5995
5773
|
return;
|
|
5996
5774
|
}
|
|
5775
|
+
const reading = await readBackgroundAgent(background);
|
|
5776
|
+
const foreground = background.readForegroundAgent();
|
|
5777
|
+
const daemonFound = background.findDaemon() !== null;
|
|
5778
|
+
printer_default.print(` State ${describeDeviceState(reading, daemonFound, foreground)}`);
|
|
5997
5779
|
printer_default.print(` Device id ${identity.device_agent_id ?? pico10.gray("not yet assigned")}`);
|
|
5998
5780
|
printer_default.print(` Server ${identity.server}`);
|
|
5999
5781
|
printer_default.print(` Token ${maskToken(identity.token)}`);
|
|
6000
5782
|
printer_default.print(` Enrolled ${identity.enrolled_at ?? pico10.gray("never")}`);
|
|
6001
5783
|
printer_default.print(` Autostart ${background.hasSavedAgent() ? "on, starts with the daemon" : pico10.gray("off")}`);
|
|
6002
|
-
const foreground = background.readForegroundAgent();
|
|
6003
5784
|
if (foreground) {
|
|
6004
5785
|
printer_default.print(` Foreground running in another terminal, PID ${foreground.pid}`);
|
|
6005
5786
|
}
|
|
6006
|
-
|
|
5787
|
+
printBackgroundStatus(reading, background);
|
|
5788
|
+
}
|
|
5789
|
+
|
|
5790
|
+
// src/cli/subcommand/handlers/updateCommand.ts
|
|
5791
|
+
var EXIT_OK2 = 0;
|
|
5792
|
+
var EXIT_FAILURE = 1;
|
|
5793
|
+
var CHECK_TIMEOUT_MILLIS = 1e4;
|
|
5794
|
+
var CHECK_FLAG = "--check";
|
|
5795
|
+
var ROLLBACK_FLAG = "--rollback";
|
|
5796
|
+
var KNOWN_FLAGS = /* @__PURE__ */ new Set([CHECK_FLAG, ROLLBACK_FLAG]);
|
|
5797
|
+
var HELP_FLAGS = /* @__PURE__ */ new Set(["--help", "-h"]);
|
|
5798
|
+
var SUDO_UID_ENV2 = "SUDO_UID";
|
|
5799
|
+
function createContext() {
|
|
5800
|
+
return { probe: createInstallProbe(), runningVersion: getVersion() };
|
|
5801
|
+
}
|
|
5802
|
+
function targetFor(kind, context) {
|
|
5803
|
+
return context.target !== void 0 ? context.target : createUpdateTarget(kind, context.probe);
|
|
5804
|
+
}
|
|
5805
|
+
function printAvailable(latest, running, command) {
|
|
5806
|
+
printer_default.print(`pinggy ${latest} is available. You run ${running}.`);
|
|
5807
|
+
printer_default.print(`Run: ${command}`);
|
|
5808
|
+
}
|
|
5809
|
+
function installCommand(kind, probe) {
|
|
5810
|
+
return kind === InstallKind.Npm ? NPM_INSTALL_COMMAND : installCommandFor(probe.platform);
|
|
5811
|
+
}
|
|
5812
|
+
async function lookUpRelease(installed) {
|
|
5813
|
+
try {
|
|
5814
|
+
const tag = await resolveLatestTag({ timeoutMillis: CHECK_TIMEOUT_MILLIS });
|
|
5815
|
+
const latest = versionFromTag(tag);
|
|
5816
|
+
const newer = isNewerVersion(latest, installed);
|
|
5817
|
+
if (newer && !await isReleaseComplete(tag, { timeoutMillis: CHECK_TIMEOUT_MILLIS })) {
|
|
5818
|
+
printer_default.error(`Release ${tag} is not ready. Try again later.`);
|
|
5819
|
+
return null;
|
|
5820
|
+
}
|
|
5821
|
+
return { tag, latest, newer };
|
|
5822
|
+
} catch {
|
|
5823
|
+
printer_default.error("Could not reach GitHub to check for updates.");
|
|
5824
|
+
return null;
|
|
5825
|
+
}
|
|
5826
|
+
}
|
|
5827
|
+
async function runCheck(kind, context) {
|
|
5828
|
+
const running = context.runningVersion;
|
|
5829
|
+
const release = await lookUpRelease(running);
|
|
5830
|
+
if (!release) return EXIT_FAILURE;
|
|
5831
|
+
recordLatestVersion(release.latest);
|
|
5832
|
+
if (release.newer) printAvailable(release.latest, running, installCommand(kind, context.probe));
|
|
5833
|
+
else printer_default.print(`pinggy ${running} is up to date.`);
|
|
5834
|
+
return EXIT_OK2;
|
|
5835
|
+
}
|
|
5836
|
+
async function underUpdateLock(action) {
|
|
5837
|
+
if (!await acquireUpdateLock()) {
|
|
5838
|
+
printer_default.error("Another pinggy update is running.");
|
|
5839
|
+
return EXIT_FAILURE;
|
|
5840
|
+
}
|
|
5841
|
+
try {
|
|
5842
|
+
return await action();
|
|
5843
|
+
} catch (error) {
|
|
5844
|
+
if (!(error instanceof UpdateError)) throw error;
|
|
5845
|
+
printer_default.error(error.message);
|
|
5846
|
+
return EXIT_FAILURE;
|
|
5847
|
+
} finally {
|
|
5848
|
+
releaseUpdateLock();
|
|
5849
|
+
}
|
|
5850
|
+
}
|
|
5851
|
+
async function installRelease(release, target, context) {
|
|
5852
|
+
const { tag, latest } = release;
|
|
5853
|
+
const runningVersion = context.runningVersion;
|
|
5854
|
+
const assetName = assetNameFor(context.probe.platform, context.architecture ?? process.arch);
|
|
5855
|
+
return underUpdateLock(async () => {
|
|
5856
|
+
let daemonRestart;
|
|
5857
|
+
try {
|
|
5858
|
+
await downloadRelease(target, tag, assetName, runningVersion, context.download);
|
|
5859
|
+
daemonRestart = await daemonRestartLineFor(target.downloadPath, latest, context);
|
|
5860
|
+
await target.install({ newVersion: latest, runningVersion });
|
|
5861
|
+
} finally {
|
|
5862
|
+
removeQuietly(target.downloadPath);
|
|
5863
|
+
}
|
|
5864
|
+
writeUpdateState({
|
|
5865
|
+
rolledBackFromVersion: void 0,
|
|
5866
|
+
failedVersion: void 0,
|
|
5867
|
+
failedAttempts: void 0,
|
|
5868
|
+
deferredVersion: void 0,
|
|
5869
|
+
deferredIpcVersion: void 0
|
|
5870
|
+
});
|
|
5871
|
+
printer_default.print(`Updated pinggy ${runningVersion} to ${latest}.`);
|
|
5872
|
+
if (daemonRestart) printer_default.print(daemonRestart);
|
|
5873
|
+
return EXIT_OK2;
|
|
5874
|
+
});
|
|
5875
|
+
}
|
|
5876
|
+
async function daemonRestartLineFor(binaryPath, version, context) {
|
|
5877
|
+
const daemon = getDaemonInfo();
|
|
5878
|
+
if (!daemon) return null;
|
|
5879
|
+
const ipcVersion = await readBinaryIpcVersion(binaryPath, context.runBinary ?? runPinggyBinary).catch(() => null);
|
|
5880
|
+
return ipcVersion !== null && ipcVersion !== daemonIpcVersion(daemon) ? daemonRestartLine(version, daemon.host) : null;
|
|
5881
|
+
}
|
|
5882
|
+
function isRollbackCopy(kind, context) {
|
|
5883
|
+
return kind === InstallKind.WindowsWritable && windowsInstallPaths(context.probe.execPath).runningFromBackup;
|
|
5884
|
+
}
|
|
5885
|
+
async function runUpdate(kind, context) {
|
|
5886
|
+
if (isRollbackCopy(kind, context)) {
|
|
5887
|
+
const { liveName } = windowsInstallPaths(context.probe.execPath);
|
|
5888
|
+
printer_default.error(`This is the rollback copy of ${liveName}. It runs only: update ${ROLLBACK_FLAG}`);
|
|
5889
|
+
return EXIT_FAILURE;
|
|
5890
|
+
}
|
|
5891
|
+
const target = targetFor(kind, context);
|
|
5892
|
+
const running = context.runningVersion;
|
|
5893
|
+
const release = await lookUpRelease(target ? target.installedVersion(running) : running);
|
|
5894
|
+
if (!release) return EXIT_FAILURE;
|
|
5895
|
+
recordLatestVersion(release.latest);
|
|
5896
|
+
if (!release.newer) {
|
|
5897
|
+
printer_default.print(`pinggy ${running} is up to date.`);
|
|
5898
|
+
return EXIT_OK2;
|
|
5899
|
+
}
|
|
5900
|
+
if (!target) {
|
|
5901
|
+
printAvailable(release.latest, running, installCommand(kind, context.probe));
|
|
5902
|
+
return EXIT_OK2;
|
|
5903
|
+
}
|
|
5904
|
+
return installRelease(release, target, context);
|
|
5905
|
+
}
|
|
5906
|
+
async function runRollback(kind, context) {
|
|
5907
|
+
const target = targetFor(kind, context);
|
|
5908
|
+
if (!target) {
|
|
5909
|
+
printer_default.error(rollbackRefusal(kind));
|
|
5910
|
+
return EXIT_FAILURE;
|
|
5911
|
+
}
|
|
5912
|
+
return underUpdateLock(async () => {
|
|
5913
|
+
const { from, to } = await target.rollback(context.runningVersion);
|
|
5914
|
+
writeUpdateState({ updatedFromVersion: void 0, updatedToVersion: void 0 });
|
|
5915
|
+
printer_default.print(`Rolled back pinggy ${from} to ${to}.`);
|
|
5916
|
+
const daemonRestart = await daemonRestartLineFor(target.rollbackBinaryPath(to), to, context);
|
|
5917
|
+
if (daemonRestart) printer_default.print(daemonRestart);
|
|
5918
|
+
return EXIT_OK2;
|
|
5919
|
+
});
|
|
5920
|
+
}
|
|
5921
|
+
function rollbackRefusal(kind) {
|
|
5922
|
+
if (kind === InstallKind.WindowsReadOnly || kind === InstallKind.UnixLoose) return "This copy of pinggy cannot update itself.";
|
|
5923
|
+
return "Rollback is not available for this install.";
|
|
5924
|
+
}
|
|
5925
|
+
async function runUpdateCommand(rest, context = createContext()) {
|
|
5926
|
+
if (rest.some((argument) => HELP_FLAGS.has(argument))) {
|
|
5927
|
+
printUpdateHelp();
|
|
5928
|
+
return EXIT_OK2;
|
|
5929
|
+
}
|
|
5930
|
+
const check = rest.includes(CHECK_FLAG);
|
|
5931
|
+
const rollback = rest.includes(ROLLBACK_FLAG);
|
|
5932
|
+
if (rest.some((argument) => !KNOWN_FLAGS.has(argument)) || check && rollback) {
|
|
5933
|
+
printUpdateHelp();
|
|
5934
|
+
return EXIT_FAILURE;
|
|
5935
|
+
}
|
|
5936
|
+
const kind = detectInstallKind(context.probe);
|
|
5937
|
+
if (kind === InstallKind.DevCheckout) {
|
|
5938
|
+
printer_default.print("This is not a packaged build. Run from your checkout, or install a release.");
|
|
5939
|
+
return EXIT_OK2;
|
|
5940
|
+
}
|
|
5941
|
+
if (parseVersion(context.runningVersion) === null) {
|
|
5942
|
+
printer_default.error("Could not read the running version.");
|
|
5943
|
+
return EXIT_FAILURE;
|
|
5944
|
+
}
|
|
5945
|
+
if (check) return runCheck(kind, context);
|
|
5946
|
+
if (process.env[SUDO_UID_ENV2]) {
|
|
5947
|
+
printer_default.error("pinggy update does not run under sudo. Run it without sudo.");
|
|
5948
|
+
return EXIT_FAILURE;
|
|
5949
|
+
}
|
|
5950
|
+
return rollback ? runRollback(kind, context) : runUpdate(kind, context);
|
|
5951
|
+
}
|
|
5952
|
+
async function handleUpdate(rest) {
|
|
5953
|
+
const exitCode = await runUpdateCommand(rest);
|
|
5954
|
+
if (exitCode !== EXIT_OK2) process.exit(exitCode);
|
|
6007
5955
|
}
|
|
6008
5956
|
|
|
6009
5957
|
// src/cli/subcommand/subcommands.ts
|
|
@@ -6052,6 +6000,9 @@ async function handleSubcommand(rawArgs) {
|
|
|
6052
6000
|
case Subcommand.Devices:
|
|
6053
6001
|
refuseDevicesSpelling(rest);
|
|
6054
6002
|
return;
|
|
6003
|
+
case Subcommand.Update:
|
|
6004
|
+
await handleUpdate(rest);
|
|
6005
|
+
return;
|
|
6055
6006
|
}
|
|
6056
6007
|
}
|
|
6057
6008
|
function handleConfig(args) {
|
|
@@ -6274,12 +6225,12 @@ async function initRemoteManagementBackground(values) {
|
|
|
6274
6225
|
}
|
|
6275
6226
|
|
|
6276
6227
|
// src/daemon/lifecycle/daemonChild.ts
|
|
6277
|
-
import
|
|
6228
|
+
import fs13 from "fs";
|
|
6278
6229
|
|
|
6279
6230
|
// src/daemon/ipc/ipcServer.ts
|
|
6280
6231
|
import http from "http";
|
|
6281
|
-
import
|
|
6282
|
-
import
|
|
6232
|
+
import fs11 from "fs";
|
|
6233
|
+
import path4 from "path";
|
|
6283
6234
|
import { WebSocketServer, WebSocket as WebSocket2 } from "ws";
|
|
6284
6235
|
|
|
6285
6236
|
// src/daemon/ws/wsProtocol.ts
|
|
@@ -6306,17 +6257,17 @@ function parseClientMessage(raw) {
|
|
|
6306
6257
|
}
|
|
6307
6258
|
|
|
6308
6259
|
// src/daemon/lifecycle/stateStore.ts
|
|
6309
|
-
import
|
|
6310
|
-
import
|
|
6260
|
+
import fs10 from "fs";
|
|
6261
|
+
import path3 from "path";
|
|
6311
6262
|
var STATE_FILENAME = "daemon-state.json";
|
|
6312
6263
|
function getStatePath() {
|
|
6313
|
-
return
|
|
6264
|
+
return path3.join(getPinggyConfigDir(), STATE_FILENAME);
|
|
6314
6265
|
}
|
|
6315
6266
|
function loadDaemonState() {
|
|
6316
6267
|
const statePath = getStatePath();
|
|
6317
6268
|
try {
|
|
6318
|
-
if (!
|
|
6319
|
-
const raw =
|
|
6269
|
+
if (!fs10.existsSync(statePath)) return null;
|
|
6270
|
+
const raw = fs10.readFileSync(statePath, "utf-8");
|
|
6320
6271
|
const state = JSON.parse(raw);
|
|
6321
6272
|
if (!Array.isArray(state.tunnels)) return null;
|
|
6322
6273
|
return state;
|
|
@@ -6330,8 +6281,8 @@ function persistDaemonState(state) {
|
|
|
6330
6281
|
const tmpPath = statePath + ".tmp";
|
|
6331
6282
|
try {
|
|
6332
6283
|
state.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
|
|
6333
|
-
|
|
6334
|
-
|
|
6284
|
+
fs10.writeFileSync(tmpPath, JSON.stringify(state, null, 2), "utf-8");
|
|
6285
|
+
fs10.renameSync(tmpPath, statePath);
|
|
6335
6286
|
} catch (err) {
|
|
6336
6287
|
logger.error("Failed to persist daemon state", { error: errorMessage(err) });
|
|
6337
6288
|
}
|
|
@@ -6339,8 +6290,8 @@ function persistDaemonState(state) {
|
|
|
6339
6290
|
function clearDaemonState() {
|
|
6340
6291
|
const statePath = getStatePath();
|
|
6341
6292
|
try {
|
|
6342
|
-
if (
|
|
6343
|
-
|
|
6293
|
+
if (fs10.existsSync(statePath)) {
|
|
6294
|
+
fs10.unlinkSync(statePath);
|
|
6344
6295
|
}
|
|
6345
6296
|
} catch {
|
|
6346
6297
|
}
|
|
@@ -6510,8 +6461,8 @@ var IPCServer = class {
|
|
|
6510
6461
|
if (n) activeNames.add(n);
|
|
6511
6462
|
}
|
|
6512
6463
|
for (const file of files) {
|
|
6513
|
-
const filePath =
|
|
6514
|
-
const stat =
|
|
6464
|
+
const filePath = path4.join(logDir, file);
|
|
6465
|
+
const stat = fs11.statSync(filePath);
|
|
6515
6466
|
const parsed = parseTunnelLogFilename(file);
|
|
6516
6467
|
if (!parsed) continue;
|
|
6517
6468
|
const running = parsed.tunnelId ? activeIds.has(parsed.tunnelId) : parsed.name ? activeNames.has(parsed.name) : false;
|
|
@@ -7157,11 +7108,11 @@ function machineDeviceAgentHostDependencies(port, record) {
|
|
|
7157
7108
|
}
|
|
7158
7109
|
|
|
7159
7110
|
// src/daemon/lifecycle/daemonLock.ts
|
|
7160
|
-
import
|
|
7111
|
+
import fs12 from "fs";
|
|
7161
7112
|
var UNREADABLE_LOCK_GRACE_MILLIS = 1e4;
|
|
7162
7113
|
function readLock(lockPath) {
|
|
7163
7114
|
try {
|
|
7164
|
-
const record = JSON.parse(
|
|
7115
|
+
const record = JSON.parse(fs12.readFileSync(lockPath, "utf-8"));
|
|
7165
7116
|
return Number.isInteger(record.pid) && record.pid > 0 ? record : null;
|
|
7166
7117
|
} catch {
|
|
7167
7118
|
return null;
|
|
@@ -7169,7 +7120,7 @@ function readLock(lockPath) {
|
|
|
7169
7120
|
}
|
|
7170
7121
|
function isUnreadableLockOld(lockPath) {
|
|
7171
7122
|
try {
|
|
7172
|
-
return Date.now() -
|
|
7123
|
+
return Date.now() - fs12.statSync(lockPath).mtimeMs > UNREADABLE_LOCK_GRACE_MILLIS;
|
|
7173
7124
|
} catch {
|
|
7174
7125
|
return true;
|
|
7175
7126
|
}
|
|
@@ -7180,7 +7131,7 @@ function isStale(lockPath, holder) {
|
|
|
7180
7131
|
}
|
|
7181
7132
|
function createLock(lockPath, record) {
|
|
7182
7133
|
try {
|
|
7183
|
-
|
|
7134
|
+
fs12.writeFileSync(lockPath, JSON.stringify(record), { encoding: "utf-8", flag: "wx" });
|
|
7184
7135
|
return true;
|
|
7185
7136
|
} catch (err) {
|
|
7186
7137
|
if (err.code === "EEXIST") return false;
|
|
@@ -7196,13 +7147,13 @@ function acquireDaemonLock() {
|
|
|
7196
7147
|
if (holder?.pid === process.pid) return true;
|
|
7197
7148
|
if (!isStale(lockPath, holder)) return false;
|
|
7198
7149
|
logger.info("Stale daemon.lock found, replacing it", { stalePid: holder?.pid });
|
|
7199
|
-
|
|
7150
|
+
fs12.rmSync(lockPath, { force: true });
|
|
7200
7151
|
return createLock(lockPath, record);
|
|
7201
7152
|
}
|
|
7202
7153
|
function releaseDaemonLock() {
|
|
7203
7154
|
const lockPath = getDaemonLockPath();
|
|
7204
7155
|
if (readLock(lockPath)?.pid === process.pid) {
|
|
7205
|
-
|
|
7156
|
+
fs12.rmSync(lockPath, { force: true });
|
|
7206
7157
|
}
|
|
7207
7158
|
}
|
|
7208
7159
|
|
|
@@ -7220,14 +7171,14 @@ function writeDaemonInfo(info) {
|
|
|
7220
7171
|
ensurePinggyConfigDir();
|
|
7221
7172
|
const infoPath = getDaemonInfoPath();
|
|
7222
7173
|
const tmpPath = infoPath + ".tmp";
|
|
7223
|
-
|
|
7224
|
-
|
|
7174
|
+
fs13.writeFileSync(tmpPath, JSON.stringify(info, null, 2), "utf-8");
|
|
7175
|
+
fs13.renameSync(tmpPath, infoPath);
|
|
7225
7176
|
}
|
|
7226
7177
|
function removeDaemonInfo() {
|
|
7227
7178
|
try {
|
|
7228
7179
|
const infoPath = getDaemonInfoPath();
|
|
7229
|
-
const info = JSON.parse(
|
|
7230
|
-
if (info.pid === process.pid)
|
|
7180
|
+
const info = JSON.parse(fs13.readFileSync(infoPath, "utf-8"));
|
|
7181
|
+
if (info.pid === process.pid) fs13.unlinkSync(infoPath);
|
|
7231
7182
|
} catch {
|
|
7232
7183
|
}
|
|
7233
7184
|
}
|
|
@@ -7456,7 +7407,8 @@ async function runDaemonChild(opts = {}) {
|
|
|
7456
7407
|
port,
|
|
7457
7408
|
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7458
7409
|
host: daemonHost,
|
|
7459
|
-
ipcVersion: IPC_VERSION
|
|
7410
|
+
ipcVersion: IPC_VERSION,
|
|
7411
|
+
cliVersion: getVersion()
|
|
7460
7412
|
};
|
|
7461
7413
|
writeDaemonInfo(info);
|
|
7462
7414
|
logger.info("Daemon info written", info);
|
|
@@ -7502,10 +7454,21 @@ async function main() {
|
|
|
7502
7454
|
const { values, positionals, hasAnyArgs } = parseCliArgs(cliOptions);
|
|
7503
7455
|
configureLogger(values);
|
|
7504
7456
|
if (values["_daemon-child"]) {
|
|
7505
|
-
const { runDaemonChild: runDaemonChild2 } = await import("./daemonChild-
|
|
7457
|
+
const { runDaemonChild: runDaemonChild2 } = await import("./daemonChild-24Y3AKII.js");
|
|
7506
7458
|
await runDaemonChild2();
|
|
7507
7459
|
return;
|
|
7508
7460
|
}
|
|
7461
|
+
if (values["_ipc-version"]) {
|
|
7462
|
+
printer_default.print(String(IPC_VERSION));
|
|
7463
|
+
return;
|
|
7464
|
+
}
|
|
7465
|
+
if (values["_update-child"]) {
|
|
7466
|
+
const { runUpdateChild } = await import("./updateChild-JNGDWIAK.js");
|
|
7467
|
+
await runUpdateChild();
|
|
7468
|
+
process.exit(0);
|
|
7469
|
+
}
|
|
7470
|
+
if (isPackagedBinary() && platform2() === "win32") removeStaleUpdateFiles();
|
|
7471
|
+
startBackgroundUpdate({ rawArgs, values, hasAnyArgs });
|
|
7509
7472
|
if (isSubcommand(rawArgs)) {
|
|
7510
7473
|
await handleSubcommand(rawArgs);
|
|
7511
7474
|
return;
|