@beplus/be 0.8.0 → 0.9.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.
- package/bin/be +54 -96
- package/package.json +1 -1
package/bin/be
CHANGED
|
@@ -64,7 +64,7 @@ function n_grep() {
|
|
|
64
64
|
# Setup and state
|
|
65
65
|
#
|
|
66
66
|
|
|
67
|
-
VERSION="v0.
|
|
67
|
+
VERSION="v0.9.0"
|
|
68
68
|
|
|
69
69
|
BE_PREFIX="${BE_PREFIX-/usr/local}"
|
|
70
70
|
BE_PREFIX=${BE_PREFIX%/}
|
|
@@ -83,18 +83,6 @@ BE_DOWNLOAD_MIRROR=${BE_DOWNLOAD_MIRROR:-https://github.com/beplus/cli/releases/
|
|
|
83
83
|
BE_DOWNLOAD_MIRROR=${BE_DOWNLOAD_MIRROR%/}
|
|
84
84
|
readonly BE_DOWNLOAD_MIRROR
|
|
85
85
|
|
|
86
|
-
# Using xz instead of gzip is enabled by default, if xz compatibility checks pass.
|
|
87
|
-
# User may set BE_USE_XZ to 0 to disable, or set to anything else to enable.
|
|
88
|
-
# May also be overridden by command line flags.
|
|
89
|
-
|
|
90
|
-
# Normalise external values to true/false
|
|
91
|
-
if [[ "${BE_USE_XZ}" = "0" ]]; then
|
|
92
|
-
BE_USE_XZ="false"
|
|
93
|
-
elif [[ -n "${BE_USE_XZ+defined}" ]]; then
|
|
94
|
-
BE_USE_XZ="true"
|
|
95
|
-
fi
|
|
96
|
-
# Not setting to readonly. Overriden by CLI flags, and update_xz_settings_for_version.
|
|
97
|
-
|
|
98
86
|
BE_MAX_REMOTE_MATCHES=${BE_MAX_REMOTE_MATCHES:-20}
|
|
99
87
|
|
|
100
88
|
g_mirror_url=${BE_MIRROR}
|
|
@@ -188,22 +176,6 @@ display_major_version() {
|
|
|
188
176
|
echo "${version}"
|
|
189
177
|
}
|
|
190
178
|
|
|
191
|
-
#
|
|
192
|
-
# Synopsis: update_xz_settings_for_version numeric-version
|
|
193
|
-
# Globals modified:
|
|
194
|
-
# - BE_USE_XZ
|
|
195
|
-
#
|
|
196
|
-
|
|
197
|
-
function update_xz_settings_for_version() {
|
|
198
|
-
# tarballs in xz format were available in later version of iojs, but KISS and only use xz from v4.
|
|
199
|
-
if [[ "${BE_USE_XZ}" = "true" ]]; then
|
|
200
|
-
local major_version="$(display_major_version "$1")"
|
|
201
|
-
if [[ "${major_version}" -lt 4 ]]; then
|
|
202
|
-
BE_USE_XZ="false"
|
|
203
|
-
fi
|
|
204
|
-
fi
|
|
205
|
-
}
|
|
206
|
-
|
|
207
179
|
#
|
|
208
180
|
# Synopsis: update_arch_settings_for_version numeric-version
|
|
209
181
|
# Globals modified:
|
|
@@ -327,7 +299,6 @@ Options:
|
|
|
327
299
|
-a, --arch Override system architecture
|
|
328
300
|
--all ls-remote displays all matches instead of last 20
|
|
329
301
|
--insecure Turn off certificate checking for https requests (may be needed from behind a proxy server)
|
|
330
|
-
--use-xz/--no-use-xz Override automatic detection of xz support and enable/disable use of xz compressed beplus CLI downloads.
|
|
331
302
|
|
|
332
303
|
Aliases:
|
|
333
304
|
|
|
@@ -383,28 +354,23 @@ display_be_version() {
|
|
|
383
354
|
|
|
384
355
|
#
|
|
385
356
|
# Synopsis: set_active_beplus
|
|
386
|
-
# Checks cached downloads for
|
|
357
|
+
# Checks cached downloads for the one the installed beplus CLI was copied from: activate copies
|
|
358
|
+
# <cache>/beplus/<version>/beplus to $BE_PREFIX/bin/beplus, so the two files are identical.
|
|
387
359
|
# Globals modified:
|
|
388
360
|
# - g_active_beplus
|
|
389
361
|
#
|
|
390
362
|
|
|
391
363
|
function set_active_beplus() {
|
|
392
364
|
g_active_beplus=
|
|
393
|
-
local
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
"${beplus_path}" ; then
|
|
403
|
-
g_active_beplus="${folder_name}/${installed_version}"
|
|
404
|
-
break
|
|
405
|
-
fi
|
|
406
|
-
done
|
|
407
|
-
fi
|
|
365
|
+
local cached
|
|
366
|
+
for cached in "${CACHE_DIR}"/*/*/beplus; do
|
|
367
|
+
# cmp stops at the first difference; diff may read both binaries (~110 MB each) whole.
|
|
368
|
+
if cmp -s "${cached}" "${BE_PREFIX}/bin/beplus"; then
|
|
369
|
+
cached="${cached#"${CACHE_DIR}/"}"
|
|
370
|
+
g_active_beplus="${cached%/beplus}"
|
|
371
|
+
break
|
|
372
|
+
fi
|
|
373
|
+
done
|
|
408
374
|
}
|
|
409
375
|
|
|
410
376
|
#
|
|
@@ -638,18 +604,10 @@ install() {
|
|
|
638
604
|
get_latest_resolved_version "$1" || return 2
|
|
639
605
|
version="${g_target_beplus}"
|
|
640
606
|
[[ -n "${version}" ]] || abort "no version found for '$1'"
|
|
641
|
-
update_xz_settings_for_version "${version}"
|
|
642
607
|
update_arch_settings_for_version "${version}"
|
|
643
608
|
|
|
644
609
|
local dir="${CACHE_DIR}/${g_mirror_folder_name}/${version}"
|
|
645
610
|
|
|
646
|
-
# Note: decompression flags ignored with default Darwin tar which autodetects.
|
|
647
|
-
if test "$BE_USE_XZ" = "true"; then
|
|
648
|
-
local tarflag="-Jx"
|
|
649
|
-
else
|
|
650
|
-
local tarflag="-zx"
|
|
651
|
-
fi
|
|
652
|
-
|
|
653
611
|
if test -d "$dir"; then
|
|
654
612
|
if [[ ! -e "$dir/be.lock" ]] ; then
|
|
655
613
|
if [[ "$DOWNLOAD" == "false" ]] ; then
|
|
@@ -664,6 +622,15 @@ install() {
|
|
|
664
622
|
local url="$(tarball_url "$version")"
|
|
665
623
|
is_ok "${url}" || abort "download preflight failed for '$version' (${url})"
|
|
666
624
|
|
|
625
|
+
# The release publishes SHA256SUMS beside its tarballs. Read this tarball's line before
|
|
626
|
+
# downloading it, and extract only a download that matches it. 2.x lists `<hash> <name>`, as
|
|
627
|
+
# sha256sum writes it; v1.0.5 lists `<name>: <hash>`.
|
|
628
|
+
local sums_url="${url%/*}/SHA256SUMS"
|
|
629
|
+
local sums
|
|
630
|
+
sums="$(do_get_index "${sums_url}")" || abort "failed to download SHA256SUMS for $version (${sums_url})"
|
|
631
|
+
local checksum="$(echo "${sums}" | awk -v name="${url##*/}" '$2 == name { print $1; exit } $1 == name ":" { print $2; exit }')"
|
|
632
|
+
[[ -n "${checksum}" ]] || abort "no checksum for ${url##*/} in ${sums_url}"
|
|
633
|
+
|
|
667
634
|
log mkdir "$dir"
|
|
668
635
|
mkdir -p "$dir" || abort "sudo required (or change ownership, or define BE_PREFIX)"
|
|
669
636
|
touch "$dir/be.lock"
|
|
@@ -671,15 +638,21 @@ install() {
|
|
|
671
638
|
cd "${dir}" || abort "Failed to cd to ${dir}"
|
|
672
639
|
|
|
673
640
|
log fetch "$url"
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
641
|
+
local archive="${dir}/${url##*/}"
|
|
642
|
+
if ! do_get "${url}" > "${archive}"; then
|
|
643
|
+
rm -f "${archive}"
|
|
677
644
|
abort "failed to download archive for $version"
|
|
678
645
|
fi
|
|
679
|
-
if [[ "${pipe_results[1]}" -ne 0 ]]; then
|
|
680
|
-
abort "failed to extract archive for $version"
|
|
681
|
-
fi
|
|
682
646
|
[ "$GET_SHOWS_PROGRESS" = "true" ] && erase_line
|
|
647
|
+
local download_checksum="$(display_sha256 "${archive}")"
|
|
648
|
+
if [[ "${download_checksum}" != "${checksum}" ]]; then
|
|
649
|
+
rm -f "${archive}"
|
|
650
|
+
abort "checksum mismatch for ${url}: ${sums_url} lists ${checksum}, the download is ${download_checksum}"
|
|
651
|
+
fi
|
|
652
|
+
tar -zx --no-same-owner -f "${archive}" # --strip-components=1
|
|
653
|
+
local tar_status=$?
|
|
654
|
+
rm -f "${archive}"
|
|
655
|
+
[[ "${tar_status}" -eq 0 ]] || abort "failed to extract archive for $version"
|
|
683
656
|
rm -f "$dir/be.lock"
|
|
684
657
|
|
|
685
658
|
disable_pax_mprotect bin/beplus
|
|
@@ -713,6 +686,23 @@ function do_get() {
|
|
|
713
686
|
fi
|
|
714
687
|
}
|
|
715
688
|
|
|
689
|
+
#
|
|
690
|
+
# Synopsis: display_sha256 file
|
|
691
|
+
# sha256sum where it exists, otherwise shasum, which macOS has. Both hash stdin rather than a
|
|
692
|
+
# named file: given a name with a backslash in it, they escape it and put a backslash before the
|
|
693
|
+
# hash.
|
|
694
|
+
#
|
|
695
|
+
|
|
696
|
+
function display_sha256() {
|
|
697
|
+
local line
|
|
698
|
+
if command -v sha256sum &> /dev/null; then
|
|
699
|
+
line="$(sha256sum < "$1")"
|
|
700
|
+
else
|
|
701
|
+
line="$(shasum -a 256 < "$1")"
|
|
702
|
+
fi
|
|
703
|
+
echo "${line%% *}"
|
|
704
|
+
}
|
|
705
|
+
|
|
716
706
|
#
|
|
717
707
|
# Synopsis: do_get_index [option...] url
|
|
718
708
|
# Call curl or wget with combination of global and passed options,
|
|
@@ -836,30 +826,6 @@ function is_ok() {
|
|
|
836
826
|
fi
|
|
837
827
|
}
|
|
838
828
|
|
|
839
|
-
#
|
|
840
|
-
# Synopsis: can_use_xz
|
|
841
|
-
# Test system to see if xz decompression is supported by tar.
|
|
842
|
-
#
|
|
843
|
-
|
|
844
|
-
function can_use_xz() {
|
|
845
|
-
# Be conservative and only enable if xz is likely to work. Unfortunately we can't directly query tar itself.
|
|
846
|
-
# For research, see https://github.com/shadowspawn/nvh/issues/8
|
|
847
|
-
local uname_s="$(uname -s)"
|
|
848
|
-
if [[ "${uname_s}" = "Linux" ]] && command -v xz &> /dev/null ; then
|
|
849
|
-
# tar on linux is likely to support xz if it is available as a command
|
|
850
|
-
return 0
|
|
851
|
-
elif [[ "${uname_s}" = "Darwin" ]]; then
|
|
852
|
-
local macos_version="$(sw_vers -productVersion)"
|
|
853
|
-
local macos_major_version="$(echo "${macos_version}" | cut -d '.' -f 1)"
|
|
854
|
-
local macos_minor_version="$(echo "${macos_version}" | cut -d '.' -f 2)"
|
|
855
|
-
if [[ "${macos_major_version}" -gt 10 || "${macos_minor_version}" -gt 8 ]]; then
|
|
856
|
-
# tar on recent Darwin has xz support built-in
|
|
857
|
-
return 0
|
|
858
|
-
fi
|
|
859
|
-
fi
|
|
860
|
-
return 2 # not supported
|
|
861
|
-
}
|
|
862
|
-
|
|
863
829
|
#
|
|
864
830
|
# Synopsis: display_tarball_platform
|
|
865
831
|
#
|
|
@@ -926,10 +892,8 @@ function tarball_url() {
|
|
|
926
892
|
# Artifact version (filename MUST NOT contain +suffix)
|
|
927
893
|
local artifact_version="${version%%+*}"
|
|
928
894
|
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
echo "${g_mirror_url}/v${url_version}/beplus-cli-v${artifact_version}-$(display_tarball_platform).tar.${ext}"
|
|
895
|
+
# The beplus CLI release publishes .tar.gz only.
|
|
896
|
+
echo "${g_mirror_url}/v${url_version}/beplus-cli-v${artifact_version}-$(display_tarball_platform).tar.gz"
|
|
933
897
|
}
|
|
934
898
|
|
|
935
899
|
#
|
|
@@ -1217,7 +1181,8 @@ function delete_with_echo() {
|
|
|
1217
1181
|
|
|
1218
1182
|
uninstall_installed() {
|
|
1219
1183
|
while true; do
|
|
1220
|
-
|
|
1184
|
+
# End of input answers no.
|
|
1185
|
+
read -r -p "Do you wish to delete beplus CLI from ${BE_PREFIX}? " yn || yn="n"
|
|
1221
1186
|
case $yn in
|
|
1222
1187
|
[Yy]* ) break ;;
|
|
1223
1188
|
[Nn]* ) exit ;;
|
|
@@ -1432,8 +1397,6 @@ while [[ $# -ne 0 ]]; do
|
|
|
1432
1397
|
-q|--quiet) set_quiet ;;
|
|
1433
1398
|
-d|--download) DOWNLOAD="true" ;;
|
|
1434
1399
|
--insecure) set_insecure ;;
|
|
1435
|
-
--use-xz) BE_USE_XZ="true" ;;
|
|
1436
|
-
--no-use-xz) BE_USE_XZ="false" ;;
|
|
1437
1400
|
--latest) display_remote_versions latest; exit ;;
|
|
1438
1401
|
--stable) display_remote_versions latest; exit ;;
|
|
1439
1402
|
-a|--arch) shift; set_arch "$1";; # set arch and continue
|
|
@@ -1452,11 +1415,6 @@ while [[ $# -ne 0 ]]; do
|
|
|
1452
1415
|
shift
|
|
1453
1416
|
done
|
|
1454
1417
|
|
|
1455
|
-
if [[ -z "${BE_USE_XZ+defined}" ]]; then
|
|
1456
|
-
BE_USE_XZ="true" # Default to using xz
|
|
1457
|
-
can_use_xz || BE_USE_XZ="false"
|
|
1458
|
-
fi
|
|
1459
|
-
|
|
1460
1418
|
set -- "${unprocessed_args[@]}"
|
|
1461
1419
|
|
|
1462
1420
|
if test $# -eq 0; then
|
package/package.json
CHANGED