pinggy 0.6.5 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/ARCHITECTURE.md +103 -39
  2. package/CLAUDE.md +21 -11
  3. package/README.md +12 -2
  4. package/dist/{TunnelManager-DXNXIH5W.js → TunnelManager-JRVEADS4.js} +4 -3
  5. package/dist/{TunnelTui-K7KESRTQ.js → TunnelTui-6H4NPUNF.js} +4 -3
  6. package/dist/{chunk-QZJGTQZC.js → chunk-2GIJXE4K.js} +3 -2
  7. package/dist/chunk-3KCXR33Y.js +954 -0
  8. package/dist/{chunk-EMCDDH3B.js → chunk-3WMTTJHI.js} +11 -299
  9. package/dist/{chunk-X6TZN5CT.js → chunk-CZOKR73F.js} +1 -1
  10. package/dist/{chunk-K5QHR5KU.js → chunk-FWTQF6AB.js} +519 -556
  11. package/dist/{chunk-3PTLHLFL.js → chunk-H527WMTF.js} +33 -240
  12. package/dist/chunk-HTIWY3O5.js +293 -0
  13. package/dist/{chunk-IRKMUV37.js → chunk-LWCVB42S.js} +2 -2
  14. package/dist/{chunk-N5WE4DYD.js → chunk-MAK5R4WQ.js} +12 -0
  15. package/dist/{chunk-7EQKHVQX.js → chunk-MHQ3CVEB.js} +4 -51
  16. package/dist/chunk-MKGD2QAI.js +51 -0
  17. package/dist/chunk-PMZJ6HFH.js +882 -0
  18. package/dist/{configStore-DXC6WMYO.js → configStore-JJUWT2YO.js} +3 -3
  19. package/dist/{daemonChild-HZ27YJKQ.js → daemonChild-24Y3AKII.js} +14 -10
  20. package/dist/{daemonConfig-MCAKZHY2.js → daemonConfig-VWK4TXVS.js} +2 -2
  21. package/dist/index.cjs +3621 -1814
  22. package/dist/index.d.cts +142 -129
  23. package/dist/index.d.ts +142 -129
  24. package/dist/index.js +18 -13
  25. package/dist/{ipcClient-XGF2KCQO.js → ipcClient-IZ5R6TPN.js} +2 -1
  26. package/dist/{main-TDQB5ZB4.js → main-HSIFQAGU.js} +19 -14
  27. package/dist/updateChild-JNGDWIAK.js +237 -0
  28. package/dist/workers/file_serve_worker.js +1 -1
  29. package/package.json +4 -3
  30. package/scripts/build_node_pty_linux.sh +27 -0
  31. package/scripts/check_linux_addons.js +168 -0
  32. package/scripts/install/install.ps1 +16 -16
  33. package/scripts/install/install.sh +57 -20
@@ -5,8 +5,9 @@
5
5
  # curl -fsSL https://pinggy.io/install.sh | sh
6
6
  # curl -fsSL https://pinggy.io/install.sh | DEVICE_AGENT_TOKEN=<token> sh
7
7
  #
8
- # The binary goes to ~/.pinggy/bin/pinggy, and a symlink in ~/.local/bin puts it on PATH. No sudo: every write is
9
- # under $HOME. When ~/.local/bin is not on PATH, 1 marked block goes into the shell's rc file, once.
8
+ # The binary goes to ~/.pinggy/versions/<version>/pinggy. ~/.pinggy/bin/pinggy links to it, and a symlink in
9
+ # ~/.local/bin puts it on PATH. No sudo: every write is under $HOME. When ~/.local/bin is not on PATH, 1 marked block
10
+ # goes into the shell's rc file, once.
10
11
  #
11
12
  # Setting, from the dashboard's command:
12
13
  # DEVICE_AGENT_TOKEN a device token. An older pinggy updates without asking, then `pinggy device connect` runs
@@ -14,20 +15,21 @@
14
15
  # Set it on sh, not on curl, so curl never holds it
15
16
  #
16
17
  # Overrides, for dev and tests:
17
- # PINGGY_VERSION a release tag, such as v0.6.1. Default: the latest release
18
+ # PINGGY_VERSION a release tag, such as v0.6.1. Default: the version pinggy.io publishes
18
19
  # PINGGY_BINARY_URL a full binary URL, file:// included. Replaces the installed binary without a version check
19
20
  # PINGGY_MANAGE a non-production dashboard host, passed to `pinggy device login` or `connect` as --manage
20
21
  #
21
22
  # The source lives in Pinggy-io/cli-js, scripts/install/. A release copies it to pinggy.io.
22
- # Design: docs/pinggy-devices/install-script-plan.md in the pinggy_backend repo.
23
23
  #
24
24
  # Nothing runs until the last line. A download cut off halfway defines some functions and runs no command.
25
25
 
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"
32
+ VERSIONS_DIR="$HOME/.pinggy/versions"
31
33
  LINK_DIR="$HOME/.local/bin"
