tarcsweb 0.6.1 → 0.6.3
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/tarcsweb.js +3 -1
- package/get.sh +29 -4
- package/package.json +1 -1
package/bin/tarcsweb.js
CHANGED
|
@@ -17,7 +17,9 @@ if (process.platform === 'win32') {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const getSh = fileURLToPath(new URL('../get.sh', import.meta.url));
|
|
20
|
-
|
|
20
|
+
// npx exports npm_config_prefix, which makes nvm refuse to install Node, so the installer gets no npm_* variables.
|
|
21
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^npm_/i.test(key)));
|
|
22
|
+
const run = spawnSync('bash', [getSh, ...process.argv.slice(2)], { stdio: 'inherit', env });
|
|
21
23
|
if (run.error) {
|
|
22
24
|
console.error(run.error.code === 'ENOENT' ? 'tarcsweb needs bash to install' : run.error.message);
|
|
23
25
|
process.exit(1);
|
package/get.sh
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
# Installs or updates tarcsweb from a GitHub release, without git, on Linux or macOS. Safe to re-run; bash 3.2 compatible.
|
|
3
3
|
# curl -fsSL https://raw.githubusercontent.com/TLucas97/tarcsweb/main/get.sh | bash
|
|
4
4
|
# bash get.sh [version] [--yes] e.g. bash get.sh v0.1.1
|
|
5
|
-
# Env: TARCSWEB_HOME (install root), TARCSWEB_API (release API base),
|
|
5
|
+
# Env: TARCSWEB_HOME (install root), TARCSWEB_API (release API base), GITHUB_TOKEN (optional, raises the API rate limit),
|
|
6
|
+
# and install.sh's own (TARCSWEB_PORT, ...).
|
|
6
7
|
set -euo pipefail
|
|
7
8
|
|
|
8
9
|
REPO_SLUG="TLucas97/tarcsweb"
|
|
@@ -30,16 +31,40 @@ json_str() {
|
|
|
30
31
|
{ grep -o "\"$1\": *\"[^\"]*\"" || true; } | head -n 1 | sed 's/^"[^"]*": *"\(.*\)"$/\1/'
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
# curl for the GitHub API. A GITHUB_TOKEN goes only to api.github.com, through stdin so it stays out of the process list.
|
|
35
|
+
api_curl() {
|
|
36
|
+
if [ -n "${GITHUB_TOKEN:-}" ] && [ "$API" = https://api.github.com ]; then
|
|
37
|
+
printf 'header = "Authorization: Bearer %s"\n' "$GITHUB_TOKEN" | curl -K - "$@"
|
|
38
|
+
else
|
|
39
|
+
curl "$@"
|
|
40
|
+
fi
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
# The latest tag, read from where github.com/<repo>/releases/latest redirects; it has no API rate limit.
|
|
44
|
+
latest_tag_from_redirect() {
|
|
45
|
+
local location
|
|
46
|
+
location="$(curl -sI --max-time 30 "https://github.com/$REPO_SLUG/releases/latest" | tr -d '\r' | awk 'tolower($1) == "location:" { print $2; exit }')" || true
|
|
47
|
+
printf '%s' "${location##*/}"
|
|
48
|
+
}
|
|
49
|
+
|
|
33
50
|
# Prints the release JSON for "latest" or a tag.
|
|
34
51
|
fetch_release() {
|
|
35
|
-
local url out code
|
|
52
|
+
local url out code tag
|
|
36
53
|
if [ "$1" = latest ]; then url="$API/repos/$REPO_SLUG/releases/latest"; else url="$API/repos/$REPO_SLUG/releases/tags/$1"; fi
|
|
37
|
-
out="$(
|
|
54
|
+
out="$(api_curl -sSL --max-time 30 -H 'Accept: application/vnd.github+json' -w '\n%{http_code}' "$url")" || die "could not reach $API (are you offline?)"
|
|
38
55
|
code="${out##*$'\n'}"
|
|
39
56
|
case "$code" in
|
|
40
57
|
200) printf '%s' "${out%$'\n'*}" ;;
|
|
41
58
|
404) if [ "$1" = latest ]; then die "$REPO_SLUG has no published release yet"; else die "release $1 not found in $REPO_SLUG"; fi ;;
|
|
42
|
-
403 | 429)
|
|
59
|
+
403 | 429)
|
|
60
|
+
# Only the tag is needed; main falls back to the archive URL for the tarball.
|
|
61
|
+
if [ "$API" = https://api.github.com ]; then
|
|
62
|
+
echo "GitHub's API rate limit was reached; reading the release from github.com instead (set GITHUB_TOKEN to raise the limit)" >&2
|
|
63
|
+
if [ "$1" = latest ]; then tag="$(latest_tag_from_redirect)"; else tag="$1"; fi
|
|
64
|
+
if [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then printf '{"tag_name": "%s"}' "$tag"; return 0; fi
|
|
65
|
+
fi
|
|
66
|
+
die "GitHub's API rate limit was reached; try again in an hour, or set GITHUB_TOKEN"
|
|
67
|
+
;;
|
|
43
68
|
*) die "GitHub's API answered HTTP $code for $url" ;;
|
|
44
69
|
esac
|
|
45
70
|
}
|