@hegeldev/hegel 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +10 -4
  2. package/dist/cbor.d.ts +15 -0
  3. package/dist/cbor.d.ts.map +1 -0
  4. package/dist/cbor.js +32 -0
  5. package/dist/cbor.js.map +1 -0
  6. package/dist/checksums.d.ts +16 -0
  7. package/dist/checksums.d.ts.map +1 -0
  8. package/dist/checksums.js +26 -0
  9. package/dist/checksums.js.map +1 -0
  10. package/dist/generators/numeric.d.ts.map +1 -1
  11. package/dist/generators/numeric.js +16 -7
  12. package/dist/generators/numeric.js.map +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.js +1 -1
  15. package/dist/libhegel.d.ts +169 -0
  16. package/dist/libhegel.d.ts.map +1 -0
  17. package/dist/libhegel.js +338 -0
  18. package/dist/libhegel.js.map +1 -0
  19. package/dist/locate.d.ts +42 -0
  20. package/dist/locate.d.ts.map +1 -0
  21. package/dist/locate.js +94 -0
  22. package/dist/locate.js.map +1 -0
  23. package/dist/runner.d.ts +30 -22
  24. package/dist/runner.d.ts.map +1 -1
  25. package/dist/runner.js +150 -201
  26. package/dist/runner.js.map +1 -1
  27. package/dist/session.d.ts +16 -13
  28. package/dist/session.d.ts.map +1 -1
  29. package/dist/session.js +32 -145
  30. package/dist/session.js.map +1 -1
  31. package/dist/testCase.d.ts +7 -7
  32. package/dist/testCase.d.ts.map +1 -1
  33. package/dist/testCase.js +1 -5
  34. package/dist/testCase.js.map +1 -1
  35. package/dist/wtf8.d.ts +2 -0
  36. package/dist/wtf8.d.ts.map +1 -1
  37. package/dist/wtf8.js +2 -0
  38. package/dist/wtf8.js.map +1 -1
  39. package/native/libhegel-darwin-arm64.dylib +0 -0
  40. package/native/libhegel-linux-amd64.so +0 -0
  41. package/native/libhegel-linux-arm64.so +0 -0
  42. package/native/libhegel-windows-amd64.dll +0 -0
  43. package/native/libhegel-windows-arm64.dll +0 -0
  44. package/package.json +9 -11
  45. package/dist/connection.d.ts +0 -82
  46. package/dist/connection.d.ts.map +0 -1
  47. package/dist/connection.js +0 -231
  48. package/dist/connection.js.map +0 -1
  49. package/dist/crc32.d.ts +0 -13
  50. package/dist/crc32.d.ts.map +0 -1
  51. package/dist/crc32.js +0 -30
  52. package/dist/crc32.js.map +0 -1
  53. package/dist/protocol.d.ts +0 -25
  54. package/dist/protocol.d.ts.map +0 -1
  55. package/dist/protocol.js +0 -77
  56. package/dist/protocol.js.map +0 -1
  57. package/dist/uv-install.sh +0 -2226
  58. package/dist/uv.d.ts +0 -20
  59. package/dist/uv.d.ts.map +0 -1
  60. package/dist/uv.js +0 -103
  61. package/dist/uv.js.map +0 -1
