11#! /usr/bin/env bash
22set -euo pipefail
33
4- NPM_PKG=" @xberg-io/crawlberg-cli"
5- PYPI_PKG=" crawlberg-cli"
4+ # ~keep Rewritten by scripts/sync_plugin_version.py on every release. The plugin only accepts a
5+ # ~keep binary at or above this version, and downloads exactly this release, so a plugin update
6+ # ~keep cannot keep running an older crawlberg that happens to be installed.
7+ PINNED_VERSION=" 1.13.1"
68
79log () { printf ' crawlberg-launch: %s\n' " $* " >&2 ; }
810die () {
@@ -12,8 +14,8 @@ die() {
1214
1315LAUNCHER=" ${CRAWLBERG_LAUNCHER:- auto} "
1416case " $LAUNCHER " in
15- auto | npx | uvx | brew | download) ;;
16- * ) die " invalid CRAWLBERG_LAUNCHER='$LAUNCHER ' (expected auto|npx|uvx| brew|download)" ;;
17+ auto | brew | download) ;;
18+ * ) die " invalid CRAWLBERG_LAUNCHER='$LAUNCHER ' (expected auto|brew|download)" ;;
1719esac
1820
1921want () { [ " $LAUNCHER " = " auto" ] || [ " $LAUNCHER " = " $1 " ]; }
@@ -32,7 +34,21 @@ BIN="$BIN_DIR/$BINARY_NAME"
3234
3335have () { command -v " $1 " > /dev/null 2>&1 ; }
3436
35- runs_ok () { [ -x " $1 " ] && " $1 " --version > /dev/null 2>&1 ; }
37+ # True when $1 runs and reports a version at or above PINNED_VERSION. A prerelease of a version
38+ # sorts below that version (SemVer), so 1.13.1-rc.1 does not satisfy a 1.13.1 pin. ~keep
39+ runs_ok () {
40+ local out found base
41+ [ -x " $1 " ] || return 1
42+ out=" $( " $1 " --version 2> /dev/null) " || return 1
43+ found=" $( printf ' %s\n' " $out " | grep -Eo ' [0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?' | head -n 1) "
44+ [ -n " $found " ] || return 1
45+ base=" ${found%% -* } "
46+ if [ " $( printf ' %s\n%s\n' " $PINNED_VERSION " " $base " | sort -V | head -n 1) " != " $PINNED_VERSION " ] ||
47+ { [ " $base " = " $PINNED_VERSION " ] && [ " $found " != " $base " ]; }; then
48+ log " ignoring $1 : version $found is older than the pinned $PINNED_VERSION "
49+ return 1
50+ fi
51+ }
3652
3753if runs_ok " $BIN " ; then
3854 log " using cached crawlberg at $BIN "
@@ -46,28 +62,6 @@ if have "$BINARY_NAME"; then
4662 fi
4763fi
4864
49- if want npx && have npx; then
50- log " resolving npx $NPM_PKG @latest ..."
51- scratch=" $( mktemp -d) "
52- # Resolve in an empty project, then execute the selected binary in the caller's cwd. ~keep
53- if npm_bin=" $( cd " $scratch " && npx -y --package " $NPM_PKG @latest" --call " command -v ${BINARY_NAME% .exe} " 2> /dev/null) " && runs_ok " $npm_bin " ; then
54- rm -rf " $scratch "
55- log " launching npm package binary $npm_bin "
56- exec " $npm_bin " " $@ "
57- fi
58- rm -rf " $scratch "
59- log " npx $NPM_PKG not available (no CLI bin yet); falling through"
60- fi
61-
62- if want uvx && have uvx; then
63- log " probing uvx --from $PYPI_PKG $BINARY_NAME ..."
64- if uvx --from " $PYPI_PKG " " $BINARY_NAME " --version > /dev/null 2>&1 ; then
65- log " launching via uvx --from $PYPI_PKG $BINARY_NAME "
66- exec uvx --from " $PYPI_PKG " " $BINARY_NAME " " $@ "
67- fi
68- log " uvx $PYPI_PKG not available (no CLI entry point yet); falling through"
69- fi
70-
7165if want brew && have brew; then
7266 log " installing via 'brew install xberg-io/tap/crawlberg' ..."
7367 if brew install xberg-io/tap/crawlberg >&2 ; then
@@ -116,7 +110,7 @@ download_install() {
116110 * ) ext=" tar.gz" ;;
117111 esac
118112
119- base_url=" https://github.com/xberg-io/crawlberg/releases/latest/ download"
113+ base_url=" https://github.com/xberg-io/crawlberg/releases/download/v ${PINNED_VERSION} "
120114 asset=" crawlberg-cli-${triple} .${ext} "
121115 asset_url=" ${base_url} /${asset} "
122116
@@ -134,7 +128,7 @@ download_install() {
134128 trap " rm -rf '$tmp '" RETURN
135129
136130 log " warning: this download path does not verify release checksums; integrity relies on TLS only."
137- log " downloading $asset from latest release ..."
131+ log " downloading $asset from release v $PINNED_VERSION ..."
138132 if ! fetch " $asset_url " " $tmp /$asset " ; then
139133 log " download: fetch failed (asset missing or network error): $asset_url ; falling through"
140134 return 1
180174die " could not locate or install a crawlberg binary. Install one manually:
181175 brew install xberg-io/tap/crawlberg
182176 cargo install crawlberg-cli --features all
183- or download a release from https://github.com/xberg-io/crawlberg/releases/latest
177+ or download a release from https://github.com/xberg-io/crawlberg/releases/tag/v ${PINNED_VERSION}
184178then ensure 'crawlberg' is on PATH (or place it at $BIN )."
0 commit comments