32
34
  LINK_PATH="$LINK_DIR/pinggy"
33
35
  RC_MARKER="# Added by the Pinggy installer"
@@ -128,8 +130,21 @@ require_downloader() {
128
130
  fi
129
131
  }
130
132
 
131
- # GitHub redirects /releases/latest to /releases/tag/<tag>. Reading the redirect costs no API call, so the
132
- # API's 60 requests an hour per IP do not apply.
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.
133
148
  resolve_target_tag() {
134
149
  if [ -n "${PINGGY_VERSION:-}" ]; then
135
150
  case "$PINGGY_VERSION" in
@@ -138,17 +153,12 @@ resolve_target_tag() {
138
153
  esac
139
154
  return 0
140
155
  fi
141
- if has_command curl; then
142
- latest_url=$(curl -fsSIL --proto '=https' -o /dev/null -w '%{url_effective}' "$RELEASES_URL/latest") \
143
- || fail "could not reach $RELEASES_URL/latest"
144
- else
145
- latest_url=$(wget -S --spider "$RELEASES_URL/latest" 2>&1 \
146
- | sed -n 's/^ *Location: *\([^ ]*\).*/\1/p' | tr -d '\r' | tail -n 1)
147
- fi
148
- tag=${latest_url##*/}
149
- case "$tag" in
150
- v[0-9]*) ;;
151
- *) 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" ;;
152
162
  esac
153
163
  }
154
164
 
@@ -198,8 +208,8 @@ remove_partial_download() {
198
208
  fi
199
209
  }
200
210
 
201
- # Writes the binary to a temp file in the install directory, so the final mv is a rename on 1 filesystem. A
202
- # running agent keeps the old inode, so replacing the file under it is safe.
211
+ # Writes the binary to a temp file under ~/.pinggy, so the final mv is a rename on 1 filesystem. The binary goes in its
212
+ # own version folder and ~/.pinggy/bin/pinggy links to it. A running agent keeps its own file.
203
213
  install_binary() {
204
214
  if [ -n "${PINGGY_BINARY_URL:-}" ]; then
205
215
  url="$PINGGY_BINARY_URL"
@@ -222,11 +232,29 @@ install_binary() {
222
232
  fail_does_not_run
223
233
  fi
224
234
 
225
- mv -f "$download_path" "$INSTALL_PATH"
235
+ previous_target=$(readlink "$INSTALL_PATH" 2>/dev/null || true)
236
+ mkdir -p "$VERSIONS_DIR/$downloaded_version"
237
+ mv -f "$download_path" "$VERSIONS_DIR/$downloaded_version/pinggy"
226
238
  download_path=""
239
+ # A temp link and a rename, because ln -sf removes the old link before it creates the new one.
240
+ ln -s "$VERSIONS_DIR/$downloaded_version/pinggy" "$INSTALL_DIR/pinggy.link.$$"
241
+ mv -f "$INSTALL_DIR/pinggy.link.$$" "$INSTALL_PATH"
242
+ prune_versions "$downloaded_version" "$(basename "$(dirname "${previous_target:-none}")")"
227
243
  say "Installed pinggy $downloaded_version to $(shown "$INSTALL_PATH")"
228
244
  }
229
245
 
246
+ # Keeps the new version and the one the link named before. Only names made of digits and dots are versions. With
247
+ # auto-update off, nothing else removes old versions.
248
+ prune_versions() {
249
+ for version_dir in "$VERSIONS_DIR"/*/; do
250
+ version_name=$(basename "$version_dir")
251
+ case "$version_name" in
252
+ *[!0-9.]* | "$1" | "$2") continue ;;
253
+ esac
254
+ rm -rf "$version_dir"
255
+ done
256
+ }
257
+
230
258
  # Steps 2 to 6 of the plan: compare with the installed binary, then download only when needed.
231
259
  install_or_update() {
232
260
  if [ -n "${PINGGY_BINARY_URL:-}" ]; then
@@ -256,6 +284,14 @@ install_or_update() {
256
284
  install_binary
257
285
  else
258
286
  say "Keeping pinggy $installed_version."
287
+ kept_older_version=1
288
+ fi
289
+ }
290
+
291
+ # A pinned or kept version lasts only until the next terminal command, unless auto-update is off.
292
+ warn_auto_update_replaces_it() {
293
+ if [ -n "${PINGGY_VERSION:-}" ] || [ "${kept_older_version:-0}" = 1 ]; then
294
+ say "Auto-update replaces this version. Set PINGGY_AUTO_UPDATE=false to keep it."
259
295
  fi
260
296
  }
261
297
 
@@ -437,6 +473,7 @@ main() {
437
473
  *) require_downloader ;;
438
474
  esac
439
475
  install_or_update
476
+ warn_auto_update_replaces_it
440
477
  link_into_path
441
478
  if has_device_token; then
442
479
  connect_with_device_token