pinggy 0.6.6 → 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 +18 -8
- package/CLAUDE.md +5 -5
- package/README.md +12 -2
- package/dist/{chunk-4XXAHYCJ.js → chunk-3KCXR33Y.js} +43 -16
- package/dist/{chunk-HAFTH5MX.js → chunk-FWTQF6AB.js} +26 -10
- package/dist/{chunk-Q5NCTGNS.js → chunk-H527WMTF.js} +1 -1
- package/dist/{chunk-FQ22KFVV.js → chunk-PMZJ6HFH.js} +1 -1
- package/dist/{daemonChild-Q6WGYKYX.js → daemonChild-24Y3AKII.js} +4 -4
- package/dist/index.cjs +67 -24
- package/dist/index.js +3 -3
- package/dist/{main-BI7ACRHS.js → main-HSIFQAGU.js} +4 -4
- package/dist/{updateChild-Z3SIRYO5.js → updateChild-JNGDWIAK.js} +2 -2
- package/package.json +3 -3
- package/scripts/build_node_pty_linux.sh +27 -0
- package/scripts/check_linux_addons.js +168 -0
- package/scripts/install/install.ps1 +13 -15
- package/scripts/install/install.sh +23 -14
package/ARCHITECTURE.md
CHANGED
|
@@ -479,7 +479,7 @@ Same code path as user-typed subcommands: the daemon does not know or care that
|
|
|
479
479
|
|
|
480
480
|
`pinggy daemon service-install` writes a platform-specific service file and enables it. `pinggy daemon service-uninstall` stops the daemon and removes it. Code: `src/daemon/lifecycle/serviceInstaller.ts`.
|
|
481
481
|
|
|
482
|
-
- Linux: systemd user unit at `~/.config/systemd/user/pinggy.service`. `Type=simple`, runs `<binary> --_daemon-child` directly (no fork). `systemctl --user enable`, then `start`.
|
|
482
|
+
- Linux: systemd user unit at `~/.config/systemd/user/pinggy.service`. `Type=simple`, runs `<binary> --_daemon-child` directly (no fork). `systemctl --user enable`, then `start`. A user unit starts at sign-in, so `service-install` then runs `loginctl enable-linger <user>`, unless `loginctl show-user` reports `Linger=yes`. Lingering starts the user's units at boot, with nobody signed in. When the command fails, as on a system that wants an admin password for it, `service-install` prints the command and still exits 0. `service-uninstall` leaves lingering on, because it belongs to the user and other units may need it.
|
|
483
483
|
- macOS: launchd `LaunchAgent` at `~/Library/LaunchAgents/io.pinggy.agent.plist`. `launchctl load`.
|
|
484
484
|
- Windows: Task Scheduler task `PinggyDaemon`, created with `schtasks /Create` and no admin rights. A logon trigger for the current user runs `<binary> daemon start`. `daemon start` spawns `--_daemon-child` detached with `windowsHide`, then exits. The task does not run `--_daemon-child` directly: `pinggy.exe` is a console program, so Task Scheduler opens a console window for it, and closing that window kills the daemon. The `daemon start` window shows for about 1s. The task ends once the daemon is up, so uninstall stops the daemon over IPC. It deletes the task first, so a failed delete leaves the daemon running. With no task, it stops nothing. A task created from an Administrator terminal keeps admin-only permissions, so a normal terminal cannot replace or delete it. When `schtasks` fails, the task exists, and `whoami /groups` shows no High or System integrity SID, pinggy tells the user to run the command from an Administrator terminal. It checks the SID, not the "Access is denied" text, because `schtasks` prints that text in the Windows language.
|
|
485
485
|
|
|
@@ -495,7 +495,7 @@ The one long-lived surface that is not a tunnel. `pinggy device connect` enrols
|
|
|
495
495
|
|
|
496
496
|
**Email sign-in.** `pinggy device login` gets the device token without the dashboard: it asks for an email, `POST /backend/api/v1/device-agent/login/start` emails a 6-digit code, and the code prompt races a `poll` every few seconds under 1 `AbortController`. A right code (and the TOTP, with MFA on) answers the token once. The email also carries an Approve link: the CLI prints the `match_code` its page shows as `Device Code: <code>`, then `We have sent a 6-digit code to <email>.` and `Enter the code below or click the approve button in the email.` A poll collects a link's approval, and a typed code answered `pending` stops the prompt so the poll can. The CLI writes `device.json`, prints the device's browser link and its QR code (`createQrCodes`, shared with the TUI): a one-time sign-in link after a typed code, the plain device page after the emailed link. Then it runs the same agent. Code in `src/devices/login/`: `deviceLogin.ts` (the command; every dependency injected, so `src/_tests_/deviceLogin.test.ts` runs it with no dashboard or terminal), `loginApi.ts` (`fetch`, `buildDashboardHttpUrl`, the public client token), `login_schema.ts` (zod), `prompts.ts` (`readline/promises`, 1 interface per question, closed on answer or abort; every question starts with a cyan `→`, and the sign-in result with a green one, through `picocolors`; `askHidden` reads the authenticator code without showing it, since the code still works after it is typed and the open link asks for one). A stdin that is not a TTY stops at once and points at `connect --token`. The token is never printed.
|
|
497
497
|
|
|
498
|
-
**Install scripts.** `scripts/install/install.sh` (macOS, Linux, POSIX `sh`) and `scripts/install/install.ps1` (Windows PowerShell 5.1 and 7) install or update the binary, put `pinggy` on PATH with no sudo, then ask "Connect this device to Pinggy? [Y/n]". Enter or `y` runs `pinggy device login -b` by full path. `-b` is the default, and the scripts pass it so an older binary the user kept also runs the agent in its daemon. An answer starting with `n` prints the login command and exits 0, so the CLI is installed with no device. With no terminal, the scripts ask nothing and print the command. `install.sh` writes `~/.pinggy/bin/pinggy` and links `~/.local/bin/pinggy` to it, adding 1 marked block to the shell's rc file when `~/.local/bin` is not on PATH. `install.ps1` writes `%LOCALAPPDATA%\Pinggy\bin\pinggy.exe` and adds that directory to the user PATH. Both read 3 things this repo owns: the release asset names, the `Pinggy CLI version: <x.y.z>` line, and the `--manage` and `-b` flags of `device login` and `connect`. A change to any of them changes both scripts in the same commit. `.github/workflows/website-cli-download-links-pr.yml` copies both, read at the release tag, to the website's `static/`, so pinggy.io serves `/install.sh` and `/install.ps1`. After `device login` or `connect` exits 0, both scripts ask "Start pinggy automatically when this computer starts? [Y/n]" and run `pinggy daemon service-install`. The question says "starts" for users.
|
|
498
|
+
**Install scripts.** `scripts/install/install.sh` (macOS, Linux, POSIX `sh`) and `scripts/install/install.ps1` (Windows PowerShell 5.1 and 7) install or update the binary, put `pinggy` on PATH with no sudo, then ask "Connect this device to Pinggy? [Y/n]". Enter or `y` runs `pinggy device login -b` by full path. `-b` is the default, and the scripts pass it so an older binary the user kept also runs the agent in its daemon. An answer starting with `n` prints the login command and exits 0, so the CLI is installed with no device. With no terminal, the scripts ask nothing and print the command. `install.sh` writes `~/.pinggy/bin/pinggy` and links `~/.local/bin/pinggy` to it, adding 1 marked block to the shell's rc file when `~/.local/bin` is not on PATH. `install.ps1` writes `%LOCALAPPDATA%\Pinggy\bin\pinggy.exe` and adds that directory to the user PATH. Both read the version to install from `https://pinggy.io/cli/version.json`, never from GitHub's `/releases/latest`. The website builds that file from `data/cli_releases.yaml`, and the release PR changes that list and both scripts in 1 commit, so the script and the binary come from 1 release. When pinggy.io does not answer, or the file has no `x.y.z` in its `version` field, the scripts exit 1 with a message that names the URL and `PINGGY_VERSION`. `PINGGY_VERSION` skips the request. The binary still downloads from the GitHub release. `install.sh` reads the field with `sed`, so the key stays `version` with a quoted value. Both read 3 things this repo owns: the release asset names, the `Pinggy CLI version: <x.y.z>` line, and the `--manage` and `-b` flags of `device login` and `connect`. A change to any of them changes both scripts in the same commit. `.github/workflows/website-cli-download-links-pr.yml` copies both, read at the release tag, to the website's `static/`, so pinggy.io serves `/install.sh` and `/install.ps1`. After `device login` or `connect` exits 0, both scripts ask "Start pinggy automatically when this computer starts? [Y/n]" and run `pinggy daemon service-install`. The question says "starts" for users. On macOS and Windows the service starts pinggy after the user signs in, not at boot. On Linux it starts at boot, because `service-install` turns on lingering. They skip the question when the service exists and runs the installed binary: `install.sh` looks for that binary's path in the launchd plist or the systemd unit file, `install.ps1` compares the command of the `PinggyDaemon` task (`Get-ScheduledTask`) with it. A service that runs any other binary gets the question, and `service-install` replaces it. `install.sh` also skips it on Linux with no systemd user manager. With no terminal, they print the `service-install` command. They remove `DEVICE_AGENT_TOKEN` before the question. Renaming the task, the plist or the unit file changes both scripts in the same commit. Lint with `shellcheck -s sh` and `PSScriptAnalyzer`.
|
|
499
499
|
|
|
500
500
|
**The token command.** The dashboard shows `curl -fsSL https://pinggy.io/install.sh | DEVICE_AGENT_TOKEN=<token> sh`, and `$env:DEVICE_AGENT_TOKEN='<token>'; irm https://pinggy.io/install.ps1 | iex` on Windows. With the variable set, both scripts update an older binary without asking, then run `pinggy device connect -b` by full path, with `--manage` when `PINGGY_MANAGE` is set. The token reaches the CLI in its environment, never on a command line, where `ps` would show it. `install.sh` gives `connect` `/dev/null` as stdin, since it reads no key. `install.ps1` removes the variable in a `finally`, because `iex` runs in the user's own window. `handleDevice()` reads `DEVICE_AGENT_TOKEN` and deletes it from `process.env` before any verb runs, so no shell, daemon or other child inherits it (`takeEnvironmentToken()` in `deviceCommand.ts`). `connect` then picks the token from `--token`, else the variable, else `device.json`, and the server from `--manage`, else `dashboard.pinggy.io` for a token from the variable, else the server in `device.json` (`resolveConnectTarget()`). An empty variable counts as unset.
|
|
501
501
|
|
|
@@ -520,7 +520,7 @@ The design lives in the `pinggy_backend` repo under `docs/pinggy-devices/`: `cli
|
|
|
520
520
|
5. Print the commands that manage the device once the CLI exits: `pinggy device status`, `stop`, `connect` and `remove` (`MANAGE_COMMANDS`). Then print that the agent starts. A refusal in steps 3 or 4 prints only the refusal.
|
|
521
521
|
6. `GET /device` every 500 ms for up to 15 s. `connected` prints the device, the email, the device link and the log path. `stopped` prints `lastError` and exits 1. Still connecting leaves it to the daemon and exits 0.
|
|
522
522
|
|
|
523
|
-
`login` signs in as the foreground does, then runs steps 3 to 6 in place of `runAgent`. After a new sign-in, `runAgent` gets `signInShown`, and step 6 leaves out the email and the device link, which the sign-in already printed. `device stop` calls `POST /device/stop`. `device status`
|
|
523
|
+
`login` signs in as the foreground does, then runs steps 3 to 6 in place of `runAgent`. After a new sign-in, `runAgent` gets `signInShown`, and step 6 leaves out the email and the device link, which the sign-in already printed. `device stop` calls `POST /device/stop`. `device status` prints a `State` line first (`describeDeviceState()`). It reads `GET /device` once, and `device-agent.json`: `running` plus the daemon agent's connection state, `running, with --foreground in another terminal`, `stopped` when no agent runs or no daemon runs, or `unknown` when `daemon.json` names a daemon that `GET /device` cannot read (another IPC version, an older daemon, no answer). It adds a `Background` line from the same reading. `device remove` stops a running background agent before it deletes `device.json`. A `--foreground` `connect` or `login` refuses while `GET /device` reports a run: 2 agents on 1 credential refuse each other with `already_connected`.
|
|
524
524
|
|
|
525
525
|
**The foreground record** (`src/devices/foregroundAgent.ts`). The daemon cannot see an agent started with `--foreground`, so `runDeviceAgent()` writes `device-agent.json` (`{pid, started_at}`) beside `device.json` while it runs, and deletes it on exit if it still names its own PID. The agent checks once a second that the file exists. `device remove` (`src/devices/removeDevice.ts`) first prints the device id, the background agent's state and the foreground record's PID, and asks "Remove this device from this machine? [y/N]". Only `y` or `yes` goes on. `-f`, the existing `cliOptions.force`, skips the question. With no TTY and no `-f`, it exits 1 and changes nothing. Then it deletes the file, waits up to 10 s for the PID to exit, and deletes `device.json`. An agent still running after that fails the remove with exit 1 and leaves `device.json` in place. No signal goes to the PID: a record left by a crash can name an unrelated process. `readForegroundAgent()` deletes a record whose PID is dead or whose `started_at` is before the last boot. `connect` and `login` refuse while a live record names another process, both in the default background start and with `--foreground`. The background start writes no record: the daemon's `GET /device` already reports it. `device status` adds a `Foreground` line.
|
|
526
526
|
|
|
@@ -571,7 +571,7 @@ The daemon's run differs from the foreground one in 3 dependencies, passed throu
|
|
|
571
571
|
| `src/devices/terminal/shellContext.ts` | Each shell's `cwd` and foreground program from the process table: `/proc` on Linux, `ps` and `lsof` on macOS, nothing on Windows. `programName()` keeps the first word, basename only, because a process can write its arguments into its own name. `ShellContextTracker` turns polls into `context` events, only on change |
|
|
572
572
|
| `src/devices/terminal/terminalRegistry.ts` | `TerminalRegistry`: terminal id to pty handle, with the per-device ceiling from `welcome` |
|
|
573
573
|
| `src/devices/terminal/ptySession.ts` | Lazy `node-pty` load, `isTerminalSupported()` (false unless the addon loads and, on macOS, `spawn-helper` can be exec'd), `spawnPty()`, the `spawn-helper` execute-bit repair, `signalForeground()` to the tty's foreground process group |
|
|
574
|
-
| `src/devices/terminal/nodePtyRuntime.ts` | `resolveNodePtyRoot()`: where `node-pty` loads from. Unpacks it onto real disk inside a `pkg` binary or an Electron `.asar` archive,
|
|
574
|
+
| `src/devices/terminal/nodePtyRuntime.ts` | `resolveNodePtyRoot()`: where `node-pty` loads from. Unpacks it onto real disk inside a `pkg` binary or an Electron `.asar` archive, into a directory named by the addon's hash. `hasExecutableSpawnHelper()`, true off macOS |
|
|
575
575
|
| `src/devices/terminal/shellAllowlist.ts` | `resolveShell()`: exact match against `/etc/shells`, or `powershell.exe` and `cmd.exe` on Windows |
|
|
576
576
|
| `src/cli/subcommand/handlers/deviceCommand.ts` | The `login`, `connect`, `stop`, `status`, `remove` verbs, and `--foreground`. `refuseDevicesSpelling()` for the old spelling |
|
|
577
577
|
| `src/utils/helpMessages.ts` | `printDeviceHelp()` |
|
|
@@ -727,15 +727,25 @@ The dashboard answers an unreadable payload with `invalid_payload` on the `devic
|
|
|
727
727
|
|
|
728
728
|
**A packaged binary loads `node-pty` from real disk, not from the snapshot.** On macOS `node-pty` does not exec the shell directly. It execs `spawn-helper`, at a path it derives from wherever its own module sits. Inside a `pkg` binary that path is `/snapshot/...`, which only exists in the `fs` module pkg patches, so the kernel cannot exec it and `posix_spawn` fails with `ENOENT`. The throw is fatal inside the addon, so no caller gets to answer for it. node-pty builds `spawn-helper` on macOS only: Linux forks the shell with `forkpty()`, and Windows uses ConPTY. `hasExecutableSpawnHelper()` asks for a helper on macOS only.
|
|
729
729
|
|
|
730
|
-
`resolveNodePtyRoot()` copies the package out of the snapshot on first use and returns that path, so every path `node-pty` derives afterwards is a real one. It copies `package.json`, `lib/`, and this platform's native directory only: 41 files and 404 KB. The snapshot carries the native directories of all 4 prebuilt platforms, about 5 MB. The `pkg.ignore` list in `package.json` keeps the package's `.pdb` debug symbols and C++ source, 56 MB, out of the binary. A glob added there must not remove anything else from the 3 copied paths. The copy lands in `~/.config/pinggy/runtime/node-pty-<version>-<platform>-<arch
|
|
730
|
+
`resolveNodePtyRoot()` copies the package out of the snapshot on first use and returns that path, so every path `node-pty` derives afterwards is a real one. It copies `package.json`, `lib/`, and this platform's native directory only: 41 files and 404 KB. The snapshot carries the native directories of all 4 prebuilt platforms, about 5 MB. The `pkg.ignore` list in `package.json` keeps the package's `.pdb` debug symbols and C++ source, 56 MB, out of the binary. A glob added there must not remove anything else from the 3 copied paths. The copy lands in `~/.config/pinggy/runtime/node-pty-<version>-<platform>-<arch>-<hash>`. `<hash>` is 12 hex characters of a SHA-256 over each `pty.node` and the directory it sits in. The copy is staged under a sibling name and renamed into place, so 2 agents starting at once cannot load a half-written copy. An agent whose rename fails because another agent's copy is already there uses that copy. An unpackaged run resolves through `require` as normal and copies nothing.
|
|
731
731
|
|
|
732
|
-
**Linux has no prebuild.** node-pty 1.1.0 ships prebuilds for `darwin-arm64`, `darwin-x64`, `win32-arm64` and `win32-x64`. On Linux `npm ci` compiles `build/Release/pty.node`. node-pty's `files` list leaves `build/` out, and pkg packs only what that list names, so `pkg.assets` names `pty.node`. Linux binaries up to 0.6.5 carried no addon, and their copy holds `package.json` and `lib/` only. `
|
|
732
|
+
**Linux has no prebuild.** node-pty 1.1.0 ships prebuilds for `darwin-arm64`, `darwin-x64`, `win32-arm64` and `win32-x64`. On Linux `npm ci` compiles `build/Release/pty.node`. node-pty's `files` list leaves `build/` out, and pkg packs only what that list names, so `pkg.assets` names `pty.node`. The hash in the copy's name keeps a binary off a copy of another addon. Binaries up to 0.6.6 named the copy without a hash. Linux binaries up to 0.6.5 carried no addon, and their copy holds `package.json` and `lib/` only. 0.6.6's linux-x64 copy holds a `pty.node` that needs glibc 2.42. The Pinggy app and the CLI can ship different addons, and each loads its own copy. Nothing deletes a copy, because another process may run from it: on macOS a process whose `spawn-helper` is gone dies at its next spawn. Old copies stay on disk. Each is under 0.5 MB on Linux and macOS, and about 3 MB on Windows.
|
|
733
733
|
|
|
734
|
-
The
|
|
734
|
+
**The compiling machine sets the addon's glibc floor.** A linker binds each libc symbol to the newest version that machine's glibc has. On Ubuntu 26.04, which `ubuntu-latest` became, glibc 2.42 gave `cfsetospeed` and `cfsetispeed` new versions, so the 0.6.6 linux-x64 `pty.node` needs `GLIBC_2.42`. On Ubuntu 24.04 the load then fails, and the agent leaves `terminal` out of `hello`. node-pty's own error lists the 3 directories it checked, but gives only the last one's error (`Cannot find module './prebuilds/linux-x64//pty.node'`). `process.dlopen()` on `build/Release/pty.node` gives the real reason (`version 'GLIBC_2.42' not found`).
|
|
735
|
+
|
|
736
|
+
So both workflows' Linux jobs run `scripts/build_node_pty_linux.sh` after `npm ci`. It runs `npm rebuild node-pty` in `node:24-bookworm` (Debian 12, glibc 2.36), whose `pty.node` needs `GLIBC_2.34` (`forkpty` and `openpty`) and `GLIBCXX_3.4.22`. Then `scripts/check_linux_addons.js` checks it, and the SDK's `addon.node` and `libpinggy.so` too. `pack:linux-x64` and `pack:linux-arm64` run that check again first. The SDK's files come prebuilt, but a failed download makes `node-pre-gyp` compile them on the runner, with the runner's glibc. The check reads each file's `.gnu.version_r` section. It refuses a missing file, one for another architecture, and one that needs a newer `GLIBC`, `GLIBCXX`, `CXXABI` or `GCC` version than RHEL 9 has. It also refuses a name of those families that carries no number, such as `GLIBC_ABI_DT_RELR` (glibc 2.36). RHEL 9 has glibc 2.34, and GCC 11's libgcc_s and libstdc++. Its x64 libgcc_s defines up to `GCC_7.0.0`, and its arm64 one up to `GCC_11.0`. Amazon Linux 2023 has the same glibc, with GCC 14's libraries. Those are the oldest distros the CLI runs on: the SDK's `libpinggy.so` needs the system's OpenSSL 3 (`libssl.so.3`), and every distro that ships it has glibc 2.34 or newer. Measured on Debian 10 and 11: the CLI does not start there, because `libssl.so.3` is missing. The e2e suite runs on the machine that built the binary, so it cannot catch an addon that needs a newer glibc. Only the check does.
|
|
737
|
+
|
|
738
|
+
| Part of the Linux binary | Newest `GLIBC` | Newest `GLIBCXX` |
|
|
739
|
+
|---|---|---|
|
|
740
|
+
| pkg's Node 20 | 2.28 | 3.4.21 |
|
|
741
|
+
| SDK `libpinggy.so` | 2.17 | 3.4.26 |
|
|
742
|
+
| SDK `addon.node` | 2.17 | none |
|
|
743
|
+
| `pty.node` from `node:24-bookworm` | 2.34 | 3.4.22 |
|
|
744
|
+
| `pty.node` from `ubuntu-latest` (Ubuntu 26.04) | 2.42 | 3.4.22 |
|
|
735
745
|
|
|
736
746
|
Not `pkg`'s own cache. `pkg` already unpacks the addon to `~/.cache/pkg/<hash>/` at mode 644, but the hash is undocumented and `node-pty` never looks there.
|
|
737
747
|
|
|
738
|
-
Measured on `macos-arm64` and `macos-x64`, and on `linux-arm64` in Docker
|
|
748
|
+
Measured on `macos-arm64` and `macos-x64`, and on `linux-arm64` in Docker: Debian 12 and 13, AlmaLinux 9, Ubuntu 22.04 and Ubuntu 26.04. A `linux-x64` `pty.node` from `build_node_pty_linux.sh` loads and runs a shell on Ubuntu 24.04. The `device-agent-terminal` e2e case opens a shell and runs 1 command on all 6 CI platforms.
|
|
739
749
|
|
|
740
750
|
### Outcomes
|
|
741
751
|
|
package/CLAUDE.md
CHANGED
|
@@ -14,7 +14,7 @@ npm run build:tsc
|
|
|
14
14
|
# Dev workflow (link SDK, build, link locally)
|
|
15
15
|
npm run dev
|
|
16
16
|
|
|
17
|
-
# Build platform binaries (via pkg)
|
|
17
|
+
# Build platform binaries (via pkg). Linux binaries need Linux and Docker: see Build System
|
|
18
18
|
npm run pack:all
|
|
19
19
|
|
|
20
20
|
# E2E suite against a packaged binary (see test/e2e/README.md)
|
|
@@ -79,7 +79,7 @@ It owns no tunnel. It reads the daemon's `GET /tunnels` through `IPCClient` and
|
|
|
79
79
|
|
|
80
80
|
1 invocation runs 1 subcommand: `isSubcommand()` reads `rawArgs[0]` only, so `pinggy device connect start my-tunnel` runs the agent and drops the rest, and tunnel flags on a `device` line parse and are ignored, except `-b` and `--foreground`.
|
|
81
81
|
|
|
82
|
-
`scripts/install/install.sh` installs into `~/.pinggy/versions/<version>/` and points the link `~/.pinggy/bin/pinggy` at it. `install.sh` and `install.ps1` install or update the binary, put it on PATH, then ask "Connect this device to Pinggy? [Y/n]" and run `pinggy device login -b` unless the answer starts with `n`. `-b` is the default, and the scripts pass it so an older binary the user kept also runs the agent in its daemon. pinggy.io serves copies that `website-cli-download-links-pr.yml` writes at each release tag. Renaming a release asset, changing the `Pinggy CLI version:` line, or changing `device login`'s `--manage` or `-b` flag means changing both scripts in the same commit. `DEVICE_AGENT_TOKEN` on either script updates without asking and runs `pinggy device connect -b` instead, with the token in the environment, never on a command line. `handleDevice()` deletes the variable from `process.env` before any verb runs, so no shell or daemon the agent starts inherits it. Renaming the variable or `connect`'s `--manage` or `-b` flag also changes both scripts in the same commit. `pinggy daemon service-install` runs only from the path the scripts install to (`installerBinaryPath()` in `src/daemon/lifecycle/serviceInstaller.ts`), so changing either script's install directory changes that function in the same commit. Once the device connects, both scripts offer `pinggy daemon service-install` unless the service exists. They look for the task name, plist or unit file that `serviceInstaller.ts` writes, and the installed binary's path in it, so renaming any of them changes both scripts in the same commit.
|
|
82
|
+
`scripts/install/install.sh` installs into `~/.pinggy/versions/<version>/` and points the link `~/.pinggy/bin/pinggy` at it. `install.sh` and `install.ps1` install or update the binary, put it on PATH, then ask "Connect this device to Pinggy? [Y/n]" and run `pinggy device login -b` unless the answer starts with `n`. `-b` is the default, and the scripts pass it so an older binary the user kept also runs the agent in its daemon. pinggy.io serves copies that `website-cli-download-links-pr.yml` writes at each release tag. The scripts read the version to install from `https://pinggy.io/cli/version.json`, which the website builds from the `data/cli_releases.yaml` that the same PR updates, and they exit 1 when it does not answer. They download the binary from the GitHub release. The updater in `src/update/` still reads GitHub's `/releases/latest`. Copies of the scripts stay in use, so that URL and its `version` field never change. Renaming a release asset, changing the `Pinggy CLI version:` line, or changing `device login`'s `--manage` or `-b` flag means changing both scripts in the same commit. `DEVICE_AGENT_TOKEN` on either script updates without asking and runs `pinggy device connect -b` instead, with the token in the environment, never on a command line. `handleDevice()` deletes the variable from `process.env` before any verb runs, so no shell or daemon the agent starts inherits it. Renaming the variable or `connect`'s `--manage` or `-b` flag also changes both scripts in the same commit. `pinggy daemon service-install` runs only from the path the scripts install to (`installerBinaryPath()` in `src/daemon/lifecycle/serviceInstaller.ts`), so changing either script's install directory changes that function in the same commit. Once the device connects, both scripts offer `pinggy daemon service-install` unless the service exists. They look for the task name, plist or unit file that `serviceInstaller.ts` writes, and the installed binary's path in it, so renaming any of them changes both scripts in the same commit.
|
|
83
83
|
|
|
84
84
|
Section 17 of `ARCHITECTURE.md` has the protocol, the retry and terminal outcome table, the `device.json` rules, and the full composition table. The design docs are in the `pinggy_backend` repo under `docs/pinggy-devices/`; read `cli.md` there before changing anything in `src/devices/`.
|
|
85
85
|
|
|
@@ -96,7 +96,7 @@ Section 17 of `ARCHITECTURE.md` has the protocol, the retry and terminal outcome
|
|
|
96
96
|
| `pinggy attach <name\|id>` | Re-attach TUI to a running tunnel |
|
|
97
97
|
| `pinggy daemon start \| stop \| status \| service-install \| service-uninstall` (alias `d`) | Daemon lifecycle and system-service installation |
|
|
98
98
|
| `pinggy update [--check \| --rollback]` | Update to the latest release now, print the latest version and change nothing, or go back to the previous version. A background check starts on its own; `PINGGY_AUTO_UPDATE=false` turns it off |
|
|
99
|
-
| `pinggy device login \| connect [--foreground] \| stop \| status \| remove [-f]` | Sign this machine in by email, or enrol it with a token, as a Pinggy device; the agent runs in the daemon, or in this terminal with `--foreground`, and `stop` stops the daemon's; show the enrolment and the background agent; show the device and its connection, ask, then stop every agent and forget the credential (`-f` skips the question) |
|
|
99
|
+
| `pinggy device login \| connect [--foreground] \| stop \| status \| remove [-f]` | Sign this machine in by email, or enrol it with a token, as a Pinggy device; the agent runs in the daemon, or in this terminal with `--foreground`, and `stop` stops the daemon's; show whether the agent runs, the enrolment and the background agent; show the device and its connection, ask, then stop every agent and forget the credential (`-f` skips the question) |
|
|
100
100
|
|
|
101
101
|
### Auto-update
|
|
102
102
|
|
|
@@ -110,13 +110,13 @@ Section 17 of `ARCHITECTURE.md` has the protocol, the retry and terminal outcome
|
|
|
110
110
|
|
|
111
111
|
tsup bundles to `dist/` (CJS + ESM). tsc type-checks only (`npm run build:tsc`). pkg builds standalone platform binaries (`out/pinggy-<platform>`). ts-jest with the ESM preset for unit tests (`jest.config.cjs`).
|
|
112
112
|
|
|
113
|
-
pkg packs every file in a dependency's `files` list and every package in its `dependencies`, whether the code loads it or not. The `pkg.ignore` list in `package.json` keeps out what the binary never loads: node-pty's `.pdb` debug symbols and C++ source, the SDK's unlinked `libcrypto.dylib` and `libssl.dylib` copies, the SDK's install-time `node-gyp` and `@mapbox/node-pre-gyp`, and zod's `src/` and `v3/`. A new glob must not match node-pty's `package.json`, `lib/`, `build/Release/pty.node`, or any file under `prebuilds/` other than a `.pdb`: `resolveNodePtyRoot()` copies those out of the snapshot at runtime. node-pty has no Linux prebuild, so on Linux `npm ci` compiles `build/Release/pty.node`. Its `files` list leaves `build/` out, so `pkg.assets` names that file. Without it the Linux binary offers no terminal. The `**` in these globs does not match a folder whose name starts with a dot, so a checkout under such a path (`~/.work/cli-js`) ignores nothing and builds the full-size binary. `"compress": "Brotli"` compresses the snapshot: on macOS arm64 the binary drops from 83 MB to 59 MB, and each run starts about 80ms later.
|
|
113
|
+
pkg packs every file in a dependency's `files` list and every package in its `dependencies`, whether the code loads it or not. The `pkg.ignore` list in `package.json` keeps out what the binary never loads: node-pty's `.pdb` debug symbols and C++ source, the SDK's unlinked `libcrypto.dylib` and `libssl.dylib` copies, the SDK's install-time `node-gyp` and `@mapbox/node-pre-gyp`, and zod's `src/` and `v3/`. A new glob must not match node-pty's `package.json`, `lib/`, `build/Release/pty.node`, or any file under `prebuilds/` other than a `.pdb`: `resolveNodePtyRoot()` copies those out of the snapshot at runtime. node-pty has no Linux prebuild, so on Linux `npm ci` compiles `build/Release/pty.node`. Its `files` list leaves `build/` out, so `pkg.assets` names that file. Without it the Linux binary offers no terminal. Pack a Linux binary on Linux, on the architecture it targets: `npm ci`, then `scripts/build_node_pty_linux.sh` (needs Docker), then `pack:linux-<arch>`. The script compiles `pty.node` in `node:24-bookworm`, because one compiled on a newer distro needs a newer glibc: from `ubuntu-latest` (Ubuntu 26.04) it needs `GLIBC_2.42` and does not load on Ubuntu 24.04. `pack:linux-<arch>` first runs `scripts/check_linux_addons.js` on `pty.node` and the SDK's `addon.node` and `libpinggy.so`. It refuses a missing file, one for another architecture, and one that needs a symbol version RHEL 9's glibc 2.34, libgcc_s or libstdc++ lacks. So `pack:all` and `pack:linux` fail on macOS, and `pack:linux` fails at its 2nd architecture. The `**` in these globs does not match a folder whose name starts with a dot, so a checkout under such a path (`~/.work/cli-js`) ignores nothing and builds the full-size binary. `"compress": "Brotli"` compresses the snapshot: on macOS arm64 the binary drops from 83 MB to 59 MB, and each run starts about 80ms later.
|
|
114
114
|
|
|
115
115
|
## Testing
|
|
116
116
|
|
|
117
117
|
**Unit tests** live in `src/_tests_/`. Use `@jest/globals` imports (no global `jest`). `TunnelManager` is a singleton, so reset it between tests with `TunnelManager.instance = undefined`, and call `jest.clearAllMocks()` in `beforeEach`.
|
|
118
118
|
|
|
119
|
-
**End-to-end tests** live in `test/e2e/`. They run against a packaged `pkg` binary, spawn real Pinggy free-tier tunnels, and assert HTTP/TCP/UDP behavior over the live edge. See `test/e2e/README.md` for layout, framework helpers, and how to add a case. CI runs them across 6 platform binaries via `.github/workflows/e2e-test.yml`.
|
|
119
|
+
**End-to-end tests** live in `test/e2e/`. They run against a packaged `pkg` binary, spawn real Pinggy free-tier tunnels, and assert HTTP/TCP/UDP behavior over the live edge. See `test/e2e/README.md` for layout, framework helpers, and how to add a case. CI runs them across 6 platform binaries via `.github/workflows/e2e-test.yml`. CI sets `PINGGY_E2E_SUITE=ci`, which runs 3 combined cases in place of 15 separate ones. The default `full` suite runs the separate ones. A change to a separate case needs the same change in its combined case.
|
|
120
120
|
|
|
121
121
|
## Key Patterns
|
|
122
122
|
|
package/README.md
CHANGED
|
@@ -263,12 +263,22 @@ pinggy device connect --token <TOKEN> --manage dashboard.pinggy.io
|
|
|
263
263
|
|
|
264
264
|
`--token` here is the device token, not the tunnel token of the same flag name in [Options](#options). The 2 credentials are unrelated and the device agent never reads the tunnel one.
|
|
265
265
|
|
|
266
|
-
### Show
|
|
266
|
+
### Show the device and whether it runs
|
|
267
267
|
```bash
|
|
268
268
|
pinggy device status
|
|
269
269
|
```
|
|
270
270
|
|
|
271
|
-
|
|
271
|
+
The first line is the device's state:
|
|
272
|
+
|
|
273
|
+
| State | Meaning |
|
|
274
|
+
|-------|---------|
|
|
275
|
+
| `running, connected` | The agent runs in the daemon and the dashboard shows the device online |
|
|
276
|
+
| `running, connecting` or `running, reconnecting` | The agent runs in the daemon and is dialling the dashboard |
|
|
277
|
+
| `running, with --foreground in another terminal` | Another terminal runs `pinggy device connect --foreground` |
|
|
278
|
+
| `stopped` | No agent runs. `pinggy device connect` starts it |
|
|
279
|
+
| `unknown` | A daemon runs but does not answer, for example after an update. `pinggy daemon stop` fixes it, and stops all running tunnels |
|
|
280
|
+
|
|
281
|
+
Then it prints the device id, server, masked token, and enrolment time from the local file. It asks the running daemon about its agent and never starts one. It contacts no server.
|
|
272
282
|
|
|
273
283
|
### Forget the local credential
|
|
274
284
|
```bash
|
|
@@ -84,6 +84,7 @@ function recordLatestVersion(version) {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
// src/devices/terminal/nodePtyRuntime.ts
|
|
87
|
+
import crypto from "crypto";
|
|
87
88
|
import fs2 from "fs";
|
|
88
89
|
import path2 from "path";
|
|
89
90
|
import { createRequire } from "module";
|
|
@@ -95,6 +96,7 @@ var EXECUTABLE_MODE = 493;
|
|
|
95
96
|
var EXECUTE_BITS = 73;
|
|
96
97
|
var RUNTIME_DIR_NAME = "runtime";
|
|
97
98
|
var ASAR_ARCHIVE_SUFFIX = ".asar";
|
|
99
|
+
var HASH_LENGTH = 12;
|
|
98
100
|
var NATIVE_DIRECTORIES = [
|
|
99
101
|
path2.join("build", "Release"),
|
|
100
102
|
path2.join("prebuilds", `${process.platform}-${process.arch}`)
|
|
@@ -143,45 +145,49 @@ function makeSpawnHelperExecutable(packageRoot) {
|
|
|
143
145
|
}
|
|
144
146
|
function unpackNodePty(snapshotRoot) {
|
|
145
147
|
const unpackedRoot = unpackedRootPath(snapshotRoot);
|
|
146
|
-
if (
|
|
148
|
+
if (isCommittedCopy(unpackedRoot)) return unpackedRoot;
|
|
147
149
|
const stagingRoot = `${unpackedRoot}.${process.pid}`;
|
|
148
150
|
fs2.rmSync(stagingRoot, { recursive: true, force: true });
|
|
149
151
|
try {
|
|
150
152
|
copyRuntimeFiles(snapshotRoot, stagingRoot);
|
|
151
153
|
makeSpawnHelperExecutable(stagingRoot);
|
|
152
|
-
removeIncompleteCopy(unpackedRoot);
|
|
153
154
|
fs2.renameSync(stagingRoot, unpackedRoot);
|
|
154
155
|
} catch (error) {
|
|
155
156
|
fs2.rmSync(stagingRoot, { recursive: true, force: true });
|
|
156
|
-
if (!
|
|
157
|
+
if (!isCommittedCopy(unpackedRoot)) throw error;
|
|
157
158
|
}
|
|
158
159
|
return unpackedRoot;
|
|
159
160
|
}
|
|
160
|
-
function
|
|
161
|
-
|
|
161
|
+
function isCommittedCopy(unpackedRoot) {
|
|
162
|
+
return fs2.existsSync(path2.join(unpackedRoot, "package.json"));
|
|
162
163
|
}
|
|
163
164
|
function unpackedRootPath(snapshotRoot) {
|
|
164
165
|
const version = readPackageVersion(snapshotRoot);
|
|
165
|
-
const
|
|
166
|
+
const hash = addonHash(snapshotRoot);
|
|
167
|
+
const directoryName = `${PACKAGE_NAME}-${version}-${process.platform}-${process.arch}-${hash}`;
|
|
166
168
|
return path2.join(getPinggyConfigDir(), RUNTIME_DIR_NAME, directoryName);
|
|
167
169
|
}
|
|
168
170
|
function readPackageVersion(packageRoot) {
|
|
169
171
|
const manifest = JSON.parse(fs2.readFileSync(path2.join(packageRoot, "package.json"), "utf8"));
|
|
170
172
|
return String(manifest.version);
|
|
171
173
|
}
|
|
172
|
-
function
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
function addonHash(snapshotRoot) {
|
|
175
|
+
const hash = crypto.createHash("sha256");
|
|
176
|
+
for (const directory of nativeDirectories(snapshotRoot)) {
|
|
177
|
+
hash.update(`${directory}\0`);
|
|
178
|
+
hash.update(fs2.readFileSync(path2.join(snapshotRoot, directory, NATIVE_FILE)));
|
|
179
|
+
}
|
|
180
|
+
return hash.digest("hex").slice(0, HASH_LENGTH);
|
|
181
|
+
}
|
|
182
|
+
function nativeDirectories(packageRoot) {
|
|
183
|
+
return NATIVE_DIRECTORIES.filter((directory) => fs2.existsSync(path2.join(packageRoot, directory, NATIVE_FILE)));
|
|
175
184
|
}
|
|
176
185
|
function copyRuntimeFiles(sourceRoot, targetRoot) {
|
|
177
186
|
fs2.mkdirSync(targetRoot, { recursive: true });
|
|
178
187
|
copyFile(path2.join(sourceRoot, "package.json"), path2.join(targetRoot, "package.json"));
|
|
179
188
|
copyDirectory(path2.join(sourceRoot, "lib"), path2.join(targetRoot, "lib"));
|
|
180
|
-
for (const directory of
|
|
181
|
-
|
|
182
|
-
if (fs2.existsSync(source)) {
|
|
183
|
-
copyDirectory(source, path2.join(targetRoot, directory));
|
|
184
|
-
}
|
|
189
|
+
for (const directory of nativeDirectories(sourceRoot)) {
|
|
190
|
+
copyDirectory(path2.join(sourceRoot, directory), path2.join(targetRoot, directory));
|
|
185
191
|
}
|
|
186
192
|
}
|
|
187
193
|
function copyDirectory(sourceDirectory, targetDirectory) {
|
|
@@ -391,7 +397,28 @@ function installSystemd(program) {
|
|
|
391
397
|
execSync(`systemctl --user start ${SYSTEMD_SERVICE_NAME}`, QUIET);
|
|
392
398
|
logger.info("systemd user service installed", { servicePath });
|
|
393
399
|
printInstalled();
|
|
394
|
-
|
|
400
|
+
enableLinger(os2.userInfo().username);
|
|
401
|
+
}
|
|
402
|
+
function lingerEnabled(username) {
|
|
403
|
+
try {
|
|
404
|
+
const output = execFileSync("loginctl", ["show-user", username, "--property=Linger"], {
|
|
405
|
+
encoding: "utf-8",
|
|
406
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
407
|
+
});
|
|
408
|
+
return output.trim() === "Linger=yes";
|
|
409
|
+
} catch {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function enableLinger(username) {
|
|
414
|
+
if (lingerEnabled(username)) return;
|
|
415
|
+
try {
|
|
416
|
+
execFileSync("loginctl", ["--no-ask-password", "enable-linger", username], QUIET);
|
|
417
|
+
logger.info("systemd lingering enabled", { username });
|
|
418
|
+
} catch (err) {
|
|
419
|
+
logger.warn("loginctl enable-linger failed", { error: errorMessage(err) });
|
|
420
|
+
printer_default.print(`pinggy starts when ${username} signs in. To start it before anyone signs in, run: loginctl enable-linger ${username}`);
|
|
421
|
+
}
|
|
395
422
|
}
|
|
396
423
|
function uninstallSystemd() {
|
|
397
424
|
const servicePath = getSystemdServicePath();
|
|
@@ -785,7 +812,7 @@ async function ensureDaemonRunning() {
|
|
|
785
812
|
return existing;
|
|
786
813
|
}
|
|
787
814
|
if (process.versions.electron) {
|
|
788
|
-
const { runDaemonChild } = await import("./daemonChild-
|
|
815
|
+
const { runDaemonChild } = await import("./daemonChild-24Y3AKII.js");
|
|
789
816
|
const handle = await runDaemonChild({
|
|
790
817
|
installSignalHandlers: false,
|
|
791
818
|
exitOnFailure: false,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
buildRemoteManagementWsUrl,
|
|
6
6
|
initiateRemoteManagement,
|
|
7
7
|
startRemoteManagement
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-H527WMTF.js";
|
|
9
9
|
import {
|
|
10
10
|
configuredLogLevel,
|
|
11
11
|
forgetDeviceAgent,
|
|
@@ -65,7 +65,7 @@ import {
|
|
|
65
65
|
runPinggyBinary,
|
|
66
66
|
versionFromTag,
|
|
67
67
|
windowsInstallPaths
|
|
68
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-PMZJ6HFH.js";
|
|
69
69
|
import {
|
|
70
70
|
InstallKind,
|
|
71
71
|
NPM_INSTALL_COMMAND,
|
|
@@ -96,7 +96,7 @@ import {
|
|
|
96
96
|
stopDaemon,
|
|
97
97
|
uninstallService,
|
|
98
98
|
writeUpdateState
|
|
99
|
-
} from "./chunk-
|
|
99
|
+
} from "./chunk-3KCXR33Y.js";
|
|
100
100
|
import {
|
|
101
101
|
DaemonHost,
|
|
102
102
|
DeviceAgentState,
|
|
@@ -1757,7 +1757,7 @@ function printDeviceHelp() {
|
|
|
1757
1757
|
console.log(" background. Without --token: start the enrolled device's agent again");
|
|
1758
1758
|
console.log(" stop Stop the agent running in the background, until the daemon");
|
|
1759
1759
|
console.log(" starts again");
|
|
1760
|
-
console.log(" status Show the
|
|
1760
|
+
console.log(" status Show whether the agent runs, the enrolment, and the background agent");
|
|
1761
1761
|
console.log(" remove Stop the agent and forget the local credential, after asking.");
|
|
1762
1762
|
console.log(" The device stays in the dashboard\n");
|
|
1763
1763
|
console.log("By default the agent runs in the daemon, and stays connected after this terminal closes.");
|
|
@@ -4857,8 +4857,7 @@ async function foregroundRefusal(dependencies) {
|
|
|
4857
4857
|
const device = reading.status.deviceAgentId ? `device ${reading.status.deviceAgentId}` : "a device";
|
|
4858
4858
|
return `This machine already runs as ${device} in the background. Stop it first: pinggy device stop`;
|
|
4859
4859
|
}
|
|
4860
|
-
|
|
4861
|
-
const reading = await readBackgroundAgent(dependencies);
|
|
4860
|
+
function printBackgroundStatus(reading, dependencies) {
|
|
4862
4861
|
if (!reading) {
|
|
4863
4862
|
return;
|
|
4864
4863
|
}
|
|
@@ -4867,6 +4866,20 @@ async function printBackgroundStatus(dependencies) {
|
|
|
4867
4866
|
dependencies.print(` Last error ${reading.status.lastError.message}`);
|
|
4868
4867
|
}
|
|
4869
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
|
+
}
|
|
4870
4883
|
function describeAgentForDaemonStatus(status) {
|
|
4871
4884
|
switch (status.state) {
|
|
4872
4885
|
case DeviceAgentState.Connected:
|
|
@@ -5759,16 +5772,19 @@ async function handleDeviceStatus(background) {
|
|
|
5759
5772
|
printer_default.print(pico10.yellow("This machine is not enrolled. Run: pinggy device login"));
|
|
5760
5773
|
return;
|
|
5761
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)}`);
|
|
5762
5779
|
printer_default.print(` Device id ${identity.device_agent_id ?? pico10.gray("not yet assigned")}`);
|
|
5763
5780
|
printer_default.print(` Server ${identity.server}`);
|
|
5764
5781
|
printer_default.print(` Token ${maskToken(identity.token)}`);
|
|
5765
5782
|
printer_default.print(` Enrolled ${identity.enrolled_at ?? pico10.gray("never")}`);
|
|
5766
5783
|
printer_default.print(` Autostart ${background.hasSavedAgent() ? "on, starts with the daemon" : pico10.gray("off")}`);
|
|
5767
|
-
const foreground = background.readForegroundAgent();
|
|
5768
5784
|
if (foreground) {
|
|
5769
5785
|
printer_default.print(` Foreground running in another terminal, PID ${foreground.pid}`);
|
|
5770
5786
|
}
|
|
5771
|
-
|
|
5787
|
+
printBackgroundStatus(reading, background);
|
|
5772
5788
|
}
|
|
5773
5789
|
|
|
5774
5790
|
// src/cli/subcommand/handlers/updateCommand.ts
|
|
@@ -7438,7 +7454,7 @@ async function main() {
|
|
|
7438
7454
|
const { values, positionals, hasAnyArgs } = parseCliArgs(cliOptions);
|
|
7439
7455
|
configureLogger(values);
|
|
7440
7456
|
if (values["_daemon-child"]) {
|
|
7441
|
-
const { runDaemonChild: runDaemonChild2 } = await import("./daemonChild-
|
|
7457
|
+
const { runDaemonChild: runDaemonChild2 } = await import("./daemonChild-24Y3AKII.js");
|
|
7442
7458
|
await runDaemonChild2();
|
|
7443
7459
|
return;
|
|
7444
7460
|
}
|
|
@@ -7447,7 +7463,7 @@ async function main() {
|
|
|
7447
7463
|
return;
|
|
7448
7464
|
}
|
|
7449
7465
|
if (values["_update-child"]) {
|
|
7450
|
-
const { runUpdateChild } = await import("./updateChild-
|
|
7466
|
+
const { runUpdateChild } = await import("./updateChild-JNGDWIAK.js");
|
|
7451
7467
|
await runUpdateChild();
|
|
7452
7468
|
process.exit(0);
|
|
7453
7469
|
}
|
|
@@ -6,16 +6,16 @@ import {
|
|
|
6
6
|
trackIPCTunnelStart,
|
|
7
7
|
trackTunnelStart,
|
|
8
8
|
trackTunnelStop
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-FWTQF6AB.js";
|
|
10
|
+
import "./chunk-H527WMTF.js";
|
|
11
11
|
import "./chunk-CZOKR73F.js";
|
|
12
12
|
import "./chunk-MHQ3CVEB.js";
|
|
13
13
|
import "./chunk-2GIJXE4K.js";
|
|
14
14
|
import "./chunk-XZ64ZAGO.js";
|
|
15
15
|
import "./chunk-3WMTTJHI.js";
|
|
16
16
|
import "./chunk-UB26QJ4T.js";
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-
|
|
17
|
+
import "./chunk-PMZJ6HFH.js";
|
|
18
|
+
import "./chunk-3KCXR33Y.js";
|
|
19
19
|
import {
|
|
20
20
|
DaemonHost
|
|
21
21
|
} from "./chunk-MKGD2QAI.js";
|
package/dist/index.cjs
CHANGED
|
@@ -3251,45 +3251,49 @@ function makeSpawnHelperExecutable(packageRoot) {
|
|
|
3251
3251
|
}
|
|
3252
3252
|
function unpackNodePty(snapshotRoot) {
|
|
3253
3253
|
const unpackedRoot = unpackedRootPath(snapshotRoot);
|
|
3254
|
-
if (
|
|
3254
|
+
if (isCommittedCopy(unpackedRoot)) return unpackedRoot;
|
|
3255
3255
|
const stagingRoot = `${unpackedRoot}.${process.pid}`;
|
|
3256
3256
|
import_fs6.default.rmSync(stagingRoot, { recursive: true, force: true });
|
|
3257
3257
|
try {
|
|
3258
3258
|
copyRuntimeFiles(snapshotRoot, stagingRoot);
|
|
3259
3259
|
makeSpawnHelperExecutable(stagingRoot);
|
|
3260
|
-
removeIncompleteCopy(unpackedRoot);
|
|
3261
3260
|
import_fs6.default.renameSync(stagingRoot, unpackedRoot);
|
|
3262
3261
|
} catch (error) {
|
|
3263
3262
|
import_fs6.default.rmSync(stagingRoot, { recursive: true, force: true });
|
|
3264
|
-
if (!
|
|
3263
|
+
if (!isCommittedCopy(unpackedRoot)) throw error;
|
|
3265
3264
|
}
|
|
3266
3265
|
return unpackedRoot;
|
|
3267
3266
|
}
|
|
3268
|
-
function
|
|
3269
|
-
|
|
3267
|
+
function isCommittedCopy(unpackedRoot) {
|
|
3268
|
+
return import_fs6.default.existsSync(import_path6.default.join(unpackedRoot, "package.json"));
|
|
3270
3269
|
}
|
|
3271
3270
|
function unpackedRootPath(snapshotRoot) {
|
|
3272
3271
|
const version = readPackageVersion(snapshotRoot);
|
|
3273
|
-
const
|
|
3272
|
+
const hash = addonHash(snapshotRoot);
|
|
3273
|
+
const directoryName = `${PACKAGE_NAME}-${version}-${process.platform}-${process.arch}-${hash}`;
|
|
3274
3274
|
return import_path6.default.join(getPinggyConfigDir(), RUNTIME_DIR_NAME, directoryName);
|
|
3275
3275
|
}
|
|
3276
3276
|
function readPackageVersion(packageRoot) {
|
|
3277
3277
|
const manifest = JSON.parse(import_fs6.default.readFileSync(import_path6.default.join(packageRoot, "package.json"), "utf8"));
|
|
3278
3278
|
return String(manifest.version);
|
|
3279
3279
|
}
|
|
3280
|
-
function
|
|
3281
|
-
|
|
3282
|
-
|
|
3280
|
+
function addonHash(snapshotRoot) {
|
|
3281
|
+
const hash = import_node_crypto.default.createHash("sha256");
|
|
3282
|
+
for (const directory of nativeDirectories(snapshotRoot)) {
|
|
3283
|
+
hash.update(`${directory}\0`);
|
|
3284
|
+
hash.update(import_fs6.default.readFileSync(import_path6.default.join(snapshotRoot, directory, NATIVE_FILE)));
|
|
3285
|
+
}
|
|
3286
|
+
return hash.digest("hex").slice(0, HASH_LENGTH);
|
|
3287
|
+
}
|
|
3288
|
+
function nativeDirectories(packageRoot) {
|
|
3289
|
+
return NATIVE_DIRECTORIES.filter((directory) => import_fs6.default.existsSync(import_path6.default.join(packageRoot, directory, NATIVE_FILE)));
|
|
3283
3290
|
}
|
|
3284
3291
|
function copyRuntimeFiles(sourceRoot, targetRoot) {
|
|
3285
3292
|
import_fs6.default.mkdirSync(targetRoot, { recursive: true });
|
|
3286
3293
|
copyFile(import_path6.default.join(sourceRoot, "package.json"), import_path6.default.join(targetRoot, "package.json"));
|
|
3287
3294
|
copyDirectory(import_path6.default.join(sourceRoot, "lib"), import_path6.default.join(targetRoot, "lib"));
|
|
3288
|
-
for (const directory of
|
|
3289
|
-
|
|
3290
|
-
if (import_fs6.default.existsSync(source)) {
|
|
3291
|
-
copyDirectory(source, import_path6.default.join(targetRoot, directory));
|
|
3292
|
-
}
|
|
3295
|
+
for (const directory of nativeDirectories(sourceRoot)) {
|
|
3296
|
+
copyDirectory(import_path6.default.join(sourceRoot, directory), import_path6.default.join(targetRoot, directory));
|
|
3293
3297
|
}
|
|
3294
3298
|
}
|
|
3295
3299
|
function copyDirectory(sourceDirectory, targetDirectory) {
|
|
@@ -3307,11 +3311,12 @@ function copyDirectory(sourceDirectory, targetDirectory) {
|
|
|
3307
3311
|
function copyFile(source, target) {
|
|
3308
3312
|
import_fs6.default.writeFileSync(target, import_fs6.default.readFileSync(source));
|
|
3309
3313
|
}
|
|
3310
|
-
var import_fs6, import_path6, import_module, require2, PACKAGE_NAME, NATIVE_FILE, SPAWN_HELPER_FILE, EXECUTABLE_MODE, EXECUTE_BITS, RUNTIME_DIR_NAME, ASAR_ARCHIVE_SUFFIX, NATIVE_DIRECTORIES;
|
|
3314
|
+
var import_node_crypto, import_fs6, import_path6, import_module, require2, PACKAGE_NAME, NATIVE_FILE, SPAWN_HELPER_FILE, EXECUTABLE_MODE, EXECUTE_BITS, RUNTIME_DIR_NAME, ASAR_ARCHIVE_SUFFIX, HASH_LENGTH, NATIVE_DIRECTORIES;
|
|
3311
3315
|
var init_nodePtyRuntime = __esm({
|
|
3312
3316
|
"src/devices/terminal/nodePtyRuntime.ts"() {
|
|
3313
3317
|
"use strict";
|
|
3314
3318
|
init_cjs_shims();
|
|
3319
|
+
import_node_crypto = __toESM(require("crypto"), 1);
|
|
3315
3320
|
import_fs6 = __toESM(require("fs"), 1);
|
|
3316
3321
|
import_path6 = __toESM(require("path"), 1);
|
|
3317
3322
|
import_module = require("module");
|
|
@@ -3324,6 +3329,7 @@ var init_nodePtyRuntime = __esm({
|
|
|
3324
3329
|
EXECUTE_BITS = 73;
|
|
3325
3330
|
RUNTIME_DIR_NAME = "runtime";
|
|
3326
3331
|
ASAR_ARCHIVE_SUFFIX = ".asar";
|
|
3332
|
+
HASH_LENGTH = 12;
|
|
3327
3333
|
NATIVE_DIRECTORIES = [
|
|
3328
3334
|
import_path6.default.join("build", "Release"),
|
|
3329
3335
|
import_path6.default.join("prebuilds", `${process.platform}-${process.arch}`)
|
|
@@ -3517,7 +3523,28 @@ function installSystemd(program) {
|
|
|
3517
3523
|
(0, import_node_child_process.execSync)(`systemctl --user start ${SYSTEMD_SERVICE_NAME}`, QUIET);
|
|
3518
3524
|
logger.info("systemd user service installed", { servicePath });
|
|
3519
3525
|
printInstalled();
|
|
3520
|
-
|
|
3526
|
+
enableLinger(import_node_os2.default.userInfo().username);
|
|
3527
|
+
}
|
|
3528
|
+
function lingerEnabled(username) {
|
|
3529
|
+
try {
|
|
3530
|
+
const output = (0, import_node_child_process.execFileSync)("loginctl", ["show-user", username, "--property=Linger"], {
|
|
3531
|
+
encoding: "utf-8",
|
|
3532
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
3533
|
+
});
|
|
3534
|
+
return output.trim() === "Linger=yes";
|
|
3535
|
+
} catch {
|
|
3536
|
+
return false;
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
function enableLinger(username) {
|
|
3540
|
+
if (lingerEnabled(username)) return;
|
|
3541
|
+
try {
|
|
3542
|
+
(0, import_node_child_process.execFileSync)("loginctl", ["--no-ask-password", "enable-linger", username], QUIET);
|
|
3543
|
+
logger.info("systemd lingering enabled", { username });
|
|
3544
|
+
} catch (err) {
|
|
3545
|
+
logger.warn("loginctl enable-linger failed", { error: errorMessage(err) });
|
|
3546
|
+
printer_default.print(`pinggy starts when ${username} signs in. To start it before anyone signs in, run: loginctl enable-linger ${username}`);
|
|
3547
|
+
}
|
|
3521
3548
|
}
|
|
3522
3549
|
function uninstallSystemd() {
|
|
3523
3550
|
const servicePath = getSystemdServicePath();
|
|
@@ -4277,7 +4304,7 @@ function writeFully(fileDescriptor, chunk) {
|
|
|
4277
4304
|
}
|
|
4278
4305
|
function receiveBody(response2, fileDescriptor) {
|
|
4279
4306
|
return new Promise((resolve, reject) => {
|
|
4280
|
-
const hash =
|
|
4307
|
+
const hash = import_node_crypto2.default.createHash("sha256");
|
|
4281
4308
|
let byteCount = 0;
|
|
4282
4309
|
response2.on("data", (chunk) => {
|
|
4283
4310
|
try {
|
|
@@ -4376,12 +4403,12 @@ async function downloadAndVerify(request2, dependencies = defaultDownloadDepende
|
|
|
4376
4403
|
throw error;
|
|
4377
4404
|
}
|
|
4378
4405
|
}
|
|
4379
|
-
var
|
|
4406
|
+
var import_node_crypto2, import_node_child_process2, import_node_fs6, import_node_path5, UpdateErrorCode, BAD_RELEASE_CODES, UpdateError, BINARY_RUN_TIMEOUT_MILLIS, DEVICE_TOKEN_ENV, VERSION_LINE, runPinggyBinary, ASSET_NAMES, MAX_REDIRECTS, IDLE_TIMEOUT_MILLIS, FREE_SPACE_MARGIN_BYTES, WINDOWS_FREE_SPACE_FACTOR, UNIX_FREE_SPACE_FACTOR, EXECUTABLE_MODE2, USER_AGENT2, SUMS_LINE, defaultDownloadDependencies;
|
|
4380
4407
|
var init_binaryUpdater = __esm({
|
|
4381
4408
|
"src/update/binaryUpdater.ts"() {
|
|
4382
4409
|
"use strict";
|
|
4383
4410
|
init_cjs_shims();
|
|
4384
|
-
|
|
4411
|
+
import_node_crypto2 = __toESM(require("crypto"), 1);
|
|
4385
4412
|
import_node_child_process2 = require("child_process");
|
|
4386
4413
|
import_node_fs6 = __toESM(require("fs"), 1);
|
|
4387
4414
|
import_node_path5 = __toESM(require("path"), 1);
|
|
@@ -8945,7 +8972,7 @@ function printDeviceHelp() {
|
|
|
8945
8972
|
console.log(" background. Without --token: start the enrolled device's agent again");
|
|
8946
8973
|
console.log(" stop Stop the agent running in the background, until the daemon");
|
|
8947
8974
|
console.log(" starts again");
|
|
8948
|
-
console.log(" status Show the
|
|
8975
|
+
console.log(" status Show whether the agent runs, the enrolment, and the background agent");
|
|
8949
8976
|
console.log(" remove Stop the agent and forget the local credential, after asking.");
|
|
8950
8977
|
console.log(" The device stays in the dashboard\n");
|
|
8951
8978
|
console.log("By default the agent runs in the daemon, and stays connected after this terminal closes.");
|
|
@@ -12255,8 +12282,7 @@ async function foregroundRefusal(dependencies) {
|
|
|
12255
12282
|
const device = reading.status.deviceAgentId ? `device ${reading.status.deviceAgentId}` : "a device";
|
|
12256
12283
|
return `This machine already runs as ${device} in the background. Stop it first: pinggy device stop`;
|
|
12257
12284
|
}
|
|
12258
|
-
|
|
12259
|
-
const reading = await readBackgroundAgent(dependencies);
|
|
12285
|
+
function printBackgroundStatus(reading, dependencies) {
|
|
12260
12286
|
if (!reading) {
|
|
12261
12287
|
return;
|
|
12262
12288
|
}
|
|
@@ -12265,6 +12291,20 @@ async function printBackgroundStatus(dependencies) {
|
|
|
12265
12291
|
dependencies.print(` Last error ${reading.status.lastError.message}`);
|
|
12266
12292
|
}
|
|
12267
12293
|
}
|
|
12294
|
+
function describeDeviceState(reading, daemonFound, foreground) {
|
|
12295
|
+
if (reading && isAgentRunning(reading.status)) {
|
|
12296
|
+
const connection = reading.status.state;
|
|
12297
|
+
const color = connection === DeviceAgentState.Connected ? import_picocolors9.default.green : import_picocolors9.default.yellow;
|
|
12298
|
+
return color(`running, ${connection}`);
|
|
12299
|
+
}
|
|
12300
|
+
if (foreground) {
|
|
12301
|
+
return import_picocolors9.default.green("running, with --foreground in another terminal");
|
|
12302
|
+
}
|
|
12303
|
+
if (reading || !daemonFound) {
|
|
12304
|
+
return `${import_picocolors9.default.red("stopped")}. To start it, run: pinggy device connect`;
|
|
12305
|
+
}
|
|
12306
|
+
return import_picocolors9.default.gray("unknown, could not read the daemon");
|
|
12307
|
+
}
|
|
12268
12308
|
function describeAgentForDaemonStatus(status) {
|
|
12269
12309
|
switch (status.state) {
|
|
12270
12310
|
case DeviceAgentState.Connected:
|
|
@@ -13305,16 +13345,19 @@ async function handleDeviceStatus(background) {
|
|
|
13305
13345
|
printer_default.print(import_picocolors14.default.yellow("This machine is not enrolled. Run: pinggy device login"));
|
|
13306
13346
|
return;
|
|
13307
13347
|
}
|
|
13348
|
+
const reading = await readBackgroundAgent(background);
|
|
13349
|
+
const foreground = background.readForegroundAgent();
|
|
13350
|
+
const daemonFound = background.findDaemon() !== null;
|
|
13351
|
+
printer_default.print(` State ${describeDeviceState(reading, daemonFound, foreground)}`);
|
|
13308
13352
|
printer_default.print(` Device id ${identity.device_agent_id ?? import_picocolors14.default.gray("not yet assigned")}`);
|
|
13309
13353
|
printer_default.print(` Server ${identity.server}`);
|
|
13310
13354
|
printer_default.print(` Token ${maskToken(identity.token)}`);
|
|
13311
13355
|
printer_default.print(` Enrolled ${identity.enrolled_at ?? import_picocolors14.default.gray("never")}`);
|
|
13312
13356
|
printer_default.print(` Autostart ${background.hasSavedAgent() ? "on, starts with the daemon" : import_picocolors14.default.gray("off")}`);
|
|
13313
|
-
const foreground = background.readForegroundAgent();
|
|
13314
13357
|
if (foreground) {
|
|
13315
13358
|
printer_default.print(` Foreground running in another terminal, PID ${foreground.pid}`);
|
|
13316
13359
|
}
|
|
13317
|
-
|
|
13360
|
+
printBackgroundStatus(reading, background);
|
|
13318
13361
|
}
|
|
13319
13362
|
var import_picocolors14, DeviceVerb, DEVICE_AGENT_TOKEN_VARIABLE;
|
|
13320
13363
|
var init_deviceCommand = __esm({
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
getRemoteManagementState,
|
|
10
10
|
initiateRemoteManagement,
|
|
11
11
|
startRemoteManagement
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-H527WMTF.js";
|
|
13
13
|
import "./chunk-MHQ3CVEB.js";
|
|
14
14
|
import {
|
|
15
15
|
bulkReplace,
|
|
@@ -36,7 +36,7 @@ import "./chunk-UB26QJ4T.js";
|
|
|
36
36
|
import {
|
|
37
37
|
getDaemonInfo,
|
|
38
38
|
isDaemonRunning
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-3KCXR33Y.js";
|
|
40
40
|
import {
|
|
41
41
|
DeviceAgentState
|
|
42
42
|
} from "./chunk-MKGD2QAI.js";
|
|
@@ -146,7 +146,7 @@ async function verifyAndLoad() {
|
|
|
146
146
|
process.exit(1);
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
await import("./main-
|
|
149
|
+
await import("./main-HSIFQAGU.js");
|
|
150
150
|
}
|
|
151
151
|
verifyAndLoad().catch((err) => {
|
|
152
152
|
printer_default.fatal(`Failed to start CLI:, ${err}`);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
runDaemonChild
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-FWTQF6AB.js";
|
|
5
5
|
import {
|
|
6
6
|
RemoteManagementUnauthorizedError,
|
|
7
7
|
TunnelOperations,
|
|
8
8
|
closeRemoteManagement,
|
|
9
9
|
getRemoteManagementState,
|
|
10
10
|
initiateRemoteManagement
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-H527WMTF.js";
|
|
12
12
|
import "./chunk-CZOKR73F.js";
|
|
13
13
|
import "./chunk-MHQ3CVEB.js";
|
|
14
14
|
import "./chunk-2GIJXE4K.js";
|
|
@@ -17,14 +17,14 @@ import {
|
|
|
17
17
|
TunnelManager
|
|
18
18
|
} from "./chunk-3WMTTJHI.js";
|
|
19
19
|
import "./chunk-UB26QJ4T.js";
|
|
20
|
-
import "./chunk-
|
|
20
|
+
import "./chunk-PMZJ6HFH.js";
|
|
21
21
|
import {
|
|
22
22
|
ensureDaemonRunning,
|
|
23
23
|
getActiveTunnelSummaries,
|
|
24
24
|
getDaemonInfo,
|
|
25
25
|
getInProcessDaemonHandle,
|
|
26
26
|
isDaemonRunning
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-3KCXR33Y.js";
|
|
28
28
|
import {
|
|
29
29
|
DaemonHost
|
|
30
30
|
} from "./chunk-MKGD2QAI.js";
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
resolveLatestTag,
|
|
17
17
|
runPinggyBinary,
|
|
18
18
|
versionFromTag
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-PMZJ6HFH.js";
|
|
20
20
|
import {
|
|
21
21
|
InstallKind,
|
|
22
22
|
backgroundInstallKind,
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
recordLatestVersion,
|
|
31
31
|
unixLayoutPaths,
|
|
32
32
|
writeUpdateState
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-3KCXR33Y.js";
|
|
34
34
|
import "./chunk-MKGD2QAI.js";
|
|
35
35
|
import {
|
|
36
36
|
errorMessage,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinggy",
|
|
3
|
-
"version": "0.6.
|
|
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",
|
|
@@ -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,7 +12,7 @@
|
|
|
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
|
|
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
|
#
|
|
@@ -31,6 +31,7 @@ function Install-Pinggy {
|
|
|
31
31
|
$ProgressPreference = 'SilentlyContinue'
|
|
32
32
|
|
|
33
33
|
$releasesUrl = 'https://github.com/Pinggy-io/cli-js/releases'
|
|
34
|
+
$versionUrl = 'https://pinggy.io/cli/version.json'
|
|
34
35
|
$installDir = Join-Path $env:LOCALAPPDATA 'Pinggy\bin'
|
|
35
36
|
$installPath = Join-Path $installDir 'pinggy.exe'
|
|
36
37
|
$versionPattern = 'Pinggy CLI version:\s*(\S+)'
|
|
@@ -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
|
-
#
|
|
63
|
-
#
|
|
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
|
-
$
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
$
|
|
79
|
-
if ($
|
|
80
|
-
throw "pinggy install: could not read the 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 $
|
|
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
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
# Set it on sh, not on curl, so curl never holds it
|
|
16
16
|
#
|
|
17
17
|
# Overrides, for dev and tests:
|
|
18
|
-
# PINGGY_VERSION a release tag, such as v0.6.1. Default: the
|
|
18
|
+
# PINGGY_VERSION a release tag, such as v0.6.1. Default: the version pinggy.io publishes
|
|
19
19
|
# PINGGY_BINARY_URL a full binary URL, file:// included. Replaces the installed binary without a version check
|
|
20
20
|
# PINGGY_MANAGE a non-production dashboard host, passed to `pinggy device login` or `connect` as --manage
|
|
21
21
|
#
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
set -eu
|
|
27
27
|
|
|
28
28
|
RELEASES_URL="https://github.com/Pinggy-io/cli-js/releases"
|
|
29
|
+
VERSION_URL="https://pinggy.io/cli/version.json"
|
|
29
30
|
INSTALL_DIR="$HOME/.pinggy/bin"
|
|
30
31
|
INSTALL_PATH="$INSTALL_DIR/pinggy"
|
|
31
32
|
VERSIONS_DIR="$HOME/.pinggy/versions"
|
|
@@ -129,8 +130,21 @@ require_downloader() {
|
|
|
129
130
|
fi
|
|
130
131
|
}
|
|
131
132
|
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
fetch_text() {
|
|
134
|
+
if has_command curl; then
|
|
135
|
+
curl -fsSL --proto '=https' --tlsv1.2 "$1"
|
|
136
|
+
else
|
|
137
|
+
wget -q --https-only -O - "$1"
|
|
138
|
+
fi
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
fail_no_latest_version() {
|
|
142
|
+
fail "$1 $VERSION_URL. Try again later, or set PINGGY_VERSION to a release tag, such as v0.6.1."
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# pinggy.io publishes the latest version in the deploy that publishes this script, so the script and the binary
|
|
146
|
+
# come from 1 release. GitHub's /releases/latest can name a newer release, or one whose binaries still upload.
|
|
147
|
+
# sh has no JSON parser, so sed reads the "version" field. The "versions" list has another key and does not match.
|
|
134
148
|
resolve_target_tag() {
|
|
135
149
|
if [ -n "${PINGGY_VERSION:-}" ]; then
|
|
136
150
|
case "$PINGGY_VERSION" in
|
|
@@ -139,17 +153,12 @@ resolve_target_tag() {
|
|
|
139
153
|
esac
|
|
140
154
|
return 0
|
|
141
155
|
fi
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
fi
|
|
149
|
-
tag=${latest_url##*/}
|
|
150
|
-
case "$tag" in
|
|
151
|
-
v[0-9]*) ;;
|
|
152
|
-
*) fail "could not read the latest release tag from $RELEASES_URL/latest" ;;
|
|
156
|
+
version_json=$(fetch_text "$VERSION_URL") || fail_no_latest_version "could not reach"
|
|
157
|
+
latest_version=$(printf '%s\n' "$version_json" \
|
|
158
|
+
| sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([0-9][0-9.]*\)".*/\1/p' | head -n 1)
|
|
159
|
+
case "$latest_version" in
|
|
160
|
+
[0-9]*.[0-9]*.[0-9]*) tag="v$latest_version" ;;
|
|
161
|
+
*) fail_no_latest_version "could not read the latest version from" ;;
|
|
153
162
|
esac
|
|
154
163
|
}
|
|
155
164
|
|