@@ -1,2226 +0,0 @@
1
- #!/bin/sh
2
- # shellcheck shell=dash
3
- # shellcheck disable=SC2039 # local is non-POSIX
4
- # shellcheck disable=SC2268 # no harm in supporting older shells
5
- #
6
- # Licensed under the MIT license
7
- # <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
8
- # option. This file may not be copied, modified, or distributed
9
- # except according to those terms.
10
-
11
- # This runs on Unix shells like bash/dash/ksh/zsh. It uses the common `local`
12
- # extension. Note: Most shells limit `local` to 1 var per line, contra bash.
13
-
14
- # Some versions of ksh have no `local` keyword. Alias it to `typeset`, but
15
- # beware this makes variables global with f()-style function syntax in ksh93.
16
- # mksh has this alias by default.
17
- has_local() {
18
- # shellcheck disable=SC2034 # deliberately unused
19
- local _has_local
20
- }
21
-
22
- has_local 2>/dev/null || alias local=typeset
23
-
24
- set -u
25
-
26
- APP_NAME="uv"
27
- APP_VERSION="0.11.2"
28
- if [ -n "${UV_DOWNLOAD_URL:-}" ]; then
29
- ARTIFACT_DOWNLOAD_URLS="$UV_DOWNLOAD_URL"
30
- elif [ -n "${INSTALLER_DOWNLOAD_URL:-}" ]; then
31
- ARTIFACT_DOWNLOAD_URLS="$INSTALLER_DOWNLOAD_URL"
32
- elif [ -n "${UV_INSTALLER_GHE_BASE_URL:-}" ]; then
33
- INSTALLER_BASE_URL="$UV_INSTALLER_GHE_BASE_URL"
34
- ARTIFACT_DOWNLOAD_URLS="${INSTALLER_BASE_URL}/astral-sh/uv/releases/download/0.11.2"
35
- elif [ -n "${UV_INSTALLER_GITHUB_BASE_URL:-}" ]; then
36
- INSTALLER_BASE_URL="$UV_INSTALLER_GITHUB_BASE_URL"
37
- ARTIFACT_DOWNLOAD_URLS="${INSTALLER_BASE_URL}/astral-sh/uv/releases/download/0.11.2"
38
- else
39
- ARTIFACT_DOWNLOAD_URLS="https://releases.astral.sh/github/uv/releases/download/0.11.2 https://github.com/astral-sh/uv/releases/download/0.11.2"
40
- fi
41
- if [ -n "${UV_PRINT_VERBOSE:-}" ]; then
42
- PRINT_VERBOSE="$UV_PRINT_VERBOSE"
43
- else
44
- PRINT_VERBOSE=${INSTALLER_PRINT_VERBOSE:-0}
45
- fi
46
- if [ -n "${UV_PRINT_QUIET:-}" ]; then
47
- PRINT_QUIET="$UV_PRINT_QUIET"
48
- else
49
- PRINT_QUIET=${INSTALLER_PRINT_QUIET:-0}
50
- fi
51
- if [ -n "${UV_NO_MODIFY_PATH:-}" ]; then
52
- NO_MODIFY_PATH="$UV_NO_MODIFY_PATH"
53
- else
54
- NO_MODIFY_PATH=${INSTALLER_NO_MODIFY_PATH:-0}
55
- fi
56
- if [ "${UV_DISABLE_UPDATE:-0}" = "1" ]; then
57
- INSTALL_UPDATER=0
58
- else
59
- INSTALL_UPDATER=1
60
- fi
61
- UNMANAGED_INSTALL="${UV_UNMANAGED_INSTALL:-}"
62
- if [ -n "${UNMANAGED_INSTALL}" ]; then
63
- NO_MODIFY_PATH=1
64
- INSTALL_UPDATER=0
65
- fi
66
- AUTH_TOKEN="${UV_GITHUB_TOKEN:-}"
67
-
68
- read -r RECEIPT <<EORECEIPT
69
- {"binaries":["CARGO_DIST_BINS"],"binary_aliases":{},"cdylibs":["CARGO_DIST_DYLIBS"],"cstaticlibs":["CARGO_DIST_STATICLIBS"],"install_layout":"unspecified","install_prefix":"AXO_INSTALL_PREFIX","modify_path":true,"provider":{"source":"cargo-dist","version":"0.31.0"},"source":{"app_name":"uv","name":"uv","owner":"astral-sh","release_type":"github"},"version":"0.11.2"}
70
- EORECEIPT
71
-
72
- # Some Linux distributions don't set HOME
73
- # https://github.com/astral-sh/uv/issues/6965#issuecomment-2915796022
74
- get_home() {
75
- if [ -n "${HOME:-}" ]; then
76
- echo "$HOME"
77
- elif [ -n "${USER:-}" ]; then
78
- getent passwd "$USER" | cut -d: -f6
79
- else
80
- getent passwd "$(id -un)" | cut -d: -f6
81
- fi
82
- }
83
-
84
- # Check if running on Windows with POSIX-compliant shell (CYGWIN, MSYS, MINGW)
85
- is_windows_posix() {
86
- case "$(uname)" in
87
- CYGWIN*|MSYS*|MINGW*)
88
- return 0
89
- ;;
90
- *)
91
- return 1
92
- ;;
93
- esac
94
- }
95
- # Convert POSIX path to Windows path
96
- convert_path_for_receipt() {
97
- local _path="$1"
98
- if is_windows_posix && check_cmd cygpath; then
99
- # Use cygpath to convert path, then escape backslashes for JSON
100
- cygpath -w "$_path" | sed 's/\\/\\\\/g'
101
- else
102
- echo "$_path"
103
- fi
104
- }
105
-
106
- # The HOME reference to show in user output. If `$HOME` isn't set, we show the absolute path instead.
107
- get_home_expression() {
108
- if [ -n "${HOME:-}" ]; then
109
- # shellcheck disable=SC2016
110
- echo '$HOME'
111
- elif [ -n "${USER:-}" ]; then
112
- getent passwd "$USER" | cut -d: -f6
113
- else
114
- getent passwd "$(id -un)" | cut -d: -f6
115
- fi
116
- }
117
- INFERRED_HOME=$(get_home)
118
- # shellcheck disable=SC2034
119
- INFERRED_HOME_EXPRESSION=$(get_home_expression)
120
-
121
- # On Windows POSIX shells, use LOCALAPPDATA for receipt storage to match axoupdater expectations
122
- if is_windows_posix && [ -n "${LOCALAPPDATA:-}" ]; then
123
- RECEIPT_HOME="$LOCALAPPDATA/uv"
124
- else
125
- RECEIPT_HOME="${XDG_CONFIG_HOME:-$INFERRED_HOME/.config}/uv"
126
- fi
127
-
128
- usage() {
129
- # print help (this cat/EOF stuff is a "heredoc" string)
130
- cat <<EOF
131
- uv-installer.sh
132
-
133
- The installer for uv 0.11.2
134
-
135
- This script detects what platform you're on and fetches an appropriate archive from
136
- https://releases.astral.sh/github/uv/releases/download/0.11.2
137
- then unpacks the binaries and installs them to the first of the following locations
138
-
139
- \$XDG_BIN_HOME
140
- \$XDG_DATA_HOME/../bin
141
- \$HOME/.local/bin
142
-
143
- It will then add that dir to PATH by adding the appropriate line to your shell profiles.
144
-
145
- USAGE:
146
- uv-installer.sh [OPTIONS]
147
-
148
- OPTIONS:
149
- -v, --verbose
150
- Enable verbose output
151
-
152
- -q, --quiet
153
- Disable progress output
154
-
155
- --no-modify-path
156
- Don't configure the PATH environment variable
157
-
158
- -h, --help
159
- Print help information
160
- EOF
161
- }
162
-
163
- download_binary_and_run_installer() {
164
- downloader --check
165
- need_cmd uname
166
- need_cmd mktemp
167
- need_cmd chmod
168
- need_cmd mkdir
169
- need_cmd rm
170
- need_cmd tar
171
- need_cmd grep
172
- need_cmd cat
173
-
174
- for arg in "$@"; do
175
- case "$arg" in
176
- --help)
177
- usage
178
- exit 0
179
- ;;
180
- --quiet)
181
- PRINT_QUIET=1
182
- ;;
183
- --verbose)
184
- PRINT_VERBOSE=1
185
- ;;
186
- --no-modify-path)
187
- say "--no-modify-path has been deprecated; please set UV_NO_MODIFY_PATH=1 in the environment"
188
- NO_MODIFY_PATH=1
189
- ;;
190
- *)
191
- OPTIND=1
192
- if [ "${arg%%--*}" = "" ]; then
193
- err "unknown option $arg"
194
- fi
195
- while getopts :hvq sub_arg "$arg"; do
196
- case "$sub_arg" in
197
- h)
198
- usage
199
- exit 0
200
- ;;
201
- v)
202
- # user wants to skip the prompt --
203
- # we don't need /dev/tty
204
- PRINT_VERBOSE=1
205
- ;;
206
- q)
207
- # user wants to skip the prompt --
208
- # we don't need /dev/tty
209
- PRINT_QUIET=1
210
- ;;
211
- *)
212
- err "unknown option -$OPTARG"
213
- ;;
214
- esac
215
- done
216
- ;;
217
- esac
218
- done
219
-
220
- get_architecture || return 1
221
- local _true_arch="$RETVAL"
222
- assert_nz "$_true_arch" "arch"
223
- local _cur_arch="$_true_arch"
224
-
225
-
226
- # look up what archives support this platform
227
- local _artifact_name
228
- _artifact_name="$(select_archive_for_arch "$_true_arch")" || return 1
229
- local _bins
230
- local _zip_ext
231
- local _arch
232
- local _checksum_style
233
- local _checksum_value
234
-
235
- # destructure selected archive info into locals
236
- case "$_artifact_name" in
237
- "uv-aarch64-apple-darwin.tar.gz")
238
- _arch="aarch64-apple-darwin"
239
- _zip_ext=".tar.gz"
240
- _checksum_style="sha256"
241
- _checksum_value="4beaa9550f93ef7f0fc02f7c28c9c48cd61fe30db00f5ac8947e0a425c3fb282"
242
- _bins="uv uvx"
243
- _bins_js_array='"uv","uvx"'
244
- _libs=""
245
- _libs_js_array=""
246
- _staticlibs=""
247
- _staticlibs_js_array=""
248
- _updater_name=""
249
- _updater_bin=""
250
- ;;
251
- "uv-aarch64-pc-windows-msvc.zip")
252
- _arch="aarch64-pc-windows-msvc"
253
- _zip_ext=".zip"
254
- _checksum_style="sha256"
255
- _checksum_value="ffdded8338205f53727b51d404563a5ac8eaa9aea53279a7b7c42177e11d478c"
256
- _bins="uv.exe uvx.exe uvw.exe"
257
- _bins_js_array='"uv.exe","uvx.exe","uvw.exe"'
258
- _libs=""
259
- _libs_js_array=""
260
- _staticlibs=""
261
- _staticlibs_js_array=""
262
- _updater_name=""
263
- _updater_bin=""
264
- ;;
265
- "uv-aarch64-unknown-linux-gnu.tar.gz")
266
- _arch="aarch64-unknown-linux-gnu"
267
- _zip_ext=".tar.gz"
268
- _checksum_style="sha256"
269
- _checksum_value="04792cac761c4a6ba78267f36f2af541b7f92196d42ac55d21d3ff6b0f5ab6a5"
270
- _bins="uv uvx"
271
- _bins_js_array='"uv","uvx"'
272
- _libs=""
273
- _libs_js_array=""
274
- _staticlibs=""
275
- _staticlibs_js_array=""
276
- _updater_name=""
277
- _updater_bin=""
278
- ;;
279
- "uv-aarch64-unknown-linux-musl.tar.gz")
280
- _arch="aarch64-unknown-linux-musl-static"
281
- _zip_ext=".tar.gz"
282
- _checksum_style="sha256"
283
- _checksum_value="275d91dd1f1955136591e7ec5e1fa21e84d0d37ead7da7c35c3683df748d9855"
284
- _bins="uv uvx"
285
- _bins_js_array='"uv","uvx"'
286
- _libs=""
287
- _libs_js_array=""
288
- _staticlibs=""
289
- _staticlibs_js_array=""
290
- _updater_name=""
291
- _updater_bin=""
292
- ;;
293
- "uv-arm-unknown-linux-musleabihf.tar.gz")
294
- _arch="arm-unknown-linux-musl-staticeabihf"
295
- _zip_ext=".tar.gz"
296
- _checksum_style="sha256"
297
- _checksum_value="ce572dac1a8f9a92960f89e99351352fae068d34b24bed86fb88e75fd5dd67d9"
298
- _bins="uv uvx"
299
- _bins_js_array='"uv","uvx"'
300
- _libs=""
301
- _libs_js_array=""
302
- _staticlibs=""
303
- _staticlibs_js_array=""
304
- _updater_name=""
305
- _updater_bin=""
306
- ;;
307
- "uv-armv7-unknown-linux-gnueabihf.tar.gz")
308
- _arch="armv7-unknown-linux-gnueabihf"
309
- _zip_ext=".tar.gz"
310
- _checksum_style="sha256"
311
- _checksum_value="3e90d7de9e3a4e2d8d1bd9ce164362fce22248474986e712039479fb6fd73136"
312
- _bins="uv uvx"
313
- _bins_js_array='"uv","uvx"'
314
- _libs=""
315
- _libs_js_array=""
316
- _staticlibs=""
317
- _staticlibs_js_array=""
318
- _updater_name=""
319
- _updater_bin=""
320
- ;;
321
- "uv-armv7-unknown-linux-musleabihf.tar.gz")
322
- _arch="armv7-unknown-linux-musl-staticeabihf"
323
- _zip_ext=".tar.gz"
324
- _checksum_style="sha256"
325
- _checksum_value="5222cdd7c7dd3263f8c243831606a9f01a1a07a40ffc3c26c03afb34491075c2"
326
- _bins="uv uvx"
327
- _bins_js_array='"uv","uvx"'
328
- _libs=""
329
- _libs_js_array=""
330
- _staticlibs=""
331
- _staticlibs_js_array=""
332
- _updater_name=""
333
- _updater_bin=""
334
- ;;
335
- "uv-i686-pc-windows-msvc.zip")
336
- _arch="i686-pc-windows-msvc"
337
- _zip_ext=".zip"
338
- _checksum_style="sha256"
339
- _checksum_value="506f8274b253b2386881a121f3b7d915b637019bda15876bbd1357235305cf12"
340
- _bins="uv.exe uvx.exe uvw.exe"
341
- _bins_js_array='"uv.exe","uvx.exe","uvw.exe"'
342
- _libs=""
343
- _libs_js_array=""
344
- _staticlibs=""
345
- _staticlibs_js_array=""
346
- _updater_name=""
347
- _updater_bin=""
348
- ;;
349
- "uv-i686-unknown-linux-gnu.tar.gz")
350
- _arch="i686-unknown-linux-gnu"
351
- _zip_ext=".tar.gz"
352
- _checksum_style="sha256"
353
- _checksum_value="c7ec378bab887443a70786382e58d76489da14a7e33b155915d648cca4bdb46c"
354
- _bins="uv uvx"
355
- _bins_js_array='"uv","uvx"'
356
- _libs=""
357
- _libs_js_array=""
358
- _staticlibs=""
359
- _staticlibs_js_array=""
360
- _updater_name=""
361
- _updater_bin=""
362
- ;;
363
- "uv-i686-unknown-linux-musl.tar.gz")
364
- _arch="i686-unknown-linux-musl-static"
365
- _zip_ext=".tar.gz"
366
- _checksum_style="sha256"
367
- _checksum_value="ade8714be45457899568c5b03ef885a0cc94476c07a0bdbe34531ba84231bab2"
368
- _bins="uv uvx"
369
- _bins_js_array='"uv","uvx"'
370
- _libs=""
371
- _libs_js_array=""
372
- _staticlibs=""
373
- _staticlibs_js_array=""
374
- _updater_name=""
375
- _updater_bin=""
376
- ;;
377
- "uv-powerpc64-unknown-linux-gnu.tar.gz")
378
- _arch="powerpc64-unknown-linux-gnu"
379
- _zip_ext=".tar.gz"
380
- _bins="uv uvx"
381
- _bins_js_array='"uv","uvx"'
382
- _libs=""
383
- _libs_js_array=""
384
- _staticlibs=""
385
- _staticlibs_js_array=""
386
- _updater_name=""
387
- _updater_bin=""
388
- ;;
389
- "uv-powerpc64le-unknown-linux-gnu.tar.gz")
390
- _arch="powerpc64le-unknown-linux-gnu"
391
- _zip_ext=".tar.gz"
392
- _checksum_style="sha256"
393
- _checksum_value="3f3a50e99364efc8ff7add10e79757a2b8458700a38180ec5f313524481b9fbc"
394
- _bins="uv uvx"
395
- _bins_js_array='"uv","uvx"'
396
- _libs=""
397
- _libs_js_array=""
398
- _staticlibs=""
399
- _staticlibs_js_array=""
400
- _updater_name=""
401
- _updater_bin=""
402
- ;;
403
- "uv-riscv64gc-unknown-linux-gnu.tar.gz")
404
- _arch="riscv64gc-unknown-linux-gnu"
405
- _zip_ext=".tar.gz"
406
- _checksum_style="sha256"
407
- _checksum_value="e56a93f0ff21d6908461a6ecbf465beae19ae22719f900284abb7680bd07ec41"
408
- _bins="uv uvx"
409
- _bins_js_array='"uv","uvx"'
410
- _libs=""
411
- _libs_js_array=""
412
- _staticlibs=""
413
- _staticlibs_js_array=""
414
- _updater_name=""
415
- _updater_bin=""
416
- ;;
417
- "uv-riscv64gc-unknown-linux-musl.tar.gz")
418
- _arch="riscv64gc-unknown-linux-musl-static"
419
- _zip_ext=".tar.gz"
420
- _checksum_style="sha256"
421
- _checksum_value="4f263571bb457a16a31cb38fba4fcc9cf1059d1d32c5b2e54c43175fcd59205d"
422
- _bins="uv uvx"
423
- _bins_js_array='"uv","uvx"'
424
- _libs=""
425
- _libs_js_array=""
426
- _staticlibs=""
427
- _staticlibs_js_array=""
428
- _updater_name=""
429
- _updater_bin=""
430
- ;;
431
- "uv-s390x-unknown-linux-gnu.tar.gz")
432
- _arch="s390x-unknown-linux-gnu"
433
- _zip_ext=".tar.gz"
434
- _checksum_style="sha256"
435
- _checksum_value="42ebe40775f2a77a514fa47399fde86473bf35bd33b6896c6410a0309fc4d205"
436
- _bins="uv uvx"
437
- _bins_js_array='"uv","uvx"'
438
- _libs=""
439
- _libs_js_array=""
440
- _staticlibs=""
441
- _staticlibs_js_array=""
442
- _updater_name=""
443
- _updater_bin=""
444
- ;;
445
- "uv-x86_64-apple-darwin.tar.gz")
446
- _arch="x86_64-apple-darwin"
447
- _zip_ext=".tar.gz"
448
- _checksum_style="sha256"
449
- _checksum_value="a9c3653245031304c50dd60ac0301bf6c112e12c38c32302a71d4fa6a63ba2cb"
450
- _bins="uv uvx"
451
- _bins_js_array='"uv","uvx"'
452
- _libs=""
453
- _libs_js_array=""
454
- _staticlibs=""
455
- _staticlibs_js_array=""
456
- _updater_name=""
457
- _updater_bin=""
458
- ;;
459
- "uv-x86_64-pc-windows-msvc.zip")
460
- _arch="x86_64-pc-windows-msvc"
461
- _zip_ext=".zip"
462
- _checksum_style="sha256"
463
- _checksum_value="171b7ccda1bbd562da6babeffcf533a1c6cc7862cf998da826e1db534fc43e48"
464
- _bins="uv.exe uvx.exe uvw.exe"
465
- _bins_js_array='"uv.exe","uvx.exe","uvw.exe"'
466
- _libs=""
467
- _libs_js_array=""
468
- _staticlibs=""
469
- _staticlibs_js_array=""
470
- _updater_name=""
471
- _updater_bin=""
472
- ;;
473
- "uv-x86_64-unknown-linux-gnu.tar.gz")
474
- _arch="x86_64-unknown-linux-gnu"
475
- _zip_ext=".tar.gz"
476
- _checksum_style="sha256"
477
- _checksum_value="7ac2ca0449c8d68dae9b99e635cd3bc9b22a4cb1de64b7c43716398447d42981"
478
- _bins="uv uvx"
479
- _bins_js_array='"uv","uvx"'
480
- _libs=""
481
- _libs_js_array=""
482
- _staticlibs=""
483
- _staticlibs_js_array=""
484
- _updater_name=""
485
- _updater_bin=""
486
- ;;
487
- "uv-x86_64-unknown-linux-musl.tar.gz")
488
- _arch="x86_64-unknown-linux-musl-static"
489
- _zip_ext=".tar.gz"
490
- _checksum_style="sha256"
491
- _checksum_value="4700d9fc75734247587deb3e25dd2c6c24f4ac69e8fe91d6acad4a6013115c06"
492
- _bins="uv uvx"
493
- _bins_js_array='"uv","uvx"'
494
- _libs=""
495
- _libs_js_array=""
496
- _staticlibs=""
497
- _staticlibs_js_array=""
498
- _updater_name=""
499
- _updater_bin=""
500
- ;;
501
- *)
502
- err "internal installer error: selected download $_artifact_name doesn't exist!?"
503
- ;;
504
- esac
505
-
506
-
507
- # Replace the placeholder binaries with the calculated array from above
508
- RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"
509
- RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_DYLIBS"'/"$_libs_js_array"/)"
510
- RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_STATICLIBS"'/"$_staticlibs_js_array"/)"
511
-
512
- local _dir
513
- local _download_result=0
514
- local _is_first_url=1
515
- say "downloading $APP_NAME $APP_VERSION ${_arch}" 1>&2
516
- for _base_url in $ARTIFACT_DOWNLOAD_URLS; do
517
- if [ "$_is_first_url" = "0" ]; then
518
- say "trying alternative download URL" 1>&2
519
- fi
520
- _is_first_url=0
521
-
522
- # download the archive
523
- local _url="$_base_url/$_artifact_name"
524
-
525
- _dir="$(ensure mktemp -d)" || return 1
526
- local _file="$_dir/input$_zip_ext"
527
-
528
- say_verbose " from $_url" 1>&2
529
- say_verbose " to $_file" 1>&2
530
-
531
- ensure mkdir -p "$_dir"
532
-
533
- if ! downloader "$_url" "$_file"; then
534
- say "failed to download $_url" 1>&2
535
- continue
536
- fi
537
-
538
- if [ -n "${_checksum_style:-}" ]; then
539
- verify_checksum "$_file" "$_checksum_style" "$_checksum_value"
540
- else
541
- say "no checksums to verify" 1>&2
542
- fi
543
-
544
- # ...and then the updater, if it exists
545
- if [ -n "$_updater_name" ] && [ "$INSTALL_UPDATER" = "1" ]; then
546
- local _updater_url="$_base_url/$_updater_name"
547
- # This renames the artifact while doing the download, removing the
548
- # target triple and leaving just the appname-update format
549
- local _updater_file="$_dir/$APP_NAME-update"
550
-
551
- if ! downloader "$_updater_url" "$_updater_file"; then
552
- say "failed to download $_updater_url"
553
- continue
554
- fi
555
-
556
- # Add the updater to the list of binaries to install
557
- _bins="$_bins $APP_NAME-update"
558
- fi
559
-
560
- _download_result=1
561
- break
562
- done
563
-
564
- if [ "$_download_result" = "0" ]; then
565
- say "this may be a standard network error, but it may also indicate" 1>&2
566
- say "that $APP_NAME's release process is not working. When in doubt" 1>&2
567
- say "please feel free to open an issue!" 1>&2
568
- exit 1
569
- fi
570
-
571
- # unpack the archive
572
- case "$_zip_ext" in
573
- ".zip")
574
- ensure unzip -q "$_file" -d "$_dir"
575
- ;;
576
-
577
- ".tar."*)
578
- ensure tar xf "$_file" --no-same-owner --strip-components 1 -C "$_dir"
579
- ;;
580
- *)
581
- err "unknown archive format: $_zip_ext"
582
- ;;
583
- esac
584
-
585
- install "$_dir" "$_bins" "$_libs" "$_staticlibs" "$_arch" "$@"
586
- local _retval=$?
587
- if [ "$_retval" != 0 ]; then
588
- return "$_retval"
589
- fi
590
-
591
- ignore rm -rf "$_dir"
592
-
593
- # Install the install receipt
594
- if [ "$INSTALL_UPDATER" = "1" ]; then
595
- if ! mkdir -p "$RECEIPT_HOME"; then
596
- err "unable to create receipt directory at $RECEIPT_HOME"
597
- else
598
- echo "$RECEIPT" > "$RECEIPT_HOME/$APP_NAME-receipt.json"
599
- # shellcheck disable=SC2320
600
- local _retval=$?
601
- fi
602
- else
603
- local _retval=0
604
- fi
605
-
606
- return "$_retval"
607
- }
608
-
609
- # Replaces $HOME with the variable name for display to the user,
610
- # only if $HOME is defined.
611
- replace_home() {
612
- local _str="$1"
613
-
614
- if [ -n "${HOME:-}" ]; then
615
- echo "$_str" | sed "s,$HOME,\$HOME,"
616
- else
617
- echo "$_str"
618
- fi
619
- }
620
-
621
- json_binary_aliases() {
622
- local _arch="$1"
623
-
624
- case "$_arch" in
625
- "aarch64-apple-darwin")
626
- echo '{}'
627
- ;;
628
- "aarch64-pc-windows-gnu")
629
- echo '{}'
630
- ;;
631
- "aarch64-unknown-linux-gnu")
632
- echo '{}'
633
- ;;
634
- "aarch64-unknown-linux-musl-dynamic")
635
- echo '{}'
636
- ;;
637
- "aarch64-unknown-linux-musl-static")
638
- echo '{}'
639
- ;;
640
- "arm-unknown-linux-gnueabihf")
641
- echo '{}'
642
- ;;
643
- "arm-unknown-linux-musl-dynamiceabihf")
644
- echo '{}'
645
- ;;
646
- "arm-unknown-linux-musl-staticeabihf")
647
- echo '{}'
648
- ;;
649
- "armv7-unknown-linux-gnueabihf")
650
- echo '{}'
651
- ;;
652
- "armv7-unknown-linux-musl-dynamiceabihf")
653
- echo '{}'
654
- ;;
655
- "armv7-unknown-linux-musl-staticeabihf")
656
- echo '{}'
657
- ;;
658
- "i686-pc-windows-gnu")
659
- echo '{}'
660
- ;;
661
- "i686-unknown-linux-gnu")
662
- echo '{}'
663
- ;;
664
- "i686-unknown-linux-musl-dynamic")
665
- echo '{}'
666
- ;;
667
- "i686-unknown-linux-musl-static")
668
- echo '{}'
669
- ;;
670
- "powerpc64-unknown-linux-gnu")
671
- echo '{}'
672
- ;;
673
- "powerpc64le-unknown-linux-gnu")
674
- echo '{}'
675
- ;;
676
- "riscv64gc-unknown-linux-gnu")
677
- echo '{}'
678
- ;;
679
- "riscv64gc-unknown-linux-musl-dynamic")
680
- echo '{}'
681
- ;;
682
- "riscv64gc-unknown-linux-musl-static")
683
- echo '{}'
684
- ;;
685
- "s390x-unknown-linux-gnu")
686
- echo '{}'
687
- ;;
688
- "x86_64-apple-darwin")
689
- echo '{}'
690
- ;;
691
- "x86_64-pc-windows-gnu")
692
- echo '{}'
693
- ;;
694
- "x86_64-unknown-linux-gnu")
695
- echo '{}'
696
- ;;
697
- "x86_64-unknown-linux-musl-dynamic")
698
- echo '{}'
699
- ;;
700
- "x86_64-unknown-linux-musl-static")
701
- echo '{}'
702
- ;;
703
- *)
704
- echo '{}'
705
- ;;
706
- esac
707
- }
708
-
709
- aliases_for_binary() {
710
- local _bin="$1"
711
- local _arch="$2"
712
-
713
- case "$_arch" in
714
- "aarch64-apple-darwin")
715
- case "$_bin" in
716
- *)
717
- echo ""
718
- ;;
719
- esac
720
- ;;
721
- "aarch64-pc-windows-gnu")
722
- case "$_bin" in
723
- *)
724
- echo ""
725
- ;;
726
- esac
727
- ;;
728
- "aarch64-unknown-linux-gnu")
729
- case "$_bin" in
730
- *)
731
- echo ""
732
- ;;
733
- esac
734
- ;;
735
- "aarch64-unknown-linux-musl-dynamic")
736
- case "$_bin" in
737
- *)
738
- echo ""
739
- ;;
740
- esac
741
- ;;
742
- "aarch64-unknown-linux-musl-static")
743
- case "$_bin" in
744
- *)
745
- echo ""
746
- ;;
747
- esac
748
- ;;
749
- "arm-unknown-linux-gnueabihf")
750
- case "$_bin" in
751
- *)
752
- echo ""
753
- ;;
754
- esac
755
- ;;
756
- "arm-unknown-linux-musl-dynamiceabihf")
757
- case "$_bin" in
758
- *)
759
- echo ""
760
- ;;
761
- esac
762
- ;;
763
- "arm-unknown-linux-musl-staticeabihf")
764
- case "$_bin" in
765
- *)
766
- echo ""
767
- ;;
768
- esac
769
- ;;
770
- "armv7-unknown-linux-gnueabihf")
771
- case "$_bin" in
772
- *)
773
- echo ""
774
- ;;
775
- esac
776
- ;;
777
- "armv7-unknown-linux-musl-dynamiceabihf")
778
- case "$_bin" in
779
- *)
780
- echo ""
781
- ;;
782
- esac
783
- ;;
784
- "armv7-unknown-linux-musl-staticeabihf")
785
- case "$_bin" in
786
- *)
787
- echo ""
788
- ;;
789
- esac
790
- ;;
791
- "i686-pc-windows-gnu")
792
- case "$_bin" in
793
- *)
794
- echo ""
795
- ;;
796
- esac
797
- ;;
798
- "i686-unknown-linux-gnu")
799
- case "$_bin" in
800
- *)
801
- echo ""
802
- ;;
803
- esac
804
- ;;
805
- "i686-unknown-linux-musl-dynamic")
806
- case "$_bin" in
807
- *)
808
- echo ""
809
- ;;
810
- esac
811
- ;;
812
- "i686-unknown-linux-musl-static")
813
- case "$_bin" in
814
- *)
815
- echo ""
816
- ;;
817
- esac
818
- ;;
819
- "powerpc64-unknown-linux-gnu")
820
- case "$_bin" in
821
- *)
822
- echo ""
823
- ;;
824
- esac
825
- ;;
826
- "powerpc64le-unknown-linux-gnu")
827
- case "$_bin" in
828
- *)
829
- echo ""
830
- ;;
831
- esac
832
- ;;
833
- "riscv64gc-unknown-linux-gnu")
834
- case "$_bin" in
835
- *)
836
- echo ""
837
- ;;
838
- esac
839
- ;;
840
- "riscv64gc-unknown-linux-musl-dynamic")
841
- case "$_bin" in
842
- *)
843
- echo ""
844
- ;;
845
- esac
846
- ;;
847
- "riscv64gc-unknown-linux-musl-static")
848
- case "$_bin" in
849
- *)
850
- echo ""
851
- ;;
852
- esac
853
- ;;
854
- "s390x-unknown-linux-gnu")
855
- case "$_bin" in
856
- *)
857
- echo ""
858
- ;;
859
- esac
860
- ;;
861
- "x86_64-apple-darwin")
862
- case "$_bin" in
863
- *)
864
- echo ""
865
- ;;
866
- esac
867
- ;;
868
- "x86_64-pc-windows-gnu")
869
- case "$_bin" in
870
- *)
871
- echo ""
872
- ;;
873
- esac
874
- ;;
875
- "x86_64-unknown-linux-gnu")
876
- case "$_bin" in
877
- *)
878
- echo ""
879
- ;;
880
- esac
881
- ;;
882
- "x86_64-unknown-linux-musl-dynamic")
883
- case "$_bin" in
884
- *)
885
- echo ""
886
- ;;
887
- esac
888
- ;;
889
- "x86_64-unknown-linux-musl-static")
890
- case "$_bin" in
891
- *)
892
- echo ""
893
- ;;
894
- esac
895
- ;;
896
- *)
897
- echo ""
898
- ;;
899
- esac
900
- }
901
-
902
- select_archive_for_arch() {
903
- local _true_arch="$1"
904
- local _archive
905
-
906
- # try each archive, checking runtime conditions like libc versions
907
- # accepting the first one that matches, as it's the best match
908
- case "$_true_arch" in
909
- "aarch64-apple-darwin")
910
- _archive="uv-aarch64-apple-darwin.tar.gz"
911
- if [ -n "$_archive" ]; then
912
- echo "$_archive"
913
- return 0
914
- fi
915
- _archive="uv-x86_64-apple-darwin.tar.gz"
916
- if [ -n "$_archive" ]; then
917
- echo "$_archive"
918
- return 0
919
- fi
920
- ;;
921
- "aarch64-pc-windows-gnu")
922
- _archive="uv-aarch64-pc-windows-msvc.zip"
923
- if [ -n "$_archive" ]; then
924
- echo "$_archive"
925
- return 0
926
- fi
927
- ;;
928
- "aarch64-pc-windows-msvc")
929
- _archive="uv-aarch64-pc-windows-msvc.zip"
930
- if [ -n "$_archive" ]; then
931
- echo "$_archive"
932
- return 0
933
- fi
934
- _archive="uv-x86_64-pc-windows-msvc.zip"
935
- if [ -n "$_archive" ]; then
936
- echo "$_archive"
937
- return 0
938
- fi
939
- _archive="uv-i686-pc-windows-msvc.zip"
940
- if [ -n "$_archive" ]; then
941
- echo "$_archive"
942
- return 0
943
- fi
944
- ;;
945
- "aarch64-unknown-linux-gnu")
946
- _archive="uv-aarch64-unknown-linux-gnu.tar.gz"
947
- if ! check_glibc "2" "28"; then
948
- _archive=""
949
- fi
950
- if [ -n "$_archive" ]; then
951
- echo "$_archive"
952
- return 0
953
- fi
954
- _archive="uv-aarch64-unknown-linux-musl.tar.gz"
955
- if [ -n "$_archive" ]; then
956
- echo "$_archive"
957
- return 0
958
- fi
959
- ;;
960
- "aarch64-unknown-linux-musl-dynamic")
961
- _archive="uv-aarch64-unknown-linux-musl.tar.gz"
962
- if [ -n "$_archive" ]; then
963
- echo "$_archive"
964
- return 0
965
- fi
966
- ;;
967
- "aarch64-unknown-linux-musl-static")
968
- _archive="uv-aarch64-unknown-linux-musl.tar.gz"
969
- if [ -n "$_archive" ]; then
970
- echo "$_archive"
971
- return 0
972
- fi
973
- ;;
974
- "arm-unknown-linux-gnueabihf")
975
- _archive="uv-arm-unknown-linux-musleabihf.tar.gz"
976
- if [ -n "$_archive" ]; then
977
- echo "$_archive"
978
- return 0
979
- fi
980
- ;;
981
- "arm-unknown-linux-musl-dynamiceabihf")
982
- _archive="uv-arm-unknown-linux-musleabihf.tar.gz"
983
- if [ -n "$_archive" ]; then
984
- echo "$_archive"
985
- return 0
986
- fi
987
- ;;
988
- "arm-unknown-linux-musl-staticeabihf")
989
- _archive="uv-arm-unknown-linux-musleabihf.tar.gz"
990
- if [ -n "$_archive" ]; then
991
- echo "$_archive"
992
- return 0
993
- fi
994
- ;;
995
- "armv7-unknown-linux-gnueabihf")
996
- _archive="uv-armv7-unknown-linux-gnueabihf.tar.gz"
997
- if ! check_glibc "2" "17"; then
998
- _archive=""
999
- fi
1000
- if [ -n "$_archive" ]; then
1001
- echo "$_archive"
1002
- return 0
1003
- fi
1004
- _archive="uv-armv7-unknown-linux-musleabihf.tar.gz"
1005
- if [ -n "$_archive" ]; then
1006
- echo "$_archive"
1007
- return 0
1008
- fi
1009
- ;;
1010
- "armv7-unknown-linux-musl-dynamiceabihf")
1011
- _archive="uv-armv7-unknown-linux-musleabihf.tar.gz"
1012
- if [ -n "$_archive" ]; then
1013
- echo "$_archive"
1014
- return 0
1015
- fi
1016
- ;;
1017
- "armv7-unknown-linux-musl-staticeabihf")
1018
- _archive="uv-armv7-unknown-linux-musleabihf.tar.gz"
1019
- if [ -n "$_archive" ]; then
1020
- echo "$_archive"
1021
- return 0
1022
- fi
1023
- ;;
1024
- "i686-pc-windows-gnu")
1025
- _archive="uv-i686-pc-windows-msvc.zip"
1026
- if [ -n "$_archive" ]; then
1027
- echo "$_archive"
1028
- return 0
1029
- fi
1030
- ;;
1031
- "i686-pc-windows-msvc")
1032
- _archive="uv-i686-pc-windows-msvc.zip"
1033
- if [ -n "$_archive" ]; then
1034
- echo "$_archive"
1035
- return 0
1036
- fi
1037
- ;;
1038
- "i686-unknown-linux-gnu")
1039
- _archive="uv-i686-unknown-linux-gnu.tar.gz"
1040
- if ! check_glibc "2" "17"; then
1041
- _archive=""
1042
- fi
1043
- if [ -n "$_archive" ]; then
1044
- echo "$_archive"
1045
- return 0
1046
- fi
1047
- _archive="uv-i686-unknown-linux-musl.tar.gz"
1048
- if [ -n "$_archive" ]; then
1049
- echo "$_archive"
1050
- return 0
1051
- fi
1052
- ;;
1053
- "i686-unknown-linux-musl-dynamic")
1054
- _archive="uv-i686-unknown-linux-musl.tar.gz"
1055
- if [ -n "$_archive" ]; then
1056
- echo "$_archive"
1057
- return 0
1058
- fi
1059
- ;;
1060
- "i686-unknown-linux-musl-static")
1061
- _archive="uv-i686-unknown-linux-musl.tar.gz"
1062
- if [ -n "$_archive" ]; then
1063
- echo "$_archive"
1064
- return 0
1065
- fi
1066
- ;;
1067
- "powerpc64-unknown-linux-gnu")
1068
- _archive="uv-powerpc64-unknown-linux-gnu.tar.gz"
1069
- if ! check_glibc "2" "17"; then
1070
- _archive=""
1071
- fi
1072
- if [ -n "$_archive" ]; then
1073
- echo "$_archive"
1074
- return 0
1075
- fi
1076
- ;;
1077
- "powerpc64le-unknown-linux-gnu")
1078
- _archive="uv-powerpc64le-unknown-linux-gnu.tar.gz"
1079
- if ! check_glibc "2" "17"; then
1080
- _archive=""
1081
- fi
1082
- if [ -n "$_archive" ]; then
1083
- echo "$_archive"
1084
- return 0
1085
- fi
1086
- ;;
1087
- "riscv64gc-unknown-linux-gnu")
1088
- _archive="uv-riscv64gc-unknown-linux-gnu.tar.gz"
1089
- if ! check_glibc "2" "31"; then
1090
- _archive=""
1091
- fi
1092
- if [ -n "$_archive" ]; then
1093
- echo "$_archive"
1094
- return 0
1095
- fi
1096
- _archive="uv-riscv64gc-unknown-linux-musl.tar.gz"
1097
- if [ -n "$_archive" ]; then
1098
- echo "$_archive"
1099
- return 0
1100
- fi
1101
- ;;
1102
- "riscv64gc-unknown-linux-musl-dynamic")
1103
- _archive="uv-riscv64gc-unknown-linux-musl.tar.gz"
1104
- if [ -n "$_archive" ]; then
1105
- echo "$_archive"
1106
- return 0
1107
- fi
1108
- ;;
1109
- "riscv64gc-unknown-linux-musl-static")
1110
- _archive="uv-riscv64gc-unknown-linux-musl.tar.gz"
1111
- if [ -n "$_archive" ]; then
1112
- echo "$_archive"
1113
- return 0
1114
- fi
1115
- ;;
1116
- "s390x-unknown-linux-gnu")
1117
- _archive="uv-s390x-unknown-linux-gnu.tar.gz"
1118
- if ! check_glibc "2" "17"; then
1119
- _archive=""
1120
- fi
1121
- if [ -n "$_archive" ]; then
1122
- echo "$_archive"
1123
- return 0
1124
- fi
1125
- ;;
1126
- "x86_64-apple-darwin")
1127
- _archive="uv-x86_64-apple-darwin.tar.gz"
1128
- if [ -n "$_archive" ]; then
1129
- echo "$_archive"
1130
- return 0
1131
- fi
1132
- ;;
1133
- "x86_64-pc-windows-gnu")
1134
- _archive="uv-x86_64-pc-windows-msvc.zip"
1135
- if [ -n "$_archive" ]; then
1136
- echo "$_archive"
1137
- return 0
1138
- fi
1139
- ;;
1140
- "x86_64-pc-windows-msvc")
1141
- _archive="uv-x86_64-pc-windows-msvc.zip"
1142
- if [ -n "$_archive" ]; then
1143
- echo "$_archive"
1144
- return 0
1145
- fi
1146
- _archive="uv-i686-pc-windows-msvc.zip"
1147
- if [ -n "$_archive" ]; then
1148
- echo "$_archive"
1149
- return 0
1150
- fi
1151
- ;;
1152
- "x86_64-unknown-linux-gnu")
1153
- _archive="uv-x86_64-unknown-linux-gnu.tar.gz"
1154
- if ! check_glibc "2" "17"; then
1155
- _archive=""
1156
- fi
1157
- if [ -n "$_archive" ]; then
1158
- echo "$_archive"
1159
- return 0
1160
- fi
1161
- _archive="uv-x86_64-unknown-linux-musl.tar.gz"
1162
- if [ -n "$_archive" ]; then
1163
- echo "$_archive"
1164
- return 0
1165
- fi
1166
- ;;
1167
- "x86_64-unknown-linux-musl-dynamic")
1168
- _archive="uv-x86_64-unknown-linux-musl.tar.gz"
1169
- if [ -n "$_archive" ]; then
1170
- echo "$_archive"
1171
- return 0
1172
- fi
1173
- ;;
1174
- "x86_64-unknown-linux-musl-static")
1175
- _archive="uv-x86_64-unknown-linux-musl.tar.gz"
1176
- if [ -n "$_archive" ]; then
1177
- echo "$_archive"
1178
- return 0
1179
- fi
1180
- ;;
1181
- *)
1182
- err "there isn't a download for your platform $_true_arch"
1183
- ;;
1184
- esac
1185
- err "no compatible downloads were found for your platform $_true_arch"
1186
- }
1187
-
1188
- check_glibc() {
1189
- local _min_glibc_major="$1"
1190
- local _min_glibc_series="$2"
1191
-
1192
- # Parsing version out from line 1 like:
1193
- # ldd (Ubuntu GLIBC 2.35-0ubuntu3.1) 2.35
1194
- _local_glibc="$(ldd --version | awk -F' ' '{ if (FNR<=1) print $NF }')"
1195
-
1196
- if [ "$(echo "${_local_glibc}" | awk -F. '{ print $1 }')" = "$_min_glibc_major" ] && [ "$(echo "${_local_glibc}" | awk -F. '{ print $2 }')" -ge "$_min_glibc_series" ]; then
1197
- return 0
1198
- else
1199
- say "System glibc version (\`${_local_glibc}') is too old; checking alternatives" >&2
1200
- return 1
1201
- fi
1202
- }
1203
-
1204
- # See discussion of late-bound vs early-bound for why we use single-quotes with env vars
1205
- # shellcheck disable=SC2016
1206
- install() {
1207
- # This code needs to both compute certain paths for itself to write to, and
1208
- # also write them to shell/rc files so that they can look them up to e.g.
1209
- # add them to PATH. This requires an active distinction between paths
1210
- # and expressions that can compute them.
1211
- #
1212
- # The distinction lies in when we want env-vars to be evaluated. For instance
1213
- # if we determine that we want to install to $HOME/.myapp, which do we add
1214
- # to e.g. $HOME/.profile:
1215
- #
1216
- # * early-bound: export PATH="/home/myuser/.myapp:$PATH"
1217
- # * late-bound: export PATH="$HOME/.myapp:$PATH"
1218
- #
1219
- # In this case most people would prefer the late-bound version, but in other
1220
- # cases the early-bound version might be a better idea. In particular when using
1221
- # other env-vars than $HOME, they are more likely to be only set temporarily
1222
- # for the duration of this install script, so it's more advisable to erase their
1223
- # existence with early-bounding.
1224
- #
1225
- # This distinction is handled by "double-quotes" (early) vs 'single-quotes' (late).
1226
- #
1227
- # However if we detect that "$SOME_VAR/..." is a subdir of $HOME, we try to rewrite
1228
- # it to be '$HOME/...' to get the best of both worlds.
1229
- #
1230
- # This script has a few different variants, the most complex one being the
1231
- # CARGO_HOME version which attempts to install things to Cargo's bin dir,
1232
- # potentially setting up a minimal version if the user hasn't ever installed Cargo.
1233
- #
1234
- # In this case we need to:
1235
- #
1236
- # * Install to $HOME/.cargo/bin/
1237
- # * Create a shell script at $HOME/.cargo/env that:
1238
- # * Checks if $HOME/.cargo/bin/ is on PATH
1239
- # * and if not prepends it to PATH
1240
- # * Edits $INFERRED_HOME/.profile to run $HOME/.cargo/env (if the line doesn't exist)
1241
- #
1242
- # To do this we need these 4 values:
1243
-
1244
- # The actual path we're going to install to
1245
- local _install_dir
1246
- # The directory C dynamic/static libraries install to
1247
- local _lib_install_dir
1248
- # The install prefix we write to the receipt.
1249
- # For organized install methods like CargoHome, which have
1250
- # subdirectories, this is the root without `/bin`. For other
1251
- # methods, this is the same as `_install_dir`.
1252
- local _receipt_install_dir
1253
- # Path to the an shell script that adds install_dir to PATH
1254
- local _env_script_path
1255
- # Potentially-late-bound version of install_dir to write env_script
1256
- local _install_dir_expr
1257
- # Potentially-late-bound version of env_script_path to write to rcfiles like $HOME/.profile
1258
- local _env_script_path_expr
1259
- # Forces the install to occur at this path, not the default
1260
- local _force_install_dir
1261
- # Which install layout to use - "flat" or "hierarchical"
1262
- local _install_layout="unspecified"
1263
- # A list of binaries which are shadowed in the PATH
1264
- local _shadowed_bins=""
1265
-
1266
- # Check the newer app-specific variable before falling back
1267
- # to the older generic one
1268
- if [ -n "${UV_INSTALL_DIR:-}" ]; then
1269
- _force_install_dir="$UV_INSTALL_DIR"
1270
- _install_layout="flat"
1271
- elif [ -n "${CARGO_DIST_FORCE_INSTALL_DIR:-}" ]; then
1272
- _force_install_dir="$CARGO_DIST_FORCE_INSTALL_DIR"
1273
- _install_layout="flat"
1274
- elif [ -n "$UNMANAGED_INSTALL" ]; then
1275
- _force_install_dir="$UNMANAGED_INSTALL"
1276
- _install_layout="flat"
1277
- fi
1278
-
1279
- # Check if the install layout should be changed from `flat` to `cargo-home`
1280
- # for backwards compatible updates of applications that switched layouts.
1281
- if [ -n "${_force_install_dir:-}" ]; then
1282
- if [ "$_install_layout" = "flat" ]; then
1283
- # If the install directory is targeting the Cargo home directory, then
1284
- # we assume this application was previously installed that layout
1285
- if [ "$_force_install_dir" = "${CARGO_HOME:-${INFERRED_HOME:-}/.cargo}" ]; then
1286
- _install_layout="cargo-home"
1287
- fi
1288
- fi
1289
- fi
1290
-
1291
- # Before actually consulting the configured install strategy, see
1292
- # if we're overriding it.
1293
- if [ -n "${_force_install_dir:-}" ]; then
1294
- case "$_install_layout" in
1295
- "hierarchical")
1296
- _install_dir="$_force_install_dir/bin"
1297
- _lib_install_dir="$_force_install_dir/lib"
1298
- _receipt_install_dir="$_force_install_dir"
1299
- _env_script_path="$_force_install_dir/env"
1300
- _install_dir_expr="$(replace_home "$_force_install_dir/bin")"
1301
- _env_script_path_expr="$(replace_home "$_force_install_dir/env")"
1302
- ;;
1303
- "cargo-home")
1304
- _install_dir="$_force_install_dir/bin"
1305
- _lib_install_dir="$_force_install_dir/bin"
1306
- _receipt_install_dir="$_force_install_dir"
1307
- _env_script_path="$_force_install_dir/env"
1308
- _install_dir_expr="$(replace_home "$_force_install_dir/bin")"
1309
- _env_script_path_expr="$(replace_home "$_force_install_dir/env")"
1310
- ;;
1311
- "flat")
1312
- _install_dir="$_force_install_dir"
1313
- _lib_install_dir="$_force_install_dir"
1314
- _receipt_install_dir="$_install_dir"
1315
- _env_script_path="$_force_install_dir/env"
1316
- _install_dir_expr="$(replace_home "$_force_install_dir")"
1317
- _env_script_path_expr="$(replace_home "$_force_install_dir/env")"
1318
- ;;
1319
- *)
1320
- err "Unrecognized install layout: $_install_layout"
1321
- ;;
1322
- esac
1323
- fi
1324
- if [ -z "${_install_dir:-}" ]; then
1325
- _install_layout="flat"
1326
- # Install to $XDG_BIN_HOME
1327
- if [ -n "${XDG_BIN_HOME:-}" ]; then
1328
- _install_dir="$XDG_BIN_HOME"
1329
- _lib_install_dir="$_install_dir"
1330
- _receipt_install_dir="$_install_dir"
1331
- _env_script_path="$XDG_BIN_HOME/env"
1332
- _install_dir_expr="$(replace_home "$_install_dir")"
1333
- _env_script_path_expr="$(replace_home "$_env_script_path")"
1334
- fi
1335
- fi
1336
- if [ -z "${_install_dir:-}" ]; then
1337
- _install_layout="flat"
1338
- # Install to $XDG_DATA_HOME/../bin
1339
- if [ -n "${XDG_DATA_HOME:-}" ]; then
1340
- _install_dir="$XDG_DATA_HOME/../bin"
1341
- _lib_install_dir="$_install_dir"
1342
- _receipt_install_dir="$_install_dir"
1343
- _env_script_path="$XDG_DATA_HOME/../bin/env"
1344
- _install_dir_expr="$(replace_home "$_install_dir")"
1345
- _env_script_path_expr="$(replace_home "$_env_script_path")"
1346
- fi
1347
- fi
1348
- if [ -z "${_install_dir:-}" ]; then
1349
- _install_layout="flat"
1350
- # Install to $HOME/.local/bin
1351
- if [ -n "${INFERRED_HOME:-}" ]; then
1352
- _install_dir="$INFERRED_HOME/.local/bin"
1353
- _lib_install_dir="$INFERRED_HOME/.local/bin"
1354
- _receipt_install_dir="$_install_dir"
1355
- _env_script_path="$INFERRED_HOME/.local/bin/env"
1356
- _install_dir_expr="$INFERRED_HOME_EXPRESSION/.local/bin"
1357
- _env_script_path_expr="$INFERRED_HOME_EXPRESSION/.local/bin/env"
1358
- fi
1359
- fi
1360
-
1361
- if [ -z "$_install_dir_expr" ]; then
1362
- err "could not find a valid path to install to!"
1363
- fi
1364
-
1365
- # Identical to the sh version, just with a .fish file extension
1366
- # We place it down here to wait until it's been assigned in every
1367
- # path.
1368
- _fish_env_script_path="${_env_script_path}.fish"
1369
- _fish_env_script_path_expr="${_env_script_path_expr}.fish"
1370
-
1371
- # Replace the temporary cargo home with the calculated one
1372
- RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_INSTALL_PREFIX,$(convert_path_for_receipt "$_receipt_install_dir"),")
1373
- # Also replace the aliases with the arch-specific one
1374
- RECEIPT=$(echo "$RECEIPT" | sed "s'\"binary_aliases\":{}'\"binary_aliases\":$(json_binary_aliases "$_arch")'")
1375
- # And replace the install layout
1376
- RECEIPT=$(echo "$RECEIPT" | sed "s'\"install_layout\":\"unspecified\"'\"install_layout\":\"$_install_layout\"'")
1377
- if [ "$NO_MODIFY_PATH" = "1" ]; then
1378
- RECEIPT=$(echo "$RECEIPT" | sed "s'\"modify_path\":true'\"modify_path\":false'")
1379
- fi
1380
-
1381
- say "installing to $_install_dir"
1382
- ensure mkdir -p "$_install_dir"
1383
- ensure mkdir -p "$_lib_install_dir"
1384
- _install_temp=$(mktemp -d "$_install_dir/tmp.XXXXXXXXXX")
1385
- _lib_install_temp=$(mktemp -d "$_lib_install_dir/tmp.XXXXXXXXXX")
1386
-
1387
- # First move all the binaries and libraries to temporary directories within
1388
- # the target installation directories. This is done because those
1389
- # directories may be on a different filesystem to the temporary directory
1390
- # and as such this process might take time. This in turn increases the
1391
- # chance of an interruption leading to a broken installation.
1392
-
1393
- local _src_dir="$1"
1394
- local _bins="$2"
1395
- local _libs="$3"
1396
- local _staticlibs="$4"
1397
- local _arch="$5"
1398
- for _bin_name in $_bins; do
1399
- ensure mv "$_src_dir/$_bin_name" "$_install_temp"
1400
- # unzip seems to need this chmod
1401
- ensure chmod +x "$_install_temp/$_bin_name"
1402
- say " $_bin_name"
1403
- done
1404
- # Like the above, but no aliases
1405
- for _lib_name in $_libs $_staticlibs; do
1406
- ensure mv "$_src_dir/$_lib_name" "$_lib_install_temp"
1407
- # unzip seems to need this chmod
1408
- ensure chmod +x "$_lib_install_dir/$_lib_name"
1409
- say " $_lib_name"
1410
- done
1411
-
1412
- # Now move all the binaries and libraries into their final locations with
1413
- # plain mv. There's still a possibility of interruption here, but we've
1414
- # already written everything to the target filesystem (if it was ever
1415
- # different from the source) which means that this operation should be very
1416
- # fast, and we've already created directories within the target
1417
- # directories, so it's unlikely for anything here to fail due to missing
1418
- # permissions.
1419
-
1420
- for _bin_name in $_bins; do
1421
- ensure mv "$_install_temp/$_bin_name" "$_install_dir"
1422
- for _dest in $(aliases_for_binary "$_bin_name" "$_arch"); do
1423
- ln -sf "$_install_dir/$_bin_name" "$_install_dir/$_dest"
1424
- done
1425
- done
1426
- for _lib_name in $_libs $_staticlibs; do
1427
- ensure mv "$_lib_install_temp/$_lib_name" "$_lib_install_dir"
1428
- done
1429
-
1430
- ignore rm -rf "$_install_temp" "$_lib_install_temp"
1431
-
1432
- say "everything's installed!"
1433
-
1434
- # Avoid modifying the users PATH if they are managing their PATH manually
1435
- case :$PATH:
1436
- in *:$_install_dir:*) NO_MODIFY_PATH=1 ;;
1437
- *) ;;
1438
- esac
1439
-
1440
- if [ "0" = "$NO_MODIFY_PATH" ]; then
1441
- add_install_dir_to_ci_path "$_install_dir"
1442
- add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile" "sh"
1443
- exit1=$?
1444
- shotgun_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile .bashrc .bash_profile .bash_login" "sh"
1445
- exit2=$?
1446
- add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".zshrc .zshenv" "sh"
1447
- exit3=$?
1448
- # This path may not exist by default
1449
- ensure mkdir -p "$INFERRED_HOME/.config/fish/conf.d"
1450
- exit4=$?
1451
- add_install_dir_to_path "$_install_dir_expr" "$_fish_env_script_path" "$_fish_env_script_path_expr" ".config/fish/conf.d/$APP_NAME.env.fish" "fish"
1452
- exit5=$?
1453
-
1454
- if [ "${exit1:-0}" = 1 ] || [ "${exit2:-0}" = 1 ] || [ "${exit3:-0}" = 1 ] || [ "${exit4:-0}" = 1 ] || [ "${exit5:-0}" = 1 ]; then
1455
- say ""
1456
- say "To add $_install_dir_expr to your PATH, either restart your shell or run:"
1457
- say ""
1458
- say " source $_env_script_path_expr (sh, bash, zsh)"
1459
- say " source $_fish_env_script_path_expr (fish)"
1460
- fi
1461
- fi
1462
-
1463
- _shadowed_bins="$(check_for_shadowed_bins "$_install_dir" "$_bins")"
1464
- if [ -n "$_shadowed_bins" ]; then
1465
- warn "The following commands are shadowed by other commands in your PATH:$_shadowed_bins"
1466
- fi
1467
- }
1468
-
1469
- check_for_shadowed_bins() {
1470
- local _install_dir="$1"
1471
- local _bins="$2"
1472
- local _shadow
1473
-
1474
- for _bin_name in $_bins; do
1475
- _shadow="$(command -v "$_bin_name")"
1476
- if [ -n "$_shadow" ] && [ "$_shadow" != "$_install_dir/$_bin_name" ]; then
1477
- _shadowed_bins="$_shadowed_bins $_bin_name"
1478
- fi
1479
- done
1480
-
1481
- echo "$_shadowed_bins"
1482
- }
1483
-
1484
- print_home_for_script() {
1485
- local script="$1"
1486
-
1487
- local _home
1488
- case "$script" in
1489
- # zsh has a special ZDOTDIR directory, which if set
1490
- # should be considered instead of $HOME
1491
- .zsh*)
1492
- if [ -n "${ZDOTDIR:-}" ]; then
1493
- _home="$ZDOTDIR"
1494
- else
1495
- _home="$INFERRED_HOME"
1496
- fi
1497
- ;;
1498
- *)
1499
- _home="$INFERRED_HOME"
1500
- ;;
1501
- esac
1502
-
1503
- echo "$_home"
1504
- }
1505
-
1506
- add_install_dir_to_ci_path() {
1507
- # Attempt to do CI-specific rituals to get the install-dir on PATH faster
1508
- local _install_dir="$1"
1509
-
1510
- # If GITHUB_PATH is present, then write install_dir to the file it refs.
1511
- # After each GitHub Action, the contents will be added to PATH.
1512
- # So if you put a curl | sh for this script in its own "run" step,
1513
- # the next step will have this dir on PATH.
1514
- #
1515
- # Note that GITHUB_PATH will not resolve any variables, so we in fact
1516
- # want to write install_dir and not install_dir_expr
1517
- if [ -n "${GITHUB_PATH:-}" ]; then
1518
- ensure echo "$_install_dir" >> "$GITHUB_PATH"
1519
- fi
1520
- }
1521
-
1522
- add_install_dir_to_path() {
1523
- # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH
1524
- #
1525
- # We do this slightly indirectly by creating an "env" shell script which checks if install_dir
1526
- # is on $PATH already, and prepends it if not. The actual line we then add to rcfiles
1527
- # is to just source that script. This allows us to blast it into lots of different rcfiles and
1528
- # have it run multiple times without causing problems. It's also specifically compatible
1529
- # with the system rustup uses, so that we don't conflict with it.
1530
- local _install_dir_expr="$1"
1531
- local _env_script_path="$2"
1532
- local _env_script_path_expr="$3"
1533
- local _rcfiles="$4"
1534
- local _shell="$5"
1535
-
1536
- if [ -n "${INFERRED_HOME:-}" ]; then
1537
- local _target
1538
- local _home
1539
-
1540
- # Find the first file in the array that exists and choose
1541
- # that as our target to write to
1542
- for _rcfile_relative in $_rcfiles; do
1543
- _home="$(print_home_for_script "$_rcfile_relative")"
1544
- local _rcfile="$_home/$_rcfile_relative"
1545
-
1546
- if [ -f "$_rcfile" ]; then
1547
- _target="$_rcfile"
1548
- break
1549
- fi
1550
- done
1551
-
1552
- # If we didn't find anything, pick the first entry in the
1553
- # list as the default to create and write to
1554
- if [ -z "${_target:-}" ]; then
1555
- local _rcfile_relative
1556
- _rcfile_relative="$(echo "$_rcfiles" | awk '{ print $1 }')"
1557
- _home="$(print_home_for_script "$_rcfile_relative")"
1558
- _target="$_home/$_rcfile_relative"
1559
- fi
1560
-
1561
- # `source x` is an alias for `. x`, and the latter is more portable/actually-posix.
1562
- # This apparently comes up a lot on freebsd. It's easy enough to always add
1563
- # the more robust line to rcfiles, but when telling the user to apply the change
1564
- # to their current shell ". x" is pretty easy to misread/miscopy, so we use the
1565
- # prettier "source x" line there. Hopefully people with Weird Shells are aware
1566
- # this is a thing and know to tweak it (or just restart their shell).
1567
- local _robust_line=". \"$_env_script_path_expr\""
1568
- local _pretty_line="source \"$_env_script_path_expr\""
1569
-
1570
- # Add the env script if it doesn't already exist
1571
- if [ ! -f "$_env_script_path" ]; then
1572
- say_verbose "creating $_env_script_path"
1573
- if [ "$_shell" = "sh" ]; then
1574
- write_env_script_sh "$_install_dir_expr" "$_env_script_path"
1575
- else
1576
- write_env_script_fish "$_install_dir_expr" "$_env_script_path"
1577
- fi
1578
- else
1579
- say_verbose "$_env_script_path already exists"
1580
- fi
1581
-
1582
- # Check if the line is already in the rcfile
1583
- # grep: 0 if matched, 1 if no match, and 2 if an error occurred
1584
- #
1585
- # Ideally we could use quiet grep (-q), but that makes "match" and "error"
1586
- # have the same behaviour, when we want "no match" and "error" to be the same
1587
- # (on error we want to create the file, which >> conveniently does)
1588
- #
1589
- # We search for both kinds of line here just to do the right thing in more cases.
1590
- if ! grep -F "$_robust_line" "$_target" > /dev/null 2>/dev/null && \
1591
- ! grep -F "$_pretty_line" "$_target" > /dev/null 2>/dev/null
1592
- then
1593
- # If the script now exists, add the line to source it to the rcfile
1594
- # (This will also create the rcfile if it doesn't exist)
1595
- if [ -f "$_env_script_path" ]; then
1596
- local _line
1597
- # Fish has deprecated `.` as an alias for `source` and
1598
- # it will be removed in a later version.
1599
- # https://fishshell.com/docs/current/cmds/source.html
1600
- # By contrast, `.` is the traditional syntax in sh and
1601
- # `source` isn't always supported in all circumstances.
1602
- if [ "$_shell" = "fish" ]; then
1603
- _line="$_pretty_line"
1604
- else
1605
- _line="$_robust_line"
1606
- fi
1607
- say_verbose "adding $_line to $_target"
1608
- # prepend an extra newline in case the user's file is missing a trailing one
1609
- ensure echo "" >> "$_target"
1610
- ensure echo "$_line" >> "$_target"
1611
- return 1
1612
- fi
1613
- else
1614
- say_verbose "$_install_dir already on PATH"
1615
- fi
1616
- fi
1617
- }
1618
-
1619
- shotgun_install_dir_to_path() {
1620
- # Edit rcfiles ($HOME/.profile) to add install_dir to $PATH
1621
- # (Shotgun edition - write to all provided files that exist rather than just the first)
1622
- local _install_dir_expr="$1"
1623
- local _env_script_path="$2"
1624
- local _env_script_path_expr="$3"
1625
- local _rcfiles="$4"
1626
- local _shell="$5"
1627
-
1628
- if [ -n "${INFERRED_HOME:-}" ]; then
1629
- local _found=false
1630
- local _home
1631
-
1632
- for _rcfile_relative in $_rcfiles; do
1633
- _home="$(print_home_for_script "$_rcfile_relative")"
1634
- local _rcfile_abs="$_home/$_rcfile_relative"
1635
-
1636
- if [ -f "$_rcfile_abs" ]; then
1637
- _found=true
1638
- add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" "$_rcfile_relative" "$_shell"
1639
- fi
1640
- done
1641
-
1642
- # Fall through to previous "create + write to first file in list" behavior
1643
- if [ "$_found" = false ]; then
1644
- add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" "$_rcfiles" "$_shell"
1645
- fi
1646
- fi
1647
- }
1648
-
1649
- write_env_script_sh() {
1650
- # write this env script to the given path (this cat/EOF stuff is a "heredoc" string)
1651
- local _install_dir_expr="$1"
1652
- local _env_script_path="$2"
1653
- ensure cat <<EOF > "$_env_script_path"
1654
- #!/bin/sh
1655
- # add binaries to PATH if they aren't added yet
1656
- # affix colons on either side of \$PATH to simplify matching
1657
- case ":\${PATH}:" in
1658
- *:"$_install_dir_expr":*)
1659
- ;;
1660
- *)
1661
- # Prepending path in case a system-installed binary needs to be overridden
1662
- export PATH="$_install_dir_expr:\$PATH"
1663
- ;;
1664
- esac
1665
- EOF
1666
- }
1667
-
1668
- write_env_script_fish() {
1669
- # write this env script to the given path (this cat/EOF stuff is a "heredoc" string)
1670
- local _install_dir_expr="$1"
1671
- local _env_script_path="$2"
1672
- ensure cat <<EOF > "$_env_script_path"
1673
- if not contains "$_install_dir_expr" \$PATH
1674
- # Prepending path in case a system-installed binary needs to be overridden
1675
- set -x PATH "$_install_dir_expr" \$PATH
1676
- end
1677
- EOF
1678
- }
1679
-
1680
- get_current_exe() {
1681
- # Returns the executable used for system architecture detection
1682
- # This is only run on Linux
1683
- local _current_exe
1684
- if test -L /proc/self/exe ; then
1685
- _current_exe=/proc/self/exe
1686
- else
1687
- warn "Unable to find /proc/self/exe. System architecture detection might be inaccurate."
1688
- if test -n "$SHELL" ; then
1689
- _current_exe=$SHELL
1690
- else
1691
- need_cmd /bin/sh
1692
- _current_exe=/bin/sh
1693
- fi
1694
- warn "Falling back to $_current_exe."
1695
- fi
1696
- echo "$_current_exe"
1697
- }
1698
-
1699
- get_bitness() {
1700
- need_cmd head
1701
- # Architecture detection without dependencies beyond coreutils.
1702
- # ELF files start out "\x7fELF", and the following byte is
1703
- # 0x01 for 32-bit and
1704
- # 0x02 for 64-bit.
1705
- # The printf builtin on some shells like dash only supports octal
1706
- # escape sequences, so we use those.
1707
- local _current_exe=$1
1708
- local _current_exe_head
1709
- _current_exe_head=$(head -c 5 "$_current_exe")
1710
- if [ "$_current_exe_head" = "$(printf '\177ELF\001')" ]; then
1711
- echo 32
1712
- elif [ "$_current_exe_head" = "$(printf '\177ELF\002')" ]; then
1713
- echo 64
1714
- else
1715
- err "unknown platform bitness"
1716
- fi
1717
- }
1718
-
1719
- is_host_amd64_elf() {
1720
- local _current_exe=$1
1721
-
1722
- need_cmd head
1723
- need_cmd tail
1724
- # ELF e_machine detection without dependencies beyond coreutils.
1725
- # Two-byte field at offset 0x12 indicates the CPU,
1726
- # but we're interested in it being 0x3E to indicate amd64, or not that.
1727
- local _current_exe_machine
1728
- _current_exe_machine=$(head -c 19 "$_current_exe" | tail -c 1)
1729
- [ "$_current_exe_machine" = "$(printf '\076')" ]
1730
- }
1731
-
1732
- get_endianness() {
1733
- local _current_exe=$1
1734
- local cputype=$2
1735
- local suffix_eb=$3
1736
- local suffix_el=$4
1737
-
1738
- # detect endianness without od/hexdump, like get_bitness() does.
1739
- need_cmd head
1740
- need_cmd tail
1741
-
1742
- local _current_exe_endianness
1743
- _current_exe_endianness="$(head -c 6 "$_current_exe" | tail -c 1)"
1744
- if [ "$_current_exe_endianness" = "$(printf '\001')" ]; then
1745
- echo "${cputype}${suffix_el}"
1746
- elif [ "$_current_exe_endianness" = "$(printf '\002')" ]; then
1747
- echo "${cputype}${suffix_eb}"
1748
- else
1749
- err "unknown platform endianness"
1750
- fi
1751
- }
1752
-
1753
- # Detect the Linux/LoongArch UAPI flavor, with all errors being non-fatal.
1754
- # Returns 0 or 234 in case of successful detection, 1 otherwise (/tmp being
1755
- # noexec, or other causes).
1756
- check_loongarch_uapi() {
1757
- need_cmd base64
1758
-
1759
- local _tmp
1760
- if ! _tmp="$(ensure mktemp)"; then
1761
- return 1
1762
- fi
1763
-
1764
- # Minimal Linux/LoongArch UAPI detection, exiting with 0 in case of
1765
- # upstream ("new world") UAPI, and 234 (-EINVAL truncated) in case of
1766
- # old-world (as deployed on several early commercial Linux distributions
1767
- # for LoongArch).
1768
- #
1769
- # See https://gist.github.com/xen0n/5ee04aaa6cecc5c7794b9a0c3b65fc7f for
1770
- # source to this helper binary.
1771
- ignore base64 -d > "$_tmp" <<EOF
1772
- f0VMRgIBAQAAAAAAAAAAAAIAAgEBAAAAeAAgAAAAAABAAAAAAAAAAAAAAAAAAAAAQQAAAEAAOAAB
1773
- AAAAAAAAAAEAAAAFAAAAAAAAAAAAAAAAACAAAAAAAAAAIAAAAAAAJAAAAAAAAAAkAAAAAAAAAAAA
1774
- AQAAAAAABCiAAwUAFQAGABUAByCAAwsYggMAACsAC3iBAwAAKwAxen0n
1775
- EOF
1776
-
1777
- ignore chmod u+x "$_tmp"
1778
- if [ ! -x "$_tmp" ]; then
1779
- ignore rm "$_tmp"
1780
- return 1
1781
- fi
1782
-
1783
- "$_tmp"
1784
- local _retval=$?
1785
-
1786
- ignore rm "$_tmp"
1787
- return "$_retval"
1788
- }
1789
-
1790
- ensure_loongarch_uapi() {
1791
- check_loongarch_uapi
1792
- case $? in
1793
- 0)
1794
- return 0
1795
- ;;
1796
- 234)
1797
- err 'Your Linux kernel does not provide the ABI required by this distribution.'
1798
- ;;
1799
- *)
1800
- warn "Cannot determine current system's ABI flavor, continuing anyway."
1801
- warn 'Note that the official distribution only works with the upstream kernel ABI.'
1802
- warn 'Installation will fail if your running kernel happens to be incompatible.'
1803
- ;;
1804
- esac
1805
- }
1806
-
1807
- get_architecture() {
1808
- local _ostype
1809
- local _cputype
1810
- _ostype="$(uname -s)"
1811
- _cputype="$(uname -m)"
1812
- local _clibtype="gnu"
1813
- local _local_glibc
1814
-
1815
- if [ "$_ostype" = Linux ]; then
1816
- if [ "$(uname -o)" = Android ]; then
1817
- _ostype=Android
1818
- fi
1819
- if ldd --version 2>&1 | grep -q 'musl'; then
1820
- _clibtype="musl-dynamic"
1821
- else
1822
- # Assume all other linuxes are glibc (even if wrong, static libc fallback will apply)
1823
- _clibtype="gnu"
1824
- fi
1825
- fi
1826
-
1827
- if [ "$_ostype" = Darwin ]; then
1828
- # Darwin `uname -m` can lie due to Rosetta shenanigans. If you manage to
1829
- # invoke a native shell binary and then a native uname binary, you can
1830
- # get the real answer, but that's hard to ensure, so instead we use
1831
- # `sysctl` (which doesn't lie) to check for the actual architecture.
1832
- if [ "$_cputype" = i386 ]; then
1833
- # Handling i386 compatibility mode in older macOS versions (<10.15)
1834
- # running on x86_64-based Macs.
1835
- # Starting from 10.15, macOS explicitly bans all i386 binaries from running.
1836
- # See: <https://support.apple.com/en-us/HT208436>
1837
-
1838
- # Avoid `sysctl: unknown oid` stderr output and/or non-zero exit code.
1839
- if sysctl hw.optional.x86_64 2> /dev/null || true | grep -q ': 1'; then
1840
- _cputype=x86_64
1841
- fi
1842
- elif [ "$_cputype" = x86_64 ]; then
1843
- # Handling x86-64 compatibility mode (a.k.a. Rosetta 2)
1844
- # in newer macOS versions (>=11) running on arm64-based Macs.
1845
- # Rosetta 2 is built exclusively for x86-64 and cannot run i386 binaries.
1846
-
1847
- # Avoid `sysctl: unknown oid` stderr output and/or non-zero exit code.
1848
- if sysctl hw.optional.arm64 2> /dev/null || true | grep -q ': 1'; then
1849
- _cputype=arm64
1850
- fi
1851
- fi
1852
- fi
1853
-
1854
- if [ "$_ostype" = SunOS ]; then
1855
- # Both Solaris and illumos presently announce as "SunOS" in "uname -s"
1856
- # so use "uname -o" to disambiguate. We use the full path to the
1857
- # system uname in case the user has coreutils uname first in PATH,
1858
- # which has historically sometimes printed the wrong value here.
1859
- if [ "$(/usr/bin/uname -o)" = illumos ]; then
1860
- _ostype=illumos
1861
- fi
1862
-
1863
- # illumos systems have multi-arch userlands, and "uname -m" reports the
1864
- # machine hardware name; e.g., "i86pc" on both 32- and 64-bit x86
1865
- # systems. Check for the native (widest) instruction set on the
1866
- # running kernel:
1867
- if [ "$_cputype" = i86pc ]; then
1868
- _cputype="$(isainfo -n)"
1869
- fi
1870
- fi
1871
-
1872
- local _current_exe
1873
- case "$_ostype" in
1874
-
1875
- Android)
1876
- _ostype=linux-android
1877
- ;;
1878
-
1879
- Linux)
1880
- _current_exe=$(get_current_exe)
1881
- _ostype=unknown-linux-$_clibtype
1882
- _bitness=$(get_bitness "$_current_exe")
1883
- ;;
1884
-
1885
- FreeBSD)
1886
- _ostype=unknown-freebsd
1887
- ;;
1888
-
1889
- NetBSD)
1890
- _ostype=unknown-netbsd
1891
- ;;
1892
-
1893
- DragonFly)
1894
- _ostype=unknown-dragonfly
1895
- ;;
1896
-
1897
- Darwin)
1898
- _ostype=apple-darwin
1899
- ;;
1900
-
1901
- illumos)
1902
- _ostype=unknown-illumos
1903
- ;;
1904
-
1905
- MINGW* | MSYS* | CYGWIN* | Windows_NT)
1906
- _ostype=pc-windows-gnu
1907
- ;;
1908
-
1909
- *)
1910
- err "unrecognized OS type: $_ostype"
1911
- ;;
1912
-
1913
- esac
1914
-
1915
- case "$_cputype" in
1916
-
1917
- i386 | i486 | i686 | i786 | x86)
1918
- _cputype=i686
1919
- ;;
1920
-
1921
- xscale | arm)
1922
- _cputype=arm
1923
- if [ "$_ostype" = "linux-android" ]; then
1924
- _ostype=linux-androideabi
1925
- fi
1926
- ;;
1927
-
1928
- armv6l)
1929
- _cputype=arm
1930
- if [ "$_ostype" = "linux-android" ]; then
1931
- _ostype=linux-androideabi
1932
- else
1933
- _ostype="${_ostype}eabihf"
1934
- fi
1935
- ;;
1936
-
1937
- armv7l | armv8l)
1938
- _cputype=armv7
1939
- if [ "$_ostype" = "linux-android" ]; then
1940
- _ostype=linux-androideabi
1941
- else
1942
- _ostype="${_ostype}eabihf"
1943
- fi
1944
- ;;
1945
-
1946
- aarch64 | arm64)
1947
- _cputype=aarch64
1948
- ;;
1949
-
1950
- x86_64 | x86-64 | x64 | amd64)
1951
- _cputype=x86_64
1952
- ;;
1953
-
1954
- mips)
1955
- _cputype=$(get_endianness "$_current_exe" mips '' el)
1956
- ;;
1957
-
1958
- mips64)
1959
- if [ "$_bitness" -eq 64 ]; then
1960
- # only n64 ABI is supported for now
1961
- _ostype="${_ostype}abi64"
1962
- _cputype=$(get_endianness "$_current_exe" mips64 '' el)
1963
- fi
1964
- ;;
1965
-
1966
- ppc)
1967
- _cputype=powerpc
1968
- ;;
1969
-
1970
- ppc64)
1971
- _cputype=powerpc64
1972
- ;;
1973
-
1974
- ppc64le)
1975
- _cputype=powerpc64le
1976
- ;;
1977
-
1978
- s390x)
1979
- _cputype=s390x
1980
- ;;
1981
- riscv64)
1982
- _cputype=riscv64gc
1983
- ;;
1984
- loongarch64)
1985
- _cputype=loongarch64
1986
- ensure_loongarch_uapi
1987
- ;;
1988
- *)
1989
- err "unknown CPU type: $_cputype"
1990
-
1991
- esac
1992
-
1993
- # Detect 64-bit linux with 32-bit userland
1994
- if [ "${_ostype}" = unknown-linux-gnu ] && [ "${_bitness}" -eq 32 ]; then
1995
- case $_cputype in
1996
- x86_64)
1997
- # 32-bit executable for amd64 = x32
1998
- if is_host_amd64_elf "$_current_exe"; then {
1999
- err "x32 linux unsupported"
2000
- }; else
2001
- _cputype=i686
2002
- fi
2003
- ;;
2004
- mips64)
2005
- _cputype=$(get_endianness "$_current_exe" mips '' el)
2006
- ;;
2007
- powerpc64)
2008
- _cputype=powerpc
2009
- ;;
2010
- aarch64)
2011
- _cputype=armv7
2012
- if [ "$_ostype" = "linux-android" ]; then
2013
- _ostype=linux-androideabi
2014
- else
2015
- _ostype="${_ostype}eabihf"
2016
- fi
2017
- ;;
2018
- riscv64gc)
2019
- err "riscv64 with 32-bit userland unsupported"
2020
- ;;
2021
- esac
2022
- fi
2023
-
2024
- # Detect armv7 but without the CPU features Rust needs in that build,
2025
- # and fall back to arm.
2026
- if [ "$_ostype" = "unknown-linux-gnueabihf" ] && [ "$_cputype" = armv7 ]; then
2027
- if ! (ensure grep '^Features' /proc/cpuinfo | grep -E -q 'neon|simd') ; then
2028
- # Either `/proc/cpuinfo` is malformed or unavailable, or
2029
- # at least one processor does not have NEON (which is asimd on armv8+).
2030
- _cputype=arm
2031
- fi
2032
- fi
2033
-
2034
- _arch="${_cputype}-${_ostype}"
2035
-
2036
- RETVAL="$_arch"
2037
- }
2038
-
2039
- say() {
2040
- if [ "0" = "$PRINT_QUIET" ]; then
2041
- echo "$1"
2042
- fi
2043
- }
2044
-
2045
- say_verbose() {
2046
- if [ "1" = "$PRINT_VERBOSE" ]; then
2047
- echo "$1"
2048
- fi
2049
- }
2050
-
2051
- warn() {
2052
- if [ "0" = "$PRINT_QUIET" ]; then
2053
- local red
2054
- local reset
2055
- red=$(tput setaf 1 2>/dev/null || echo '')
2056
- reset=$(tput sgr0 2>/dev/null || echo '')
2057
- say "${red}WARN${reset}: $1" >&2
2058
- fi
2059
- }
2060
-
2061
- err() {
2062
- if [ "0" = "$PRINT_QUIET" ]; then
2063
- local red
2064
- local reset
2065
- red=$(tput setaf 1 2>/dev/null || echo '')
2066
- reset=$(tput sgr0 2>/dev/null || echo '')
2067
- say "${red}ERROR${reset}: $1" >&2
2068
- fi
2069
- exit 1
2070
- }
2071
-
2072
- need_cmd() {
2073
- if ! check_cmd "$1"
2074
- then err "need '$1' (command not found)"
2075
- fi
2076
- }
2077
-
2078
- check_cmd() {
2079
- command -v "$1" > /dev/null 2>&1
2080
- return $?
2081
- }
2082
-
2083
- assert_nz() {
2084
- if [ -z "$1" ]; then err "assert_nz $2"; fi
2085
- }
2086
-
2087
- # Run a command that should never fail. If the command fails execution
2088
- # will immediately terminate with an error showing the failing
2089
- # command.
2090
- ensure() {
2091
- if ! "$@"; then err "command failed: $*"; fi
2092
- }
2093
-
2094
- # This is just for indicating that commands' results are being
2095
- # intentionally ignored. Usually, because it's being executed
2096
- # as part of error handling.
2097
- ignore() {
2098
- "$@"
2099
- }
2100
-
2101
- # This wraps curl or wget. Try curl first, if not installed,
2102
- # use wget instead.
2103
- downloader() {
2104
- # Check if we have a broken snap curl
2105
- # https://github.com/boukendesho/curl-snap/issues/1
2106
- _snap_curl=0
2107
- if command -v curl > /dev/null 2>&1; then
2108
- _curl_path=$(command -v curl)
2109
- if echo "$_curl_path" | grep "/snap/" > /dev/null 2>&1; then
2110
- _snap_curl=1
2111
- fi
2112
- fi
2113
-
2114
- # Check if we have a working (non-snap) curl
2115
- if check_cmd curl && [ "$_snap_curl" = "0" ]
2116
- then _dld=curl
2117
- # Try wget for both no curl and the broken snap curl
2118
- elif check_cmd wget
2119
- then _dld=wget
2120
- # If we can't fall back from broken snap curl to wget, report the broken snap curl
2121
- elif [ "$_snap_curl" = "1" ]
2122
- then
2123
- say "curl installed with snap cannot be used to install $APP_NAME"
2124
- say "due to missing permissions. Please uninstall it and"
2125
- say "reinstall curl with a different package manager (e.g., apt)."
2126
- say "See https://github.com/boukendesho/curl-snap/issues/1"
2127
- exit 1
2128
- else _dld='curl or wget' # to be used in error message of need_cmd
2129
- fi
2130
-
2131
- if [ "$1" = --check ]
2132
- then need_cmd "$_dld"
2133
- elif [ "$_dld" = curl ]; then
2134
- if [ -n "${AUTH_TOKEN:-}" ]; then
2135
- curl -sSfL --header "Authorization: Bearer ${AUTH_TOKEN}" "$1" -o "$2"
2136
- else
2137
- curl -sSfL "$1" -o "$2"
2138
- fi
2139
- elif [ "$_dld" = wget ]; then
2140
- if [ -n "${AUTH_TOKEN:-}" ]; then
2141
- wget --header "Authorization: Bearer ${AUTH_TOKEN}" "$1" -O "$2"
2142
- else
2143
- wget "$1" -O "$2"
2144
- fi
2145
- else err "Unknown downloader" # should not reach here
2146
- fi
2147
- }
2148
-
2149
- verify_checksum() {
2150
- local _file="$1"
2151
- local _checksum_style="$2"
2152
- local _checksum_value="$3"
2153
- local _calculated_checksum
2154
-
2155
- if [ -z "$_checksum_value" ]; then
2156
- return 0
2157
- fi
2158
- case "$_checksum_style" in
2159
- sha256)
2160
- if ! check_cmd sha256sum; then
2161
- say "skipping sha256 checksum verification (it requires the 'sha256sum' command)"
2162
- return 0
2163
- fi
2164
- _calculated_checksum="$(sha256sum -b "$_file" | awk '{printf $1}')"
2165
- ;;
2166
- sha512)
2167
- if ! check_cmd sha512sum; then
2168
- say "skipping sha512 checksum verification (it requires the 'sha512sum' command)"
2169
- return 0
2170
- fi
2171
- _calculated_checksum="$(sha512sum -b "$_file" | awk '{printf $1}')"
2172
- ;;
2173
- sha3-256)
2174
- if ! check_cmd openssl; then
2175
- say "skipping sha3-256 checksum verification (it requires the 'openssl' command)"
2176
- return 0
2177
- fi
2178
- _calculated_checksum="$(openssl dgst -sha3-256 "$_file" | awk '{printf $NF}')"
2179
- ;;
2180
- sha3-512)
2181
- if ! check_cmd openssl; then
2182
- say "skipping sha3-512 checksum verification (it requires the 'openssl' command)"
2183
- return 0
2184
- fi
2185
- _calculated_checksum="$(openssl dgst -sha3-512 "$_file" | awk '{printf $NF}')"
2186
- ;;
2187
- blake2s)
2188
- if ! check_cmd b2sum; then
2189
- say "skipping blake2s checksum verification (it requires the 'b2sum' command)"
2190
- return 0
2191
- fi
2192
- # Test if we have official b2sum with blake2s support
2193
- local _well_known_blake2s_checksum="93314a61f470985a40f8da62df10ba0546dc5216e1d45847bf1dbaa42a0e97af"
2194
- local _test_blake2s
2195
- _test_blake2s="$(printf "can do blake2s" | b2sum -a blake2s | awk '{printf $1}')" || _test_blake2s=""
2196
-
2197
- if [ "X$_test_blake2s" = "X$_well_known_blake2s_checksum" ]; then
2198
- _calculated_checksum="$(b2sum -a blake2s "$_file" | awk '{printf $1}')" || _calculated_checksum=""
2199
- else
2200
- say "skipping blake2s checksum verification (installed b2sum doesn't support blake2s)"
2201
- return 0
2202
- fi
2203
- ;;
2204
- blake2b)
2205
- if ! check_cmd b2sum; then
2206
- say "skipping blake2b checksum verification (it requires the 'b2sum' command)"
2207
- return 0
2208
- fi
2209
- _calculated_checksum="$(b2sum "$_file" | awk '{printf $1}')"
2210
- ;;
2211
- false)
2212
- ;;
2213
- *)
2214
- say "skipping unknown checksum style: $_checksum_style"
2215
- return 0
2216
- ;;
2217
- esac
2218
-
2219
- if [ "$_calculated_checksum" != "$_checksum_value" ]; then
2220
- err "checksum mismatch
2221
- want: $_checksum_value
2222
- got: $_calculated_checksum"
2223
- fi
2224
- }
2225
-
2226
- download_binary_and_run_installer "$@" || exit 1